diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-04-17 14:14:01 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-17 21:29:04 +0000 |
commit | 8f0bf890b4b15148a149bf9bbeead4eed6675e8a (patch) | |
tree | f6c98170aea417f2dd2190ec71f94af150949817 /core/fxcrt/cfx_bytestring_unittest.cpp | |
parent | c329d59b16b89f3533f9d309ed297938af865ae0 (diff) | |
download | pdfium-8f0bf890b4b15148a149bf9bbeead4eed6675e8a.tar.xz |
Add iterators for Byte/WideStringCs.
Change-Id: I40ec07c0da54bcf36c83fa26ff457cd4b98a91cf
Reviewed-on: https://pdfium-review.googlesource.com/4261
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_bytestring_unittest.cpp')
-rw-r--r-- | core/fxcrt/cfx_bytestring_unittest.cpp | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/core/fxcrt/cfx_bytestring_unittest.cpp b/core/fxcrt/cfx_bytestring_unittest.cpp index 9cfc773fad..42627c2299 100644 --- a/core/fxcrt/cfx_bytestring_unittest.cpp +++ b/core/fxcrt/cfx_bytestring_unittest.cpp @@ -4,10 +4,12 @@ #include "core/fxcrt/cfx_bytestring.h" +#include <algorithm> #include <vector> #include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/base/stl_util.h" TEST(fxcrt, ByteStringOperatorSubscript) { // CFX_ByteString includes the NUL terminator for non-empty strings. @@ -1031,6 +1033,70 @@ TEST(fxcrt, ByteStringCOperatorNE) { EXPECT_TRUE(c_string3 != byte_string_c); } +TEST(fxcrt, ByteStringCNullIterator) { + CFX_ByteStringC null_str; + int32_t sum = 0; + bool any_present = false; + for (const auto& c : null_str) { + sum += c; // Avoid unused arg warnings. + any_present = true; + } + EXPECT_FALSE(any_present); + EXPECT_EQ(0, sum); +} + +TEST(fxcrt, ByteStringCEmptyIterator) { + CFX_ByteStringC empty_str(""); + int32_t sum = 0; + bool any_present = false; + for (const auto& c : empty_str) { + any_present = true; + sum += c; // Avoid unused arg warnings. + } + EXPECT_FALSE(any_present); + EXPECT_EQ(0, sum); +} + +TEST(fxcrt, ByteStringCOneCharIterator) { + CFX_ByteStringC one_str("a"); + int32_t sum = 0; + bool any_present = false; + for (const auto& c : one_str) { + any_present = true; + sum += c; // Avoid unused arg warnings. + } + EXPECT_TRUE(any_present); + EXPECT_EQ('a', sum); +} + +TEST(fxcrt, ByteStringCMultiCharIterator) { + CFX_ByteStringC one_str("abc"); + int32_t sum = 0; + bool any_present = false; + for (const auto& c : one_str) { + any_present = true; + sum += c; // Avoid unused arg warnings. + } + EXPECT_TRUE(any_present); + EXPECT_EQ('a' + 'b' + 'c', sum); +} + +TEST(fxcrt, ByteStringCAnyAllNoneOf) { + CFX_ByteStringC str("aaaaaaaaaaaaaaaaab"); + EXPECT_FALSE(std::all_of(str.begin(), str.end(), + [](const char& c) { return c == 'a'; })); + + EXPECT_FALSE(std::none_of(str.begin(), str.end(), + [](const char& c) { return c == 'a'; })); + + EXPECT_TRUE(std::any_of(str.begin(), str.end(), + [](const char& c) { return c == 'a'; })); + + EXPECT_TRUE(pdfium::ContainsValue(str, 'a')); + EXPECT_TRUE(pdfium::ContainsValue(str, 'b')); + EXPECT_FALSE(pdfium::ContainsValue(str, 'z')); +} + TEST(fxcrt, ByteStringFormatWidth) { { CFX_ByteString str; @@ -1109,3 +1175,67 @@ TEST(fxcrt, ByteStringInitializerList) { many_str = {"fish", " and ", "chips", " and ", "soda"}; EXPECT_EQ("fish and chips and soda", many_str); } + +TEST(fxcrt, ByteStringNullIterator) { + CFX_ByteString null_str; + int32_t sum = 0; + bool any_present = false; + for (const auto& c : null_str) { + sum += c; // Avoid unused arg warnings. + any_present = true; + } + EXPECT_FALSE(any_present); + EXPECT_EQ(0, sum); +} + +TEST(fxcrt, ByteStringEmptyIterator) { + CFX_ByteString empty_str(""); + int32_t sum = 0; + bool any_present = false; + for (const auto& c : empty_str) { + any_present = true; + sum += c; // Avoid unused arg warnings. + } + EXPECT_FALSE(any_present); + EXPECT_EQ(0, sum); +} + +TEST(fxcrt, ByteStringOneCharIterator) { + CFX_ByteString one_str("a"); + int32_t sum = 0; + bool any_present = false; + for (const auto& c : one_str) { + any_present = true; + sum += c; // Avoid unused arg warnings. + } + EXPECT_TRUE(any_present); + EXPECT_EQ('a', sum); +} + +TEST(fxcrt, ByteStringMultiCharIterator) { + CFX_ByteString one_str("abc"); + int32_t sum = 0; + bool any_present = false; + for (const auto& c : one_str) { + any_present = true; + sum += c; // Avoid unused arg warnings. + } + EXPECT_TRUE(any_present); + EXPECT_EQ('a' + 'b' + 'c', sum); +} + +TEST(fxcrt, ByteStringAnyAllNoneOf) { + CFX_ByteString str("aaaaaaaaaaaaaaaaab"); + EXPECT_FALSE(std::all_of(str.begin(), str.end(), + [](const char& c) { return c == 'a'; })); + + EXPECT_FALSE(std::none_of(str.begin(), str.end(), + [](const char& c) { return c == 'a'; })); + + EXPECT_TRUE(std::any_of(str.begin(), str.end(), + [](const char& c) { return c == 'a'; })); + + EXPECT_TRUE(pdfium::ContainsValue(str, 'a')); + EXPECT_TRUE(pdfium::ContainsValue(str, 'b')); + EXPECT_FALSE(pdfium::ContainsValue(str, 'z')); +} |