test_datastructures.c 13.8 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
  fail_unless((girara_list_merge(NULL, NULL) == NULL), NULL);
  fail_unless((girara_list_merge(list1, NULL) == list1), NULL);
109
  fail_unless((girara_list_merge(NULL, list2) == NULL), 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 230 231 232 233
    ++p;
  GIRARA_LIST_FOREACH_END(unsorted_list, const char*, iter, value);

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

static void
node_free(void* data)
{
  if (g_strcmp0((char*)data, "root") == 0) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
234
    fail_unless((node_free_called == 0), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
235
  } else if (g_strcmp0((char*)data, "child") == 0) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
236
    fail_unless((node_free_called == 1), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
237 238 239 240 241 242 243 244 245
  } 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
246 247 248 249
  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
250
  girara_list_t* rchildren = girara_node_get_children(root);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
251 252
  fail_unless((rchildren != NULL), NULL);
  fail_unless((girara_list_size(rchildren) == 0), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
253 254 255 256 257 258
  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
259 260
  fail_unless((girara_node_get_num_children(root) == 1), NULL);
  fail_unless((node_free_called == 0), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
261
  girara_node_free(root);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
262
  fail_unless((node_free_called == 2), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
263 264 265 266 267

  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
268
  fail_unless((node_free_called == 1), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
269
  girara_node_free(root);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
270
  fail_unless((node_free_called == 2), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
271 272 273 274 275 276 277 278

  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
279
    fail_unless((girara_node_get_num_children(child) == 10), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
280
  }
Sebastian Ramacher's avatar
Sebastian Ramacher committed
281
  fail_unless((girara_node_get_num_children(root) == 5), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
282 283

  girara_list_t* children = girara_node_get_children(root);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
284 285
  fail_unless((children != NULL), NULL);
  fail_unless((girara_list_size(children) == 5), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
286 287 288 289 290 291
  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
292 293 294
    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
295 296 297
    g_free(expected);

    girara_list_t* grandchildren = girara_node_get_children(child);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
298 299
    fail_unless((grandchildren != NULL), NULL);
    fail_unless((girara_list_size(grandchildren) == 10), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
300 301 302 303
    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
304
      expected = g_strdup_printf("child_%u_%u", i, j);
Moritz Lipp's avatar
Moritz Lipp committed
305
      girara_tree_node_t* gchild = (girara_tree_node_t*)girara_list_iterator_data(iter2);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
306 307 308
      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
309 310 311 312
      g_free(expected);
      ++j;
      girara_list_iterator_next(iter2);
    }
Sebastian Ramacher's avatar
Sebastian Ramacher committed
313
    fail_unless((j == 10), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
314 315 316 317 318
    girara_list_iterator_free(iter2);
    girara_list_free(grandchildren);
    girara_list_iterator_next(iter);
    ++i;
  }
Sebastian Ramacher's avatar
Sebastian Ramacher committed
319
  fail_unless((i == 5), NULL);
Moritz Lipp's avatar
Moritz Lipp committed
320 321 322 323 324 325
  girara_list_iterator_free(iter);
  girara_list_free(children);

  girara_node_free(root);
} END_TEST

326 327 328 329 330 331 332 333 334 335 336 337
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
338
  fail_unless((list != NULL), NULL);
339 340

  /* test parameters */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
341 342 343 344
  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);
345 346 347

  /* test functionality */
  girara_list_append(list, (void*) 0xDEAD);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
348 349
  fail_unless((girara_list_find(list, find_compare, (void*) 0xDEAD) == NULL), NULL);
  fail_unless((girara_list_find(list, find_compare, (void*) 0xCAFE) != NULL), NULL);
350 351 352 353 354
  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
355
  fail_unless((list != NULL), NULL);
356 357 358

  /* test parameters */
  girara_list_prepend(list, NULL);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
359
  fail_unless((girara_list_size(list) != 0), NULL);
360 361 362 363

  girara_list_free(list);
} END_TEST

Sebastian Ramacher's avatar
Sebastian Ramacher committed
364
static Suite* suite_datastructures(void)
Moritz Lipp's avatar
Moritz Lipp committed
365 366 367 368 369 370
{
  TCase* tcase = NULL;
  Suite* suite = suite_create("Datastructures");

  /* list free */
  tcase = tcase_create("list_free_function");
Sebastian Ramacher's avatar
Sebastian Ramacher committed
371 372 373 374
  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
375 376 377 378 379 380 381 382 383
  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
384
  tcase_add_test(tcase, test_datastructures_sorted_list_basic);
Moritz Lipp's avatar
Moritz Lipp committed
385 386 387
  tcase_add_test(tcase, test_datastructures_sorted_list);
  suite_add_tcase(suite, tcase);

388 389 390 391 392
  /* merge lists */
  tcase = tcase_create("list_merge");
  tcase_add_test(tcase, test_datastructures_list_merge);
  suite_add_tcase(suite, tcase);

393 394 395 396 397
  /* search lists */
  tcase = tcase_create("list_find");
  tcase_add_test(tcase, test_datastructures_list_find);
  suite_add_tcase(suite, tcase);

398
  /* prepend lists */
399 400 401 402
  tcase = tcase_create("list_prepend");
  tcase_add_test(tcase, test_datastructures_list_prepend);
  suite_add_tcase(suite, tcase);

403 404 405 406
  /* list iterators */
  tcase = tcase_create("list_iterators");
  suite_add_tcase(suite, tcase);

Moritz Lipp's avatar
Moritz Lipp committed
407 408 409 410 411 412 413 414 415 416 417 418
  /* 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;
}
Sebastian Ramacher's avatar
Sebastian Ramacher committed
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434

int main()
{
  Suite* suite          = NULL;
  SRunner* suite_runner = NULL;
  int number_failed     = 0;

  /* test datastructures */
  suite        = suite_datastructures();
  suite_runner = srunner_create(suite);
  srunner_run_all(suite_runner, CK_NORMAL);
  number_failed += srunner_ntests_failed(suite_runner);
  srunner_free(suite_runner);

  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}