Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: webrtc/base/base64_unittest.cc

Issue 2685533002: Replace occurences of string by std::string. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 338
339 size_t Base64Unescape(const char *src, size_t szsrc, char *dest, 339 size_t Base64Unescape(const char *src, size_t szsrc, char *dest,
340 size_t szdest) { 340 size_t szdest) {
341 std::string unescaped; 341 std::string unescaped;
342 EXPECT_TRUE(Base64::DecodeFromArray(src, szsrc, Base64::DO_LAX, &unescaped, 342 EXPECT_TRUE(Base64::DecodeFromArray(src, szsrc, Base64::DO_LAX, &unescaped,
343 NULL)); 343 NULL));
344 memcpy(dest, unescaped.data(), min(unescaped.size(), szdest)); 344 memcpy(dest, unescaped.data(), min(unescaped.size(), szdest));
345 return unescaped.size(); 345 return unescaped.size();
346 } 346 }
347 347
348 size_t Base64Unescape(const char *src, size_t szsrc, string *s) { 348 size_t Base64Unescape(const char *src, size_t szsrc, std::string *s) {
349 EXPECT_TRUE(Base64::DecodeFromArray(src, szsrc, Base64::DO_LAX, s, NULL)); 349 EXPECT_TRUE(Base64::DecodeFromArray(src, szsrc, Base64::DO_LAX, s, NULL));
350 return s->size(); 350 return s->size();
351 } 351 }
352 352
353 TEST(Base64, EncodeDecodeBattery) { 353 TEST(Base64, EncodeDecodeBattery) {
354 LOG(LS_VERBOSE) << "Testing base-64"; 354 LOG(LS_VERBOSE) << "Testing base-64";
355 355
356 size_t i; 356 size_t i;
357 357
358 // Check the short strings; this tests the math (and boundaries) 358 // Check the short strings; this tests the math (and boundaries)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // Our decoder treats the padding '=' characters at the end as 410 // Our decoder treats the padding '=' characters at the end as
411 // optional. If encode_buffer has any, run some additional 411 // optional. If encode_buffer has any, run some additional
412 // tests that fiddle with them. 412 // tests that fiddle with them.
413 char* first_equals = strchr(encode_buffer, '='); 413 char* first_equals = strchr(encode_buffer, '=');
414 if (first_equals) { 414 if (first_equals) {
415 // How many equals signs does the string start with? 415 // How many equals signs does the string start with?
416 int equals = (*(first_equals+1) == '=') ? 2 : 1; 416 int equals = (*(first_equals+1) == '=') ? 2 : 1;
417 417
418 // Try chopping off the equals sign(s) entirely. The decoder 418 // Try chopping off the equals sign(s) entirely. The decoder
419 // should still be okay with this. 419 // should still be okay with this.
420 string decoded2("this junk should also be ignored"); 420 std::string decoded2("this junk should also be ignored");
421 *first_equals = '\0'; 421 *first_equals = '\0';
422 EXPECT_NE(0U, Base64Unescape(encode_buffer, first_equals-encode_buffer, 422 EXPECT_NE(0U, Base64Unescape(encode_buffer, first_equals-encode_buffer,
423 &decoded2)); 423 &decoded2));
424 EXPECT_EQ(decoded2.size(), base64_tests[i].plain_length); 424 EXPECT_EQ(decoded2.size(), base64_tests[i].plain_length);
425 EXPECT_EQ_ARRAY(decoded2.size(), decoded2.data(), base64_tests[i].plaintex t, i); 425 EXPECT_EQ_ARRAY(decoded2.size(), decoded2.data(), base64_tests[i].plaintex t, i);
426 426
427 size_t len; 427 size_t len;
428 428
429 // try putting some extra stuff after the equals signs, or in between them 429 // try putting some extra stuff after the equals signs, or in between them
430 if (equals == 2) { 430 if (equals == 2) {
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 char next_char; 990 char next_char;
991 EXPECT_TRUE(Base64::GetNextBase64Char('A', &next_char)); 991 EXPECT_TRUE(Base64::GetNextBase64Char('A', &next_char));
992 EXPECT_EQ('B', next_char); 992 EXPECT_EQ('B', next_char);
993 EXPECT_TRUE(Base64::GetNextBase64Char('Z', &next_char)); 993 EXPECT_TRUE(Base64::GetNextBase64Char('Z', &next_char));
994 EXPECT_EQ('a', next_char); 994 EXPECT_EQ('a', next_char);
995 EXPECT_TRUE(Base64::GetNextBase64Char('/', &next_char)); 995 EXPECT_TRUE(Base64::GetNextBase64Char('/', &next_char));
996 EXPECT_EQ('A', next_char); 996 EXPECT_EQ('A', next_char);
997 EXPECT_FALSE(Base64::GetNextBase64Char('&', &next_char)); 997 EXPECT_FALSE(Base64::GetNextBase64Char('&', &next_char));
998 EXPECT_FALSE(Base64::GetNextBase64Char('Z', NULL)); 998 EXPECT_FALSE(Base64::GetNextBase64Char('Z', NULL));
999 } 999 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698