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

Side by Side Diff: test/compiled/String.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 26 matching lines...) Expand all
37 37
38 // Valid string 38 // Valid string
39 OwnedString s2(2); 39 OwnedString s2(2);
40 EXPECT_FALSE(s2.is_invalid()); 40 EXPECT_FALSE(s2.is_invalid());
41 41
42 // Ensure we still have an invalid string. 42 // Ensure we still have an invalid string.
43 OwnedString s3(s); 43 OwnedString s3(s);
44 EXPECT_TRUE(s3.is_invalid()); 44 EXPECT_TRUE(s3.is_invalid());
45 45
46 // Empty valid string lead to valid string. 46 // Empty valid string lead to valid string.
47 OwnedString s4(u""_str); 47 OwnedString s4(ABP_TEXT(""_str));
48 EXPECT_FALSE(s4.is_invalid()); 48 EXPECT_FALSE(s4.is_invalid());
49 } 49 }
50 50
51 TEST(TestStringTrimSpaces, zeroLengthString) 51 TEST(TestStringTrimSpaces, zeroLengthString)
52 { 52 {
53 EXPECT_EQ(u""_str, TrimSpaces(DependentString())); 53 EXPECT_EQ(ABP_TEXT(""_str), TrimSpaces(DependentString()));
54 EXPECT_EQ(u""_str, TrimSpaces(OwnedString())); 54 EXPECT_EQ(ABP_TEXT(""_str), TrimSpaces(OwnedString()));
55 EXPECT_EQ(u""_str, TrimSpaces(u""_str)); 55 EXPECT_EQ(ABP_TEXT(""_str), TrimSpaces(ABP_TEXT(""_str)));
56 } 56 }
57 57
58 TEST(TestStringTrimSpaces, spacesAreRemoved) 58 TEST(TestStringTrimSpaces, spacesAreRemoved)
59 { 59 {
60 for (uint16_t leftSpaces = 0; leftSpaces < 5; ++leftSpaces) 60 for (uint16_t leftSpaces = 0; leftSpaces < 5; ++leftSpaces)
61 { 61 {
62 for (uint16_t rightSpaces = 0; rightSpaces < 5; ++rightSpaces) 62 for (uint16_t rightSpaces = 0; rightSpaces < 5; ++rightSpaces)
63 { 63 {
64 for (uint16_t nonSpaces = 0; nonSpaces < 5; ++nonSpaces) 64 for (uint16_t nonSpaces = 0; nonSpaces < 5; ++nonSpaces)
65 { 65 {
66 OwnedString str; 66 OwnedString str;
67 std::string leftSpacesStdString(leftSpaces, ' '); 67 std::string leftSpacesStdString(leftSpaces, ' ');
68 str.append(leftSpacesStdString.c_str(), leftSpacesStdString.length()); 68 str.append(leftSpacesStdString.c_str(), leftSpacesStdString.length());
69 std::string stdString(nonSpaces, 'a'); 69 std::string stdString(nonSpaces, 'a');
70 OwnedString trimmedString; 70 OwnedString trimmedString;
71 trimmedString.append(stdString.c_str(), stdString.length()); 71 trimmedString.append(stdString.c_str(), stdString.length());
72 str.append(trimmedString); 72 str.append(trimmedString);
73 std::string rightSpacesStdString(rightSpaces, ' '); 73 std::string rightSpacesStdString(rightSpaces, ' ');
74 str.append(rightSpacesStdString.c_str(), rightSpacesStdString.length()); 74 str.append(rightSpacesStdString.c_str(), rightSpacesStdString.length());
75 EXPECT_EQ(trimmedString, TrimSpaces(str)); 75 EXPECT_EQ(trimmedString, TrimSpaces(str));
76 } 76 }
77 } 77 }
78 } 78 }
79 } 79 }
80 80
81 TEST(TestStringSplitString, test) 81 TEST(TestStringSplitString, test)
82 { 82 {
83 { 83 {
84 auto str = u"123:abc"_str; 84 auto str = ABP_TEXT("123:abc"_str);
85 auto split = SplitString(str, 3); 85 auto split = SplitString(str, 3);
86 EXPECT_EQ(u"123"_str, split.first); 86 EXPECT_EQ(ABP_TEXT("123"_str), split.first);
87 EXPECT_EQ(u"abc"_str, split.second); 87 EXPECT_EQ(ABP_TEXT("abc"_str), split.second);
88 } 88 }
89 { 89 {
90 auto str = u"123:abc"_str; 90 auto str = ABP_TEXT("123:abc"_str);
91 auto split = SplitString(str, 0); 91 auto split = SplitString(str, 0);
92 EXPECT_EQ(u""_str, split.first); 92 EXPECT_EQ(ABP_TEXT(""_str), split.first);
93 EXPECT_EQ(u"23:abc"_str, split.second); 93 EXPECT_EQ(ABP_TEXT("23:abc"_str), split.second);
94 } 94 }
95 { 95 {
96 auto str = u"123:abc"_str; 96 auto str = ABP_TEXT("123:abc"_str);
97 auto split = SplitString(str, 6); 97 auto split = SplitString(str, 6);
98 EXPECT_EQ(u"123:ab"_str, split.first); 98 EXPECT_EQ(ABP_TEXT("123:ab"_str), split.first);
99 EXPECT_EQ(u""_str, split.second); 99 EXPECT_EQ(ABP_TEXT(""_str), split.second);
100 } 100 }
101 { 101 {
102 auto str = u"123:abc"_str; 102 auto str = ABP_TEXT("123:abc"_str);
103 auto split = SplitString(str, 7); 103 auto split = SplitString(str, 7);
104 EXPECT_EQ(u"123:abc"_str, split.first); 104 EXPECT_EQ(ABP_TEXT("123:abc"_str), split.first);
105 EXPECT_EQ(u""_str, split.second); 105 EXPECT_EQ(ABP_TEXT(""_str), split.second);
106 } 106 }
107 { 107 {
108 auto str = u"123:abc"_str; 108 auto str = ABP_TEXT("123:abc"_str);
109 auto split = SplitString(str, 10); 109 auto split = SplitString(str, 10);
110 EXPECT_EQ(u"123:abc"_str, split.first); 110 EXPECT_EQ(ABP_TEXT("123:abc"_str), split.first);
111 EXPECT_EQ(u""_str, split.second); 111 EXPECT_EQ(ABP_TEXT(""_str), split.second);
112 } 112 }
113 } 113 }
114 114
115 TEST(TestStringLexicalCast, toIntegers) 115 TEST(TestStringLexicalCast, toIntegers)
116 { 116 {
117 EXPECT_EQ(0, lexical_cast<int32_t>(u"0"_str)); 117 EXPECT_EQ(0, lexical_cast<int32_t>(ABP_TEXT("0"_str)));
118 EXPECT_EQ(1, lexical_cast<int32_t>(u"1"_str)); 118 EXPECT_EQ(1, lexical_cast<int32_t>(ABP_TEXT("1"_str)));
119 EXPECT_EQ(2, lexical_cast<int32_t>(u"2"_str)); 119 EXPECT_EQ(2, lexical_cast<int32_t>(ABP_TEXT("2"_str)));
120 EXPECT_EQ(10, lexical_cast<int32_t>(u"10"_str)); 120 EXPECT_EQ(10, lexical_cast<int32_t>(ABP_TEXT("10"_str)));
121 EXPECT_EQ(10, lexical_cast<int32_t>(u"010"_str)); 121 EXPECT_EQ(10, lexical_cast<int32_t>(ABP_TEXT("010"_str)));
122 EXPECT_EQ(-1, lexical_cast<int32_t>(u"-1"_str)); 122 EXPECT_EQ(-1, lexical_cast<int32_t>(ABP_TEXT("-1"_str)));
123 EXPECT_EQ(-2, lexical_cast<int32_t>(u"-2"_str)); 123 EXPECT_EQ(-2, lexical_cast<int32_t>(ABP_TEXT("-2"_str)));
124 EXPECT_EQ(-20, lexical_cast<int32_t>(u"-20"_str)); 124 EXPECT_EQ(-20, lexical_cast<int32_t>(ABP_TEXT("-20"_str)));
125 EXPECT_EQ(-20, lexical_cast<int32_t>(u"-020"_str)); 125 EXPECT_EQ(-20, lexical_cast<int32_t>(ABP_TEXT("-020"_str)));
126 EXPECT_EQ(0, lexical_cast<int32_t>(u"0-2"_str)); 126 EXPECT_EQ(0, lexical_cast<int32_t>(ABP_TEXT("0-2"_str)));
127 EXPECT_EQ(-2147483647, lexical_cast<int32_t>(u"-2147483647"_str)); 127 EXPECT_EQ(-2147483647, lexical_cast<int32_t>(ABP_TEXT("-2147483647"_str)));
128 EXPECT_EQ(-2147483648, lexical_cast<int32_t>(u"-2147483648"_str)); 128 EXPECT_EQ(-2147483648, lexical_cast<int32_t>(ABP_TEXT("-2147483648"_str)));
129 EXPECT_EQ( 0, lexical_cast<int32_t>(u"-2147483649"_str)); 129 EXPECT_EQ( 0, lexical_cast<int32_t>(ABP_TEXT("-2147483649"_str)));
130 EXPECT_EQ( 0, lexical_cast<int32_t>(u"-2157483649"_str)); 130 EXPECT_EQ( 0, lexical_cast<int32_t>(ABP_TEXT("-2157483649"_str)));
131 EXPECT_EQ( 0, lexical_cast<int32_t>(u"-3147483649"_str)); 131 EXPECT_EQ( 0, lexical_cast<int32_t>(ABP_TEXT("-3147483649"_str)));
132 EXPECT_EQ(-2147483648, lexical_cast<int32_t>(u"-02147483648"_str)); 132 EXPECT_EQ(-2147483648, lexical_cast<int32_t>(ABP_TEXT("-02147483648"_str)));
133 EXPECT_EQ(-2147483648, lexical_cast<int32_t>(u"-000002147483648"_str)); 133 EXPECT_EQ(-2147483648, lexical_cast<int32_t>(ABP_TEXT("-000002147483648"_str)) );
134 EXPECT_EQ( 0, lexical_cast<int32_t>(u"-21474836480"_str)); 134 EXPECT_EQ( 0, lexical_cast<int32_t>(ABP_TEXT("-21474836480"_str)));
135 EXPECT_EQ(2147483647, lexical_cast<int32_t>(u"2147483647"_str)); 135 EXPECT_EQ(2147483647, lexical_cast<int32_t>(ABP_TEXT("2147483647"_str)));
136 EXPECT_EQ(2147483647, lexical_cast<int32_t>(u"000002147483647"_str)); 136 EXPECT_EQ(2147483647, lexical_cast<int32_t>(ABP_TEXT("000002147483647"_str)));
137 EXPECT_EQ(2147483647, lexical_cast<int32_t>(u"02147483647"_str)); 137 EXPECT_EQ(2147483647, lexical_cast<int32_t>(ABP_TEXT("02147483647"_str)));
138 EXPECT_EQ( 0, lexical_cast<int32_t>(u"21474836470"_str)); 138 EXPECT_EQ( 0, lexical_cast<int32_t>(ABP_TEXT("21474836470"_str)));
139 EXPECT_EQ( 0, lexical_cast<int32_t>(u"2147483648"_str)); 139 EXPECT_EQ( 0, lexical_cast<int32_t>(ABP_TEXT("2147483648"_str)));
140 EXPECT_EQ( 0, lexical_cast<int32_t>(u"2157483648"_str)); 140 EXPECT_EQ( 0, lexical_cast<int32_t>(ABP_TEXT("2157483648"_str)));
141 EXPECT_EQ( 0, lexical_cast<int32_t>(u"3147483648"_str)); 141 EXPECT_EQ( 0, lexical_cast<int32_t>(ABP_TEXT("3147483648"_str)));
142 EXPECT_EQ(0u, lexical_cast<uint32_t>(u"0"_str)); 142 EXPECT_EQ(0u, lexical_cast<uint32_t>(ABP_TEXT("0"_str)));
143 EXPECT_EQ(2u, lexical_cast<uint32_t>(u"2"_str)); 143 EXPECT_EQ(2u, lexical_cast<uint32_t>(ABP_TEXT("2"_str)));
144 EXPECT_EQ(123u, lexical_cast<uint32_t>(u"123"_str)); 144 EXPECT_EQ(123u, lexical_cast<uint32_t>(ABP_TEXT("123"_str)));
145 EXPECT_EQ(123u, lexical_cast<uint32_t>(u"0123"_str)); 145 EXPECT_EQ(123u, lexical_cast<uint32_t>(ABP_TEXT("0123"_str)));
146 EXPECT_EQ(123u, lexical_cast<uint32_t>(u"0000123"_str)); 146 EXPECT_EQ(123u, lexical_cast<uint32_t>(ABP_TEXT("0000123"_str)));
147 EXPECT_EQ(4294967294u, lexical_cast<uint32_t>(u"4294967294"_str)); 147 EXPECT_EQ(4294967294u, lexical_cast<uint32_t>(ABP_TEXT("4294967294"_str)));
148 EXPECT_EQ(4294967295u, lexical_cast<uint32_t>(u"4294967295"_str)); 148 EXPECT_EQ(4294967295u, lexical_cast<uint32_t>(ABP_TEXT("4294967295"_str)));
149 EXPECT_EQ( 0u, lexical_cast<uint32_t>(u"4294967296"_str)); 149 EXPECT_EQ( 0u, lexical_cast<uint32_t>(ABP_TEXT("4294967296"_str)));
150 EXPECT_EQ( 0u, lexical_cast<uint32_t>(u"4594967295"_str)); 150 EXPECT_EQ( 0u, lexical_cast<uint32_t>(ABP_TEXT("4594967295"_str)));
151 EXPECT_EQ( 0u, lexical_cast<uint32_t>(u"5294967295"_str)); 151 EXPECT_EQ( 0u, lexical_cast<uint32_t>(ABP_TEXT("5294967295"_str)));
152 EXPECT_EQ( 0u, lexical_cast<uint32_t>(u"42949672950"_str)); 152 EXPECT_EQ( 0u, lexical_cast<uint32_t>(ABP_TEXT("42949672950"_str)));
153 EXPECT_EQ(4294967295u, lexical_cast<uint32_t>(u"04294967295"_str)); 153 EXPECT_EQ(4294967295u, lexical_cast<uint32_t>(ABP_TEXT("04294967295"_str)));
154 154
155 EXPECT_EQ(0, lexical_cast<int32_t>(u" 123"_str)); 155 EXPECT_EQ(0, lexical_cast<int32_t>(ABP_TEXT(" 123"_str)));
156 EXPECT_EQ(0u, lexical_cast<uint32_t>(u" 123"_str)); 156 EXPECT_EQ(0u, lexical_cast<uint32_t>(ABP_TEXT(" 123"_str)));
157 EXPECT_EQ(0, lexical_cast<int32_t>(u"123abc"_str)); 157 EXPECT_EQ(0, lexical_cast<int32_t>(ABP_TEXT("123abc"_str)));
158 EXPECT_EQ(0u, lexical_cast<uint32_t>(u"123abc"_str)); 158 EXPECT_EQ(0u, lexical_cast<uint32_t>(ABP_TEXT("123abc"_str)));
159 EXPECT_EQ(0, lexical_cast<int32_t>(u"1 23"_str)); 159 EXPECT_EQ(0, lexical_cast<int32_t>(ABP_TEXT("1 23"_str)));
160 EXPECT_EQ(0u, lexical_cast<uint32_t>(u"1 23"_str)); 160 EXPECT_EQ(0u, lexical_cast<uint32_t>(ABP_TEXT("1 23"_str)));
161 } 161 }
162 162
163 TEST(TestStringLexicalCast, toBoolean) 163 TEST(TestStringLexicalCast, toBoolean)
164 { 164 {
165 EXPECT_TRUE(lexical_cast<bool>(u"true"_str)); 165 EXPECT_TRUE(lexical_cast<bool>(ABP_TEXT("true"_str)));
166 EXPECT_FALSE(lexical_cast<bool>(u"true123"_str)); 166 EXPECT_FALSE(lexical_cast<bool>(ABP_TEXT("true123"_str)));
167 EXPECT_FALSE(lexical_cast<bool>(u"false"_str)); 167 EXPECT_FALSE(lexical_cast<bool>(ABP_TEXT("false"_str)));
168 EXPECT_FALSE(lexical_cast<bool>(u"some-string"_str)); 168 EXPECT_FALSE(lexical_cast<bool>(ABP_TEXT("some-string"_str)));
169 EXPECT_FALSE(lexical_cast<bool>(u""_str)); 169 EXPECT_FALSE(lexical_cast<bool>(ABP_TEXT(""_str)));
170 EXPECT_FALSE(lexical_cast<bool>(DependentString())); 170 EXPECT_FALSE(lexical_cast<bool>(DependentString()));
171 } 171 }
172 172
173 TEST(TestStringLexicalCast, toOwnedString) 173 TEST(TestStringLexicalCast, toOwnedString)
174 { 174 {
175 EXPECT_EQ(u"some-string"_str, lexical_cast<OwnedString>(u"some-string"_str)); 175 EXPECT_EQ(ABP_TEXT("some-string"_str), lexical_cast<OwnedString>(ABP_TEXT("som e-string"_str)));
176 EXPECT_EQ(u""_str, lexical_cast<OwnedString>(u""_str)); 176 EXPECT_EQ(ABP_TEXT(""_str), lexical_cast<OwnedString>(ABP_TEXT(""_str)));
177 } 177 }
OLDNEW
« compiled/String.h ('K') | « test/compiled/RegExp.cpp ('k') | test/compiled/StringMap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld