OLD | NEW |
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 Loading... |
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 freed.Remove('F'); |
| 323 EXPECT_EQ("RD", freed); |
| 324 freed.Remove('D'); |
| 325 EXPECT_EQ("R", freed); |
| 326 freed.Remove('X'); |
| 327 EXPECT_EQ("R", freed); |
| 328 freed.Remove('R'); |
| 329 EXPECT_EQ("", freed); |
| 330 |
| 331 CFX_ByteString empty; |
| 332 empty.Remove('X'); |
| 333 EXPECT_EQ("", empty); |
| 334 } |
| 335 |
| 336 TEST(fxcrt, ByteStringReplace) { |
| 337 CFX_ByteString fred("FRED"); |
| 338 fred.Replace("FR", "BL"); |
| 339 EXPECT_EQ("BLED", fred); |
| 340 fred.Replace("D", "DDY"); |
| 341 EXPECT_EQ("BLEDDY", fred); |
| 342 fred.Replace("LEDD", ""); |
| 343 EXPECT_EQ("BY", fred); |
| 344 fred.Replace("X", "CLAMS"); |
| 345 EXPECT_EQ("BY", fred); |
| 346 fred.Replace("BY", "HI"); |
| 347 EXPECT_EQ("HI", fred); |
| 348 fred.Replace("", "CLAMS"); |
| 349 EXPECT_EQ("HI", fred); |
| 350 fred.Replace("HI", ""); |
| 351 EXPECT_EQ("", fred); |
| 352 } |
| 353 |
| 354 TEST(fxcrt, ByteStringInsert) { |
| 355 CFX_ByteString fred("FRED"); |
| 356 fred.Insert(-1, 'X'); |
| 357 EXPECT_EQ("XFRED", fred); |
| 358 fred.Insert(0, 'S'); |
| 359 EXPECT_EQ("SXFRED", fred); |
| 360 fred.Insert(2, 'T'); |
| 361 EXPECT_EQ("SXTFRED", fred); |
| 362 fred.Insert(5, 'U'); |
| 363 EXPECT_EQ("SXTFRUED", fred); |
| 364 fred.Insert(8, 'V'); |
| 365 EXPECT_EQ("SXTFRUEDV", fred); |
| 366 fred.Insert(12, 'P'); |
| 367 EXPECT_EQ("SXTFRUEDVP", fred); |
| 368 { |
| 369 CFX_ByteString empty; |
| 370 empty.Insert(-1, 'X'); |
| 371 EXPECT_EQ("X", empty); |
| 372 } |
| 373 { |
| 374 CFX_ByteString empty; |
| 375 empty.Insert(0, 'X'); |
| 376 EXPECT_EQ("X", empty); |
| 377 } |
| 378 { |
| 379 CFX_ByteString empty; |
| 380 empty.Insert(5, 'X'); |
| 381 EXPECT_EQ("X", empty); |
| 382 } |
| 383 } |
| 384 |
| 385 TEST(fxcrt, ByteStringDelete) { |
| 386 CFX_ByteString fred("FRED"); |
| 387 fred.Delete(0, 2); |
| 388 EXPECT_EQ("ED", fred); |
| 389 fred.Delete(1); |
| 390 EXPECT_EQ("E", fred); |
| 391 fred.Delete(-1); |
| 392 EXPECT_EQ("", fred); |
| 393 fred.Delete(1); |
| 394 EXPECT_EQ("", fred); |
| 395 |
| 396 CFX_ByteString empty; |
| 397 empty.Delete(0); |
| 398 EXPECT_EQ("", empty); |
| 399 empty.Delete(-1); |
| 400 EXPECT_EQ("", empty); |
| 401 empty.Delete(1); |
| 402 EXPECT_EQ("", empty); |
| 403 } |
| 404 |
| 405 TEST(fxcrt, ByteStringMid) { |
| 406 CFX_ByteString fred("FRED"); |
| 407 EXPECT_EQ("", fred.Mid(0, 0)); |
| 408 EXPECT_EQ("", fred.Mid(3, 0)); |
| 409 EXPECT_EQ("FRED", fred.Mid(0)); |
| 410 EXPECT_EQ("RED", fred.Mid(1)); |
| 411 EXPECT_EQ("ED", fred.Mid(2)); |
| 412 EXPECT_EQ("D", fred.Mid(3)); |
| 413 EXPECT_EQ("F", fred.Mid(0, 1)); |
| 414 EXPECT_EQ("R", fred.Mid(1, 1)); |
| 415 EXPECT_EQ("E", fred.Mid(2, 1)); |
| 416 EXPECT_EQ("D", fred.Mid(3, 1)); |
| 417 EXPECT_EQ("FR", fred.Mid(0, 2)); |
| 418 EXPECT_EQ("FRED", fred.Mid(0, 4)); |
| 419 EXPECT_EQ("FRED", fred.Mid(0, 10)); |
| 420 |
| 421 EXPECT_EQ("FR", fred.Mid(-1, 2)); |
| 422 EXPECT_EQ("RED", fred.Mid(1, 4)); |
| 423 EXPECT_EQ("", fred.Mid(4, 1)); |
| 424 |
| 425 CFX_ByteString empty; |
| 426 EXPECT_EQ("", empty.Mid(0, 0)); |
| 427 EXPECT_EQ("", empty.Mid(0)); |
| 428 EXPECT_EQ("", empty.Mid(1)); |
| 429 EXPECT_EQ("", empty.Mid(-1)); |
| 430 } |
| 431 |
| 432 TEST(fxcrt, ByteStringLeft) { |
| 433 CFX_ByteString fred("FRED"); |
| 434 EXPECT_EQ("", fred.Left(0)); |
| 435 EXPECT_EQ("F", fred.Left(1)); |
| 436 EXPECT_EQ("FR", fred.Left(2)); |
| 437 EXPECT_EQ("FRE", fred.Left(3)); |
| 438 EXPECT_EQ("FRED", fred.Left(4)); |
| 439 |
| 440 EXPECT_EQ("FRED", fred.Left(5)); |
| 441 EXPECT_EQ("", fred.Left(-1)); |
| 442 |
| 443 CFX_ByteString empty; |
| 444 EXPECT_EQ("", empty.Left(0)); |
| 445 EXPECT_EQ("", empty.Left(1)); |
| 446 EXPECT_EQ("", empty.Left(-1)); |
| 447 } |
| 448 |
| 449 TEST(fxcrt, ByteStringRight) { |
| 450 CFX_ByteString fred("FRED"); |
| 451 EXPECT_EQ("", fred.Right(0)); |
| 452 EXPECT_EQ("D", fred.Right(1)); |
| 453 EXPECT_EQ("ED", fred.Right(2)); |
| 454 EXPECT_EQ("RED", fred.Right(3)); |
| 455 EXPECT_EQ("FRED", fred.Right(4)); |
| 456 |
| 457 EXPECT_EQ("FRED", fred.Right(5)); |
| 458 EXPECT_EQ("", fred.Right(-1)); |
| 459 |
| 460 CFX_ByteString empty; |
| 461 EXPECT_EQ("", empty.Right(0)); |
| 462 EXPECT_EQ("", empty.Right(1)); |
| 463 EXPECT_EQ("", empty.Right(-1)); |
| 464 } |
| 465 |
| 466 TEST(fxcrt, ByteStringUpperLower) { |
| 467 CFX_ByteString fred("F-Re.42D"); |
| 468 fred.MakeLower(); |
| 469 EXPECT_EQ("f-re.42d", fred); |
| 470 fred.MakeUpper(); |
| 471 EXPECT_EQ("F-RE.42D", fred); |
| 472 |
| 473 CFX_ByteString empty; |
| 474 empty.MakeLower(); |
| 475 EXPECT_EQ("", empty); |
| 476 empty.MakeUpper(); |
| 477 EXPECT_EQ("", empty); |
| 478 } |
| 479 |
| 480 TEST(fxcrt, ByteStringTrimRight) { |
| 481 CFX_ByteString fred(" FRED "); |
| 482 fred.TrimRight(); |
| 483 EXPECT_EQ(" FRED", fred); |
| 484 fred.TrimRight('E'); |
| 485 EXPECT_EQ(" FRED", fred); |
| 486 fred.TrimRight('D'); |
| 487 EXPECT_EQ(" FRE", fred); |
| 488 fred.TrimRight("ERP"); |
| 489 EXPECT_EQ(" F", fred); |
| 490 |
| 491 CFX_ByteString blank(" "); |
| 492 blank.TrimRight("ERP"); |
| 493 EXPECT_EQ(" ", blank); |
| 494 blank.TrimRight('E'); |
| 495 EXPECT_EQ(" ", blank); |
| 496 blank.TrimRight(); |
| 497 EXPECT_EQ("", blank); |
| 498 |
| 499 CFX_ByteString empty; |
| 500 empty.TrimRight("ERP"); |
| 501 EXPECT_EQ("", empty); |
| 502 empty.TrimRight('E'); |
| 503 EXPECT_EQ("", empty); |
| 504 empty.TrimRight(); |
| 505 EXPECT_EQ("", empty); |
| 506 } |
| 507 |
| 508 TEST(fxcrt, ByteStringTrimLeft) { |
| 509 CFX_ByteString fred(" FRED "); |
| 510 fred.TrimLeft(); |
| 511 EXPECT_EQ("FRED ", fred); |
| 512 fred.TrimLeft('E'); |
| 513 EXPECT_EQ("FRED ", fred); |
| 514 fred.TrimLeft('F'); |
| 515 EXPECT_EQ("RED ", fred); |
| 516 fred.TrimLeft("ERP"); |
| 517 EXPECT_EQ("D ", fred); |
| 518 |
| 519 CFX_ByteString blank(" "); |
| 520 blank.TrimLeft("ERP"); |
| 521 EXPECT_EQ(" ", blank); |
| 522 blank.TrimLeft('E'); |
| 523 EXPECT_EQ(" ", blank); |
| 524 blank.TrimLeft(); |
| 525 EXPECT_EQ("", blank); |
| 526 |
| 527 CFX_ByteString empty; |
| 528 empty.TrimLeft("ERP"); |
| 529 EXPECT_EQ("", empty); |
| 530 empty.TrimLeft('E'); |
| 531 EXPECT_EQ("", empty); |
| 532 empty.TrimLeft(); |
| 533 EXPECT_EQ("", empty); |
| 534 } |
| 535 |
318 TEST(fxcrt, ByteStringCNotNull) { | 536 TEST(fxcrt, ByteStringCNotNull) { |
319 CFX_ByteStringC string3("abc"); | 537 CFX_ByteStringC string3("abc"); |
320 CFX_ByteStringC string6("abcdef"); | 538 CFX_ByteStringC string6("abcdef"); |
321 CFX_ByteStringC alternate_string3("abcdef", 3); | 539 CFX_ByteStringC alternate_string3("abcdef", 3); |
322 CFX_ByteStringC embedded_nul_string7("abc\0def", 7); | 540 CFX_ByteStringC embedded_nul_string7("abc\0def", 7); |
323 CFX_ByteStringC illegal_string7("abcdef", 7); | 541 CFX_ByteStringC illegal_string7("abcdef", 7); |
324 | 542 |
325 EXPECT_EQ(3, string3.GetLength()); | 543 EXPECT_EQ(3, string3.GetLength()); |
326 EXPECT_EQ(6, string6.GetLength()); | 544 EXPECT_EQ(6, string6.GetLength()); |
327 EXPECT_EQ(3, alternate_string3.GetLength()); | 545 EXPECT_EQ(3, alternate_string3.GetLength()); |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 } | 898 } |
681 } | 899 } |
682 | 900 |
683 TEST(fxcrt, EmptyByteString) { | 901 TEST(fxcrt, EmptyByteString) { |
684 CFX_ByteString empty_str; | 902 CFX_ByteString empty_str; |
685 EXPECT_TRUE(empty_str.IsEmpty()); | 903 EXPECT_TRUE(empty_str.IsEmpty()); |
686 EXPECT_EQ(0, empty_str.GetLength()); | 904 EXPECT_EQ(0, empty_str.GetLength()); |
687 const FX_CHAR* cstr = empty_str.c_str(); | 905 const FX_CHAR* cstr = empty_str.c_str(); |
688 EXPECT_EQ(0, FXSYS_strlen(cstr)); | 906 EXPECT_EQ(0, FXSYS_strlen(cstr)); |
689 } | 907 } |
OLD | NEW |