test/map_tests.c

Thu, 04 Oct 2012 18:23:32 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 04 Oct 2012 18:23:32 +0200
changeset 43
02f38adea013
parent 42
ff3dd1ee7dee
child 44
46356d74e873
permissions
-rw-r--r--

fixed crash fails by completing the implementation of the tested function....

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) {
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
18 UcxKey key = ucx_key("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
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
20 UCX_TEST_ASSERT(strncmp(key.data, "This is a text.", 15) == 0, "failed");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
21 UCX_TEST_ASSERT(key.len == 15, "failed");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
22 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
23
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
24 UCX_TEST_END
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
25 }
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
26
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
27 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
28
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
29 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
30
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
31 int td[5];
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
32 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
33
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
34 UCX_TEST_BEGIN
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
35 ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
36 ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
37 ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
38 ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
39 ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
40
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
41 UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[0], "failed Key0");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
42 UCX_TEST_ASSERT(map->map[0]->next != NULL, "no list at slot 0");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
43 UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2], "failed Key2");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
44 UCX_TEST_ASSERT(map->map[0]->next->next != NULL, "list corrupt at slot 0");
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
45 UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4],
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
46 "failed Key4")
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
47 UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL,
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
48 "slot 0 not terminated")
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
49
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
50 UCX_TEST_ASSERT(map->map[1] == NULL, "slot 1 not terminated");
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
51
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
52 UCX_TEST_ASSERT(*((int*)map->map[2]->data) == td[3], "failed KeY3");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
53 UCX_TEST_ASSERT(map->map[2]->next == NULL, "slot 2 not terminated");
20
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
55 UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1], "failed Key1");
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
56
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
57 ucx_map_cstr_put(map, "Key0", &td[3]); /* 0 */
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
58
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
59 UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[3], "overwrite failed");
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
60 UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2],
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
61 "overwrite failed")
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
62 UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4],
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
63 "overwrite failed")
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
64 UCX_TEST_ASSERT(map->map[0]->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
65
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
66 UCX_TEST_END
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
67 ucx_map_free(map);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
68 }
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
69
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
70 UCX_TEST_IMPLEMENT(test_ucx_map_get) {
34
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
71 UcxMap *map = ucx_map_new(4);
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
72
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
73 int td[5];
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
74 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
75
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
76 ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
77 ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
78 ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
79 ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
80 ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
81 UCX_TEST_BEGIN
34
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
82
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
83 td[0] = *((int*)ucx_map_cstr_get(map, "Key0"));
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
84 td[1] = *((int*)ucx_map_cstr_get(map, "Key1"));
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
85 td[2] = *((int*)ucx_map_cstr_get(map, "Key2"));
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
86 td[3] = *((int*)ucx_map_cstr_get(map, "KeY3"));
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
87 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
88 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
89 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
90 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
91 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
92 UCX_TEST_ASSERT(td[4] == 80000, "failed key 4");
34
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
93
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
94 UCX_TEST_END
34
0dcd2ca2a223 completed map tests
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
95 ucx_map_free(map);
20
db7d9860dbbd added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 }
29
bce0d7f2912b fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
97
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
98 UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, mapptr) {
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
99 UcxMap *map = (UcxMap*) mapptr;
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
100 int v1 = 10;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
101 int v2 = 15;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
102 int v3 = 7;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
103 int v4 = 9;
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
104
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
105 ucx_map_cstr_put(map, "v1", &v1);
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
106 ucx_map_cstr_put(map, "v2", &v2);
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
107 ucx_map_cstr_put(map, "v3", &v3);
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
108 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
109
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
110 UcxMapIterator i = ucx_map_iterator(map);
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
111 int check = 0;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
112 int hit = 0;
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
113
41
7f90a03e186e simplified UCX_MAP_FOREACH
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
114 int* v;
7f90a03e186e simplified UCX_MAP_FOREACH
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
115 UCX_MAP_FOREACH(v, i) {
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
116 check += *v;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
117 hit++;
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
118 }
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
119
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
120 UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits");
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
121 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
122 }
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
123
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
124 UCX_TEST_IMPLEMENT(test_ucx_map_iterator) {
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
125 UcxMap *map = ucx_map_new(16);
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
126 UCX_TEST_BEGIN
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
127 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
128 UCX_TEST_END
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
129 ucx_map_free(map);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
130 }
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
131
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
132 UCX_TEST_IMPLEMENT(test_ucx_map_iterator_chain) {
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
133 UcxMap *map = ucx_map_new(1);
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
134 UCX_TEST_BEGIN
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
135 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
136 UCX_TEST_END
31
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
137 ucx_map_free(map);
91ac86557290 added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
138 }
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
139
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
140 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
141 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
142
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
143 ucx_map_cstr_put(map, "test", "test");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
144 ucx_map_cstr_put(map, "key", "value");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
145 ucx_map_cstr_put(map, "other.very.long.key", "value");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
146 ucx_map_cstr_put(map, "testkey", "testvalue");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
147 ucx_map_cstr_put(map, "simple", "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
148 "to test if the buffer extension works as designed");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
149
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
150 FILE *f = fopen("test_ucx_map_store", "w");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
151 int r;
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
152
43
02f38adea013 fixed crash fails by completing the implementation of the tested function....
Mike Becker <universe@uap-core.de>
parents: 42
diff changeset
153 fwrite(" # comment test\n", 1, 16, f);
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
154 r = ucx_map_store(map, f);
43
02f38adea013 fixed crash fails by completing the implementation of the tested function....
Mike Becker <universe@uap-core.de>
parents: 42
diff changeset
155 fwrite("!discard this", 1, 13, f);
42
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
156
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
157 fclose(f);
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
158 ucx_map_free(map);
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
159 map = ucx_map_new(1);
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
160 f = fopen("test_ucx_map_store", "r");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
161 r += ucx_map_load(map, f);
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
162
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
163 UCX_TEST_BEGIN
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
164 char *value;
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
165 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
166
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
167 value = 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
168 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
169 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
170
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
171 value = 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
172 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
173 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
174
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
175 value = 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
176 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
177 "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
178 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
179 "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
180
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
181 value = 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
182 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
183 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
184 "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
185
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
186 value = 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
187 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
188 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
189 "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
190 "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
191
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
192 UCX_TEST_END
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
193 fclose(f);
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
194
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
195 unlink("test_ucx_map_store");
ff3dd1ee7dee (broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents: 41
diff changeset
196 }

mercurial