summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_widestring_unittest.cpp
diff options
context:
space:
mode:
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]; }, ".*");