33 #include <google/protobuf/stubs/strutil.h>
37 #include <google/protobuf/stubs/stl_util.h>
38 #include <google/protobuf/testing/googletest.h>
39 #include <gtest/gtest.h>
42 #define snprintf _snprintf
51 TEST(StringUtilityTest, ImmuneToLocales) {
53 char* old_locale_cstr = setlocale(LC_NUMERIC,
nullptr);
63 if (setlocale(LC_NUMERIC,
"es_ES") ==
nullptr &&
64 setlocale(LC_NUMERIC,
"es_ES.utf8") ==
nullptr) {
67 <<
"Couldn't set locale to es_ES. Skipping this test.";
74 setlocale(LC_NUMERIC, old_locale.c_str());
77 #define EXPECT_EQ_ARRAY(len, x, y, msg) \
78 for (int j = 0; j < len; ++j) { \
79 EXPECT_EQ(x[j], y[j]) << "" # x << " != " # y \
80 << " byte " << j << ": " << msg; \
94 { 1,
"\000",
"AA==" },
95 { 1,
"\001",
"AQ==" },
96 { 1,
"\002",
"Ag==" },
97 { 1,
"\004",
"BA==" },
98 { 1,
"\010",
"CA==" },
99 { 1,
"\020",
"EA==" },
100 { 1,
"\040",
"IA==" },
101 { 1,
"\100",
"QA==" },
102 { 1,
"\200",
"gA==" },
104 { 1,
"\377",
"/w==" },
105 { 1,
"\376",
"/g==" },
106 { 1,
"\375",
"/Q==" },
107 { 1,
"\373",
"+w==" },
108 { 1,
"\367",
"9w==" },
109 { 1,
"\357",
"7w==" },
110 { 1,
"\337",
"3w==" },
111 { 1,
"\277",
"vw==" },
112 { 1,
"\177",
"fw==" },
113 { 2,
"\000\000",
"AAA=" },
114 { 2,
"\000\001",
"AAE=" },
115 { 2,
"\000\002",
"AAI=" },
116 { 2,
"\000\004",
"AAQ=" },
117 { 2,
"\000\010",
"AAg=" },
118 { 2,
"\000\020",
"ABA=" },
119 { 2,
"\000\040",
"ACA=" },
120 { 2,
"\000\100",
"AEA=" },
121 { 2,
"\000\200",
"AIA=" },
122 { 2,
"\001\000",
"AQA=" },
123 { 2,
"\002\000",
"AgA=" },
124 { 2,
"\004\000",
"BAA=" },
125 { 2,
"\010\000",
"CAA=" },
126 { 2,
"\020\000",
"EAA=" },
127 { 2,
"\040\000",
"IAA=" },
128 { 2,
"\100\000",
"QAA=" },
129 { 2,
"\200\000",
"gAA=" },
131 { 2,
"\377\377",
"//8=" },
132 { 2,
"\377\376",
"//4=" },
133 { 2,
"\377\375",
"//0=" },
134 { 2,
"\377\373",
"//s=" },
135 { 2,
"\377\367",
"//c=" },
136 { 2,
"\377\357",
"/+8=" },
137 { 2,
"\377\337",
"/98=" },
138 { 2,
"\377\277",
"/78=" },
139 { 2,
"\377\177",
"/38=" },
140 { 2,
"\376\377",
"/v8=" },
141 { 2,
"\375\377",
"/f8=" },
142 { 2,
"\373\377",
"+/8=" },
143 { 2,
"\367\377",
"9/8=" },
144 { 2,
"\357\377",
"7/8=" },
145 { 2,
"\337\377",
"3/8=" },
146 { 2,
"\277\377",
"v/8=" },
147 { 2,
"\177\377",
"f/8=" },
149 { 3,
"\000\000\000",
"AAAA" },
150 { 3,
"\000\000\001",
"AAAB" },
151 { 3,
"\000\000\002",
"AAAC" },
152 { 3,
"\000\000\004",
"AAAE" },
153 { 3,
"\000\000\010",
"AAAI" },
154 { 3,
"\000\000\020",
"AAAQ" },
155 { 3,
"\000\000\040",
"AAAg" },
156 { 3,
"\000\000\100",
"AABA" },
157 { 3,
"\000\000\200",
"AACA" },
158 { 3,
"\000\001\000",
"AAEA" },
159 { 3,
"\000\002\000",
"AAIA" },
160 { 3,
"\000\004\000",
"AAQA" },
161 { 3,
"\000\010\000",
"AAgA" },
162 { 3,
"\000\020\000",
"ABAA" },
163 { 3,
"\000\040\000",
"ACAA" },
164 { 3,
"\000\100\000",
"AEAA" },
165 { 3,
"\000\200\000",
"AIAA" },
166 { 3,
"\001\000\000",
"AQAA" },
167 { 3,
"\002\000\000",
"AgAA" },
168 { 3,
"\004\000\000",
"BAAA" },
169 { 3,
"\010\000\000",
"CAAA" },
170 { 3,
"\020\000\000",
"EAAA" },
171 { 3,
"\040\000\000",
"IAAA" },
172 { 3,
"\100\000\000",
"QAAA" },
173 { 3,
"\200\000\000",
"gAAA" },
175 { 3,
"\377\377\377",
"////" },
176 { 3,
"\377\377\376",
"///+" },
177 { 3,
"\377\377\375",
"///9" },
178 { 3,
"\377\377\373",
"///7" },
179 { 3,
"\377\377\367",
"///3" },
180 { 3,
"\377\377\357",
"///v" },
181 { 3,
"\377\377\337",
"///f" },
182 { 3,
"\377\377\277",
"//+/" },
183 { 3,
"\377\377\177",
"//9/" },
184 { 3,
"\377\376\377",
"//7/" },
185 { 3,
"\377\375\377",
"//3/" },
186 { 3,
"\377\373\377",
"//v/" },
187 { 3,
"\377\367\377",
"//f/" },
188 { 3,
"\377\357\377",
"/+//" },
189 { 3,
"\377\337\377",
"/9//" },
190 { 3,
"\377\277\377",
"/7//" },
191 { 3,
"\377\177\377",
"/3//" },
192 { 3,
"\376\377\377",
"/v//" },
193 { 3,
"\375\377\377",
"/f//" },
194 { 3,
"\373\377\377",
"+///" },
195 { 3,
"\367\377\377",
"9///" },
196 { 3,
"\357\377\377",
"7///" },
197 { 3,
"\337\377\377",
"3///" },
198 { 3,
"\277\377\377",
"v///" },
199 { 3,
"\177\377\377",
"f///" },
210 { 2,
"\243\361",
"o/E=" },
211 { 2,
"\024\167",
"FHc=" },
212 { 2,
"\313\252",
"y6o=" },
213 { 2,
"\046\041",
"JiE=" },
214 { 2,
"\145\236",
"ZZ4=" },
215 { 2,
"\254\325",
"rNU=" },
216 { 2,
"\061\330",
"Mdg=" },
217 { 2,
"\245\032",
"pRo=" },
218 { 2,
"\006\000",
"BgA=" },
219 { 2,
"\375\131",
"/Vk=" },
220 { 2,
"\303\210",
"w4g=" },
221 { 2,
"\040\037",
"IB8=" },
222 { 2,
"\261\372",
"sfo=" },
223 { 2,
"\335\014",
"3Qw=" },
224 { 2,
"\233\217",
"m48=" },
225 { 2,
"\373\056",
"+y4=" },
226 { 2,
"\247\232",
"p5o=" },
227 { 2,
"\107\053",
"Rys=" },
228 { 2,
"\204\077",
"hD8=" },
229 { 2,
"\276\211",
"vok=" },
230 { 2,
"\313\110",
"y0g=" },
231 { 2,
"\363\376",
"8/4=" },
232 { 2,
"\251\234",
"qZw=" },
233 { 2,
"\103\262",
"Q7I=" },
234 { 2,
"\142\312",
"Yso=" },
235 { 2,
"\067\211",
"N4k=" },
236 { 2,
"\220\001",
"kAE=" },
237 { 2,
"\152\240",
"aqA=" },
238 { 2,
"\367\061",
"9zE=" },
239 { 2,
"\133\255",
"W60=" },
240 { 2,
"\176\035",
"fh0=" },
241 { 2,
"\032\231",
"Gpk=" },
243 { 3,
"\013\007\144",
"Cwdk" },
244 { 3,
"\030\112\106",
"GEpG" },
245 { 3,
"\047\325\046",
"J9Um" },
246 { 3,
"\310\160\022",
"yHAS" },
247 { 3,
"\131\100\237",
"WUCf" },
248 { 3,
"\064\342\134",
"NOJc" },
249 { 3,
"\010\177\004",
"CH8E" },
250 { 3,
"\345\147\205",
"5WeF" },
251 { 3,
"\300\343\360",
"wOPw" },
252 { 3,
"\061\240\201",
"MaCB" },
253 { 3,
"\225\333\044",
"ldsk" },
254 { 3,
"\215\137\352",
"jV/q" },
255 { 3,
"\371\147\160",
"+Wdw" },
256 { 3,
"\030\320\051",
"GNAp" },
257 { 3,
"\044\174\241",
"JHyh" },
258 { 3,
"\260\127\037",
"sFcf" },
259 { 3,
"\111\045\033",
"SSUb" },
260 { 3,
"\202\114\107",
"gkxH" },
261 { 3,
"\057\371\042",
"L/ki" },
262 { 3,
"\223\247\244",
"k6ek" },
263 { 3,
"\047\216\144",
"J45k" },
264 { 3,
"\203\070\327",
"gzjX" },
265 { 3,
"\247\140\072",
"p2A6" },
266 { 3,
"\124\115\116",
"VE1O" },
267 { 3,
"\157\162\050",
"b3Io" },
268 { 3,
"\357\223\004",
"75ME" },
269 { 3,
"\052\117\156",
"Kk9u" },
270 { 3,
"\347\154\000",
"52wA" },
271 { 3,
"\303\012\142",
"wwpi" },
272 { 3,
"\060\035\362",
"MB3y" },
273 { 3,
"\130\226\361",
"WJbx" },
274 { 3,
"\173\013\071",
"ews5" },
275 { 3,
"\336\004\027",
"3gQX" },
276 { 3,
"\357\366\234",
"7/ac" },
277 { 3,
"\353\304\111",
"68RJ" },
278 { 3,
"\024\264\131",
"FLRZ" },
279 { 3,
"\075\114\251",
"PUyp" },
280 { 3,
"\315\031\225",
"zRmV" },
281 { 3,
"\154\201\276",
"bIG+" },
282 { 3,
"\200\066\072",
"gDY6" },
283 { 3,
"\142\350\267",
"Yui3" },
284 { 3,
"\033\000\166",
"GwB2" },
285 { 3,
"\210\055\077",
"iC0/" },
286 { 3,
"\341\037\124",
"4R9U" },
287 { 3,
"\161\103\152",
"cUNq" },
288 { 3,
"\270\142\131",
"uGJZ" },
289 { 3,
"\337\076\074",
"3z48" },
290 { 3,
"\375\106\362",
"/Uby" },
291 { 3,
"\227\301\127",
"l8FX" },
292 { 3,
"\340\002\234",
"4AKc" },
293 { 3,
"\121\064\033",
"UTQb" },
294 { 3,
"\157\134\143",
"b1xj" },
295 { 3,
"\247\055\327",
"py3X" },
296 { 3,
"\340\142\005",
"4GIF" },
297 { 3,
"\060\260\143",
"MLBj" },
298 { 3,
"\075\203\170",
"PYN4" },
299 { 3,
"\143\160\016",
"Y3AO" },
300 { 3,
"\313\013\063",
"ywsz" },
301 { 3,
"\174\236\135",
"fJ5d" },
302 { 3,
"\103\047\026",
"QycW" },
303 { 3,
"\365\005\343",
"9QXj" },
304 { 3,
"\271\160\223",
"uXCT" },
305 { 3,
"\362\255\172",
"8q16" },
306 { 3,
"\113\012\015",
"SwoN" },
318 { 3,
"abc",
"YWJj" },
319 { 4,
"abcd",
"YWJjZA==" },
320 { 5,
"abcde",
"YWJjZGU=" },
321 { 6,
"abcdef",
"YWJjZGVm" },
322 { 7,
"abcdefg",
"YWJjZGVmZw==" },
323 { 8,
"abcdefgh",
"YWJjZGVmZ2g=" },
324 { 9,
"abcdefghi",
"YWJjZGVmZ2hp" },
325 { 10,
"abcdefghij",
"YWJjZGVmZ2hpag==" },
326 { 11,
"abcdefghijk",
"YWJjZGVmZ2hpams=" },
327 { 12,
"abcdefghijkl",
"YWJjZGVmZ2hpamts" },
328 { 13,
"abcdefghijklm",
"YWJjZGVmZ2hpamtsbQ==" },
329 { 14,
"abcdefghijklmn",
"YWJjZGVmZ2hpamtsbW4=" },
330 { 15,
"abcdefghijklmno",
"YWJjZGVmZ2hpamtsbW5v" },
331 { 16,
"abcdefghijklmnop",
"YWJjZGVmZ2hpamtsbW5vcA==" },
332 { 17,
"abcdefghijklmnopq",
"YWJjZGVmZ2hpamtsbW5vcHE=" },
333 { 18,
"abcdefghijklmnopqr",
"YWJjZGVmZ2hpamtsbW5vcHFy" },
334 { 19,
"abcdefghijklmnopqrs",
"YWJjZGVmZ2hpamtsbW5vcHFycw==" },
335 { 20,
"abcdefghijklmnopqrst",
"YWJjZGVmZ2hpamtsbW5vcHFyc3Q=" },
336 { 21,
"abcdefghijklmnopqrstu",
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1" },
337 { 22,
"abcdefghijklmnopqrstuv",
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dg==" },
338 { 23,
"abcdefghijklmnopqrstuvw",
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnc=" },
339 { 24,
"abcdefghijklmnopqrstuvwx",
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4" },
340 { 25,
"abcdefghijklmnopqrstuvwxy",
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eQ==" },
341 { 26,
"abcdefghijklmnopqrstuvwxyz",
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo=" },
352 {
"I was always good at math and science, and I never realized "
353 "that was unusual or somehow undesirable. So one of the things "
354 "I care a lot about is helping to remove that stigma, "
355 "to show girls that you can be feminine, you can like the things "
356 "that girls like, but you can also be really good at technology. "
357 "You can be really good at building things."
358 " - Marissa Meyer, Newsweek, 2010-12-22"
361 "SSB3YXMgYWx3YXlzIGdvb2QgYXQgbWF0aCBhbmQgc2NpZW5jZSwgYW5kIEkg"
362 "bmV2ZXIgcmVhbGl6ZWQgdGhhdCB3YXMgdW51c3VhbCBvciBzb21laG93IHVu"
363 "ZGVzaXJhYmxlLiBTbyBvbmUgb2YgdGhlIHRoaW5ncyBJIGNhcmUgYSBsb3Qg"
364 "YWJvdXQgaXMgaGVscGluZyB0byByZW1vdmUgdGhhdCBzdGlnbWEsIHRvIHNo"
365 "b3cgZ2lybHMgdGhhdCB5b3UgY2FuIGJlIGZlbWluaW5lLCB5b3UgY2FuIGxp"
366 "a2UgdGhlIHRoaW5ncyB0aGF0IGdpcmxzIGxpa2UsIGJ1dCB5b3UgY2FuIGFs"
367 "c28gYmUgcmVhbGx5IGdvb2QgYXQgdGVjaG5vbG9neS4gWW91IGNhbiBiZSBy"
368 "ZWFsbHkgZ29vZCBhdCBidWlsZGluZyB0aGluZ3MuIC0gTWFyaXNzYSBNZXll"
369 "ciwgTmV3c3dlZWssIDIwMTAtMTItMjIK"},
371 {
"Typical first year for a new cluster: "
375 "~1 network rewiring "
378 "~8 network maintenances "
379 "~12 router reloads "
380 "~3 router failures "
381 "~dozens of minor 30-second blips for dns "
382 "~1000 individual machine failures "
383 "~thousands of hard drive failures "
384 "slow disks, bad memory, misconfigured machines, flaky machines, etc."
385 " - Jeff Dean, The Joys of Real Hardware"
388 "VHlwaWNhbCBmaXJzdCB5ZWFyIGZvciBhIG5ldyBjbHVzdGVyOiB-MC41IG92"
389 "ZXJoZWF0aW5nIH4xIFBEVSBmYWlsdXJlIH4xIHJhY2stbW92ZSB-MSBuZXR3"
390 "b3JrIHJld2lyaW5nIH4yMCByYWNrIGZhaWx1cmVzIH41IHJhY2tzIGdvIHdv"
391 "bmt5IH44IG5ldHdvcmsgbWFpbnRlbmFuY2VzIH4xMiByb3V0ZXIgcmVsb2Fk"
392 "cyB-MyByb3V0ZXIgZmFpbHVyZXMgfmRvemVucyBvZiBtaW5vciAzMC1zZWNv"
393 "bmQgYmxpcHMgZm9yIGRucyB-MTAwMCBpbmRpdmlkdWFsIG1hY2hpbmUgZmFp"
394 "bHVyZXMgfnRob3VzYW5kcyBvZiBoYXJkIGRyaXZlIGZhaWx1cmVzIHNsb3cg"
395 "ZGlza3MsIGJhZCBtZW1vcnksIG1pc2NvbmZpZ3VyZWQgbWFjaGluZXMsIGZs"
396 "YWt5IG1hY2hpbmVzLCBldGMuIC0gSmVmZiBEZWFuLCBUaGUgSm95cyBvZiBS"
397 "ZWFsIEhhcmR3YXJlCg"},
399 {
"I'm the head of the webspam team at Google. "
400 "That means that if you type your name into Google and get porn back, "
401 "it's my fault. Unless you're a porn star, in which case porn is a "
402 "completely reasonable response."
403 " - Matt Cutts, Google Plus"
406 "SSdtIHRoZSBoZWFkIG9mIHRoZSB3ZWJzcGFtIHRlYW0gYXQgR29vZ2xlLiAg"
407 "VGhhdCBtZWFucyB0aGF0IGlmIHlvdSB0eXBlIHlvdXIgbmFtZSBpbnRvIEdv"
408 "b2dsZSBhbmQgZ2V0IHBvcm4gYmFjaywgaXQncyBteSBmYXVsdC4gVW5sZXNz"
409 "IHlvdSdyZSBhIHBvcm4gc3RhciwgaW4gd2hpY2ggY2FzZSBwb3JuIGlzIGEg"
410 "Y29tcGxldGVseSByZWFzb25hYmxlIHJlc3BvbnNlLiAtIE1hdHQgQ3V0dHMs"
411 "IEdvb2dsZSBQbHVzCg"},
413 {
"It will still be a long time before machines approach human "
415 "But luckily, machines don't actually have to be intelligent; "
416 "they just have to fake it. Access to a wealth of information, "
417 "combined with a rudimentary decision-making capacity, "
418 "can often be almost as useful. Of course, the results are better yet "
419 "when coupled with intelligence. A reference librarian with access to "
420 "a good search engine is a formidable tool."
421 " - Craig Silverstein, Siemens Pictures of the Future, Spring 2004"
424 "SXQgd2lsbCBzdGlsbCBiZSBhIGxvbmcgdGltZSBiZWZvcmUgbWFjaGluZXMg"
425 "YXBwcm9hY2ggaHVtYW4gaW50ZWxsaWdlbmNlLiBCdXQgbHVja2lseSwgbWFj"
426 "aGluZXMgZG9uJ3QgYWN0dWFsbHkgaGF2ZSB0byBiZSBpbnRlbGxpZ2VudDsg"
427 "dGhleSBqdXN0IGhhdmUgdG8gZmFrZSBpdC4gQWNjZXNzIHRvIGEgd2VhbHRo"
428 "IG9mIGluZm9ybWF0aW9uLCBjb21iaW5lZCB3aXRoIGEgcnVkaW1lbnRhcnkg"
429 "ZGVjaXNpb24tbWFraW5nIGNhcGFjaXR5LCBjYW4gb2Z0ZW4gYmUgYWxtb3N0"
430 "IGFzIHVzZWZ1bC4gT2YgY291cnNlLCB0aGUgcmVzdWx0cyBhcmUgYmV0dGVy"
431 "IHlldCB3aGVuIGNvdXBsZWQgd2l0aCBpbnRlbGxpZ2VuY2UuIEEgcmVmZXJl"
432 "bmNlIGxpYnJhcmlhbiB3aXRoIGFjY2VzcyB0byBhIGdvb2Qgc2VhcmNoIGVu"
433 "Z2luZSBpcyBhIGZvcm1pZGFibGUgdG9vbC4gLSBDcmFpZyBTaWx2ZXJzdGVp"
434 "biwgU2llbWVucyBQaWN0dXJlcyBvZiB0aGUgRnV0dXJlLCBTcHJpbmcgMjAw"
441 TEST(Base64, EscapeAndUnescape) {
443 for (
int i = 0;
i <
sizeof(base64_tests) /
sizeof(base64_tests[0]); ++
i) {
444 char encode_buffer[100];
446 char decode_buffer[100];
451 const unsigned char* unsigned_plaintext =
452 reinterpret_cast<const unsigned char*
>(base64_tests[
i].plaintext);
457 cipher_length = strlen(base64_tests[i].
ciphertext);
460 memset(encode_buffer, 0,
sizeof(encode_buffer));
464 sizeof(encode_buffer));
475 memset(encode_buffer, 0,
sizeof(encode_buffer));
478 encode_buffer, cipher_length);
488 Base64Unescape(StringPiece(encode_buffer, cipher_length), &decode_str));
497 std::string encoded(
"this junk should be ignored");
503 std::string decoded(
"this junk should be ignored");
505 Base64Unescape(StringPiece(encode_buffer, cipher_length), &decoded));
506 EXPECT_EQ(decoded.size(), base64_tests[i].plain_length);
507 EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i);
513 char* first_equals = strchr(encode_buffer,
'=');
516 int equals = (*(first_equals+1) ==
'=') ? 2 : 1;
520 std::string decoded2(
"this junk should also be ignored");
521 *first_equals =
'\0';
523 StringPiece(encode_buffer, first_equals - encode_buffer), &decoded2));
524 EXPECT_EQ(decoded.size(), base64_tests[i].plain_length);
525 EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i);
529 decoded2.assign(
"this junk should be ignored");
531 *(first_equals+1) =
'\0';
533 StringPiece(encode_buffer, first_equals - encode_buffer + 1),
535 EXPECT_EQ(decoded.size(), base64_tests[i].plain_length);
536 EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i);
540 decoded2.assign(
"this junk should be ignored");
542 *(first_equals+1) =
'\0';
545 StringPiece(encode_buffer, first_equals - encode_buffer + 1),
553 snprintf(first_equals, 6,
" = = ");
554 len = first_equals - encode_buffer + 5;
556 snprintf(first_equals, 6,
" = ");
557 len = first_equals - encode_buffer + 3;
559 decoded2.assign(
"this junk should be ignored");
562 EXPECT_EQ(decoded.size(), base64_tests[i].plain_length);
563 EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i);
569 snprintf(first_equals, 6,
" = = ");
570 len = first_equals - encode_buffer + 5;
572 snprintf(first_equals, 6,
" = ");
573 len = first_equals - encode_buffer + 3;
583 memset(websafe, 0,
sizeof(websafe));
584 strncpy(websafe, base64_tests[i].
ciphertext, cipher_length);
585 for (
int c = 0;
c <
sizeof(websafe); ++
c) {
586 if (
'+' == websafe[c]) { websafe[
c] =
'-'; }
587 if (
'/' == websafe[c]) { websafe[
c] =
'_'; }
591 memset(encode_buffer, 0,
sizeof(encode_buffer));
595 sizeof(encode_buffer),
607 memset(encode_buffer, 0,
sizeof(encode_buffer));
610 encode_buffer, cipher_length,
true);
618 encoded =
"this junk should be ignored";
622 EXPECT_EQ(encoded.size(), cipher_length);
626 memset(decode_buffer, 0,
sizeof(decode_buffer));
628 decode_buffer,
sizeof(decode_buffer));
635 memcmp(decode_buffer, base64_tests[i].
plaintext, decode_length));
638 memset(decode_buffer, 0,
sizeof(decode_buffer));
640 decode_buffer, decode_length);
647 memcmp(decode_buffer, base64_tests[i].
plaintext, decode_length));
650 for (
int c = cipher_length - 1;
c >= 0 &&
'=' == encode_buffer[
c]; --
c) {
651 encode_buffer[
c] =
'.';
655 memset(decode_buffer, 0,
sizeof(decode_buffer));
657 decode_buffer,
sizeof(decode_buffer));
664 memcmp(decode_buffer, base64_tests[i].
plaintext, decode_length));
667 memset(decode_buffer, 0,
sizeof(decode_buffer));
669 decode_buffer, decode_length);
676 memcmp(decode_buffer, base64_tests[i].
plaintext, decode_length));
679 decoded =
"this junk should be ignored";
682 EXPECT_EQ(decoded.size(), base64_tests[i].plain_length);
683 EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i);
688 for (
int c = 0;
c <
sizeof(websafe); ++
c) {
689 if (
'=' == websafe[c]) {
697 memset(encode_buffer, 0,
sizeof(encode_buffer));
701 sizeof(encode_buffer),
713 memset(encode_buffer, 0,
sizeof(encode_buffer));
716 encode_buffer, cipher_length,
false);
725 encoded =
"this junk should be ignored";
727 EXPECT_EQ(encoded.size(), cipher_length);
731 memset(decode_buffer, 0,
sizeof(decode_buffer));
733 decode_buffer,
sizeof(decode_buffer));
740 memcmp(decode_buffer, base64_tests[i].
plaintext, decode_length));
743 memset(decode_buffer, 0,
sizeof(decode_buffer));
745 decode_buffer, decode_length);
752 memcmp(decode_buffer, base64_tests[i].
plaintext, decode_length));
756 decoded =
"this junk should be ignored";
759 EXPECT_EQ(decoded.size(), base64_tests[i].plain_length);
760 EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i);
768 const unsigned char* unsigned_plaintext =
772 std::vector<char>
buffer(cipher_length + 1);
781 buffer[ encode_length ] =
'\0';
787 const char* bad_data =
"ab-/";
800 const unsigned int ui = 4;
802 const unsigned long ul = 6;
803 const long long ll = -7;
804 const unsigned long long ull = 8;
805 const ptrdiff_t ptrdiff = -9;
806 const size_t size = 10;
820 answer =
StrCat(ptrdiff, intptr);
822 answer =
StrCat(uintptr, 0);
828 std::tuple<std::string, std::string, const char*, char>> {};
830 TEST_P(ReplaceChars, ReplacesAllOccurencesOfAnyCharInReplaceWithAReplaceChar) {
832 std::string string_to_replace_in = std::get<1>(GetParam());
833 const char* what_to_replace = std::get<2>(GetParam());
834 char replacement = std::get<3>(GetParam());
836 ASSERT_EQ(expected, string_to_replace_in);
858 TEST_P(StripWs, AlwaysStripsLeadingAndTrailingWhitespace) {
860 std::string string_to_strip = std::get<1>(GetParam());
880 " no whitespace ")));