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-11 16:25:24 +01:00
|
|
|
test_suite_t suite;
|
2023-02-11 15:06:47 +01:00
|
|
|
size_t len;
|
2023-02-11 14:17:02 +01:00
|
|
|
|
2023-02-11 16:25:24 +01:00
|
|
|
suite = test_suite_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-11 16:25:24 +01:00
|
|
|
test_add (&suite, test_assert_op (len, ==, 17), "strtrimr return value");
|
|
|
|
test_add (&suite, test_assert_op (strlen (s), ==, 17), "strtrimr length");
|
2023-02-11 15:06:47 +01:00
|
|
|
char *sn = strtriml (s);
|
2023-02-11 16:25:24 +01:00
|
|
|
test_add (&suite, test_assert_op (sn, ==, s + 4), "strtriml pointer");
|
|
|
|
test_add (&suite, test_assert_op (strlen (sn), ==, 13), "strtriml length");
|
2023-02-11 15:06:47 +01:00
|
|
|
char s2[] = " Hello, World!\n ";
|
|
|
|
sn = strtrim (s2);
|
2023-02-11 16:25:24 +01:00
|
|
|
test_add (&suite, test_assert_op (sn, ==, s2 + 4), "strtrim pointer");
|
|
|
|
test_add (&suite, test_assert_op (strlen (s2), ==, 17), "strtrim original pointer length");
|
|
|
|
test_add (&suite, test_assert_op (strlen (sn), ==, 13), "strtrim new pointer length");
|
2023-02-12 16:53:02 +01:00
|
|
|
|
|
|
|
char *s3 = "Hello, World!\n";
|
|
|
|
test_add (&suite, test_assert_op (strcount (s3, 'l'), ==, 3), "strcount multiple occurances");
|
|
|
|
test_add (&suite, test_assert_op (strcount (s3, '\n'), ==, 1), "strcount one occurance");
|
|
|
|
test_add (&suite, test_assert_op (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);
|
|
|
|
test_add (&suite, test_assert (!strcmp (s4, "hello, world!\n")), "strdowncase");
|
|
|
|
test_add (&suite, test_assert (!strcmp (s5, "HELLO, WORLD!\n")), "strupcase");
|
2023-02-11 16:25:24 +01:00
|
|
|
|
|
|
|
return test_suite_get_results (&suite);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
|
|
|
test_group_t group;
|
|
|
|
|
|
|
|
group = test_group_new ();
|
|
|
|
test_group_add (&group, test_cstr);
|
|
|
|
test_group_run (&group);
|
|
|
|
test_group_free (&group);
|
2023-02-11 15:06:47 +01:00
|
|
|
|
2023-02-11 14:17:02 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|