test/test_map.cpp

changeset 604
056e5f592d84
parent 595
0da254bf23e6
child 630
ac5e7f789048
equal deleted inserted replaced
603:c49104015a6b 604:056e5f592d84
71 // verify key iterator 71 // verify key iterator
72 { 72 {
73 auto keyiter = cxMapIteratorKeys(map); 73 auto keyiter = cxMapIteratorKeys(map);
74 std::unordered_set<std::string> keys; 74 std::unordered_set<std::string> keys;
75 cx_foreach(CxHashKey*, elem, keyiter) { 75 cx_foreach(CxHashKey*, elem, keyiter) {
76 // we use that our test keys contain NULL-terminated strings 76 keys.insert(std::string(elem->data.cstr, elem->len));
77 keys.insert(std::string(elem->data.cstr));
78 } 77 }
79 EXPECT_EQ(keyiter.index, map->size); 78 EXPECT_EQ(keyiter.index, map->size);
80 ASSERT_EQ(keys.size(), map->size); 79 ASSERT_EQ(keys.size(), map->size);
81 for (auto &&k: keys) { 80 for (auto &&k: keys) {
82 EXPECT_NE(refmap.find(k), refmap.end()); 81 EXPECT_NE(refmap.find(k), refmap.end());
101 // verify pair iterator 100 // verify pair iterator
102 { 101 {
103 auto pairiter = cxMapIterator(map); 102 auto pairiter = cxMapIterator(map);
104 std::unordered_map<std::string, std::string> pairs; 103 std::unordered_map<std::string, std::string> pairs;
105 cx_foreach(CxMapEntry*, entry, pairiter) { 104 cx_foreach(CxMapEntry*, entry, pairiter) {
106 pairs[std::string(entry->key->data.cstr)] = std::string((char *) entry->value); 105 pairs[std::string(entry->key->data.cstr, entry->key->len)] = std::string((char *) entry->value);
107 } 106 }
108 EXPECT_EQ(pairiter.index, map->size); 107 EXPECT_EQ(pairiter.index, map->size);
109 ASSERT_EQ(pairs.size(), refmap.size()); 108 ASSERT_EQ(pairs.size(), refmap.size());
110 for (auto &&p: pairs) { 109 for (auto &&p: pairs) {
111 ASSERT_EQ(p.second, refmap.at(p.first)); 110 ASSERT_EQ(p.second, refmap.at(p.first));

mercurial