- Tests are now separated in test files in the tests-directory
[strongswan.git] / Source / charon / tests / linked_list_test.c
1 /**
2 * @file linked_list_test.c
3 *
4 * @brief Tests to test the Linked List type linked_list_t
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include <string.h>
24
25 #include "../tester.h"
26 #include "../linked_list.h"
27
28 /*
29 * Description in header-file
30 */
31 void test_linked_list(tester_t *tester)
32 {
33 void *test_value = NULL;
34
35 linked_list_t *linked_list = linked_list_create();
36 tester->assert_true(tester,(linked_list->count == 0), "count check");
37
38 linked_list->insert_first(linked_list,"one");
39 tester->assert_true(tester,(linked_list->count == 1), "count check");
40
41 linked_list->insert_first(linked_list,"two");
42 tester->assert_true(tester,(linked_list->count == 2), "count check");
43
44 linked_list->insert_first(linked_list,"three");
45 tester->assert_true(tester,(linked_list->count == 3), "count check");
46
47 linked_list->insert_first(linked_list,"four");
48 tester->assert_true(tester,(linked_list->count == 4), "count check");
49
50 linked_list->insert_first(linked_list,"five");
51 tester->assert_true(tester,(linked_list->count == 5), "count check");
52
53 tester->assert_true(tester,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
54 tester->assert_true(tester,(strcmp((char *) test_value,"five") == 0), "get_first value check");
55 tester->assert_true(tester,(linked_list->count == 5), "count check");
56
57 tester->assert_true(tester,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
58 tester->assert_true(tester,(strcmp((char *) test_value,"one") == 0), "get_last value check");
59 tester->assert_true(tester,(linked_list->count == 5), "count check");
60 tester->assert_true(tester,(linked_list->remove_first(linked_list,&test_value) == SUCCESS), "remove_first call check");
61 tester->assert_true(tester,(strcmp((char *) test_value,"five") == 0), "remove_first value check");
62 tester->assert_true(tester,(linked_list->count == 4), "count check");
63
64 tester->assert_true(tester,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
65 tester->assert_true(tester,(strcmp((char *) test_value,"four") == 0), "get_first value check");
66 tester->assert_true(tester,(linked_list->count == 4), "count check");
67
68 tester->assert_true(tester,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
69 tester->assert_true(tester,(strcmp((char *) test_value,"one") == 0), "get_last value check");
70 tester->assert_true(tester,(linked_list->count == 4), "count check");
71
72 tester->assert_true(tester,(linked_list->remove_last(linked_list,&test_value) == SUCCESS), "remove_last call check");
73 tester->assert_true(tester,(strcmp((char *) test_value,"one") == 0), "remove_last value check");
74 tester->assert_true(tester,(linked_list->count == 3), "count check");
75
76 tester->assert_true(tester,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
77 tester->assert_true(tester,(strcmp((char *) test_value,"two") == 0), "get_last value check");
78 tester->assert_true(tester,(linked_list->count == 3), "count check");
79
80 tester->assert_true(tester,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
81 tester->assert_true(tester,(strcmp((char *) test_value,"four") == 0), "get_first value check");
82 tester->assert_true(tester,(linked_list->count == 3), "count check");
83
84 tester->assert_true(tester,(linked_list->destroy(linked_list) == SUCCESS), "destroy call check");
85 }