test/test_map.cpp

Fri, 27 May 2022 12:59:41 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 27 May 2022 12:59:41 +0200
changeset 557
2aae1246b578
parent 556
3d19cae7e924
child 561
bb17790af41e
permissions
-rw-r--r--

remove unused header

556
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "cx/hash_map.h"
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 #include "cx/utils.h"
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 #include "util_allocator.h"
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 #include <gtest/gtest.h>
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 #include <unordered_map>
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 #include <unordered_set>
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 struct map_operation {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 enum {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 put, rm
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 } op;
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 char const *key;
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 char const *value;
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 };
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 auto generate_map_operations() -> std::vector<map_operation> {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 return {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 {map_operation::put, "key 1", "test"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 {map_operation::put, "key 2", "blub"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 {map_operation::put, "key 3", "hallo"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 {map_operation::put, "key 2", "foobar"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 {map_operation::put, "key 4", "value 4"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 {map_operation::put, "key 5", "value 5"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 {map_operation::put, "key 6", "value 6"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 {map_operation::rm, "key 4", nullptr},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 {map_operation::put, "key 7", "value 7"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 {map_operation::put, "key 8", "value 8"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 {map_operation::rm, "does not exist", nullptr},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 {map_operation::put, "key 9", "value 9"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 {map_operation::put, "key 6", "other value"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 {map_operation::put, "key 7", "something else"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 {map_operation::rm, "key 8", nullptr},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 {map_operation::rm, "key 2", nullptr},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 {map_operation::put, "key 8", "new value"},
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 };
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 static void verify_map_contents(
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 CxMap *map,
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 std::unordered_map<std::string, std::string> const &refmap
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 ) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 // verify key iterator
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 auto keyiter = cxMapIteratorKeys(map);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 std::unordered_set<std::string> keys;
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 cx_foreach(CxDataPtr*, elem, keyiter) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 // we use that our test keys contain NULL-terminated strings
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 keys.insert(std::string(reinterpret_cast<const char *>(elem->data)));
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 ASSERT_EQ(keys.size(), map->size);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 for (auto &&k: keys) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 EXPECT_NE(refmap.find(k), refmap.end());
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 // verify value iterator
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 auto valiter = cxMapIteratorValues(map);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 std::unordered_set<std::string> values; // we use that the values in our test data are unique strings
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 cx_foreach(char const*, elem, valiter) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 values.insert(std::string(elem));
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 ASSERT_EQ(values.size(), map->size);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 for (auto &&v: values) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 EXPECT_NE(std::find_if(refmap.begin(), refmap.end(),
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 [v](auto const &e) { return e.second == v; }), refmap.end());
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 // verify pair iterator
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 auto pairiter = cxMapIterator(map);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 std::unordered_map<std::string, std::string> pairs;
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 cx_foreach(CxMapEntry*, entry, pairiter) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 pairs[std::string((char const *) entry->key->data)] = std::string((char *) entry->value);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 ASSERT_EQ(pairs.size(), refmap.size());
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 for (auto &&p: pairs) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 ASSERT_EQ(p.second, refmap.at(p.first));
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 TEST(CxHashMap, Create) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 CxTestingAllocator allocator;
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 auto map = cxHashMapCreate(&allocator, 0);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 auto hmap = reinterpret_cast<struct cx_hash_map_s *>(map);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 EXPECT_GT(hmap->bucket_count, 0);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 cx_for_n(i, hmap->bucket_count) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 EXPECT_EQ(hmap->buckets[i], nullptr);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 EXPECT_EQ(map->size, 0);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 EXPECT_EQ(map->allocator, &allocator);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 cxMapDestroy(map);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 EXPECT_TRUE(allocator.verify());
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 TEST(CxHashMap, BasicOperations) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 // create the map
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 CxTestingAllocator allocator;
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 auto map = cxHashMapCreate(&allocator, 8);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 // create a reference map
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 std::unordered_map<std::string, std::string> refmap;
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 // generate operations
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 auto ops = generate_map_operations();
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 // verify iterators for empty map
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 verify_map_contents(map, refmap);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 // execute operations and verify results
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 for (auto &&op: ops) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 CxDataPtr key = {reinterpret_cast<const unsigned char *>(op.key), 1 + strlen(op.key)};
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 if (op.op == map_operation::put) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 // execute a put operation and verify that the exact value can be read back
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 refmap[std::string(op.key)] = std::string(op.value);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 int result = cxMapPut(map, key, (void *) op.value);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 EXPECT_EQ(result, 0);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 auto added = cxMapGet(map, key);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 EXPECT_EQ(memcmp(op.value, added, strlen(op.value)), 0);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 } else {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 // execute a remove and verify that the removed element was returned (or nullptr)
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 auto found = refmap.find(op.key);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 auto removed = cxMapRemove(map, key);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 if (found == refmap.end()) {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 EXPECT_EQ(removed, nullptr);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 } else {
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 EXPECT_EQ(std::string((char *) removed), found->second);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 refmap.erase(found);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 // compare the current map state with the reference map
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 verify_map_contents(map, refmap);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 }
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 // destroy the map and verify the memory (de)allocations
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 cxMapDestroy(map);
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 EXPECT_TRUE(allocator.verify());
3d19cae7e924 #199 tests for hash map
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170 }

mercurial