diff --git a/c_pointers/getline_test.c b/c_pointers/getline_test.c new file mode 100644 index 0000000..34fed55 --- /dev/null +++ b/c_pointers/getline_test.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include "minunit.h" +#include "getline.h" + + +#define STRING_LENGTH 14 + + + +int tests_run = 0; + + +// unit test function for trim() +static char *test_trim() { + + char *foo = malloc(STRING_LENGTH + 1 * sizeof(*foo)); + int wurst = snprintf(foo, STRING_LENGTH + 1, "%s", " hallo welt"); + + assertf(wurst <= STRING_LENGTH, "buffer overflow"); + + mu_assert("error", !(strcmp(trim(foo), "hallo welt"))); + + return 0; + +} + + +// function to run all tests +static char *all_tests() { + + mu_run_test(test_trim); + + return 0; + +} + + +int main(void) { + + char *result = all_tests(); + + if (result != 0) { + printf("%s\n", result); + } else { + printf("ALL TESTS PASSED\n"); + } + + printf("Tests run: %d\n", tests_run); + + return result != 0; +} \ No newline at end of file