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

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

Issue 1877993002: Make CFX_{Byte,Wide}String::Remove() no-touch if possible (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Extra blank line. 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_wstring.cpp ('k') | 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 // 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_basic.h" 5 #include "core/fxcrt/include/fx_basic.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, WideStringOperatorSubscript) { 9 TEST(fxcrt, WideStringOperatorSubscript) {
10 // CFX_WideString includes the NUL terminator for non-empty strings. 10 // CFX_WideString includes the NUL terminator for non-empty strings.
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 freed.Remove(L'X'); 287 freed.Remove(L'X');
288 EXPECT_EQ(L"R", freed); 288 EXPECT_EQ(L"R", freed);
289 freed.Remove(L'R'); 289 freed.Remove(L'R');
290 EXPECT_EQ(L"", freed); 290 EXPECT_EQ(L"", freed);
291 291
292 CFX_WideString empty; 292 CFX_WideString empty;
293 empty.Remove(L'X'); 293 empty.Remove(L'X');
294 EXPECT_EQ(L"", empty); 294 EXPECT_EQ(L"", empty);
295 } 295 }
296 296
297 TEST(fxcrt, WideStringRemoveCopies) {
298 CFX_WideString freed(L"FREED");
299 const FX_WCHAR* old_buffer = freed.c_str();
300
301 // No change with single reference - no copy.
302 freed.Remove(L'Q');
303 EXPECT_EQ(L"FREED", freed);
304 EXPECT_EQ(old_buffer, freed.c_str());
305
306 // Change with single reference - no copy.
307 freed.Remove(L'E');
308 EXPECT_EQ(L"FRD", freed);
309 EXPECT_EQ(old_buffer, freed.c_str());
310
311 // No change with multiple references - no copy.
312 CFX_WideString shared(freed);
313 freed.Remove(L'Q');
314 EXPECT_EQ(L"FRD", freed);
315 EXPECT_EQ(old_buffer, freed.c_str());
316 EXPECT_EQ(old_buffer, shared.c_str());
317
318 // Change with multiple references -- must copy.
319 freed.Remove(L'D');
320 EXPECT_EQ(L"FR", freed);
321 EXPECT_NE(old_buffer, freed.c_str());
322 EXPECT_EQ(L"FRD", shared);
323 EXPECT_EQ(old_buffer, shared.c_str());
324 }
325
297 TEST(fxcrt, WideStringReplace) { 326 TEST(fxcrt, WideStringReplace) {
298 CFX_WideString fred(L"FRED"); 327 CFX_WideString fred(L"FRED");
299 fred.Replace(L"FR", L"BL"); 328 fred.Replace(L"FR", L"BL");
300 EXPECT_EQ(L"BLED", fred); 329 EXPECT_EQ(L"BLED", fred);
301 fred.Replace(L"D", L"DDY"); 330 fred.Replace(L"D", L"DDY");
302 EXPECT_EQ(L"BLEDDY", fred); 331 EXPECT_EQ(L"BLEDDY", fred);
303 fred.Replace(L"LEDD", L""); 332 fred.Replace(L"LEDD", L"");
304 EXPECT_EQ(L"BY", fred); 333 EXPECT_EQ(L"BY", fred);
305 fred.Replace(L"X", L"CLAMS"); 334 fred.Replace(L"X", L"CLAMS");
306 EXPECT_EQ(L"BY", fred); 335 EXPECT_EQ(L"BY", fred);
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 } 830 }
802 } 831 }
803 832
804 TEST(fxcrt, EmptyWideString) { 833 TEST(fxcrt, EmptyWideString) {
805 CFX_WideString empty_str; 834 CFX_WideString empty_str;
806 EXPECT_TRUE(empty_str.IsEmpty()); 835 EXPECT_TRUE(empty_str.IsEmpty());
807 EXPECT_EQ(0, empty_str.GetLength()); 836 EXPECT_EQ(0, empty_str.GetLength());
808 const FX_WCHAR* cstr = empty_str.c_str(); 837 const FX_WCHAR* cstr = empty_str.c_str();
809 EXPECT_EQ(0, FXSYS_wcslen(cstr)); 838 EXPECT_EQ(0, FXSYS_wcslen(cstr));
810 } 839 }
OLDNEW
« no previous file with comments | « core/fxcrt/fx_basic_wstring.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698