Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-present eyeo GmbH | |
4 * | |
5 * Adblock Plus is free software: you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License version 3 as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
18 #include <string> | |
19 #include "gtest/gtest.h" | |
20 #include "compiled/StringMap.h" | |
21 | |
22 template<template <typename T> class S> | |
23 void testStringMap() | |
24 { | |
25 S<std::string> map; | |
26 auto key = u"Foobar"_str; | |
27 EXPECT_EQ(key.length(), 6); | |
28 EXPECT_EQ(map.size(), 0); | |
29 | |
30 map[u"Foobar"_str] = std::string("one"); | |
sergei
2018/01/29 13:38:44
just wonder, is it required to use `std::string("o
hub
2018/01/29 16:57:46
constructor is implicit, so it is not needed.
| |
31 EXPECT_EQ(map.size(), 1); | |
32 | |
33 map[u""_str] = std::string("null"); | |
34 EXPECT_EQ(map.size(), 2); | |
35 | |
36 auto entry = map.find(u"Foobar"_str); | |
37 EXPECT_TRUE(entry); | |
38 | |
39 entry = map.find(u"Foobar2"_str); | |
40 EXPECT_FALSE(entry); | |
41 | |
42 map[u"Foobar2"_str] = std::string("two"); | |
43 entry = map.find(u"Foobar2"_str); | |
44 EXPECT_TRUE(entry); | |
45 | |
46 map[u"Foobar3"_str] = std::string("three"); | |
47 entry = map.find(u"Foobar3"_str); | |
48 EXPECT_TRUE(entry); | |
49 | |
50 EXPECT_EQ(map.size(), 4); | |
51 | |
52 map.erase(u"Foobar2"_str); | |
53 | |
54 // DISABLED. This should be true, but it isn't | |
55 //EXPECT_EQ(map.size(), 2); | |
sergei
2018/01/29 13:38:44
it should be compared against 3, not 2.
hub
2018/01/29 16:57:46
forgot to change that one.
Done
| |
56 | |
57 entry = map.find(u"Foobar2"_str); | |
58 EXPECT_FALSE(entry); | |
59 | |
60 int i = 0; | |
61 for (const auto& e : map) | |
62 { | |
63 EXPECT_FALSE(e.is_invalid()); | |
64 // DISABLED entries that are deleted shouldn't be returned. | |
65 // See issue #6281 | |
66 //EXPECT_FALSE(e.is_deleted()); | |
67 i++; | |
68 } | |
69 | |
70 EXPECT_EQ(i, 4); // SHOULD be 3. See issue #6281 | |
71 EXPECT_EQ(i, map.size()); | |
72 } | |
73 | |
74 TEST(TestStringMap, stringMap) | |
75 { | |
76 testStringMap<StringMap>(); | |
77 } | |
78 | |
79 TEST(TestStringMap, ownedStringMap) | |
80 { | |
81 testStringMap<OwnedStringMap>(); | |
82 } | |
OLD | NEW |