test/map_tests.c

Mon, 25 Feb 2013 12:18:31 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 25 Feb 2013 12:18:31 +0100
changeset 85
0ef0df7aa2c2
parent 80
0125e4089f88
child 88
18823857ce79
permissions
-rw-r--r--

fixed comments + added ucx_buffer_clear

20
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 *
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 */
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 #include "map_tests.h"
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
7 UCX_TEST_IMPLEMENT(test_ucx_map_new) {
20
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 UcxMap *map = ucx_map_new(16);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
9 UCX_TEST_BEGIN
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
10 UCX_TEST_ASSERT(map->size == 16, "wrong size");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
11 UCX_TEST_ASSERT(map->map != NULL, "failed");
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
12
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
13 UCX_TEST_END
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
14 ucx_map_free(map);
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
15 }
20
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
17 UCX_TEST_IMPLEMENT(test_ucx_key) {
71
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
18 UcxKey key = ucx_key((void*)"This is a text.", 15);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
19 UCX_TEST_BEGIN
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
20 UCX_TEST_ASSERT(strncmp((const char*)key.data, "This is a text.", 15) == 0,
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
21 "failed");
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
22 UCX_TEST_ASSERT(key.len == 15, "failed");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
23 UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed");
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
24
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
25 UCX_TEST_END
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
26 }
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
27
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
28 UCX_TEST_IMPLEMENT(test_ucx_map_put) {
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
30 UcxMap *map = ucx_map_new(4);
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
31
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
32 int td[5];
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
33 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
20
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
35 UCX_TEST_BEGIN
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
36 ucx_map_cstr_put(map, "Key2", &td[2]); /* 3.2 */
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
37 ucx_map_cstr_put(map, "Key0", &td[0]); /* 0.0 */
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
38 ucx_map_cstr_put(map, "Key1", &td[1]); /* 3.0 */
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
39 ucx_map_cstr_put(map, "KeY3", &td[3]); /* 3.1 */
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
40 ucx_map_cstr_put(map, "KEY4", &td[4]); /* 1.0 */
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
41
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
42 UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[0], "failed Key0");
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
43 UCX_TEST_ASSERT(*((int*)map->map[1]->data) == td[4], "failed KEY4");
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
44 UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1], "failed Key1");
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
45
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
46 UCX_TEST_ASSERT(map->map[3]->next != NULL, "no list at slot 3");
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
47 UCX_TEST_ASSERT(map->map[3]->next->next != NULL, "list corrupt at slot 3");
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
48 UCX_TEST_ASSERT(*((int*)map->map[3]->next->data) == td[3],
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
49 "failed KeY3")
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
50 UCX_TEST_ASSERT(*((int*)map->map[3]->next->next->data) == td[2],
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
51 "failed KeY2");
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
52
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
53 UCX_TEST_ASSERT(map->map[0]->next == NULL, "slot 0 not terminated");
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
54 UCX_TEST_ASSERT(map->map[1]->next == NULL, "slot 1 not terminated");
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
55 UCX_TEST_ASSERT(map->map[2] == NULL, "slot 2 not empty");
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
56 UCX_TEST_ASSERT(map->map[3]->next->next->next == NULL,
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
57 "slot 3 not terminated")
20
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
59 ucx_map_cstr_put(map, "KeY3", &td[4]); /* replace 3.1 */
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
60
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
61 UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1],
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
62 "overwrite failed")
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
63 UCX_TEST_ASSERT(*((int*)map->map[3]->next->data) == td[4],
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
64 "overwrite failed");
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
65 UCX_TEST_ASSERT(*((int*)map->map[3]->next->next->data) == td[2],
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
66 "overwrite failed")
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
67 UCX_TEST_ASSERT(map->map[3]->next->next->next == NULL, "overwrite failed");
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
68
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
69 UCX_TEST_END
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
70 ucx_map_free(map);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
71 }
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
72
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
73 UCX_TEST_IMPLEMENT(test_ucx_map_get) {
34
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
74 UcxMap *map = ucx_map_new(4);
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
75
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
76 int td[5];
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
77 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
78
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
79 ucx_map_cstr_put(map, "Key2", &td[2]);
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
80 ucx_map_cstr_put(map, "Key0", &td[0]);
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
81 ucx_map_cstr_put(map, "Key1", &td[1]);
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
82 ucx_map_cstr_put(map, "KeY3", &td[3]);
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
83 ucx_map_cstr_put(map, "KEY4", &td[4]);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
84 UCX_TEST_BEGIN
34
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
85
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
86 td[0] = *((int*)ucx_map_cstr_get(map, "Key0"));
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
87 td[1] = *((int*)ucx_map_cstr_get(map, "Key1"));
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
88 td[2] = *((int*)ucx_map_cstr_get(map, "Key2"));
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
89 td[3] = *((int*)ucx_map_cstr_get(map, "KeY3"));
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
90 td[4] = *((int*)ucx_map_cstr_get(map, "KEY4"));
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
91 UCX_TEST_ASSERT(td[0] == 10, "failed key 0");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
92 UCX_TEST_ASSERT(td[1] == 42, "failed key 1");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
93 UCX_TEST_ASSERT(td[2] == 70, "failed key 2");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
94 UCX_TEST_ASSERT(td[3] == 11200, "failed key 3");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
95 UCX_TEST_ASSERT(td[4] == 80000, "failed key 4");
34
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
96
53
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
97 UCX_TEST_ASSERT(map->count == 5, "expected 5 remaining values");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
98 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key0") != NULL, "element removed");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
99
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
100 UCX_TEST_END
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
101 ucx_map_free(map);
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
102 }
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
103
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
104 UCX_TEST_IMPLEMENT(test_ucx_map_remove) {
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
105 UcxMap *map = ucx_map_new(4);
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
106
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
107 int td[5];
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
108 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
109
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
110 ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
111 ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
112 ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
113 ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
114 ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
115 UCX_TEST_BEGIN
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
116
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
117 td[0] = *((int*)ucx_map_cstr_remove(map, "Key0"));
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
118 td[1] = *((int*)ucx_map_cstr_get(map, "Key1"));
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
119 td[2] = *((int*)ucx_map_cstr_remove(map, "Key2"));
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
120 td[3] = *((int*)ucx_map_cstr_get(map, "KeY3"));
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
121 td[4] = *((int*)ucx_map_cstr_get(map, "KEY4"));
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
122 UCX_TEST_ASSERT(td[0] == 10, "failed key 0");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
123 UCX_TEST_ASSERT(td[1] == 42, "failed key 1");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
124 UCX_TEST_ASSERT(td[2] == 70, "failed key 2");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
125 UCX_TEST_ASSERT(td[3] == 11200, "failed key 3");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
126 UCX_TEST_ASSERT(td[4] == 80000, "failed key 4");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
127
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
128 UCX_TEST_ASSERT(map->count == 3, "expected 3 remaining values");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
129 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key0")==NULL, "element not removed");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
130 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key1")!=NULL, "element removed");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
131 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key2")==NULL, "element not removed");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
132 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "KeY3")!=NULL, "element removed");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
133 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "KEY4")!=NULL, "element removed");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
134
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
135 UCX_TEST_ASSERT(ucx_map_cstr_remove(map, "Key2") == NULL,
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
136 "subsequent remove call shall return NULL");
e533c170bfb8 added ucx_map_remove
Mike Becker <universe@uap-core.de>
parents: 52
diff changeset
137
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
138 UCX_TEST_END
34
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
139 ucx_map_free(map);
20
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 }
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
141
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
142 UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, mapptr) {
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
143 UcxMap *map = (UcxMap*) mapptr;
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
144 int v1 = 10;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
145 int v2 = 15;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
146 int v3 = 7;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
147 int v4 = 9;
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
148
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
149 ucx_map_cstr_put(map, "v1", &v1);
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
150 ucx_map_cstr_put(map, "v2", &v2);
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
151 ucx_map_cstr_put(map, "v3", &v3);
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
152 ucx_map_cstr_put(map, "v4", &v4);
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
153
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
154 UcxMapIterator i = ucx_map_iterator(map);
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
155 int check = 0;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
156 int hit = 0;
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
157
41
7f90a03e186e simplified UCX_MAP_FOREACH
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
158 int* v;
7f90a03e186e simplified UCX_MAP_FOREACH
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
159 UCX_MAP_FOREACH(v, i) {
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
160 check += *v;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
161 hit++;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
162 }
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
163
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
164 UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits");
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
165 UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
166 }
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
167
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
168 UCX_TEST_IMPLEMENT(test_ucx_map_iterator) {
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
169 UcxMap *map = ucx_map_new(16);
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
170 UCX_TEST_BEGIN
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
171 UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map)
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
172 UCX_TEST_END
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
173 ucx_map_free(map);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
174 }
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
175
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
176 UCX_TEST_IMPLEMENT(test_ucx_map_iterator_chain) {
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
177 UcxMap *map = ucx_map_new(1);
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
178 UCX_TEST_BEGIN
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
179 UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map)
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
180 UCX_TEST_END
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
181 ucx_map_free(map);
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
182 }
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
183
48
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
184 void* test_ucx_map_store_load_encdec(void *value, void *data, size_t *size) {
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
185 const char *string = (const char*) value;
46
48ca036d7d9c implemented encoder/decoder for map store/load
Mike Becker <universe@uap-core.de>
parents: 44
diff changeset
186 size_t n = strlen(string);
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
187 char *encoded = (char*) malloc(n+1);
46
48ca036d7d9c implemented encoder/decoder for map store/load
Mike Becker <universe@uap-core.de>
parents: 44
diff changeset
188 for (int i = 0 ; i < n ; i++) {
48ca036d7d9c implemented encoder/decoder for map store/load
Mike Becker <universe@uap-core.de>
parents: 44
diff changeset
189 encoded[i] = string[n-1-i];
48ca036d7d9c implemented encoder/decoder for map store/load
Mike Becker <universe@uap-core.de>
parents: 44
diff changeset
190 }
48ca036d7d9c implemented encoder/decoder for map store/load
Mike Becker <universe@uap-core.de>
parents: 44
diff changeset
191 encoded[n] = 0;
48
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
192 *size = n+1;
46
48ca036d7d9c implemented encoder/decoder for map store/load
Mike Becker <universe@uap-core.de>
parents: 44
diff changeset
193 return encoded;
48ca036d7d9c implemented encoder/decoder for map store/load
Mike Becker <universe@uap-core.de>
parents: 44
diff changeset
194 }
48ca036d7d9c implemented encoder/decoder for map store/load
Mike Becker <universe@uap-core.de>
parents: 44
diff changeset
195
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
196 UCX_TEST_IMPLEMENT(test_ucx_map_store_load) {
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
197 UcxMap *map = ucx_map_new(4);
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
198
71
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
199 ucx_map_cstr_put(map, "test", (void*)"test");
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
200 ucx_map_cstr_put(map, "key", (void*)"value");
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
201 ucx_map_cstr_put(map, "other.very.long.key", (void*)"value");
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
202 ucx_map_cstr_put(map, "testkey", (void*)"testvalue");
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
203 ucx_map_cstr_put(map, "simple", (void*)"not a key but an extremely long "
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
204 "value to test if the buffer extension works as designed");
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
205
55
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
206 UCX_TEST_BEGIN
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
207 FILE *f = tmpfile();
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
208 UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted")
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
209 int r;
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
210
43
02f38adea013 fixed crash fails by completing the implementation of the tested function....
Mike Becker <universe@uap-core.de>
parents: 42
diff changeset
211 fwrite(" # comment test\n", 1, 16, f);
46
48ca036d7d9c implemented encoder/decoder for map store/load
Mike Becker <universe@uap-core.de>
parents: 44
diff changeset
212 r = ucx_map_store_enc(map, f, test_ucx_map_store_load_encdec, NULL);
43
02f38adea013 fixed crash fails by completing the implementation of the tested function....
Mike Becker <universe@uap-core.de>
parents: 42
diff changeset
213 fwrite("!discard this", 1, 13, f);
55
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
214 fflush(f);
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
215
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
216 ucx_map_free(map);
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
217 map = ucx_map_new(1);
55
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
218 fseek(f, 0, SEEK_SET);
48
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
219 UcxAllocator allocator = UCX_ALLOCATOR_DEFAULT;
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
220 r += ucx_map_load_enc(map, f, allocator,
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
221 test_ucx_map_store_load_encdec, NULL);
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
222 fclose(f);
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
223
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
224 const char *value;
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
225 UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
226
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
227 value = (const char *) ucx_map_cstr_get(map, "test");
43
02f38adea013 fixed crash fails by completing the implementation of the tested function....
Mike Becker <universe@uap-core.de>
parents: 42
diff changeset
228 UCX_TEST_ASSERT(value != NULL, "value not found for key: test");
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
229 UCX_TEST_ASSERT(strcmp(value, "test") == 0, "value error for key: test");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
230
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
231 value = (const char *) ucx_map_cstr_get(map, "key");
43
02f38adea013 fixed crash fails by completing the implementation of the tested function....
Mike Becker <universe@uap-core.de>
parents: 42
diff changeset
232 UCX_TEST_ASSERT(value != NULL, "value not found for key: key");
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
233 UCX_TEST_ASSERT(strcmp(value, "value") == 0, "value error for key: key");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
234
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
235 value = (const char *) ucx_map_cstr_get(map, "other.very.long.key");
43
02f38adea013 fixed crash fails by completing the implementation of the tested function....
Mike Becker <universe@uap-core.de>
parents: 42
diff changeset
236 UCX_TEST_ASSERT(value != NULL,
02f38adea013 fixed crash fails by completing the implementation of the tested function....
Mike Becker <universe@uap-core.de>
parents: 42
diff changeset
237 "value not found for key: other.very.long.key");
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
238 UCX_TEST_ASSERT(strcmp(value, "value") == 0,
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
239 "value error for key: other.very.long.key");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
240
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
241 value = (const char *) ucx_map_cstr_get(map, "testkey");
43
02f38adea013 fixed crash fails by completing the implementation of the tested function....
Mike Becker <universe@uap-core.de>
parents: 42
diff changeset
242 UCX_TEST_ASSERT(value != NULL, "value not found for key: testkey");
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
243 UCX_TEST_ASSERT(strcmp(value, "testvalue") == 0,
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
244 "value error for key: testkey");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
245
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
246 value = (const char *) ucx_map_cstr_get(map, "simple");
43
02f38adea013 fixed crash fails by completing the implementation of the tested function....
Mike Becker <universe@uap-core.de>
parents: 42
diff changeset
247 UCX_TEST_ASSERT(value != NULL, "value not found for key: simple");
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
248 UCX_TEST_ASSERT(strcmp(value, "not a key but an extremely long value "
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
249 "to test if the buffer extension works as designed") == 0,
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
250 "value error for key: simple");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
251
55
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
252 void *d;
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
253 UcxMapIterator iter = ucx_map_iterator(map);
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
254 UCX_MAP_FOREACH(d, iter) {
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
255 free(d);
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
256 }
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
257 ucx_map_free(map);
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
258 UCX_TEST_END
48
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
259 }
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
260
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
261 UCX_TEST_IMPLEMENT(test_ucx_map_store_load_with_mempool) {
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
262 UcxMap *map = ucx_map_new(4);
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
263
71
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
264 ucx_map_cstr_put(map, "test", (void*)"test");
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
265 ucx_map_cstr_put(map, "key", (void*)"value");
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
266 ucx_map_cstr_put(map, "testkey", (void*)"testvalue");
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
267 ucx_map_cstr_put(map, "simple", (void*)"a simple value");
48
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
268
55
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
269 UCX_TEST_BEGIN
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
270 FILE *f = tmpfile();
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
271 UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted");
48
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
272 int r;
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
273 r = ucx_map_store_enc(map, f, NULL, NULL);
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
274 ucx_map_free(map);
55
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
275 fflush(f);
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
276
48
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
277 UcxMempool *pool = ucx_mempool_new(4);
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
278 map = ucx_map_new(4);
55
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
279 fseek(f, 0, SEEK_SET);
48
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
280 UcxAllocator allocator = UCX_ALLOCATOR_MEMPOOL(pool);
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
281 r += ucx_map_load_enc(map, f, allocator,
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
282 test_ucx_map_store_load_encdec, NULL);
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
283 fclose(f);
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
284
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
285 UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed");
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
286 UcxMapIterator iter = ucx_map_iterator(map);
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
287 const char *value; size_t n;
48
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
288 UCX_MAP_FOREACH(value, iter) {
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
289 n = strlen(value);
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
290 UCX_TEST_ASSERT(strncmp((const char*) pool->data[iter.index], value, n),
48
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
291 "values of map does not match pooled values");
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
292 }
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
293
621a4430c404 map can now load values from file into pooled memory
Mike Becker <universe@uap-core.de>
parents: 46
diff changeset
294 ucx_mempool_free(pool);
55
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
295 ucx_map_free(map);
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 53
diff changeset
296 UCX_TEST_END
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
297 }
44
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
298
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
299 UCX_TEST_IMPLEMENT(test_ucx_map_clone) {
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
300 UcxMap *map = ucx_map_new(4);
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
301
71
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
302 ucx_map_cstr_put(map, "key1", (void*)"value1");
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
303 ucx_map_cstr_put(map, "key2", (void*)"value2");
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
304 ucx_map_cstr_put(map, "key3", (void*)"value3");
44
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
305
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
306 UcxMap *clone = ucx_map_clone(map, NULL, NULL);
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
307
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
308 const char *v1 = (const char *) ucx_map_cstr_get(map, "key1");
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
309 const char *v2 = (const char *) ucx_map_cstr_get(map, "key2");
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
310 const char *v3 = (const char *) ucx_map_cstr_get(map, "key3");
44
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
311
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
312 UCX_TEST_BEGIN
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
313
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
314 UCX_TEST_ASSERT(v1 != NULL, "failed key 1");
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
315 UCX_TEST_ASSERT(v2 != NULL, "failed key 2");
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
316 UCX_TEST_ASSERT(v3 != NULL, "failed key 3");
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
317
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
318 const char *c1 = (const char *) ucx_map_cstr_get(clone, "key1");
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
319 const char *c2 = (const char *) ucx_map_cstr_get(clone, "key2");
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
320 const char *c3 = (const char *) ucx_map_cstr_get(clone, "key3");
44
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
321
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
322 UCX_TEST_ASSERT(c1 != NULL, "failed key 1 (clone)");
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
323 UCX_TEST_ASSERT(c2 != NULL, "failed key 2 (clone)");
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
324 UCX_TEST_ASSERT(c3 != NULL, "failed key 3 (clone)");
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
325
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
326 UCX_TEST_ASSERT(strcmp(c1, v1) == 0, "value error for key1");
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
327 UCX_TEST_ASSERT(strcmp(c2, v2) == 0, "value error for key2");
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
328 UCX_TEST_ASSERT(strcmp(c3, v3) == 0, "value error for key3");
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
329
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
330 UCX_TEST_END
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
331
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
332 ucx_map_free(map);
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
333 ucx_map_free(clone);
46356d74e873 added map clone
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
334 }
51
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
335
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
336 UCX_TEST_IMPLEMENT(test_ucx_map_rehash) {
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
337 UcxMap *map = ucx_map_new(4);
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
338
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
339 char keys[10][5];
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
340 char values[10][7];
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
341 for (int i = 0 ; i < 10 ; i++) {
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
342 strcpy(keys[i], "key");
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
343 keys[i][3] = 48+i; keys[i][4] = 0;
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
344 strcpy(values[i], "value");
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
345 values[i][5] = 48+i; values[i][6] = 0;
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
346
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
347 ucx_map_cstr_put(map, keys[i], values[i]);
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
348 }
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
349
52
34f50d0bada4 added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
350 ucx_map_rehash(map);
51
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
351
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
352 UCX_TEST_BEGIN
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
353 UCX_TEST_ASSERT(map->size == 25, "new capacity shall be 2.5 * count");
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
354 UCX_TEST_ASSERT(map->count == 10, "new map element count incorrect");
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
355 for (int i = 0 ; i < 10 ; i++) {
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
356 const char *value = (const char *) ucx_map_cstr_get(map, keys[i]);
51
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
357 UCX_TEST_ASSERT(value != NULL, "new map is missing old keys");
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
358 UCX_TEST_ASSERT(strncmp(value, values[i], 6) == 0,
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
359 "new map contains incorrect values");
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
360 }
52
34f50d0bada4 added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
361 ucx_map_rehash(map);
34f50d0bada4 added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
362 UCX_TEST_ASSERT(map->size == 25,
51
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
363 "subsequent rehashing call shall not change size");
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
364 UCX_TEST_END
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
365
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
366 ucx_map_free(map);
1c78cd19fb6b added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
367 }

mercurial