diff options
author | axtloss <axtlos@getcryst.al> | 2024-09-27 12:11:52 +0200 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2024-09-27 12:11:52 +0200 |
commit | 7aa261f8d57cb53cc334f6bf1920a6f8517ff054 (patch) | |
tree | f23a96feda17de737c71b45dc94e7e044410ad35 /tests/test_trim.c | |
parent | 27bb394bc0bf2ca66d06931bf1e73a3e20d5741a (diff) | |
download | extlib-7aa261f8d57cb53cc334f6bf1920a6f8517ff054.tar.gz extlib-7aa261f8d57cb53cc334f6bf1920a6f8517ff054.tar.bz2 |
Rework test suite to be more modular
Diffstat (limited to 'tests/test_trim.c')
-rw-r--r-- | tests/test_trim.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_trim.c b/tests/test_trim.c new file mode 100644 index 0000000..f0aeed6 --- /dev/null +++ b/tests/test_trim.c @@ -0,0 +1,35 @@ +#include <string.h> +#define USE_SECURE_MEM +#include "../src/extlib.h" +#undef free + +int +test_trim () +{ + int errno = 0; + char *test_string = strdup ("\t\thi\t\t"); + int rem_front = 0; + int rem_back = 0; + char *trimmed_string = trim (test_string, &rem_front, &rem_back); + if (strstr (trimmed_string, "\t") != NULL) + { + errno = 1; + } + else if (rem_front != 2 && rem_back != 2) + { + errno = 2; + } + + free (trimmed_string - rem_front); + free_secure ((void **) &test_string, strlen (test_string)); + return errno; +} + +struct test_t* +test_trim_t () +{ + struct test_t *test = malloc (sizeof (struct test_t)); + test->test_func = test_trim; + test->test_name = "test_trim"; + test->test_desc = "trim"; +} |