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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 freed.Remove('X'); | 326 freed.Remove('X'); |
327 EXPECT_EQ("R", freed); | 327 EXPECT_EQ("R", freed); |
328 freed.Remove('R'); | 328 freed.Remove('R'); |
329 EXPECT_EQ("", freed); | 329 EXPECT_EQ("", freed); |
330 | 330 |
331 CFX_ByteString empty; | 331 CFX_ByteString empty; |
332 empty.Remove('X'); | 332 empty.Remove('X'); |
333 EXPECT_EQ("", empty); | 333 EXPECT_EQ("", empty); |
334 } | 334 } |
335 | 335 |
| 336 TEST(fxcrt, ByteStringRemoveCopies) { |
| 337 CFX_ByteString freed("FREED"); |
| 338 const FX_CHAR* old_buffer = freed.c_str(); |
| 339 |
| 340 // No change with single reference - no copy. |
| 341 freed.Remove('Q'); |
| 342 EXPECT_EQ("FREED", freed); |
| 343 EXPECT_EQ(old_buffer, freed.c_str()); |
| 344 |
| 345 // Change with single reference - no copy. |
| 346 freed.Remove('E'); |
| 347 EXPECT_EQ("FRD", freed); |
| 348 EXPECT_EQ(old_buffer, freed.c_str()); |
| 349 |
| 350 // No change with multiple references - no copy. |
| 351 CFX_ByteString shared(freed); |
| 352 freed.Remove('Q'); |
| 353 EXPECT_EQ("FRD", freed); |
| 354 EXPECT_EQ(old_buffer, freed.c_str()); |
| 355 EXPECT_EQ(old_buffer, shared.c_str()); |
| 356 |
| 357 // Change with multiple references -- must copy. |
| 358 freed.Remove('D'); |
| 359 EXPECT_EQ("FR", freed); |
| 360 EXPECT_NE(old_buffer, freed.c_str()); |
| 361 EXPECT_EQ("FRD", shared); |
| 362 EXPECT_EQ(old_buffer, shared.c_str()); |
| 363 } |
| 364 |
336 TEST(fxcrt, ByteStringReplace) { | 365 TEST(fxcrt, ByteStringReplace) { |
337 CFX_ByteString fred("FRED"); | 366 CFX_ByteString fred("FRED"); |
338 fred.Replace("FR", "BL"); | 367 fred.Replace("FR", "BL"); |
339 EXPECT_EQ("BLED", fred); | 368 EXPECT_EQ("BLED", fred); |
340 fred.Replace("D", "DDY"); | 369 fred.Replace("D", "DDY"); |
341 EXPECT_EQ("BLEDDY", fred); | 370 EXPECT_EQ("BLEDDY", fred); |
342 fred.Replace("LEDD", ""); | 371 fred.Replace("LEDD", ""); |
343 EXPECT_EQ("BY", fred); | 372 EXPECT_EQ("BY", fred); |
344 fred.Replace("X", "CLAMS"); | 373 fred.Replace("X", "CLAMS"); |
345 EXPECT_EQ("BY", fred); | 374 EXPECT_EQ("BY", fred); |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 } | 989 } |
961 } | 990 } |
962 | 991 |
963 TEST(fxcrt, EmptyByteString) { | 992 TEST(fxcrt, EmptyByteString) { |
964 CFX_ByteString empty_str; | 993 CFX_ByteString empty_str; |
965 EXPECT_TRUE(empty_str.IsEmpty()); | 994 EXPECT_TRUE(empty_str.IsEmpty()); |
966 EXPECT_EQ(0, empty_str.GetLength()); | 995 EXPECT_EQ(0, empty_str.GetLength()); |
967 const FX_CHAR* cstr = empty_str.c_str(); | 996 const FX_CHAR* cstr = empty_str.c_str(); |
968 EXPECT_EQ(0, FXSYS_strlen(cstr)); | 997 EXPECT_EQ(0, FXSYS_strlen(cstr)); |
969 } | 998 } |
OLD | NEW |