aboutsummaryrefslogtreecommitdiff
path: root/test/list.c
blob: 8c095d6c755a4e9beb035b07afc52391c9068d35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#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;

  struct imv_list *list;

  list = imv_split_string("word", ' ');
  assert_true(list);
  assert_true(list->len == 1);
  assert_false(strcmp(list->items[0], "word"));
  imv_list_deep_free(list);

  list = imv_split_string("hello world this is a test", ' ');
  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"));
  imv_list_deep_free(list);

  list = imv_split_string("  odd  whitespace test  ", ' ');
  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"));
  imv_list_deep_free(list);
}

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: */