test/list_tests.c

Mon, 22 Jul 2013 11:53:39 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 22 Jul 2013 11:53:39 +0200
changeset 122
540d99722f1f
parent 103
test/dlist_tests.c@08018864fb91
child 123
7fb0f74517c5
permissions
-rw-r--r--

removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)

9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
103
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
3 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
5 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
6 * Redistribution and use in source and binary forms, with or without
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
7 * modification, are permitted provided that the following conditions are met:
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
8 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
10 * notice, this list of conditions and the following disclaimer.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
11 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
14 * documentation and/or other materials provided with the distribution.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
15 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
29 #include "list_tests.h"
94
57ea041df22f renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents: 90
diff changeset
30 #include "ucx/utils.h"
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
32 UCX_TEST_IMPLEMENT(test_ucx_list_append) {
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
33 UcxList *list = ucx_list_append(NULL, (void*)"Hello");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
34 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
35
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
36 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
37 "failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
38
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
39 list = ucx_list_append(list, (void*)" World!");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
40
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
41 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
42 "failed");
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
43 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
44 UCX_TEST_END
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
45
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
46 ucx_list_free(list);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
47 }
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
49 UCX_TEST_IMPLEMENT(test_ucx_list_prepend) {
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
50 UcxList *list = ucx_list_prepend(NULL, (void*)" World!");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
51 UCX_TEST_BEGIN
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
52
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
53 list = ucx_list_prepend(list, (void*)"Hello");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
54
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
55 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
56 "failed");
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
57 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
58 "failed");
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
59 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
60
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
61 UCX_TEST_END
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
62 ucx_list_free(list);
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
63 }
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
64
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
65 UCX_TEST_IMPLEMENT(test_ucx_list_equals) {
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
66 UcxList *list = ucx_list_append(NULL, (void*)"Hello");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
67 list = ucx_list_append(list, (void*)" World!");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
68 UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
69 list2 = ucx_list_prepend(list2, (void*)"Hello");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
70 UcxList *list3 = ucx_list_prepend(NULL, (void*)" Welt!");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
71 list3 = ucx_list_prepend(list3, (void*)"Hallo");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
72 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
73
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
74 UCX_TEST_ASSERT(ucx_list_equals(list, list2, ucx_strcmp, NULL), "failed");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
75 UCX_TEST_ASSERT(!ucx_list_equals(list, list3, ucx_strcmp, NULL), "failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
76
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
77 UCX_TEST_END
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
78 ucx_list_free(list3);
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
79 ucx_list_free(list2);
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
80 ucx_list_free(list);
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
81 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
82
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
83 UCX_TEST_IMPLEMENT(test_ucx_list_concat) {
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
84 UcxList *list = ucx_list_append(NULL, (void*)"Hello");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
85 UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
86 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
87
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
88 list = ucx_list_concat(list, list2);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
89
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
90 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
91 "failed");
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
92 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
93 "failed");
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
94 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
95
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
96 UCX_TEST_END
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
97 ucx_list_free(list);
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
98 }
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
99
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
100 UCX_TEST_IMPLEMENT(test_ucx_list_size) {
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
101 UcxList *list = ucx_list_append(NULL, (void*)"This ");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
102 UCX_TEST_BEGIN
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
103 list = ucx_list_append(list, (void*)"list ");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
104 list = ucx_list_append(list, (void*)"has ");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
105 list = ucx_list_append(list, (void*)"size ");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
106 list = ucx_list_append(list, (void*)"5!");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
107
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
108 UCX_TEST_ASSERT(ucx_list_size(list) == 5, "failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
109
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
110 UCX_TEST_END
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
111 ucx_list_free(list);
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 }
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
114 UCX_TEST_IMPLEMENT(test_ucx_list_first) {
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
115 UcxList *list = ucx_list_append(NULL, (void*)"Find ");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
116 UCX_TEST_BEGIN
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
117 list = ucx_list_append(list, (void*)"the ");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
118 list = ucx_list_append(list, (void*)"first!");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
119
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
120 const char* first = (const char*) (ucx_list_first(list)->data);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
121
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
122 UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed");
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
123
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
124 UCX_TEST_END
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
125 ucx_list_free(list);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
126 }
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
128 UCX_TEST_IMPLEMENT(test_ucx_list_last) {
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
129 UcxList *list = ucx_list_append(NULL, (void*)"Find ");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
130 UCX_TEST_BEGIN
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
131 list = ucx_list_append(list, (void*)"the ");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
132 list = ucx_list_append(list, (void*)"last!");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
133
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
134 const char* last = (const char*) (ucx_list_last(list)->data);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
135
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
136 UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed");
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
137
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
138 UCX_TEST_END
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
139 ucx_list_free(list);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
140 }
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
141
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
142 UCX_TEST_IMPLEMENT(test_ucx_list_get) {
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
143 UcxList *list = ucx_list_append(NULL, (void*)"Find ");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
144 UCX_TEST_BEGIN
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
145 list = ucx_list_append(list, (void*)"the ");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
146 list = ucx_list_append(list, (void*)"mid!");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
147
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
148 const char* mid = (const char*) (ucx_list_get(list, 1)->data);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
149
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
150 UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed");
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
151
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
152 UCX_TEST_END
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
153 ucx_list_free(list);
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 }
11
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
155
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
156 UCX_TEST_IMPLEMENT(test_ucx_list_contains) {
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
157 UcxList *l = ucx_list_append(NULL, (void*)"Contains ");
90
ef3163857e88 added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
158 UCX_TEST_BEGIN
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
159 l = ucx_list_append(l, (void*)"a ");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
160 l = ucx_list_append(l, (void*)"string!");
90
ef3163857e88 added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
161
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
162 UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_strcmp,NULL),"failed");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
163 UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_strcmp,NULL),"failed");
90
ef3163857e88 added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
164
ef3163857e88 added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
165 UCX_TEST_END
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
166 ucx_list_free(l);
90
ef3163857e88 added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
167 }
ef3163857e88 added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
168
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
169 UCX_TEST_IMPLEMENT(test_ucx_list_remove) {
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
170 UcxList *list = ucx_list_append(NULL, (void*)"Hello");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
171 UCX_TEST_BEGIN
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
172 list = ucx_list_append(list, (void*)" fucking");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
173 list = ucx_list_append(list, (void*)" World!");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
174
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
175 list = ucx_list_remove(list, ucx_list_get(list, 1));
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
176
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
177 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
178 "failed");
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
179 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
180 "failed");
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
181 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
182
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
183 UCX_TEST_END
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
184 ucx_list_free(list);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
185 }
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
186
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
187 UCX_TEST_IMPLEMENT(test_ucx_list_clone) {
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
188
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
189 char *hello = (char*)malloc(6);
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
190 char *world = (char*)malloc(8);
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
191
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
192 memcpy(hello, "Hello", 6);
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
193 memcpy(world, " World!", 8);
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
194
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
195 UcxList *list = ucx_list_append(NULL, hello);
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
196 list = ucx_list_append(list, world);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
197
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
198 UcxList *copy = ucx_list_clone(list, ucx_strcpy, NULL);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
199 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
200
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
201 UCX_TEST_ASSERT(ucx_list_equals(list, copy, ucx_strcmp, NULL), "failed");
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
202 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
203 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
204
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
205 UCX_TEST_END
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
206 free(copy->next->data);
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
207 free(copy->data);
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
208
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
209 free(world);
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
210 free(hello);
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
211 ucx_list_free(list);
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
212 ucx_list_free(copy);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
213 }
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
214
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
215 UCX_TEST_IMPLEMENT(test_ucx_list_sort) {
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
216 UcxList *list = ucx_list_append(NULL, (void*)"this");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
217 list = ucx_list_append(list, (void*)"is");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
218 list = ucx_list_append(list, (void*)"a");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
219 list = ucx_list_append(list, (void*)"test");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
220 list = ucx_list_append(list, (void*)"for");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
221 list = ucx_list_append(list, (void*)"partial");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
222 list = ucx_list_append(list, (void*)"correctness");
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
223
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
224 UcxList *expected = ucx_list_append(NULL, (void*)"a");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
225 expected = ucx_list_append(expected, (void*)"correctness");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
226 expected = ucx_list_append(expected, (void*)"for");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
227 expected = ucx_list_append(expected, (void*)"is");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
228 expected = ucx_list_append(expected, (void*)"partial");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
229 expected = ucx_list_append(expected, (void*)"test");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
230 expected = ucx_list_append(expected, (void*)"this");
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
231
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
232 list = ucx_list_sort(list, ucx_strcmp, NULL);
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
233
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
234 UCX_TEST_BEGIN
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
235 UCX_TEST_ASSERT(
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
236 ucx_list_equals(list, expected, ucx_strcmp, NULL), "failed");
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
237 UcxList *l = list;
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
238 UCX_TEST_ASSERT(l->prev == NULL, "prev field of first entry is not null");
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
239 while (l->next != NULL) {
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
240 UCX_TEST_ASSERT(l->next->prev == l, "prev pointer corrupted");
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
241 l = l->next;
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
242 }
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
243 UCX_TEST_END
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
244
122
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
245 ucx_list_free(expected);
540d99722f1f removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
246 ucx_list_free(list);
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
247 }

mercurial