2017-04-12 22:20:34 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "list.h"
|
|
|
|
|
|
|
|
static void test_split_string(void **state)
|
|
|
|
{
|
|
|
|
(void)state;
|
|
|
|
|
2017-11-21 22:51:54 +01:00
|
|
|
struct list *list;
|
2017-04-12 22:20:34 +02:00
|
|
|
|
2017-11-21 22:51:54 +01:00
|
|
|
list = list_from_string("word", ' ');
|
2017-04-12 22:20:34 +02:00
|
|
|
assert_true(list);
|
|
|
|
assert_true(list->len == 1);
|
|
|
|
assert_false(strcmp(list->items[0], "word"));
|
2017-11-21 22:51:54 +01:00
|
|
|
list_deep_free(list);
|
2017-04-12 22:20:34 +02:00
|
|
|
|
2017-11-21 22:51:54 +01:00
|
|
|
list = list_from_string("hello world this is a test", ' ');
|
2017-04-12 22:20:34 +02:00
|
|
|
assert_true(list);
|
|
|
|
assert_true(list->len == 6);
|
|
|
|
assert_false(strcmp(list->items[0], "hello"));
|
|
|
|
assert_false(strcmp(list->items[1], "world"));
|
|
|
|
assert_false(strcmp(list->items[2], "this"));
|
|
|
|
assert_false(strcmp(list->items[3], "is"));
|
|
|
|
assert_false(strcmp(list->items[4], "a"));
|
|
|
|
assert_false(strcmp(list->items[5], "test"));
|
2017-11-21 22:51:54 +01:00
|
|
|
list_deep_free(list);
|
2017-04-12 22:20:34 +02:00
|
|
|
|
2017-11-21 22:51:54 +01:00
|
|
|
list = list_from_string(" odd whitespace test ", ' ');
|
2017-04-12 22:20:34 +02:00
|
|
|
assert_true(list);
|
|
|
|
assert_true(list->len == 3);
|
|
|
|
assert_false(strcmp(list->items[0], "odd"));
|
|
|
|
assert_false(strcmp(list->items[1], "whitespace"));
|
|
|
|
assert_false(strcmp(list->items[2], "test"));
|
2017-11-21 22:51:54 +01:00
|
|
|
list_deep_free(list);
|
2017-04-12 22:20:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test(test_split_string),
|
|
|
|
};
|
|
|
|
|
|
|
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vim:set ts=2 sts=2 sw=2 et: */
|