changed tests from prints to asserts, callable from meson
Msrc/meson.build
| @@ -5,4 +5,5 @@ cutils_lib = library('cutils', src, include_directories : inc, install: true) | |||
|---|---|---|---|
| 5 | 5 | ||
| 6 | 6 | cutils_dep = declare_dependency(link_with : cutils_lib, include_directories : inc) | |
| 7 | 7 | ||
| 8 | - | executable('test_cutils', srctest, include_directories : inc, c_args: CFLAGS ) | |
| 8 | + | e = executable('test_cutils', srctest, include_directories : inc, c_args: CFLAGS ) | |
| 9 | + | test('test functionality', e) | |
Msrc/test.c
| @@ -1,5 +1,6 @@ | |||
|---|---|---|---|
| 1 | 1 | #include <cutils/cutils.h> | |
| 2 | 2 | #include <stdio.h> | |
| 3 | + | #include <assert.h> | |
| 3 | 4 | ||
| 4 | 5 | struct test | |
| 5 | 6 | { | |
| @@ -36,28 +37,29 @@ static void test1(void) | |||
|---|---|---|---|
| 36 | 37 | my_struct->a = 7; | |
| 37 | 38 | my_struct->b = 7; | |
| 38 | 39 | vector_push(test, my_struct); | |
| 39 | - | printf("%ld\n", test->length); | |
| 40 | + | assert(test->length == 3); | |
| 40 | 41 | ||
| 41 | 42 | vector_remove(test, 0,free); | |
| 42 | - | printf("%ld\n", test->length); | |
| 43 | + | assert(test->length == 2); | |
| 43 | 44 | ||
| 44 | 45 | my_struct = malloc(sizeof(*my_struct)); | |
| 45 | 46 | my_struct->a = 8; | |
| 46 | 47 | my_struct->b = 8; | |
| 47 | 48 | vector_insert(test, 2, my_struct); | |
| 48 | - | printf("%ld\n", test->length); | |
| 49 | + | assert(test->length == 3); | |
| 49 | 50 | ||
| 50 | 51 | my_struct = malloc(sizeof(*my_struct)); | |
| 51 | 52 | my_struct->a = 8; | |
| 52 | 53 | my_struct->b = 8; | |
| 53 | 54 | ||
| 54 | 55 | find = vector_find(test, my_struct, cmp_str); | |
| 55 | - | printf("pos: %lu\n", *find); | |
| 56 | + | ||
| 57 | + | assert(*find == 2); | |
| 56 | 58 | free(find); | |
| 57 | 59 | ||
| 58 | 60 | free(my_struct); | |
| 59 | 61 | my_struct = vector_pop(test); | |
| 60 | - | printf("struct a: %d, b: %d\n", my_struct->a, my_struct->b); | |
| 62 | + | assert(my_struct->a == 8 && my_struct->b == 8); | |
| 61 | 63 | free(my_struct); | |
| 62 | 64 | ||
| 63 | 65 | delete_vector(test,free); | |
| @@ -75,28 +77,28 @@ static void test2(void) | |||
|---|---|---|---|
| 75 | 77 | string_push(test, 'b'); | |
| 76 | 78 | string_push(test, 'c'); | |
| 77 | 79 | string_push(test, 'd'); | |
| 78 | - | printf("%ld\n", test->length); | |
| 80 | + | assert(test->length == 4); | |
| 79 | 81 | ||
| 80 | 82 | cstring = to_cstring(test); | |
| 81 | - | printf("%s\n", cstring); | |
| 83 | + | assert(strcmp(cstring, "abcd") == 0); | |
| 82 | 84 | free(cstring); | |
| 83 | 85 | ||
| 84 | 86 | string_remove(test, 3); | |
| 85 | 87 | cstring = to_cstring(test); | |
| 86 | - | printf("%s\n", cstring); | |
| 88 | + | assert(strcmp(cstring, "abc") == 0); | |
| 87 | 89 | free(cstring); | |
| 88 | - | printf("%ld\n", test->length); | |
| 90 | + | assert(test->length == 3); | |
| 89 | 91 | ||
| 90 | 92 | string_insert(test, 0,'a'); | |
| 91 | 93 | cstring = to_cstring(test); | |
| 92 | - | printf("%s\n", cstring); | |
| 94 | + | assert(strcmp(cstring, "aabc") == 0); | |
| 93 | 95 | free(cstring); | |
| 94 | 96 | ||
| 95 | 97 | test2 = from_cstring("xyz"); | |
| 96 | 98 | ||
| 97 | 99 | string_concat(test,test2); | |
| 98 | 100 | cstring = to_cstring(test); | |
| 99 | - | printf("%s\n", cstring); | |
| 101 | + | assert(strcmp(cstring, "aabcxyz") == 0); | |
| 100 | 102 | free(cstring); | |
| 101 | 103 | ||
| 102 | 104 | delete_string(test2); | |