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.cpp74
1 files changed, 67 insertions, 7 deletions
diff --git a/core/fxcrt/cfx_widestring_unittest.cpp b/core/fxcrt/cfx_widestring_unittest.cpp
index 6e7b63c5fa..a23763218d 100644
--- a/core/fxcrt/cfx_widestring_unittest.cpp
+++ b/core/fxcrt/cfx_widestring_unittest.cpp
@@ -10,13 +10,51 @@
#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 includes the NUL terminator for non-empty strings.
CFX_WideString abc(L"abc");
+#ifndef NDEBUG
+ EXPECT_DEATH({ abc[-1]; }, ".*");
+#endif
EXPECT_EQ(L'a', abc[0]);
EXPECT_EQ(L'b', abc[1]);
EXPECT_EQ(L'c', abc[2]);
- EXPECT_EQ(L'\0', abc[3]);
+#ifndef NDEBUG
+ EXPECT_DEATH({ abc[4]; }, ".*");
+#endif
+}
+
+TEST(fxcrt, WideStringSetAt) {
+ CFX_WideString abc(L"abc");
+#ifndef NDEBUG
+ EXPECT_DEATH({ abc.SetAt(-1, L'd'); }, ".*");
+#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);
+#ifndef NDEBUG
+ EXPECT_DEATH({ abc.SetAt(3, L'g'); }, ".*");
+#endif
}
TEST(fxcrt, WideStringOperatorLT) {
@@ -742,13 +780,35 @@ 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) {
- // CFX_WideStringC includes the NUL terminator for non-empty strings.
CFX_WideStringC abc(L"abc");
- EXPECT_EQ(L'a', abc.CharAt(0));
- EXPECT_EQ(L'b', abc.CharAt(1));
- EXPECT_EQ(L'c', abc.CharAt(2));
- EXPECT_EQ(L'\0', abc.CharAt(3));
+#ifndef NDEBUG
+ EXPECT_DEATH({ abc[-1]; }, ".*");
+#endif
+ EXPECT_EQ(L'a', static_cast<wchar_t>(abc[0]));
+ EXPECT_EQ(L'b', static_cast<wchar_t>(abc[1]));
+ EXPECT_EQ(L'c', static_cast<wchar_t>(abc[2]));
+#ifndef NDEBUG
+ EXPECT_DEATH({ abc[4]; }, ".*");
+#endif
}
TEST(fxcrt, WideStringCOperatorLT) {