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

Side by Side Diff: core/fxcrt/fx_basic_bstring_unittest.cpp

Issue 1847193002: Beef up unit test for CFX_ByteString and CFX_WideString. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 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 | « core/fxcrt/fx_basic_bstring.cpp ('k') | core/fxcrt/fx_basic_wstring.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/fxcrt/include/fx_string.h" 5 #include "core/fxcrt/include/fx_string.h"
6 #include "testing/fx_string_testhelpers.h" 6 #include "testing/fx_string_testhelpers.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 TEST(fxcrt, ByteStringOperatorSubscript) { 9 TEST(fxcrt, ByteStringOperatorSubscript) {
10 // CFX_ByteString includes the NUL terminator for non-empty strings. 10 // CFX_ByteString includes the NUL terminator for non-empty strings.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 EXPECT_EQ("FRED", copy); 308 EXPECT_EQ("FRED", copy);
309 309
310 // Test invalid arguments. 310 // Test invalid arguments.
311 copy = fred; 311 copy = fred;
312 fred.ConcatInPlace(-6, "freddy"); 312 fred.ConcatInPlace(-6, "freddy");
313 CFX_ByteString not_aliased("xxxxxx"); 313 CFX_ByteString not_aliased("xxxxxx");
314 EXPECT_EQ("FREDDY", fred); 314 EXPECT_EQ("FREDDY", fred);
315 EXPECT_EQ("xxxxxx", not_aliased); 315 EXPECT_EQ("xxxxxx", not_aliased);
316 } 316 }
317 317
318 TEST(fxcrt, ByteStringRemove) {
319 CFX_ByteString freed("FREED");
320 freed.Remove('E');
321 EXPECT_EQ("FRD", freed);
322
323 freed.Remove('F');
324 EXPECT_EQ("RD", freed);
325
326 freed.Remove('D');
327 EXPECT_EQ("R", freed);
328
329 freed.Remove('X');
330 EXPECT_EQ("R", freed);
331
dsinclair 2016/03/31 21:03:56 freed.Remove('R'); EXPECT_EQ("", freed) ?
Tom Sepez 2016/03/31 21:28:56 Done.
332 CFX_ByteString empty;
333 empty.Remove('X');
334 EXPECT_EQ("", empty);
335 }
336
337 TEST(fxcrt, ByteStringReplace) {
338 CFX_ByteString fred("FRED");
339 fred.Replace("FR", "BL");
340 EXPECT_EQ("BLED", fred);
341
342 fred.Replace("D", "DDY");
343 EXPECT_EQ("BLEDDY", fred);
344
345 fred.Replace("LEDD", "");
346 EXPECT_EQ("BY", fred);
347
348 fred.Replace("X", "CLAMS");
349 EXPECT_EQ("BY", fred);
350
351 fred.Replace("", "CLAMS");
352 EXPECT_EQ("BY", fred);
353 }
dsinclair 2016/03/31 21:03:56 fred.Replace("BY", "HI"); EXPECT_EQ("HI", fred);
Tom Sepez 2016/03/31 21:28:56 Done.
354
355 TEST(fxcrt, ByteStringInsert) {
356 CFX_ByteString fred("FRED");
357 fred.Insert(-1, 'X');
358 EXPECT_EQ("XFRED", fred);
359
360 fred.Insert(0, 'S');
361 EXPECT_EQ("SXFRED", fred);
362
363 fred.Insert(2, 'T');
364 EXPECT_EQ("SXTFRED", fred);
365
366 fred.Insert(5, 'U');
367 EXPECT_EQ("SXTFRUED", fred);
368
369 fred.Insert(8, 'V');
370 EXPECT_EQ("SXTFRUEDV", fred);
371
372 fred.Insert(12, 'P');
373 EXPECT_EQ("SXTFRUEDVP", fred);
374
375 {
376 CFX_ByteString empty;
377 empty.Insert(-1, 'X');
378 EXPECT_EQ("X", empty);
379 }
380 {
381 CFX_ByteString empty;
382 empty.Insert(0, 'X');
383 EXPECT_EQ("X", empty);
384 }
385 {
386 CFX_ByteString empty;
387 empty.Insert(5, 'X');
388 EXPECT_EQ("X", empty);
389 }
390 }
391
392 TEST(fxcrt, ByteStringDelete) {
393 CFX_ByteString fred("FRED");
394 fred.Delete(0, 2);
395 EXPECT_EQ("ED", fred);
396 fred.Delete(1);
397 EXPECT_EQ("E", fred);
398 fred.Delete(-1);
399 EXPECT_EQ("", fred);
400 fred.Delete(1);
401 EXPECT_EQ("", fred);
402
403 CFX_ByteString empty;
404 empty.Delete(0);
405 EXPECT_EQ("", empty);
406 empty.Delete(-1);
407 EXPECT_EQ("", empty);
408 empty.Delete(1);
409 EXPECT_EQ("", empty);
410 }
411
412 TEST(fxcrt, ByteStringMid) {
413 CFX_ByteString fred("FRED");
414 EXPECT_EQ("", fred.Mid(0, 0));
415 EXPECT_EQ("", fred.Mid(3, 0));
416 EXPECT_EQ("FRED", fred.Mid(0));
417 EXPECT_EQ("RED", fred.Mid(1));
418 EXPECT_EQ("ED", fred.Mid(2));
419 EXPECT_EQ("D", fred.Mid(3));
420 EXPECT_EQ("F", fred.Mid(0, 1));
421 EXPECT_EQ("R", fred.Mid(1, 1));
422 EXPECT_EQ("E", fred.Mid(2, 1));
423 EXPECT_EQ("D", fred.Mid(3, 1));
424 EXPECT_EQ("FR", fred.Mid(0, 2));
425 EXPECT_EQ("FRED", fred.Mid(0, 4));
dsinclair 2016/03/31 21:03:56 Mid(0, 10)
Tom Sepez 2016/03/31 21:28:56 Done.
426
427 EXPECT_EQ("FR", fred.Mid(-1, 2));
428 EXPECT_EQ("RED", fred.Mid(1, 4));
429 EXPECT_EQ("", fred.Mid(4, 1));
430
431 CFX_ByteString empty;
432 EXPECT_EQ("", empty.Mid(0, 0));
433 EXPECT_EQ("", empty.Mid(0));
434 EXPECT_EQ("", empty.Mid(1));
435 EXPECT_EQ("", empty.Mid(-1));
436 }
437
438 TEST(fxcrt, ByteStringLeft) {
439 CFX_ByteString fred("FRED");
440 EXPECT_EQ("", fred.Left(0));
441 EXPECT_EQ("F", fred.Left(1));
442 EXPECT_EQ("FR", fred.Left(2));
443 EXPECT_EQ("FRE", fred.Left(3));
444 EXPECT_EQ("FRED", fred.Left(4));
445
446 EXPECT_EQ("FRED", fred.Left(5));
447 EXPECT_EQ("", fred.Left(-1));
448
449 CFX_ByteString empty;
450 EXPECT_EQ("", empty.Left(0));
451 EXPECT_EQ("", empty.Left(1));
452 EXPECT_EQ("", empty.Left(-1));
453 }
454
455 TEST(fxcrt, ByteStringRight) {
456 CFX_ByteString fred("FRED");
457 EXPECT_EQ("", fred.Right(0));
458 EXPECT_EQ("D", fred.Right(1));
459 EXPECT_EQ("ED", fred.Right(2));
460 EXPECT_EQ("RED", fred.Right(3));
461 EXPECT_EQ("FRED", fred.Right(4));
462
463 EXPECT_EQ("FRED", fred.Right(5));
464 EXPECT_EQ("", fred.Right(-1));
465
466 CFX_ByteString empty;
467 EXPECT_EQ("", empty.Right(0));
468 EXPECT_EQ("", empty.Right(1));
469 EXPECT_EQ("", empty.Right(-1));
470 }
471
472 TEST(fxcrt, ByteStringUpperLower) {
473 CFX_ByteString fred("F-Re.42D");
474 fred.MakeLower();
475 EXPECT_EQ("f-re.42d", fred);
476 fred.MakeUpper();
477 EXPECT_EQ("F-RE.42D", fred);
478
479 CFX_ByteString empty;
480 empty.MakeLower();
481 EXPECT_EQ("", empty);
482 empty.MakeUpper();
483 EXPECT_EQ("", empty);
484 }
485
486 TEST(fxcrt, ByteStringTrimRight) {
487 CFX_ByteString fred(" FRED ");
488 fred.TrimRight();
489 EXPECT_EQ(" FRED", fred);
490 fred.TrimRight('E');
491 EXPECT_EQ(" FRED", fred);
492 fred.TrimRight('D');
493 EXPECT_EQ(" FRE", fred);
494 fred.TrimRight("ERP");
495 EXPECT_EQ(" F", fred);
496
497 CFX_ByteString blank(" ");
498 blank.TrimRight("ERP");
499 EXPECT_EQ(" ", blank);
500 blank.TrimRight('E');
501 EXPECT_EQ(" ", blank);
502 blank.TrimRight();
503 EXPECT_EQ("", blank);
504
505 CFX_ByteString empty;
506 empty.TrimRight("ERP");
507 EXPECT_EQ("", empty);
508 empty.TrimRight('E');
509 EXPECT_EQ("", empty);
510 empty.TrimRight();
511 EXPECT_EQ("", empty);
512 }
513
514 TEST(fxcrt, ByteStringTrimLeft) {
515 CFX_ByteString fred(" FRED ");
516 fred.TrimLeft();
517 EXPECT_EQ("FRED ", fred);
518 fred.TrimLeft('E');
519 EXPECT_EQ("FRED ", fred);
520 fred.TrimLeft('F');
521 EXPECT_EQ("RED ", fred);
522 fred.TrimLeft("ERP");
523 EXPECT_EQ("D ", fred);
524
525 CFX_ByteString blank(" ");
526 blank.TrimLeft("ERP");
527 EXPECT_EQ(" ", blank);
528 blank.TrimLeft('E');
529 EXPECT_EQ(" ", blank);
530 blank.TrimLeft();
531 EXPECT_EQ("", blank);
532
533 CFX_ByteString empty;
534 empty.TrimLeft("ERP");
535 EXPECT_EQ("", empty);
536 empty.TrimLeft('E');
537 EXPECT_EQ("", empty);
538 empty.TrimLeft();
539 EXPECT_EQ("", empty);
540 }
541
318 TEST(fxcrt, ByteStringCNotNull) { 542 TEST(fxcrt, ByteStringCNotNull) {
319 CFX_ByteStringC string3("abc"); 543 CFX_ByteStringC string3("abc");
320 CFX_ByteStringC string6("abcdef"); 544 CFX_ByteStringC string6("abcdef");
321 CFX_ByteStringC alternate_string3("abcdef", 3); 545 CFX_ByteStringC alternate_string3("abcdef", 3);
322 CFX_ByteStringC embedded_nul_string7("abc\0def", 7); 546 CFX_ByteStringC embedded_nul_string7("abc\0def", 7);
323 CFX_ByteStringC illegal_string7("abcdef", 7); 547 CFX_ByteStringC illegal_string7("abcdef", 7);
324 548
325 EXPECT_EQ(3, string3.GetLength()); 549 EXPECT_EQ(3, string3.GetLength());
326 EXPECT_EQ(6, string6.GetLength()); 550 EXPECT_EQ(6, string6.GetLength());
327 EXPECT_EQ(3, alternate_string3.GetLength()); 551 EXPECT_EQ(3, alternate_string3.GetLength());
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 } 904 }
681 } 905 }
682 906
683 TEST(fxcrt, EmptyByteString) { 907 TEST(fxcrt, EmptyByteString) {
684 CFX_ByteString empty_str; 908 CFX_ByteString empty_str;
685 EXPECT_TRUE(empty_str.IsEmpty()); 909 EXPECT_TRUE(empty_str.IsEmpty());
686 EXPECT_EQ(0, empty_str.GetLength()); 910 EXPECT_EQ(0, empty_str.GetLength());
687 const FX_CHAR* cstr = empty_str.c_str(); 911 const FX_CHAR* cstr = empty_str.c_str();
688 EXPECT_EQ(0, FXSYS_strlen(cstr)); 912 EXPECT_EQ(0, FXSYS_strlen(cstr));
689 } 913 }
OLDNEW
« no previous file with comments | « core/fxcrt/fx_basic_bstring.cpp ('k') | core/fxcrt/fx_basic_wstring.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698