| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 */ | |
| 1 | 17 |
| 2 #include <string> | 18 #include <string> |
|
sergei
2018/01/26 22:13:36
Could you please remove the empty lines and add th
hub
2018/01/27 03:33:37
Done.
| |
| 3 | |
| 4 #include "gtest/gtest.h" | 19 #include "gtest/gtest.h" |
| 5 | |
| 6 #include "compiled/StringMap.h" | 20 #include "compiled/StringMap.h" |
| 7 | 21 |
| 8 template<template <typename T> class S> | 22 template<template <typename T> class S> |
| 9 void testStringMap() | 23 void testStringMap() |
| 10 { | 24 { |
| 11 S<std::string> map; | 25 S<std::string> map; |
| 12 auto key = u"Foobar"_str; | 26 auto key = u"Foobar"_str; |
| 13 EXPECT_EQ(key.length(), 6); | 27 EXPECT_EQ(key.length(), 6); |
| 14 EXPECT_EQ(map.size(), 0); | 28 EXPECT_EQ(map.size(), 0); |
| 15 | 29 |
| 16 map[u"Foobar"_str] = std::string("one"); | 30 map[u"Foobar"_str] = "one"; |
| 17 EXPECT_EQ(map.size(), 1); | 31 EXPECT_EQ(map.size(), 1); |
| 18 | 32 |
| 19 map[u""_str] = std::string("null"); | 33 map[u""_str] = "null"; |
| 20 EXPECT_EQ(map.size(), 2); | 34 EXPECT_EQ(map.size(), 2); |
| 21 | 35 |
| 22 auto entry = map.find(u"Foobar"_str); | 36 auto entry = map.find(u"Foobar"_str); |
| 23 EXPECT_TRUE(entry); | 37 EXPECT_TRUE(entry); |
| 24 | 38 |
| 25 entry = map.find(u"Foobar2"_str); | 39 entry = map.find(u"Foobar2"_str); |
| 26 EXPECT_FALSE(entry); | 40 EXPECT_FALSE(entry); |
| 27 | 41 |
| 28 map[u"Foobar2"_str] = std::string("two"); | 42 map[u"Foobar2"_str] = "two"; |
| 29 entry = map.find(u"Foobar2"_str); | 43 entry = map.find(u"Foobar2"_str); |
| 30 EXPECT_TRUE(entry); | 44 EXPECT_TRUE(entry); |
| 31 | 45 |
| 32 map[u"Foobar3"_str] = std::string("three"); | 46 map[u"Foobar3"_str] = "three"; |
| 33 entry = map.find(u"Foobar3"_str); | 47 entry = map.find(u"Foobar3"_str); |
| 34 EXPECT_TRUE(entry); | 48 EXPECT_TRUE(entry); |
| 35 | 49 |
| 36 EXPECT_EQ(map.size(), 4); | 50 EXPECT_EQ(map.size(), 4); |
| 37 | 51 |
| 38 map.erase(u"Foobar2"_str); | 52 map.erase(u"Foobar2"_str); |
| 39 | 53 |
| 40 // DISABLED. This should be true, but it isn't | 54 // DISABLED. This should be true, but it isn't |
| 41 //EXPECT_EQ(map.size(), 2); | 55 //EXPECT_EQ(map.size(), 3); |
| 42 | 56 |
| 43 entry = map.find(u"Foobar2"_str); | 57 entry = map.find(u"Foobar2"_str); |
| 44 EXPECT_FALSE(entry); | 58 EXPECT_FALSE(entry); |
| 45 | 59 |
| 46 int i = 0; | 60 int i = 0; |
| 47 for (const auto& e : map) | 61 for (const auto& e : map) |
| 48 { | 62 { |
| 49 EXPECT_FALSE(e.is_invalid()); | 63 EXPECT_FALSE(e.is_invalid()); |
| 50 // DISABLED entries that are deleted shouldn't be returned. | 64 // DISABLED entries that are deleted shouldn't be returned. |
| 51 // See issue #6281 | 65 // See issue #6281 |
| 52 //EXPECT_FALSE(e.is_deleted()); | 66 //EXPECT_FALSE(e.is_deleted()); |
| 53 i++; | 67 i++; |
| 54 } | 68 } |
| 55 | 69 |
| 56 EXPECT_EQ(i, 4); // SHOULD be 3. See issue #6281 | 70 EXPECT_EQ(i, 4); // SHOULD be 3. See issue #6281 |
| 57 EXPECT_EQ(i, map.size()); | 71 EXPECT_EQ(i, map.size()); |
| 58 } | 72 } |
| 59 | 73 |
| 60 TEST(TestStringMap, stringMap) | 74 TEST(TestStringMap, stringMap) |
| 61 { | 75 { |
| 62 testStringMap<StringMap>(); | 76 testStringMap<StringMap>(); |
| 63 } | 77 } |
| 64 | 78 |
| 65 TEST(TestStringMap, ownedStringMap) | 79 TEST(TestStringMap, ownedStringMap) |
| 66 { | 80 { |
| 67 testStringMap<OwnedStringMap>(); | 81 testStringMap<OwnedStringMap>(); |
| 68 } | 82 } |
| LEFT | RIGHT |