diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-09-11 20:22:24 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-09-11 20:22:24 -0400 |
commit | 1251aa55b97b3b4ca7c2c670bdbd683a76eb6daa (patch) | |
tree | 9c3f6d9638046dbbeacd284cf5a70b5d7f901f75 /tests.c | |
parent | e697056101dcd1461eee2bde3e169e4d7ddaec20 (diff) | |
download | multihome-1251aa55b97b3b4ca7c2c670bdbd683a76eb6daa.tar.gz |
Refactor headers and relocate tests
Diffstat (limited to 'tests.c')
-rw-r--r-- | tests.c | 77 |
1 files changed, 77 insertions, 0 deletions
@@ -0,0 +1,77 @@ +#include "multihome.h" + +#ifdef ENABLE_TESTING +void test_split() { + puts("split()"); + char **result; + size_t result_alloc; + + result = split("one two three", " ", &result_alloc); + assert(strcmp(result[0], "one") == 0 && strcmp(result[1], "two") == 0 && strcmp(result[2], "three") == 0); + assert(result_alloc != 0); + free_array((void *)result, result_alloc); +} + +void test_count_substrings() { + puts("count_substrings()"); + size_t result; + result = count_substrings("one two three", " "); + assert(result == 2); +} + +void test_mkdirs() { + puts("mkdirs()"); + int result; + char *input = "this/is/a/test"; + + if (access(input, F_OK) == 0) { + assert(remove("this/is/a/test") == 0); + assert(remove("this/is/a") == 0); + assert(remove("this/is") == 0); + assert(remove("this") == 0); + } + + result = mkdirs(input); + assert(result == 0); + assert(access(input, F_OK) == 0); +} + +void test_shell() { + puts("shell()"); + assert(shell((char *[]){"/bin/echo", "testing", NULL}) == 0); + assert(shell((char *[]){"/bin/date", NULL}) == 0); + assert(shell((char *[]){"/bin/unlikelyToExistAnywhere", NULL}) != 0); +} + +void test_touch() { + puts("touch()"); + char *input = "touched_file.txt"; + + if (access(input, F_OK) == 0) { + remove(input); + } + + assert(touch(input) == 0); + assert(access(input, F_OK) == 0); +} + +void test_strip_domainname() { + puts("strip_domainname()"); + char *input = "subdomain.domain.tld"; + char *truth = "subdomain"; + char *result; + + result = strip_domainname(input); + assert(strcmp(result, truth) == 0); +} + +void test_main() { + test_count_substrings(); + test_split(); + test_mkdirs(); + test_shell(); + test_touch(); + test_strip_domainname(); + exit(0); +} +#endif |