summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_bytestring_unittest.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-09-13 09:45:14 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-09-13 20:31:57 +0000
commite762774c7571dbfcc08a0928ea1bae684b605713 (patch)
treef27c1290e2e9de4e10d3e791d4408ba67818b09b /core/fxcrt/cfx_bytestring_unittest.cpp
parentb4a6948a97575b194d373e5801fe83d297cdc46f (diff)
downloadpdfium-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_bytestring_unittest.cpp')
-rw-r--r--core/fxcrt/cfx_bytestring_unittest.cpp134
1 files changed, 134 insertions, 0 deletions
diff --git a/core/fxcrt/cfx_bytestring_unittest.cpp b/core/fxcrt/cfx_bytestring_unittest.cpp
index a4c5187c11..6bbe305268 100644
--- a/core/fxcrt/cfx_bytestring_unittest.cpp
+++ b/core/fxcrt/cfx_bytestring_unittest.cpp
@@ -833,6 +833,73 @@ TEST(fxcrt, ByteStringReleaseBuffer) {
}
}
+TEST(fxcrt, ByteStringEmptyReverseIterator) {
+ CFX_ByteString empty;
+ auto iter = empty.rbegin();
+ EXPECT_TRUE(iter == empty.rend());
+ EXPECT_FALSE(iter != empty.rend());
+ EXPECT_FALSE(iter < empty.rend());
+}
+
+TEST(fxcrt, ByteStringOneCharReverseIterator) {
+ CFX_ByteString one_str("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, ByteStringMultiCharReverseIterator) {
+ CFX_ByteString multi_str("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, ByteStringCNotNull) {
CFX_ByteStringC string3("abc");
CFX_ByteStringC string6("abcdef");
@@ -1200,6 +1267,73 @@ TEST(fxcrt, ByteStringCMultiCharIterator) {
EXPECT_EQ('a' + 'b' + 'c', sum);
}
+TEST(fxcrt, ByteStringCEmptyReverseIterator) {
+ CFX_ByteStringC empty;
+ auto iter = empty.rbegin();
+ EXPECT_TRUE(iter == empty.rend());
+ EXPECT_FALSE(iter != empty.rend());
+ EXPECT_FALSE(iter < empty.rend());
+}
+
+TEST(fxcrt, ByteStringCOneCharReverseIterator) {
+ CFX_ByteStringC one_str("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, ByteStringCMultiCharReverseIterator) {
+ CFX_ByteStringC multi_str("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, ByteStringCAnyAllNoneOf) {
CFX_ByteStringC str("aaaaaaaaaaaaaaaaab");
EXPECT_FALSE(std::all_of(str.begin(), str.end(),