Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/compiled/StringMap.cpp

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

Powered by Google App Engine
This is Rietveld