summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_widestring_unittest.cpp
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-08-15 10:37:59 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-15 15:03:10 +0000
commit8a1758bf11c2d741e0cddc761b1dd2cdf564db93 (patch)
tree82cbafc46f574a05ae0c1d1d3d7f9ebde6cb932d /core/fxcrt/cfx_widestring_unittest.cpp
parent171cb27a720036c48ae3a6176084e880742af0a9 (diff)
downloadpdfium-8a1758bf11c2d741e0cddc761b1dd2cdf564db93.tar.xz
Remove GetAt from string classes
This method duplicates the behaviour of the const [] operator and doesn't offer any additional safety. Folding them into one implementation. SetAt is retained, since implementing the non-const [] operator to replace SetAt has potential performance concerns. Specifically many non-obvious cases of reading an element using [] will cause a realloc & copy. BUG=pdfium:860 Change-Id: I3ef5e5e5a15376f040256b646eb0d90636e24b67 Reviewed-on: https://pdfium-review.googlesource.com/10870 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_widestring_unittest.cpp')
-rw-r--r--core/fxcrt/cfx_widestring_unittest.cpp77
1 files changed, 27 insertions, 50 deletions
diff --git a/core/fxcrt/cfx_widestring_unittest.cpp b/core/fxcrt/cfx_widestring_unittest.cpp
index a23763218d..e7206dde06 100644
--- a/core/fxcrt/cfx_widestring_unittest.cpp
+++ b/core/fxcrt/cfx_widestring_unittest.cpp
@@ -10,26 +10,8 @@
#include "testing/gtest/include/gtest/gtest.h"
-TEST(fxcrt, WideStringGetAt) {
- CFX_WideString short_string(L"a");
- CFX_WideString longer_string(L"abc");
- CFX_WideString embedded_nul_string(L"ab\0c", 4);
-
-#ifndef NDEBUG
- EXPECT_DEATH({ short_string.GetAt(-1); }, ".*");
-#endif
- EXPECT_EQ(L'a', short_string.GetAt(0));
-#ifndef NDEBUG
- EXPECT_DEATH({ short_string.GetAt(1); }, ".*");
-#endif
- EXPECT_EQ(L'c', longer_string.GetAt(2));
- EXPECT_EQ(L'b', embedded_nul_string.GetAt(1));
- EXPECT_EQ(L'\0', embedded_nul_string.GetAt(2));
- EXPECT_EQ(L'c', embedded_nul_string.GetAt(3));
-}
-
-TEST(fxcrt, WideStringOperatorSubscript) {
- CFX_WideString abc(L"abc");
+TEST(fxcrt, WideStringElementAccess) {
+ const CFX_WideString abc(L"abc");
#ifndef NDEBUG
EXPECT_DEATH({ abc[-1]; }, ".*");
#endif
@@ -39,21 +21,34 @@ TEST(fxcrt, WideStringOperatorSubscript) {
#ifndef NDEBUG
EXPECT_DEATH({ abc[4]; }, ".*");
#endif
-}
-TEST(fxcrt, WideStringSetAt) {
- CFX_WideString abc(L"abc");
+ CFX_WideString mutable_abc = abc;
+ EXPECT_EQ(abc.c_str(), mutable_abc.c_str());
+ EXPECT_EQ(L'a', mutable_abc[0]);
+ EXPECT_EQ(L'b', mutable_abc[1]);
+ EXPECT_EQ(L'c', mutable_abc[2]);
+ EXPECT_EQ(abc.c_str(), mutable_abc.c_str());
#ifndef NDEBUG
- EXPECT_DEATH({ abc.SetAt(-1, L'd'); }, ".*");
+ EXPECT_DEATH({ mutable_abc.SetAt(-1, L'd'); }, ".*");
+ EXPECT_EQ(L"abc", abc);
#endif
- abc.SetAt(0, L'd');
- EXPECT_EQ(L"dbc", abc);
- abc.SetAt(1, L'e');
- EXPECT_EQ(L"dec", abc);
- abc.SetAt(2, L'f');
- EXPECT_EQ(L"def", abc);
+ const wchar_t* c_str = abc.c_str();
+ mutable_abc.SetAt(0, L'd');
+ EXPECT_EQ(c_str, abc.c_str());
+ EXPECT_NE(c_str, mutable_abc.c_str());
+ EXPECT_EQ(L"abc", abc);
+ EXPECT_EQ(L"dbc", mutable_abc);
+
+ mutable_abc.SetAt(1, L'e');
+ EXPECT_EQ(L"abc", abc);
+ EXPECT_EQ(L"dec", mutable_abc);
+
+ mutable_abc.SetAt(2, L'f');
+ EXPECT_EQ(L"abc", abc);
+ EXPECT_EQ(L"def", mutable_abc);
#ifndef NDEBUG
- EXPECT_DEATH({ abc.SetAt(3, L'g'); }, ".*");
+ EXPECT_DEATH({ mutable_abc.SetAt(3, L'g'); }, ".*");
+ EXPECT_EQ(L"abc", abc);
#endif
}
@@ -780,25 +775,7 @@ TEST(fxcrt, WideStringCFromVector) {
EXPECT_EQ(nullptr, cleared_string.raw_str());
}
-TEST(fxcrt, WideStringCGetAt) {
- CFX_WideStringC short_string(L"a");
- CFX_WideStringC longer_string(L"abc");
- CFX_WideStringC embedded_nul_string(L"ab\0c", 4);
-
-#ifndef NDEBUG
- EXPECT_DEATH({ short_string.GetAt(-1); }, ".*");
-#endif
- EXPECT_EQ(L'a', static_cast<wchar_t>(short_string.GetAt(0)));
-#ifndef NDEBUG
- EXPECT_DEATH({ short_string.GetAt(1); }, ".*");
-#endif
- EXPECT_EQ(L'c', static_cast<wchar_t>(longer_string.GetAt(2)));
- EXPECT_EQ(L'b', static_cast<wchar_t>(embedded_nul_string.GetAt(1)));
- EXPECT_EQ(L'\0', static_cast<wchar_t>(embedded_nul_string.GetAt(2)));
- EXPECT_EQ(L'c', static_cast<wchar_t>(embedded_nul_string.GetAt(3)));
-}
-
-TEST(fxcrt, WideStringCOperatorSubscript) {
+TEST(fxcrt, WideStringCElementAccess) {
CFX_WideStringC abc(L"abc");
#ifndef NDEBUG
EXPECT_DEATH({ abc[-1]; }, ".*");