2023-02-11 15:06:47 +01:00
|
|
|
#include <assert.h>
|
2023-02-11 14:17:02 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2023-02-11 15:06:47 +01:00
|
|
|
#include <string.h>
|
2023-02-11 14:17:02 +01:00
|
|
|
|
2023-02-11 15:06:47 +01:00
|
|
|
#include "cstr.h"
|
2023-02-11 14:17:02 +01:00
|
|
|
#define CUTILS_DEBUG_TRACE
|
|
|
|
#include "debug.h"
|
|
|
|
#include "log.h"
|
2023-02-11 16:25:24 +01:00
|
|
|
#include "test.h"
|
2023-02-11 14:17:02 +01:00
|
|
|
|
2023-02-11 16:25:24 +01:00
|
|
|
test_results_t
|
|
|
|
test_cstr (void)
|
2023-02-11 14:17:02 +01:00
|
|
|
{
|
2023-02-12 17:27:48 +01:00
|
|
|
test_group_t group;
|
2023-02-11 15:06:47 +01:00
|
|
|
size_t len;
|
2023-02-11 14:17:02 +01:00
|
|
|
|
2023-02-12 17:27:48 +01:00
|
|
|
group = test_group_new ();
|
2023-02-11 14:17:02 +01:00
|
|
|
|
2023-02-11 15:06:47 +01:00
|
|
|
char s[] = " Hello, World!\n ";
|
|
|
|
len = strtrimr (s);
|
2023-02-12 17:27:48 +01:00
|
|
|
test_add (&group, test_assert (len == 17), "strtrimr return value");
|
|
|
|
test_add (&group, test_assert (strlen (s) == 17), "strtrimr length");
|
2023-02-11 15:06:47 +01:00
|
|
|
char *sn = strtriml (s);
|
2023-02-12 17:27:48 +01:00
|
|
|
test_add (&group, test_assert (sn == s + 4), "strtriml pointer");
|
|
|
|
test_add (&group, test_assert (strlen (sn) == 13), "strtriml length");
|
2023-02-11 15:06:47 +01:00
|
|
|
char s2[] = " Hello, World!\n ";
|
|
|
|
sn = strtrim (s2);
|
2023-02-12 17:27:48 +01:00
|
|
|
test_add (&group, test_assert (sn == s2 + 4), "strtrim pointer");
|
|
|
|
test_add (&group, test_assert (strlen (s2) == 17), "strtrim original pointer length");
|
|
|
|
test_add (&group, test_assert (strlen (sn) == 13), "strtrim new pointer length");
|
2023-02-12 16:53:02 +01:00
|
|
|
|
|
|
|
char *s3 = "Hello, World!\n";
|
2023-02-12 17:27:48 +01:00
|
|
|
test_add (&group, test_assert (strcount (s3, 'l') == 3), "strcount multiple occurances");
|
|
|
|
test_add (&group, test_assert (strcount (s3, '\n') == 1), "strcount one occurance");
|
|
|
|
test_add (&group, test_assert (strcount (s3, 'X') == 0), "strcount no occurance");
|
2023-02-12 17:00:07 +01:00
|
|
|
|
|
|
|
char s4[] = "Hello, World!\n";
|
|
|
|
char s5[] = "Hello, World!\n";
|
|
|
|
strdowncase (s4);
|
|
|
|
strupcase (s5);
|
2023-02-12 17:27:48 +01:00
|
|
|
test_add (&group, test_assert (!strcmp (s4, "hello, world!\n")), "strdowncase");
|
|
|
|
test_add (&group, test_assert (!strcmp (s5, "HELLO, WORLD!\n")), "strupcase");
|
2023-02-11 16:25:24 +01:00
|
|
|
|
2023-02-12 17:34:54 +01:00
|
|
|
char *s6 = " x ";
|
|
|
|
char *s7 = " \r\n\t\v\f";
|
|
|
|
test_add (&group, test_assert (!strisblank (s6)), "strisblank false");
|
|
|
|
test_add (&group, test_assert (strisblank (s7)), "strisblank true");
|
|
|
|
|
2023-02-12 17:27:48 +01:00
|
|
|
return test_group_get_results (&group);
|
2023-02-11 16:25:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2023-02-12 17:27:48 +01:00
|
|
|
test_suite_t suite;
|
2023-02-11 16:25:24 +01:00
|
|
|
|
2023-02-12 17:27:48 +01:00
|
|
|
suite = test_suite_new ();
|
|
|
|
test_suite_add (&suite, test_cstr);
|
|
|
|
test_suite_run (&suite);
|
|
|
|
test_suite_free (&suite);
|
2023-02-11 15:06:47 +01:00
|
|
|
|
2023-02-11 14:17:02 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|