| 1 |
|
| 2 |
|
| 3 |
#include <libpayload.h> |
| 4 |
#include <tests/test.h> |
| 5 |
|
| 6 |
static void test_strsep(void **state) |
| 7 |
{ |
| 8 |
|
| 9 |
char test1[] = "abc,def|ghi jklm,\no"; |
| 10 |
const char *delim = ", \n"; |
| 11 |
|
| 12 |
char *stringp = test1; |
| 13 |
assert_string_equal(strsep(&stringp, delim), "abc"); |
| 14 |
assert_ptr_equal(stringp, test1 + 4); |
| 15 |
assert_string_equal(strsep(&stringp, delim), "def|ghi"); |
| 16 |
assert_ptr_equal(stringp, test1 + 12); |
| 17 |
assert_string_equal(strsep(&stringp, delim), "jklm"); |
| 18 |
assert_ptr_equal(stringp, test1 + 17); |
| 19 |
assert_string_equal(strsep(&stringp, delim), ""); |
| 20 |
assert_ptr_equal(stringp, test1 + 18); |
| 21 |
assert_string_equal(strsep(&stringp, delim), "o"); |
| 22 |
assert_null(stringp); |
| 23 |
assert_null(strsep(&stringp, delim)); |
| 24 |
assert_null(stringp); |
| 25 |
|
| 26 |
char test2[] = ""; |
| 27 |
stringp = test2; |
| 28 |
assert_string_equal(strsep(&stringp, delim), ""); |
| 29 |
assert_null(strsep(&stringp, delim)); |
| 30 |
} |
| 31 |
|
| 32 |
int main(void) |
| 33 |
{ |
| 34 |
const struct CMUnitTest tests[] = { |
| 35 |
cmocka_unit_test(test_strsep), |
| 36 |
}; |
| 37 |
|
| 38 |
return lp_run_group_tests(tests, NULL, NULL); |
| 39 |
} |