summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_widestring_unittest.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-17 14:14:01 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-17 21:29:04 +0000
commit8f0bf890b4b15148a149bf9bbeead4eed6675e8a (patch)
treef6c98170aea417f2dd2190ec71f94af150949817 /core/fxcrt/cfx_widestring_unittest.cpp
parentc329d59b16b89f3533f9d309ed297938af865ae0 (diff)
downloadpdfium-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_widestring_unittest.cpp')
-rw-r--r--core/fxcrt/cfx_widestring_unittest.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/core/fxcrt/cfx_widestring_unittest.cpp b/core/fxcrt/cfx_widestring_unittest.cpp
index 498b4f0b6a..a9cb2d34cd 100644
--- a/core/fxcrt/cfx_widestring_unittest.cpp
+++ b/core/fxcrt/cfx_widestring_unittest.cpp
@@ -4,6 +4,7 @@
#include "core/fxcrt/cfx_widestring.h"
+#include <algorithm>
#include <vector>
#include "testing/fx_string_testhelpers.h"
@@ -871,6 +872,70 @@ TEST(fxcrt, WideStringCFind) {
EXPECT_EQ(2, hibyte_string.Find(L'\xff08'));
}
+TEST(fxcrt, WideStringCNullIterator) {
+ CFX_WideStringC 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, WideStringCEmptyIterator) {
+ CFX_WideStringC empty_str(L"");
+ 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, WideStringCOneCharIterator) {
+ CFX_WideStringC one_str(L"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(static_cast<int32_t>(L'a'), sum);
+}
+
+TEST(fxcrt, WideStringCMultiCharIterator) {
+ CFX_WideStringC one_str(L"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(static_cast<int32_t>(L'a' + L'b' + L'c'), sum);
+}
+
+TEST(fxcrt, WideStringCAnyAllNoneOf) {
+ CFX_WideStringC str(L"aaaaaaaaaaaaaaaaab");
+ EXPECT_FALSE(std::all_of(str.begin(), str.end(),
+ [](const wchar_t& c) { return c == L'a'; }));
+
+ EXPECT_FALSE(std::none_of(str.begin(), str.end(),
+ [](const wchar_t& c) { return c == L'a'; }));
+
+ EXPECT_TRUE(std::any_of(str.begin(), str.end(),
+ [](const wchar_t& c) { return c == L'a'; }));
+
+ EXPECT_TRUE(pdfium::ContainsValue(str, L'a'));
+ EXPECT_TRUE(pdfium::ContainsValue(str, L'b'));
+ EXPECT_FALSE(pdfium::ContainsValue(str, L'z'));
+}
+
TEST(fxcrt, WideStringFormatWidth) {
{
CFX_WideString str;
@@ -966,3 +1031,67 @@ TEST(fxcrt, WidStringInitializerList) {
many_str = {L"fish", L" and ", L"chips", L" and ", L"soda"};
EXPECT_EQ(L"fish and chips and soda", many_str);
}
+
+TEST(fxcrt, WideStringNullIterator) {
+ CFX_WideString 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, WideStringEmptyIterator) {
+ CFX_WideString empty_str(L"");
+ 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, WideStringOneCharIterator) {
+ CFX_WideString one_str(L"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(static_cast<int32_t>(L'a'), sum);
+}
+
+TEST(fxcrt, WideStringMultiCharIterator) {
+ CFX_WideString one_str(L"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(static_cast<int32_t>(L'a' + L'b' + L'c'), sum);
+}
+
+TEST(fxcrt, WideStringAnyAllNoneOf) {
+ CFX_WideString str(L"aaaaaaaaaaaaaaaaab");
+ EXPECT_FALSE(std::all_of(str.begin(), str.end(),
+ [](const wchar_t& c) { return c == L'a'; }));
+
+ EXPECT_FALSE(std::none_of(str.begin(), str.end(),
+ [](const wchar_t& c) { return c == L'a'; }));
+
+ EXPECT_TRUE(std::any_of(str.begin(), str.end(),
+ [](const wchar_t& c) { return c == L'a'; }));
+
+ EXPECT_TRUE(pdfium::ContainsValue(str, L'a'));
+ EXPECT_TRUE(pdfium::ContainsValue(str, L'b'));
+ EXPECT_FALSE(pdfium::ContainsValue(str, L'z'));
+}