diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-09-13 09:45:14 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-13 20:31:57 +0000 |
commit | e762774c7571dbfcc08a0928ea1bae684b605713 (patch) | |
tree | f27c1290e2e9de4e10d3e791d4408ba67818b09b /core/fxcrt/cfx_widestring_unittest.cpp | |
parent | b4a6948a97575b194d373e5801fe83d297cdc46f (diff) | |
download | pdfium-e762774c7571dbfcc08a0928ea1bae684b605713.tar.xz |
Add reverse iterators to CFX String classes.
Reverse iteration with signed lengths and indices is kinda icky
without this abstraction, and STL provides this pretty much "for
free" given the existing forward iterator.
Change-Id: I97c36c8bd23c0aa48195bc17da7c672292b4cde2
Reviewed-on: https://pdfium-review.googlesource.com/13770
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_widestring_unittest.cpp')
-rw-r--r-- | core/fxcrt/cfx_widestring_unittest.cpp | 134 |
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(), |