test_datastructures.c 14.2 KB
Newer Older
1
/* See LICENSE file for license and copyright information */
2

Moritz Lipp's avatar
Moritz Lipp committed
3
#include <check.h>
4
#include <glib.h>
Sebastian Ramacher's avatar
Sebastian Ramacher committed
5
#include <stdint.h>
6
#include <datastructures.h>
7

8 9
#include "tests.h"

10
static unsigned int list_free_called = 0;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
11
static unsigned int node_free_called = 0;
12 13 14 15

static void
list_free(void* data)
{
Sebastian Ramacher's avatar
Sebastian Ramacher committed
16 17
  fail_unless(list_free_called == 0u, NULL);
  fail_unless((intptr_t) data == 0xDEAD, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
18

19 20 21
  ++list_free_called;
}

Moritz Lipp's avatar
Moritz Lipp committed
22 23 24
START_TEST(test_datastructures_list) {
  girara_list_t* list = girara_list_new();
  // size of empty list
Sebastian Ramacher's avatar
Sebastian Ramacher committed
25
  fail_unless(girara_list_size(list) == 0, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
26 27 28 29 30 31 32

  // append
  for (intptr_t i = 0; i != 10; ++i) {
    girara_list_append(list, (void*)i);
  }

  // size of list
Sebastian Ramacher's avatar
Sebastian Ramacher committed
33
  fail_unless(girara_list_size(list) == 10, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
34 35 36

  // iterator tests
  girara_list_iterator_t* iter = girara_list_iterator(list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
37
  fail_unless(iter != NULL, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
38 39

  for (intptr_t i = 0; i != 10; ++i) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
40
    fail_unless(((intptr_t) girara_list_iterator_data(iter) == i), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
41
    if (i < 9) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
42 43 44 45
      fail_unless((girara_list_iterator_is_valid(iter)), NULL);
      fail_unless((girara_list_iterator_has_next(iter)), NULL);
      fail_unless((girara_list_iterator_next(iter) != NULL), NULL);
      fail_unless((girara_list_iterator_is_valid(iter)), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
46
    } else {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
47 48 49 50
      fail_unless((girara_list_iterator_is_valid(iter)), NULL);
      fail_unless((!girara_list_iterator_has_next(iter)), NULL);
      fail_unless((girara_list_iterator_next(iter) == NULL), NULL);
      fail_unless((!girara_list_iterator_is_valid(iter)), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
51 52 53 54 55 56 57 58 59
    }
  }

  girara_list_iterator_free(iter);
  girara_list_free(list);

  // contains
  list = girara_list_new();
  for (intptr_t i = 0; i != 10; ++i) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
60
    fail_unless((girara_list_contains(list, (void*) i) == false), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
61
    girara_list_append(list, (void*)i);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
62
    fail_unless((girara_list_contains(list, (void*) i) == true), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
63 64 65 66
  }

  // position
  for (intptr_t i = 0; i != 10; ++i) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
67
    fail_unless((girara_list_position(list, (void*) i) == i), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
68
  }
Sebastian Ramacher's avatar
Sebastian Ramacher committed
69
  fail_unless((girara_list_position(list, (void*) 10) == -1), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
70 71 72

  // remove
  for (intptr_t i = 9; i >= 0; --i) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
73
    fail_unless((girara_list_contains(list, (void*) i) == true), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
74
    girara_list_remove(list, (void*)i);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
75
    fail_unless((girara_list_contains(list, (void*)i) == false), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
76 77 78 79
    girara_list_append(list, (void*)i);
  }

  iter = girara_list_iterator(list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
80
  fail_unless((iter != NULL), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
81 82

  for (intptr_t i = 9; i >= 0; --i) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
83
    fail_unless(((intptr_t)girara_list_iterator_data(iter) == i), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
84
    if (i > 0) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
85 86 87 88
      fail_unless((girara_list_iterator_is_valid(iter)), NULL);
      fail_unless((girara_list_iterator_has_next(iter)), NULL);
      fail_unless((girara_list_iterator_next(iter) != NULL), NULL);
      fail_unless((girara_list_iterator_is_valid(iter)), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
89
    } else {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
90 91 92 93
      fail_unless((girara_list_iterator_is_valid(iter)), NULL);
      fail_unless((!girara_list_iterator_has_next(iter)), NULL);
      fail_unless((girara_list_iterator_next(iter) == NULL), NULL);
      fail_unless((!girara_list_iterator_is_valid(iter)), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
94 95 96 97 98 99 100
    }
  }

  girara_list_iterator_free(iter);
  girara_list_free(list);
} END_TEST

101 102 103
START_TEST(test_datastructures_list_merge) {
  girara_list_t* list1 = girara_list_new();
  girara_list_t* list2 = girara_list_new();
Sebastian Ramacher's avatar
Sebastian Ramacher committed
104 105
  fail_unless((list1 != NULL), NULL);
  fail_unless((list2 != NULL), NULL);
106

Sebastian Ramacher's avatar
Sebastian Ramacher committed
107 108 109
  fail_unless((girara_list_merge(NULL, NULL) == NULL), NULL);
  fail_unless((girara_list_merge(list1, NULL) == list1), NULL);
  fail_unless((girara_list_merge(NULL, list2) == list2), NULL);
110 111 112 113 114

  girara_list_append(list1, (void*)0);
  girara_list_append(list2, (void*)1);

  girara_list_t* list3 = girara_list_merge(list1, list2);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
115 116 117
  fail_unless((list3 == list1), NULL);
  fail_unless((girara_list_nth(list3, 0) == (void*)0), NULL);
  fail_unless((girara_list_nth(list3, 1) == (void*)1), NULL);
118 119 120
  girara_list_free(list1);
  girara_list_free(list2);
} END_TEST
Moritz Lipp's avatar
Moritz Lipp committed
121

Sebastian Ramacher's avatar
Sebastian Ramacher committed
122
START_TEST(test_datastructures_list_free_empty) {
123
  // free empty list
Moritz Lipp's avatar
Moritz Lipp committed
124
  girara_list_t* list = girara_list_new();
Sebastian Ramacher's avatar
Sebastian Ramacher committed
125
  fail_unless((list != NULL), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
126 127 128
  girara_list_free(list);

  list = girara_list_new2(NULL);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
129
  fail_unless((list != NULL), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
130 131
  girara_list_free(list);

Sebastian Ramacher's avatar
Sebastian Ramacher committed
132
  list = girara_list_new2(g_free);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
133
  fail_unless((list != NULL), NULL);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
134
  girara_list_free(list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
135
} END_TEST
Sebastian Ramacher's avatar
Sebastian Ramacher committed
136

Sebastian Ramacher's avatar
Sebastian Ramacher committed
137
START_TEST(test_datastructures_list_free_already_cleared) {
138
  // free cleared list
Sebastian Ramacher's avatar
Sebastian Ramacher committed
139
  girara_list_t* list = girara_list_new();
Sebastian Ramacher's avatar
Sebastian Ramacher committed
140
  fail_unless((list != NULL), NULL);
141
  girara_list_append(list, (void*) 0xDEAD);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
142
  fail_unless((girara_list_size(list) == 1), NULL);
143
  girara_list_clear(list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
144
  fail_unless((girara_list_size(list) == 0), NULL);
145
  girara_list_free(list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
146
} END_TEST
147

Sebastian Ramacher's avatar
Sebastian Ramacher committed
148
START_TEST(test_datastructures_list_free_free_function) {
149
  // free function
Sebastian Ramacher's avatar
Sebastian Ramacher committed
150 151
  girara_list_t* list = girara_list_new();
  list_free_called = 0;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
152
  fail_unless((list != NULL), NULL);
153 154 155
  girara_list_set_free_function(list, list_free);
  girara_list_append(list, (void*) 0xDEAD);
  girara_list_free(list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
156
  fail_unless((list_free_called == 1), NULL);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
157
} END_TEST
158

Sebastian Ramacher's avatar
Sebastian Ramacher committed
159
START_TEST(test_datastructures_list_free_free_function_remove) {
Moritz Lipp's avatar
Moritz Lipp committed
160 161
  // remove with free function
  list_free_called = 0;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
162
  girara_list_t* list = girara_list_new2(list_free);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
163
  fail_unless((list != NULL), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
164 165
  girara_list_append(list, (void*)0xDEAD);
  girara_list_remove(list, (void*)0xDEAD);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
166
  fail_unless((girara_list_size(list) == 0), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
167
  girara_list_free(list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
168
  fail_unless((list_free_called == 1), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
169 170
} END_TEST

Sebastian Ramacher's avatar
Sebastian Ramacher committed
171
START_TEST(test_datastructures_sorted_list_basic) {
Moritz Lipp's avatar
Moritz Lipp committed
172
  girara_list_t* list = girara_sorted_list_new(NULL);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
173
  fail_unless((list != NULL), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
174
  girara_list_free(list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
175
} END_TEST
Moritz Lipp's avatar
Moritz Lipp committed
176

Sebastian Ramacher's avatar
Sebastian Ramacher committed
177 178
START_TEST(test_datastructures_sorted_list) {
  girara_list_t* list = girara_sorted_list_new2((girara_compare_function_t) g_strcmp0,
Moritz Lipp's avatar
Moritz Lipp committed
179
      (girara_free_function_t) g_free);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
180
  fail_unless((list != NULL), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
181
  girara_list_t* unsorted_list = girara_list_new2((girara_free_function_t) g_free);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
182
  fail_unless((unsorted_list != NULL), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208

  static const char* test_strings[] = {
    "A",
    "C",
    "Baa",
    "Za",
    "Bba",
    "Bab",
    NULL
  };
  static const char* test_strings_sorted[] = {
    "A",
    "Baa",
    "Bab",
    "Bba",
    "C",
    "Za",
    NULL
  };

  // append
  for (const char** p = test_strings; *p != NULL; ++p) {
    girara_list_append(list, (void*)g_strdup(*p));
    girara_list_append(unsorted_list, (void*)g_strdup(*p));
  }

Sebastian Ramacher's avatar
Sebastian Ramacher committed
209 210
  fail_unless((girara_list_size(list) == sizeof(test_strings) / sizeof(char*) - 1), NULL);
  fail_unless((girara_list_size(unsorted_list) == sizeof(test_strings) / sizeof(char*) - 1), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
211 212 213 214

  // check sorting
  const char** p = test_strings_sorted;
  GIRARA_LIST_FOREACH(list, const char*, iter, value)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
215
    fail_unless((g_strcmp0(value, *p) == 0), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
216 217 218 219 220 221
    ++p;
  GIRARA_LIST_FOREACH_END(list, const char*, iter, value);

  girara_list_sort(unsorted_list, (girara_compare_function_t) g_strcmp0);
  p = test_strings_sorted;
  GIRARA_LIST_FOREACH(unsorted_list, const char*, iter, value)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
222
    fail_unless((g_strcmp0(value, *p) == 0), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
223 224 225 226 227 228 229
    ++p;
  GIRARA_LIST_FOREACH_END(unsorted_list, const char*, iter, value);

  girara_list_free(list);
  girara_list_free(unsorted_list);
} END_TEST

230 231 232 233 234 235 236 237 238 239 240
START_TEST(test_datastructures_list_iterator_remove) {
  girara_list_t* list = girara_list_new();
  for (intptr_t i = 0; i != 10; ++i) {
    girara_list_append(list, (void*)i);
  }
  fail_unless(girara_list_size(list) == 10);

  intptr_t next = 0;
  GIRARA_LIST_FOREACH(list, intptr_t, iter, data)
    fail_unless(next++ == data);
    if (data == 5) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
241
      /* this is broken … this will cause an invalid read */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
242
      girara_list_remove(list, (void*) data);
243 244 245 246 247 248 249 250 251 252 253
    }
  GIRARA_LIST_FOREACH_END(list, intptr_t, iter, data);

  for (intptr_t s = 0; s != 5; ++s) {
    fail_unless((intptr_t)girara_list_nth(list, s) == s);
  }
  for (intptr_t s = 5; s != 9; ++s) {
    fail_unless((intptr_t)girara_list_nth(list, s) == s + 1);
  }
} END_TEST

Moritz Lipp's avatar
Moritz Lipp committed
254 255 256 257
static void
node_free(void* data)
{
  if (g_strcmp0((char*)data, "root") == 0) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
258
    fail_unless((node_free_called == 0), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
259
  } else if (g_strcmp0((char*)data, "child") == 0) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
260
    fail_unless((node_free_called == 1), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
261 262 263 264 265 266 267 268 269
  } else {
    fail("Should not be reached");
  }

  ++node_free_called;
}

START_TEST(test_datastructures_node) {
  girara_tree_node_t* root = girara_node_new("root");
Sebastian Ramacher's avatar
Sebastian Ramacher committed
270 271 272 273
  fail_unless((girara_node_get_num_children(root) == 0), NULL);
  fail_unless((girara_node_get_parent(root) == NULL), NULL);
  fail_unless((girara_node_get_root(root) == root), NULL);
  fail_unless((g_strcmp0((char*) girara_node_get_data(root), "root") == 0), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
274
  girara_list_t* rchildren = girara_node_get_children(root);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
275 276
  fail_unless((rchildren != NULL), NULL);
  fail_unless((girara_list_size(rchildren) == 0), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
277 278 279 280 281 282
  girara_list_free(rchildren);
  girara_node_free(root);

  root = girara_node_new("root");
  girara_node_set_free_function(root, node_free);
  girara_node_append_data(root, "child");
Sebastian Ramacher's avatar
Sebastian Ramacher committed
283 284
  fail_unless((girara_node_get_num_children(root) == 1), NULL);
  fail_unless((node_free_called == 0), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
285
  girara_node_free(root);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
286
  fail_unless((node_free_called == 2), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
287 288 289 290 291

  node_free_called = 0;
  root = girara_node_new("root");
  girara_node_set_free_function(root, node_free);
  girara_node_set_data(root, "child");
Sebastian Ramacher's avatar
Sebastian Ramacher committed
292
  fail_unless((node_free_called == 1), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
293
  girara_node_free(root);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
294
  fail_unless((node_free_called == 2), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
295 296 297 298 299 300 301 302

  root = girara_node_new(g_strdup("root"));
  girara_node_set_free_function(root, g_free);
  for (unsigned int i = 0; i != 5; ++i) {
    girara_tree_node_t* child = girara_node_append_data(root, g_strdup_printf("child_%u", i));
    for (unsigned int j = 0; j != 10; ++j) {
      girara_node_append_data(child, g_strdup_printf("child_%u_%u", i, j));
    }
Sebastian Ramacher's avatar
Sebastian Ramacher committed
303
    fail_unless((girara_node_get_num_children(child) == 10), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
304
  }
Sebastian Ramacher's avatar
Sebastian Ramacher committed
305
  fail_unless((girara_node_get_num_children(root) == 5), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
306 307

  girara_list_t* children = girara_node_get_children(root);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
308 309
  fail_unless((children != NULL), NULL);
  fail_unless((girara_list_size(children) == 5), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
310 311 312 313 314 315
  unsigned int i = 0;
  girara_list_iterator_t* iter = girara_list_iterator(children);
  while (girara_list_iterator_is_valid(iter))
  {
    char* expected = g_strdup_printf("child_%u", i);
    girara_tree_node_t* child = (girara_tree_node_t*)girara_list_iterator_data(iter);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
316 317 318
    fail_unless((g_strcmp0((char*)girara_node_get_data(child), expected) == 0), NULL);
    fail_unless((girara_node_get_parent(child) == root), NULL);
    fail_unless((girara_node_get_root(child) == root), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
319 320 321
    g_free(expected);

    girara_list_t* grandchildren = girara_node_get_children(child);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
322 323
    fail_unless((grandchildren != NULL), NULL);
    fail_unless((girara_list_size(grandchildren) == 10), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
324 325 326 327
    unsigned int j = 0;
    girara_list_iterator_t* iter2 = girara_list_iterator(grandchildren);
    while (girara_list_iterator_is_valid(iter2))
    {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
328
      expected = g_strdup_printf("child_%u_%u", i, j);
Moritz Lipp's avatar
Moritz Lipp committed
329
      girara_tree_node_t* gchild = (girara_tree_node_t*)girara_list_iterator_data(iter2);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
330 331 332
      fail_unless((g_strcmp0((char*)girara_node_get_data(gchild), expected) == 0), NULL);
      fail_unless((girara_node_get_parent(gchild) == child), NULL);
      fail_unless((girara_node_get_root(gchild) == root), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
333 334 335 336
      g_free(expected);
      ++j;
      girara_list_iterator_next(iter2);
    }
Sebastian Ramacher's avatar
Sebastian Ramacher committed
337
    fail_unless((j == 10), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
338 339 340 341 342
    girara_list_iterator_free(iter2);
    girara_list_free(grandchildren);
    girara_list_iterator_next(iter);
    ++i;
  }
Sebastian Ramacher's avatar
Sebastian Ramacher committed
343
  fail_unless((i == 5), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
344 345 346 347 348 349
  girara_list_iterator_free(iter);
  girara_list_free(children);

  girara_node_free(root);
} END_TEST

350 351 352 353 354 355 356 357 358 359 360 361
static int
find_compare(const void* item, const void* data)
{
  if (item == data) {
    return 1;
  } else {
    return 0;
  }
}

START_TEST(test_datastructures_list_find) {
  girara_list_t* list = girara_list_new();
Sebastian Ramacher's avatar
Sebastian Ramacher committed
362
  fail_unless((list != NULL), NULL);
363 364

  /* test parameters */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
365 366 367 368
  fail_unless((girara_list_find(NULL, NULL, NULL) == NULL), NULL);
  fail_unless((girara_list_find(list, NULL, NULL) == NULL), NULL);
  fail_unless((girara_list_find(NULL, NULL, (void*) 0xDEAD) == NULL), NULL);
  fail_unless((girara_list_find(NULL, find_compare, NULL) == NULL), NULL);
369 370 371

  /* test functionality */
  girara_list_append(list, (void*) 0xDEAD);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
372 373
  fail_unless((girara_list_find(list, find_compare, (void*) 0xDEAD) == NULL), NULL);
  fail_unless((girara_list_find(list, find_compare, (void*) 0xCAFE) != NULL), NULL);
374 375 376 377 378
  girara_list_free(list);
} END_TEST

START_TEST(test_datastructures_list_prepend) {
  girara_list_t* list = girara_list_new();
Sebastian Ramacher's avatar
Sebastian Ramacher committed
379
  fail_unless((list != NULL), NULL);
380 381 382

  /* test parameters */
  girara_list_prepend(list, NULL);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
383
  fail_unless((girara_list_size(list) != 0), NULL);
384 385 386 387

  girara_list_free(list);
} END_TEST

388
Suite* suite_datastructures(void)
Moritz Lipp's avatar
Moritz Lipp committed
389 390 391 392 393 394
{
  TCase* tcase = NULL;
  Suite* suite = suite_create("Datastructures");

  /* list free */
  tcase = tcase_create("list_free_function");
Sebastian Ramacher's avatar
Sebastian Ramacher committed
395 396 397 398
  tcase_add_test(tcase, test_datastructures_list_free_empty);
  tcase_add_test(tcase, test_datastructures_list_free_already_cleared);
  tcase_add_test(tcase, test_datastructures_list_free_free_function);
  tcase_add_test(tcase, test_datastructures_list_free_free_function_remove);
Moritz Lipp's avatar
Moritz Lipp committed
399 400 401 402 403 404 405 406 407
  suite_add_tcase(suite, tcase);

  /* list create */
  tcase = tcase_create("list_basics");
  tcase_add_test(tcase, test_datastructures_list);
  suite_add_tcase(suite, tcase);

  /* sorted list */
  tcase = tcase_create("list_sorted");
Sebastian Ramacher's avatar
Sebastian Ramacher committed
408
  tcase_add_test(tcase, test_datastructures_sorted_list_basic);
Moritz Lipp's avatar
Moritz Lipp committed
409 410 411
  tcase_add_test(tcase, test_datastructures_sorted_list);
  suite_add_tcase(suite, tcase);

412 413 414 415 416
  /* merge lists */
  tcase = tcase_create("list_merge");
  tcase_add_test(tcase, test_datastructures_list_merge);
  suite_add_tcase(suite, tcase);

417 418 419 420 421
  /* search lists */
  tcase = tcase_create("list_find");
  tcase_add_test(tcase, test_datastructures_list_find);
  suite_add_tcase(suite, tcase);

422
  /* prepend lists */
423 424 425 426
  tcase = tcase_create("list_prepend");
  tcase_add_test(tcase, test_datastructures_list_prepend);
  suite_add_tcase(suite, tcase);

427 428
  /* list iterators */
  tcase = tcase_create("list_iterators");
Sebastian Ramacher's avatar
Sebastian Ramacher committed
429
  /* tcase_add_test(tcase, test_datastructures_list_iterator_remove); */
430 431
  suite_add_tcase(suite, tcase);

Moritz Lipp's avatar
Moritz Lipp committed
432 433 434 435 436 437 438 439 440 441 442 443
  /* node free */
  tcase = tcase_create("node_free");
  tcase_add_test(tcase, test_datastructures_sorted_list);
  suite_add_tcase(suite, tcase);

  /* node basics */
  tcase = tcase_create("node_basics");
  tcase_add_test(tcase, test_datastructures_node);
  suite_add_tcase(suite, tcase);

  return suite;
}