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

Side by Side Diff: test/compiled/StringMap.cpp

Issue 29721753: Issue 6180 - use ABP_TEXT everywhere in order to let String be a UTF-8 string (Closed) Base URL: https://github.com/adblockplus/adblockpluscore.git@adb2678354813ce5b6de095072954c5a784a7bc4
Patch Set: Created March 13, 2018, 6:20 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 10 matching lines...) Expand all
21 21
22 ABP_NS_USING 22 ABP_NS_USING
23 23
24 template<template <typename T> class S> 24 template<template <typename T> class S>
25 void testStringMap() 25 void testStringMap()
26 { 26 {
27 S<std::string> map; 27 S<std::string> map;
28 28
29 EXPECT_EQ(map.begin(), map.end()); 29 EXPECT_EQ(map.begin(), map.end());
30 30
31 auto key = u"Foobar"_str; 31 auto key = ABP_TEXT("Foobar"_str);
32 EXPECT_EQ(6u, key.length()); 32 EXPECT_EQ(6u, key.length());
33 EXPECT_EQ(0u, map.size()); 33 EXPECT_EQ(0u, map.size());
34 34
35 map[u"Foobar"_str] = "one"; 35 map[ABP_TEXT("Foobar"_str)] = "one";
36 EXPECT_EQ(1u, map.size()); 36 EXPECT_EQ(1u, map.size());
37 EXPECT_NE(map.begin(), map.end()); 37 EXPECT_NE(map.begin(), map.end());
38 38
39 map[u""_str] = "null"; 39 map[ABP_TEXT(""_str)] = "null";
40 EXPECT_EQ(2u, map.size()); 40 EXPECT_EQ(2u, map.size());
41 41
42 auto entry = map.find(u"Foobar"_str); 42 auto entry = map.find(ABP_TEXT("Foobar"_str));
43 EXPECT_TRUE(entry); 43 EXPECT_TRUE(entry);
44 44
45 entry = map.find(u"Foobar2"_str); 45 entry = map.find(ABP_TEXT("Foobar2"_str));
46 EXPECT_FALSE(entry); 46 EXPECT_FALSE(entry);
47 47
48 map[u"Foobar2"_str] = "two"; 48 map[ABP_TEXT("Foobar2"_str)] = "two";
49 entry = map.find(u"Foobar2"_str); 49 entry = map.find(ABP_TEXT("Foobar2"_str));
50 EXPECT_TRUE(entry); 50 EXPECT_TRUE(entry);
51 51
52 map[u"Foobar3"_str] = "three"; 52 map[ABP_TEXT("Foobar3"_str)] = "three";
53 entry = map.find(u"Foobar3"_str); 53 entry = map.find(ABP_TEXT("Foobar3"_str));
54 EXPECT_TRUE(entry); 54 EXPECT_TRUE(entry);
55 55
56 EXPECT_EQ(4u, map.size()); 56 EXPECT_EQ(4u, map.size());
57 57
58 EXPECT_TRUE(map.erase(u"Foobar2"_str)); 58 EXPECT_TRUE(map.erase(ABP_TEXT("Foobar2"_str)));
59 // already deleted. Returns false. 59 // already deleted. Returns false.
60 EXPECT_FALSE(map.erase(u"Foobar2"_str)); 60 EXPECT_FALSE(map.erase(ABP_TEXT("Foobar2"_str)));
61 // invalid. Returns false. 61 // invalid. Returns false.
62 EXPECT_FALSE(map.erase(u"Foobar42"_str)); 62 EXPECT_FALSE(map.erase(ABP_TEXT("Foobar42"_str)));
63 63
64 EXPECT_EQ(4u, map.size()); 64 EXPECT_EQ(4u, map.size());
65 65
66 entry = map.find(u"Foobar2"_str); 66 entry = map.find(ABP_TEXT("Foobar2"_str));
67 EXPECT_FALSE(entry); 67 EXPECT_FALSE(entry);
68 68
69 uint32_t i = 0; 69 uint32_t i = 0;
70 for (const auto& e : map) 70 for (const auto& e : map)
71 { 71 {
72 EXPECT_FALSE(e.is_invalid()); 72 EXPECT_FALSE(e.is_invalid());
73 // entries that are deleted shouldn't be returned. 73 // entries that are deleted shouldn't be returned.
74 EXPECT_FALSE(e.is_deleted()); 74 EXPECT_FALSE(e.is_deleted());
75 i++; 75 i++;
76 } 76 }
77 77
78 EXPECT_EQ(3u, i); 78 EXPECT_EQ(3u, i);
79 // We did not return deleted entries (there is one). 79 // We did not return deleted entries (there is one).
80 // So size is different than actual count. 80 // So size is different than actual count.
81 EXPECT_NE(i, map.size()); 81 EXPECT_NE(i, map.size());
82 } 82 }
83 83
84 TEST(TestStringMap, stringMap) 84 TEST(TestStringMap, stringMap)
85 { 85 {
86 testStringMap<StringMap>(); 86 testStringMap<StringMap>();
87 } 87 }
88 88
89 TEST(TestStringMap, ownedStringMap) 89 TEST(TestStringMap, ownedStringMap)
90 { 90 {
91 testStringMap<OwnedStringMap>(); 91 testStringMap<OwnedStringMap>();
92 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld