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.cpp134
1 files changed, 134 insertions, 0 deletions
diff --git a/core/fxcrt/cfx_widestring_unittest.cpp b/core/fxcrt/cfx_widestring_unittest.cpp
index 1c8aca9aca..6f3bc0837f 100644
--- a/core/fxcrt/cfx_widestring_unittest.cpp
+++ b/core/fxcrt/cfx_widestring_unittest.cpp
@@ -756,6 +756,73 @@ TEST(fxcrt, WideStringReleaseBuffer) {
}
}
+TEST(fxcrt, WideStringEmptyReverseIterator) {
+ CFX_WideString empty;
+ auto iter = empty.rbegin();
+ EXPECT_TRUE(iter == empty.rend());
+ EXPECT_FALSE(iter != empty.rend());
+ EXPECT_FALSE(iter < empty.rend());
+}
+
+TEST(fxcrt, WideStringOneCharReverseIterator) {
+ CFX_WideString one_str(L"a");
+ auto iter = one_str.rbegin();
+ EXPECT_FALSE(iter == one_str.rend());
+ EXPECT_TRUE(iter != one_str.rend());
+ EXPECT_TRUE(iter < one_str.rend());
+
+ char ch = *iter++;
+ EXPECT_EQ('a', ch);
+ EXPECT_TRUE(iter == one_str.rend());
+ EXPECT_FALSE(iter != one_str.rend());
+ EXPECT_FALSE(iter < one_str.rend());
+}
+
+TEST(fxcrt, WideStringMultiCharReverseIterator) {
+ CFX_WideString multi_str(L"abcd");
+ auto iter = multi_str.rbegin();
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ char ch = *iter++;
+ EXPECT_EQ('d', ch);
+ EXPECT_EQ('c', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *(++iter);
+ EXPECT_EQ('b', ch);
+ EXPECT_EQ('b', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *iter++;
+ EXPECT_EQ('b', ch);
+ EXPECT_EQ('a', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *iter++;
+ EXPECT_EQ('a', ch);
+ EXPECT_TRUE(iter == multi_str.rend());
+
+ ch = *(--iter);
+ EXPECT_EQ('a', ch);
+ EXPECT_EQ('a', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *iter--;
+ EXPECT_EQ('a', ch);
+ EXPECT_EQ('b', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *iter--;
+ EXPECT_EQ('b', ch);
+ EXPECT_EQ('c', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *(--iter);
+ EXPECT_EQ('d', ch);
+ EXPECT_EQ('d', *iter);
+ EXPECT_TRUE(iter == multi_str.rbegin());
+}
+
TEST(fxcrt, WideStringUTF16LE_Encode) {
struct UTF16LEEncodeCase {
CFX_WideString ws;
@@ -1022,6 +1089,73 @@ TEST(fxcrt, WideStringCMultiCharIterator) {
EXPECT_EQ(static_cast<int32_t>(L'a' + L'b' + L'c'), sum);
}
+TEST(fxcrt, WideStringCEmptyReverseIterator) {
+ CFX_WideStringC empty;
+ auto iter = empty.rbegin();
+ EXPECT_TRUE(iter == empty.rend());
+ EXPECT_FALSE(iter != empty.rend());
+ EXPECT_FALSE(iter < empty.rend());
+}
+
+TEST(fxcrt, WideStringCOneCharReverseIterator) {
+ CFX_WideStringC one_str(L"a");
+ auto iter = one_str.rbegin();
+ EXPECT_FALSE(iter == one_str.rend());
+ EXPECT_TRUE(iter != one_str.rend());
+ EXPECT_TRUE(iter < one_str.rend());
+
+ char ch = *iter++;
+ EXPECT_EQ('a', ch);
+ EXPECT_TRUE(iter == one_str.rend());
+ EXPECT_FALSE(iter != one_str.rend());
+ EXPECT_FALSE(iter < one_str.rend());
+}
+
+TEST(fxcrt, WideStringCMultiCharReverseIterator) {
+ CFX_WideStringC multi_str(L"abcd");
+ auto iter = multi_str.rbegin();
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ char ch = *iter++;
+ EXPECT_EQ('d', ch);
+ EXPECT_EQ('c', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *(++iter);
+ EXPECT_EQ('b', ch);
+ EXPECT_EQ('b', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *iter++;
+ EXPECT_EQ('b', ch);
+ EXPECT_EQ('a', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *iter++;
+ EXPECT_EQ('a', ch);
+ EXPECT_TRUE(iter == multi_str.rend());
+
+ ch = *(--iter);
+ EXPECT_EQ('a', ch);
+ EXPECT_EQ('a', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *iter--;
+ EXPECT_EQ('a', ch);
+ EXPECT_EQ('b', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *iter--;
+ EXPECT_EQ('b', ch);
+ EXPECT_EQ('c', *iter);
+ EXPECT_FALSE(iter == multi_str.rend());
+
+ ch = *(--iter);
+ EXPECT_EQ('d', ch);
+ EXPECT_EQ('d', *iter);
+ EXPECT_TRUE(iter == multi_str.rbegin());
+}
+
TEST(fxcrt, WideStringCAnyAllNoneOf) {
CFX_WideStringC str(L"aaaaaaaaaaaaaaaaab");
EXPECT_FALSE(std::all_of(str.begin(), str.end(),