diff options
Diffstat (limited to 'core/fxcrt/cfx_widestring_unittest.cpp')
-rw-r--r-- | core/fxcrt/cfx_widestring_unittest.cpp | 129 |
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')); +} |