Merge to XFA: Fix comparison of CFX_ByteString and CFX_WideString.
Original Review URL: https://codereview.chromium.org/1141763002
BUG=pdfium:160
TBR=thestig@chromium.org
Review URL: https://codereview.chromium.org/1140093003
diff --git a/core/src/fxcrt/fx_basic_bstring.cpp b/core/src/fxcrt/fx_basic_bstring.cpp
index 3162149..65f4b36 100644
--- a/core/src/fxcrt/fx_basic_bstring.cpp
+++ b/core/src/fxcrt/fx_basic_bstring.cpp
@@ -254,10 +254,10 @@
bool CFX_ByteString::Equal(const char* ptr) const
{
if (!m_pData) {
- return !ptr;
+ return !ptr || ptr[0] == '\0';
}
if (!ptr) {
- return false;
+ return m_pData->m_nDataLength == 0;
}
return strlen(ptr) == m_pData->m_nDataLength &&
FXSYS_memcmp32(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0;
@@ -272,10 +272,10 @@
}
bool CFX_ByteString::Equal(const CFX_ByteString& other) const
{
- if (!m_pData) {
+ if (IsEmpty()) {
return other.IsEmpty();
}
- if (!other.m_pData) {
+ if (other.IsEmpty()) {
return false;
}
return other.m_pData->m_nDataLength == m_pData->m_nDataLength &&
diff --git a/core/src/fxcrt/fx_basic_bstring_unittest.cpp b/core/src/fxcrt/fx_basic_bstring_unittest.cpp
index 9f37cbc..1f80207 100644
--- a/core/src/fxcrt/fx_basic_bstring_unittest.cpp
+++ b/core/src/fxcrt/fx_basic_bstring_unittest.cpp
@@ -46,105 +46,207 @@
}
TEST(fxcrt, ByteStringOperatorEQ) {
+ CFX_ByteString null_string;
+ EXPECT_TRUE(null_string == null_string);
+
+ CFX_ByteString empty_string("");
+ EXPECT_TRUE(empty_string == empty_string);
+ EXPECT_TRUE(empty_string == null_string);
+ EXPECT_TRUE(null_string == empty_string);
+
+ CFX_ByteString deleted_string("hello");
+ deleted_string.Delete(0, 5);
+ EXPECT_TRUE(deleted_string == deleted_string);
+ EXPECT_TRUE(deleted_string == null_string);
+ EXPECT_TRUE(deleted_string == empty_string);
+ EXPECT_TRUE(null_string == deleted_string);
+ EXPECT_TRUE(empty_string == deleted_string);
+
CFX_ByteString byte_string("hello");
- ASSERT_TRUE(byte_string == byte_string);
+ EXPECT_TRUE(byte_string == byte_string);
+ EXPECT_FALSE(byte_string == null_string);
+ EXPECT_FALSE(byte_string == empty_string);
+ EXPECT_FALSE(byte_string == deleted_string);
+ EXPECT_FALSE(null_string == byte_string);
+ EXPECT_FALSE(empty_string == byte_string);
+ EXPECT_FALSE(deleted_string == byte_string);
CFX_ByteString byte_string_same1("hello");
- ASSERT_TRUE(byte_string == byte_string_same1);
- ASSERT_TRUE(byte_string_same1 == byte_string);
+ EXPECT_TRUE(byte_string == byte_string_same1);
+ EXPECT_TRUE(byte_string_same1 == byte_string);
CFX_ByteString byte_string_same2(byte_string);
- ASSERT_TRUE(byte_string == byte_string_same2);
- ASSERT_TRUE(byte_string_same2 == byte_string);
+ EXPECT_TRUE(byte_string == byte_string_same2);
+ EXPECT_TRUE(byte_string_same2 == byte_string);
CFX_ByteString byte_string1("he");
CFX_ByteString byte_string2("hellp");
CFX_ByteString byte_string3("hellod");
- ASSERT_FALSE(byte_string == byte_string1);
- ASSERT_FALSE(byte_string == byte_string2);
- ASSERT_FALSE(byte_string == byte_string3);
- ASSERT_FALSE(byte_string1 == byte_string);
- ASSERT_FALSE(byte_string2 == byte_string);
- ASSERT_FALSE(byte_string3 == byte_string);
+ EXPECT_FALSE(byte_string == byte_string1);
+ EXPECT_FALSE(byte_string == byte_string2);
+ EXPECT_FALSE(byte_string == byte_string3);
+ EXPECT_FALSE(byte_string1 == byte_string);
+ EXPECT_FALSE(byte_string2 == byte_string);
+ EXPECT_FALSE(byte_string3 == byte_string);
+
+ CFX_ByteStringC null_string_c;
+ CFX_ByteStringC empty_string_c("");
+ EXPECT_TRUE(null_string == null_string_c);
+ EXPECT_TRUE(null_string == empty_string_c);
+ EXPECT_TRUE(empty_string == null_string_c);
+ EXPECT_TRUE(empty_string == empty_string_c);
+ EXPECT_TRUE(deleted_string == null_string_c);
+ EXPECT_TRUE(deleted_string == empty_string_c);
+ EXPECT_TRUE(null_string_c == null_string);
+ EXPECT_TRUE(empty_string_c == null_string);
+ EXPECT_TRUE(null_string_c == empty_string);
+ EXPECT_TRUE(empty_string_c == empty_string);
+ EXPECT_TRUE(null_string_c == deleted_string);
+ EXPECT_TRUE(empty_string_c == deleted_string);
CFX_ByteStringC byte_string_c_same1("hello");
- ASSERT_TRUE(byte_string == byte_string_c_same1);
- ASSERT_TRUE(byte_string_c_same1 == byte_string);
+ EXPECT_TRUE(byte_string == byte_string_c_same1);
+ EXPECT_TRUE(byte_string_c_same1 == byte_string);
CFX_ByteStringC byte_string_c1("he");
CFX_ByteStringC byte_string_c2("hellp");
CFX_ByteStringC byte_string_c3("hellod");
- ASSERT_FALSE(byte_string == byte_string_c1);
- ASSERT_FALSE(byte_string == byte_string_c2);
- ASSERT_FALSE(byte_string == byte_string_c3);
- ASSERT_FALSE(byte_string_c1 == byte_string);
- ASSERT_FALSE(byte_string_c2 == byte_string);
- ASSERT_FALSE(byte_string_c3 == byte_string);
+ EXPECT_FALSE(byte_string == byte_string_c1);
+ EXPECT_FALSE(byte_string == byte_string_c2);
+ EXPECT_FALSE(byte_string == byte_string_c3);
+ EXPECT_FALSE(byte_string_c1 == byte_string);
+ EXPECT_FALSE(byte_string_c2 == byte_string);
+ EXPECT_FALSE(byte_string_c3 == byte_string);
+
+ const char* c_null_string = nullptr;
+ const char* c_empty_string = "";
+ EXPECT_TRUE(null_string == c_null_string);
+ EXPECT_TRUE(null_string == c_empty_string);
+ EXPECT_TRUE(empty_string == c_null_string);
+ EXPECT_TRUE(empty_string == c_empty_string);
+ EXPECT_TRUE(deleted_string == c_null_string);
+ EXPECT_TRUE(deleted_string == c_empty_string);
+ EXPECT_TRUE(c_null_string == null_string);
+ EXPECT_TRUE(c_empty_string == null_string);
+ EXPECT_TRUE(c_null_string == empty_string);
+ EXPECT_TRUE(c_empty_string == empty_string);
+ EXPECT_TRUE(c_null_string == deleted_string);
+ EXPECT_TRUE(c_empty_string == deleted_string);
const char* c_string_same1 = "hello";
- ASSERT_TRUE(byte_string == c_string_same1);
- ASSERT_TRUE(c_string_same1 == byte_string);
+ EXPECT_TRUE(byte_string == c_string_same1);
+ EXPECT_TRUE(c_string_same1 == byte_string);
const char* c_string1 = "he";
const char* c_string2 = "hellp";
const char* c_string3 = "hellod";
- ASSERT_FALSE(byte_string == c_string1);
- ASSERT_FALSE(byte_string == c_string2);
- ASSERT_FALSE(byte_string == c_string3);
- ASSERT_FALSE(c_string1 == byte_string);
- ASSERT_FALSE(c_string2 == byte_string);
- ASSERT_FALSE(c_string3 == byte_string);
+ EXPECT_FALSE(byte_string == c_string1);
+ EXPECT_FALSE(byte_string == c_string2);
+ EXPECT_FALSE(byte_string == c_string3);
+ EXPECT_FALSE(c_string1 == byte_string);
+ EXPECT_FALSE(c_string2 == byte_string);
+ EXPECT_FALSE(c_string3 == byte_string);
}
TEST(fxcrt, ByteStringOperatorNE) {
+ CFX_ByteString null_string;
+ EXPECT_FALSE(null_string != null_string);
+
+ CFX_ByteString empty_string("");
+ EXPECT_FALSE(empty_string != empty_string);
+ EXPECT_FALSE(empty_string != null_string);
+ EXPECT_FALSE(null_string != empty_string);
+
+ CFX_ByteString deleted_string("hello");
+ deleted_string.Delete(0, 5);
+ EXPECT_FALSE(deleted_string != deleted_string);
+ EXPECT_FALSE(deleted_string != null_string);
+ EXPECT_FALSE(deleted_string != empty_string);
+ EXPECT_FALSE(deleted_string != deleted_string);
+ EXPECT_FALSE(null_string != deleted_string);
+ EXPECT_FALSE(empty_string != deleted_string);
+ EXPECT_FALSE(deleted_string != deleted_string);
+
CFX_ByteString byte_string("hello");
- ASSERT_FALSE(byte_string != byte_string);
+ EXPECT_FALSE(byte_string != byte_string);
+ EXPECT_TRUE(byte_string != null_string);
+ EXPECT_TRUE(byte_string != empty_string);
+ EXPECT_TRUE(byte_string != deleted_string);
+ EXPECT_TRUE(null_string != byte_string);
+ EXPECT_TRUE(empty_string != byte_string);
+ EXPECT_TRUE(deleted_string != byte_string);
CFX_ByteString byte_string_same1("hello");
- ASSERT_FALSE(byte_string != byte_string_same1);
- ASSERT_FALSE(byte_string_same1 != byte_string);
+ EXPECT_FALSE(byte_string != byte_string_same1);
+ EXPECT_FALSE(byte_string_same1 != byte_string);
CFX_ByteString byte_string_same2(byte_string);
- ASSERT_FALSE(byte_string != byte_string_same2);
- ASSERT_FALSE(byte_string_same2 != byte_string);
+ EXPECT_FALSE(byte_string != byte_string_same2);
+ EXPECT_FALSE(byte_string_same2 != byte_string);
CFX_ByteString byte_string1("he");
CFX_ByteString byte_string2("hellp");
CFX_ByteString byte_string3("hellod");
- ASSERT_TRUE(byte_string != byte_string1);
- ASSERT_TRUE(byte_string != byte_string2);
- ASSERT_TRUE(byte_string != byte_string3);
- ASSERT_TRUE(byte_string1 != byte_string);
- ASSERT_TRUE(byte_string2 != byte_string);
- ASSERT_TRUE(byte_string3 != byte_string);
+ EXPECT_TRUE(byte_string != byte_string1);
+ EXPECT_TRUE(byte_string != byte_string2);
+ EXPECT_TRUE(byte_string != byte_string3);
+ EXPECT_TRUE(byte_string1 != byte_string);
+ EXPECT_TRUE(byte_string2 != byte_string);
+ EXPECT_TRUE(byte_string3 != byte_string);
+
+ CFX_ByteStringC null_string_c;
+ CFX_ByteStringC empty_string_c("");
+ EXPECT_FALSE(null_string != null_string_c);
+ EXPECT_FALSE(null_string != empty_string_c);
+ EXPECT_FALSE(empty_string != null_string_c);
+ EXPECT_FALSE(empty_string != empty_string_c);
+ EXPECT_FALSE(null_string_c != null_string);
+ EXPECT_FALSE(empty_string_c != null_string);
+ EXPECT_FALSE(null_string_c != empty_string);
+ EXPECT_FALSE(empty_string_c != empty_string);
CFX_ByteStringC byte_string_c_same1("hello");
- ASSERT_FALSE(byte_string != byte_string_c_same1);
- ASSERT_FALSE(byte_string_c_same1 != byte_string);
+ EXPECT_FALSE(byte_string != byte_string_c_same1);
+ EXPECT_FALSE(byte_string_c_same1 != byte_string);
CFX_ByteStringC byte_string_c1("he");
CFX_ByteStringC byte_string_c2("hellp");
CFX_ByteStringC byte_string_c3("hellod");
- ASSERT_TRUE(byte_string != byte_string_c1);
- ASSERT_TRUE(byte_string != byte_string_c2);
- ASSERT_TRUE(byte_string != byte_string_c3);
- ASSERT_TRUE(byte_string_c1 != byte_string);
- ASSERT_TRUE(byte_string_c2 != byte_string);
- ASSERT_TRUE(byte_string_c3 != byte_string);
+ EXPECT_TRUE(byte_string != byte_string_c1);
+ EXPECT_TRUE(byte_string != byte_string_c2);
+ EXPECT_TRUE(byte_string != byte_string_c3);
+ EXPECT_TRUE(byte_string_c1 != byte_string);
+ EXPECT_TRUE(byte_string_c2 != byte_string);
+ EXPECT_TRUE(byte_string_c3 != byte_string);
+
+ const char* c_null_string = nullptr;
+ const char* c_empty_string = "";
+ EXPECT_FALSE(null_string != c_null_string);
+ EXPECT_FALSE(null_string != c_empty_string);
+ EXPECT_FALSE(empty_string != c_null_string);
+ EXPECT_FALSE(empty_string != c_empty_string);
+ EXPECT_FALSE(deleted_string != c_null_string);
+ EXPECT_FALSE(deleted_string != c_empty_string);
+ EXPECT_FALSE(c_null_string != null_string);
+ EXPECT_FALSE(c_empty_string != null_string);
+ EXPECT_FALSE(c_null_string != empty_string);
+ EXPECT_FALSE(c_empty_string != empty_string);
+ EXPECT_FALSE(c_null_string != deleted_string);
+ EXPECT_FALSE(c_empty_string != deleted_string);
const char* c_string_same1 = "hello";
- ASSERT_FALSE(byte_string != c_string_same1);
- ASSERT_FALSE(c_string_same1 != byte_string);
+ EXPECT_FALSE(byte_string != c_string_same1);
+ EXPECT_FALSE(c_string_same1 != byte_string);
const char* c_string1 = "he";
const char* c_string2 = "hellp";
const char* c_string3 = "hellod";
- ASSERT_TRUE(byte_string != c_string1);
- ASSERT_TRUE(byte_string != c_string2);
- ASSERT_TRUE(byte_string != c_string3);
- ASSERT_TRUE(c_string1 != byte_string);
- ASSERT_TRUE(c_string2 != byte_string);
- ASSERT_TRUE(c_string3 != byte_string);
+ EXPECT_TRUE(byte_string != c_string1);
+ EXPECT_TRUE(byte_string != c_string2);
+ EXPECT_TRUE(byte_string != c_string3);
+ EXPECT_TRUE(c_string1 != byte_string);
+ EXPECT_TRUE(c_string2 != byte_string);
+ EXPECT_TRUE(c_string3 != byte_string);
}
TEST(fxcrt, ByteStringCNull) {
@@ -373,104 +475,104 @@
TEST(fxcrt, ByteStringCOperatorEQ) {
CFX_ByteStringC byte_string_c("hello");
- ASSERT_TRUE(byte_string_c == byte_string_c);
+ EXPECT_TRUE(byte_string_c == byte_string_c);
CFX_ByteStringC byte_string_c_same1("hello");
- ASSERT_TRUE(byte_string_c == byte_string_c_same1);
- ASSERT_TRUE(byte_string_c_same1 == byte_string_c);
+ EXPECT_TRUE(byte_string_c == byte_string_c_same1);
+ EXPECT_TRUE(byte_string_c_same1 == byte_string_c);
CFX_ByteStringC byte_string_c_same2(byte_string_c);
- ASSERT_TRUE(byte_string_c == byte_string_c_same2);
- ASSERT_TRUE(byte_string_c_same2 == byte_string_c);
+ EXPECT_TRUE(byte_string_c == byte_string_c_same2);
+ EXPECT_TRUE(byte_string_c_same2 == byte_string_c);
CFX_ByteStringC byte_string_c1("he");
CFX_ByteStringC byte_string_c2("hellp");
CFX_ByteStringC byte_string_c3("hellod");
- ASSERT_FALSE(byte_string_c == byte_string_c1);
- ASSERT_FALSE(byte_string_c == byte_string_c2);
- ASSERT_FALSE(byte_string_c == byte_string_c3);
- ASSERT_FALSE(byte_string_c1 == byte_string_c);
- ASSERT_FALSE(byte_string_c2 == byte_string_c);
- ASSERT_FALSE(byte_string_c3 == byte_string_c);
+ EXPECT_FALSE(byte_string_c == byte_string_c1);
+ EXPECT_FALSE(byte_string_c == byte_string_c2);
+ EXPECT_FALSE(byte_string_c == byte_string_c3);
+ EXPECT_FALSE(byte_string_c1 == byte_string_c);
+ EXPECT_FALSE(byte_string_c2 == byte_string_c);
+ EXPECT_FALSE(byte_string_c3 == byte_string_c);
CFX_ByteString byte_string_same1("hello");
- ASSERT_TRUE(byte_string_c == byte_string_same1);
- ASSERT_TRUE(byte_string_same1 == byte_string_c);
+ EXPECT_TRUE(byte_string_c == byte_string_same1);
+ EXPECT_TRUE(byte_string_same1 == byte_string_c);
CFX_ByteString byte_string1("he");
CFX_ByteString byte_string2("hellp");
CFX_ByteString byte_string3("hellod");
- ASSERT_FALSE(byte_string_c == byte_string1);
- ASSERT_FALSE(byte_string_c == byte_string2);
- ASSERT_FALSE(byte_string_c == byte_string3);
- ASSERT_FALSE(byte_string1 == byte_string_c);
- ASSERT_FALSE(byte_string2 == byte_string_c);
- ASSERT_FALSE(byte_string3 == byte_string_c);
+ EXPECT_FALSE(byte_string_c == byte_string1);
+ EXPECT_FALSE(byte_string_c == byte_string2);
+ EXPECT_FALSE(byte_string_c == byte_string3);
+ EXPECT_FALSE(byte_string1 == byte_string_c);
+ EXPECT_FALSE(byte_string2 == byte_string_c);
+ EXPECT_FALSE(byte_string3 == byte_string_c);
const char* c_string_same1 = "hello";
- ASSERT_TRUE(byte_string_c == c_string_same1);
- ASSERT_TRUE(c_string_same1 == byte_string_c);
+ EXPECT_TRUE(byte_string_c == c_string_same1);
+ EXPECT_TRUE(c_string_same1 == byte_string_c);
const char* c_string1 = "he";
const char* c_string2 = "hellp";
const char* c_string3 = "hellod";
- ASSERT_FALSE(byte_string_c == c_string1);
- ASSERT_FALSE(byte_string_c == c_string2);
- ASSERT_FALSE(byte_string_c == c_string3);
+ EXPECT_FALSE(byte_string_c == c_string1);
+ EXPECT_FALSE(byte_string_c == c_string2);
+ EXPECT_FALSE(byte_string_c == c_string3);
- ASSERT_FALSE(c_string1 == byte_string_c);
- ASSERT_FALSE(c_string2 == byte_string_c);
- ASSERT_FALSE(c_string3 == byte_string_c);
+ EXPECT_FALSE(c_string1 == byte_string_c);
+ EXPECT_FALSE(c_string2 == byte_string_c);
+ EXPECT_FALSE(c_string3 == byte_string_c);
}
TEST(fxcrt, ByteStringCOperatorNE) {
CFX_ByteStringC byte_string_c("hello");
- ASSERT_FALSE(byte_string_c != byte_string_c);
+ EXPECT_FALSE(byte_string_c != byte_string_c);
CFX_ByteStringC byte_string_c_same1("hello");
- ASSERT_FALSE(byte_string_c != byte_string_c_same1);
- ASSERT_FALSE(byte_string_c_same1 != byte_string_c);
+ EXPECT_FALSE(byte_string_c != byte_string_c_same1);
+ EXPECT_FALSE(byte_string_c_same1 != byte_string_c);
CFX_ByteStringC byte_string_c_same2(byte_string_c);
- ASSERT_FALSE(byte_string_c != byte_string_c_same2);
- ASSERT_FALSE(byte_string_c_same2 != byte_string_c);
+ EXPECT_FALSE(byte_string_c != byte_string_c_same2);
+ EXPECT_FALSE(byte_string_c_same2 != byte_string_c);
CFX_ByteStringC byte_string_c1("he");
CFX_ByteStringC byte_string_c2("hellp");
CFX_ByteStringC byte_string_c3("hellod");
- ASSERT_TRUE(byte_string_c != byte_string_c1);
- ASSERT_TRUE(byte_string_c != byte_string_c2);
- ASSERT_TRUE(byte_string_c != byte_string_c3);
- ASSERT_TRUE(byte_string_c1 != byte_string_c);
- ASSERT_TRUE(byte_string_c2 != byte_string_c);
- ASSERT_TRUE(byte_string_c3 != byte_string_c);
+ EXPECT_TRUE(byte_string_c != byte_string_c1);
+ EXPECT_TRUE(byte_string_c != byte_string_c2);
+ EXPECT_TRUE(byte_string_c != byte_string_c3);
+ EXPECT_TRUE(byte_string_c1 != byte_string_c);
+ EXPECT_TRUE(byte_string_c2 != byte_string_c);
+ EXPECT_TRUE(byte_string_c3 != byte_string_c);
CFX_ByteString byte_string_same1("hello");
- ASSERT_FALSE(byte_string_c != byte_string_same1);
- ASSERT_FALSE(byte_string_same1 != byte_string_c);
+ EXPECT_FALSE(byte_string_c != byte_string_same1);
+ EXPECT_FALSE(byte_string_same1 != byte_string_c);
CFX_ByteString byte_string1("he");
CFX_ByteString byte_string2("hellp");
CFX_ByteString byte_string3("hellod");
- ASSERT_TRUE(byte_string_c != byte_string1);
- ASSERT_TRUE(byte_string_c != byte_string2);
- ASSERT_TRUE(byte_string_c != byte_string3);
- ASSERT_TRUE(byte_string1 != byte_string_c);
- ASSERT_TRUE(byte_string2 != byte_string_c);
- ASSERT_TRUE(byte_string3 != byte_string_c);
+ EXPECT_TRUE(byte_string_c != byte_string1);
+ EXPECT_TRUE(byte_string_c != byte_string2);
+ EXPECT_TRUE(byte_string_c != byte_string3);
+ EXPECT_TRUE(byte_string1 != byte_string_c);
+ EXPECT_TRUE(byte_string2 != byte_string_c);
+ EXPECT_TRUE(byte_string3 != byte_string_c);
const char* c_string_same1 = "hello";
- ASSERT_FALSE(byte_string_c != c_string_same1);
- ASSERT_FALSE(c_string_same1 != byte_string_c);
+ EXPECT_FALSE(byte_string_c != c_string_same1);
+ EXPECT_FALSE(c_string_same1 != byte_string_c);
const char* c_string1 = "he";
const char* c_string2 = "hellp";
const char* c_string3 = "hellod";
- ASSERT_TRUE(byte_string_c != c_string1);
- ASSERT_TRUE(byte_string_c != c_string2);
- ASSERT_TRUE(byte_string_c != c_string3);
+ EXPECT_TRUE(byte_string_c != c_string1);
+ EXPECT_TRUE(byte_string_c != c_string2);
+ EXPECT_TRUE(byte_string_c != c_string3);
- ASSERT_TRUE(c_string1 != byte_string_c);
- ASSERT_TRUE(c_string2 != byte_string_c);
- ASSERT_TRUE(c_string3 != byte_string_c);
+ EXPECT_TRUE(c_string1 != byte_string_c);
+ EXPECT_TRUE(c_string2 != byte_string_c);
+ EXPECT_TRUE(c_string3 != byte_string_c);
}
diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp
index ce3166b..0511b84 100644
--- a/core/src/fxcrt/fx_basic_wstring.cpp
+++ b/core/src/fxcrt/fx_basic_wstring.cpp
@@ -206,10 +206,10 @@
bool CFX_WideString::Equal(const wchar_t* ptr) const
{
if (!m_pData) {
- return !ptr;
+ return !ptr || ptr[0] == L'\0';
}
if (!ptr) {
- return false;
+ return m_pData->m_nDataLength == 0;
}
return wcslen(ptr) == m_pData->m_nDataLength &&
wmemcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0;
@@ -224,10 +224,10 @@
}
bool CFX_WideString::Equal(const CFX_WideString& other) const
{
- if (!m_pData) {
+ if (IsEmpty()) {
return other.IsEmpty();
}
- if (!other.m_pData) {
+ if (other.IsEmpty()) {
return false;
}
return other.m_pData->m_nDataLength == m_pData->m_nDataLength &&
diff --git a/core/src/fxcrt/fx_basic_wstring_unittest.cpp b/core/src/fxcrt/fx_basic_wstring_unittest.cpp
index 3b15006..21b5ae5 100644
--- a/core/src/fxcrt/fx_basic_wstring_unittest.cpp
+++ b/core/src/fxcrt/fx_basic_wstring_unittest.cpp
@@ -46,106 +46,207 @@
}
TEST(fxcrt, WideStringOperatorEQ) {
+ CFX_WideString null_string;
+ EXPECT_TRUE(null_string == null_string);
+
+ CFX_WideString empty_string(L"");
+ EXPECT_TRUE(empty_string == empty_string);
+ EXPECT_TRUE(empty_string == null_string);
+ EXPECT_TRUE(null_string == empty_string);
+
+ CFX_WideString deleted_string(L"hello");
+ deleted_string.Delete(0, 5);
+ EXPECT_TRUE(deleted_string == deleted_string);
+ EXPECT_TRUE(deleted_string == null_string);
+ EXPECT_TRUE(deleted_string == empty_string);
+ EXPECT_TRUE(null_string == deleted_string);
+ EXPECT_TRUE(null_string == empty_string);
+
CFX_WideString wide_string(L"hello");
- ASSERT_TRUE(wide_string == wide_string);
+ EXPECT_TRUE(wide_string == wide_string);
+ EXPECT_FALSE(wide_string == null_string);
+ EXPECT_FALSE(wide_string == empty_string);
+ EXPECT_FALSE(wide_string == deleted_string);
+ EXPECT_FALSE(null_string == wide_string);
+ EXPECT_FALSE(empty_string == wide_string);
+ EXPECT_FALSE(deleted_string == wide_string);
CFX_WideString wide_string_same1(L"hello");
- ASSERT_TRUE(wide_string == wide_string_same1);
- ASSERT_TRUE(wide_string_same1 == wide_string);
+ EXPECT_TRUE(wide_string == wide_string_same1);
+ EXPECT_TRUE(wide_string_same1 == wide_string);
CFX_WideString wide_string_same2(wide_string);
- ASSERT_TRUE(wide_string == wide_string_same2);
- ASSERT_TRUE(wide_string_same2 == wide_string);
+ EXPECT_TRUE(wide_string == wide_string_same2);
+ EXPECT_TRUE(wide_string_same2 == wide_string);
CFX_WideString wide_string1(L"he");
CFX_WideString wide_string2(L"hellp");
CFX_WideString wide_string3(L"hellod");
- ASSERT_FALSE(wide_string == wide_string1);
- ASSERT_FALSE(wide_string == wide_string2);
- ASSERT_FALSE(wide_string == wide_string3);
- ASSERT_FALSE(wide_string1 == wide_string);
- ASSERT_FALSE(wide_string2 == wide_string);
- ASSERT_FALSE(wide_string3 == wide_string);
+ EXPECT_FALSE(wide_string == wide_string1);
+ EXPECT_FALSE(wide_string == wide_string2);
+ EXPECT_FALSE(wide_string == wide_string3);
+ EXPECT_FALSE(wide_string1 == wide_string);
+ EXPECT_FALSE(wide_string2 == wide_string);
+ EXPECT_FALSE(wide_string3 == wide_string);
+
+ CFX_WideStringC null_string_c;
+ CFX_WideStringC empty_string_c(L"");
+ EXPECT_TRUE(null_string == null_string_c);
+ EXPECT_TRUE(null_string == empty_string_c);
+ EXPECT_TRUE(empty_string == null_string_c);
+ EXPECT_TRUE(empty_string == empty_string_c);
+ EXPECT_TRUE(deleted_string == null_string_c);
+ EXPECT_TRUE(deleted_string == empty_string_c);
+ EXPECT_TRUE(null_string_c == null_string);
+ EXPECT_TRUE(empty_string_c == null_string);
+ EXPECT_TRUE(null_string_c == empty_string);
+ EXPECT_TRUE(empty_string_c == empty_string);
+ EXPECT_TRUE(null_string_c == deleted_string);
+ EXPECT_TRUE(empty_string_c == deleted_string);
CFX_WideStringC wide_string_c_same1(L"hello");
- ASSERT_TRUE(wide_string == wide_string_c_same1);
- ASSERT_TRUE(wide_string_c_same1 == wide_string);
+ EXPECT_TRUE(wide_string == wide_string_c_same1);
+ EXPECT_TRUE(wide_string_c_same1 == wide_string);
CFX_WideStringC wide_string_c1(L"he");
CFX_WideStringC wide_string_c2(L"hellp");
CFX_WideStringC wide_string_c3(L"hellod");
- ASSERT_FALSE(wide_string == wide_string_c1);
- ASSERT_FALSE(wide_string == wide_string_c2);
- ASSERT_FALSE(wide_string == wide_string_c3);
- ASSERT_FALSE(wide_string_c1 == wide_string);
- ASSERT_FALSE(wide_string_c2 == wide_string);
- ASSERT_FALSE(wide_string_c3 == wide_string);
+ EXPECT_FALSE(wide_string == wide_string_c1);
+ EXPECT_FALSE(wide_string == wide_string_c2);
+ EXPECT_FALSE(wide_string == wide_string_c3);
+ EXPECT_FALSE(wide_string_c1 == wide_string);
+ EXPECT_FALSE(wide_string_c2 == wide_string);
+ EXPECT_FALSE(wide_string_c3 == wide_string);
+
+ const wchar_t* c_null_string = nullptr;
+ const wchar_t* c_empty_string = L"";
+ EXPECT_TRUE(null_string == c_null_string);
+ EXPECT_TRUE(null_string == c_empty_string);
+ EXPECT_TRUE(empty_string == c_null_string);
+ EXPECT_TRUE(empty_string == c_empty_string);
+ EXPECT_TRUE(deleted_string == c_null_string);
+ EXPECT_TRUE(deleted_string == c_empty_string);
+ EXPECT_TRUE(c_null_string == null_string);
+ EXPECT_TRUE(c_empty_string == null_string);
+ EXPECT_TRUE(c_null_string == empty_string);
+ EXPECT_TRUE(c_empty_string == empty_string);
+ EXPECT_TRUE(c_null_string == deleted_string);
+ EXPECT_TRUE(c_empty_string == deleted_string);
const wchar_t* c_string_same1 = L"hello";
- ASSERT_TRUE(wide_string == c_string_same1);
- ASSERT_TRUE(c_string_same1 == wide_string);
+ EXPECT_TRUE(wide_string == c_string_same1);
+ EXPECT_TRUE(c_string_same1 == wide_string);
const wchar_t* c_string1 = L"he";
const wchar_t* c_string2 = L"hellp";
const wchar_t* c_string3 = L"hellod";
- ASSERT_FALSE(wide_string == c_string1);
- ASSERT_FALSE(wide_string == c_string2);
- ASSERT_FALSE(wide_string == c_string3);
- ASSERT_FALSE(c_string1 == wide_string);
- ASSERT_FALSE(c_string2 == wide_string);
- ASSERT_FALSE(c_string3 == wide_string);
+ EXPECT_FALSE(wide_string == c_string1);
+ EXPECT_FALSE(wide_string == c_string2);
+ EXPECT_FALSE(wide_string == c_string3);
+ EXPECT_FALSE(c_string1 == wide_string);
+ EXPECT_FALSE(c_string2 == wide_string);
+ EXPECT_FALSE(c_string3 == wide_string);
}
TEST(fxcrt, WideStringOperatorNE) {
+ CFX_WideString null_string;
+ EXPECT_FALSE(null_string != null_string);
+
+ CFX_WideString empty_string(L"");
+ EXPECT_FALSE(empty_string != empty_string);
+ EXPECT_FALSE(empty_string != null_string);
+ EXPECT_FALSE(null_string != empty_string);
+
+ CFX_WideString deleted_string(L"hello");
+ deleted_string.Delete(0, 5);
+ EXPECT_FALSE(deleted_string != deleted_string);
+ EXPECT_FALSE(deleted_string != null_string);
+ EXPECT_FALSE(deleted_string != empty_string);
+ EXPECT_FALSE(null_string != deleted_string);
+ EXPECT_FALSE(null_string != empty_string);
+
CFX_WideString wide_string(L"hello");
- ASSERT_FALSE(wide_string != wide_string);
+ EXPECT_FALSE(wide_string != wide_string);
+ EXPECT_TRUE(wide_string != null_string);
+ EXPECT_TRUE(wide_string != empty_string);
+ EXPECT_TRUE(wide_string != deleted_string);
+ EXPECT_TRUE(null_string != wide_string);
+ EXPECT_TRUE(empty_string != wide_string);
+ EXPECT_TRUE(deleted_string != wide_string);
CFX_WideString wide_string_same1(L"hello");
- ASSERT_FALSE(wide_string != wide_string_same1);
- ASSERT_FALSE(wide_string_same1 != wide_string);
+ EXPECT_FALSE(wide_string != wide_string_same1);
+ EXPECT_FALSE(wide_string_same1 != wide_string);
CFX_WideString wide_string_same2(wide_string);
- ASSERT_FALSE(wide_string != wide_string_same2);
- ASSERT_FALSE(wide_string_same2 != wide_string);
+ EXPECT_FALSE(wide_string != wide_string_same2);
+ EXPECT_FALSE(wide_string_same2 != wide_string);
CFX_WideString wide_string1(L"he");
CFX_WideString wide_string2(L"hellp");
CFX_WideString wide_string3(L"hellod");
- ASSERT_TRUE(wide_string != wide_string1);
- ASSERT_TRUE(wide_string != wide_string2);
- ASSERT_TRUE(wide_string != wide_string3);
- ASSERT_TRUE(wide_string1 != wide_string);
- ASSERT_TRUE(wide_string2 != wide_string);
- ASSERT_TRUE(wide_string3 != wide_string);
+ EXPECT_TRUE(wide_string != wide_string1);
+ EXPECT_TRUE(wide_string != wide_string2);
+ EXPECT_TRUE(wide_string != wide_string3);
+ EXPECT_TRUE(wide_string1 != wide_string);
+ EXPECT_TRUE(wide_string2 != wide_string);
+ EXPECT_TRUE(wide_string3 != wide_string);
+
+ CFX_WideStringC null_string_c;
+ CFX_WideStringC empty_string_c(L"");
+ EXPECT_FALSE(null_string != null_string_c);
+ EXPECT_FALSE(null_string != empty_string_c);
+ EXPECT_FALSE(empty_string != null_string_c);
+ EXPECT_FALSE(empty_string != empty_string_c);
+ EXPECT_FALSE(deleted_string != null_string_c);
+ EXPECT_FALSE(deleted_string != empty_string_c);
+ EXPECT_FALSE(null_string_c != null_string);
+ EXPECT_FALSE(empty_string_c != null_string);
+ EXPECT_FALSE(null_string_c != empty_string);
+ EXPECT_FALSE(empty_string_c != empty_string);
CFX_WideStringC wide_string_c_same1(L"hello");
- ASSERT_FALSE(wide_string != wide_string_c_same1);
- ASSERT_FALSE(wide_string_c_same1 != wide_string);
+ EXPECT_FALSE(wide_string != wide_string_c_same1);
+ EXPECT_FALSE(wide_string_c_same1 != wide_string);
CFX_WideStringC wide_string_c1(L"he");
CFX_WideStringC wide_string_c2(L"hellp");
CFX_WideStringC wide_string_c3(L"hellod");
- ASSERT_TRUE(wide_string != wide_string_c1);
- ASSERT_TRUE(wide_string != wide_string_c2);
- ASSERT_TRUE(wide_string != wide_string_c3);
- ASSERT_TRUE(wide_string_c1 != wide_string);
- ASSERT_TRUE(wide_string_c2 != wide_string);
- ASSERT_TRUE(wide_string_c3 != wide_string);
+ EXPECT_TRUE(wide_string != wide_string_c1);
+ EXPECT_TRUE(wide_string != wide_string_c2);
+ EXPECT_TRUE(wide_string != wide_string_c3);
+ EXPECT_TRUE(wide_string_c1 != wide_string);
+ EXPECT_TRUE(wide_string_c2 != wide_string);
+ EXPECT_TRUE(wide_string_c3 != wide_string);
+
+ const wchar_t* c_null_string = nullptr;
+ const wchar_t* c_empty_string = L"";
+ EXPECT_FALSE(null_string != c_null_string);
+ EXPECT_FALSE(null_string != c_empty_string);
+ EXPECT_FALSE(empty_string != c_null_string);
+ EXPECT_FALSE(empty_string != c_empty_string);
+ EXPECT_FALSE(deleted_string != c_null_string);
+ EXPECT_FALSE(deleted_string != c_empty_string);
+ EXPECT_FALSE(c_null_string != null_string);
+ EXPECT_FALSE(c_empty_string != null_string);
+ EXPECT_FALSE(c_null_string != empty_string);
+ EXPECT_FALSE(c_empty_string != empty_string);
+ EXPECT_FALSE(c_null_string != deleted_string);
+ EXPECT_FALSE(c_empty_string != deleted_string);
const wchar_t* c_string_same1 = L"hello";
- ASSERT_FALSE(wide_string != c_string_same1);
- ASSERT_FALSE(c_string_same1 != wide_string);
+ EXPECT_FALSE(wide_string != c_string_same1);
+ EXPECT_FALSE(c_string_same1 != wide_string);
const wchar_t* c_string1 = L"he";
const wchar_t* c_string2 = L"hellp";
const wchar_t* c_string3 = L"hellod";
- ASSERT_TRUE(wide_string != c_string1);
- ASSERT_TRUE(wide_string != c_string2);
- ASSERT_TRUE(wide_string != c_string3);
-
- ASSERT_TRUE(c_string1 != wide_string);
- ASSERT_TRUE(c_string2 != wide_string);
- ASSERT_TRUE(c_string3 != wide_string);
+ EXPECT_TRUE(wide_string != c_string1);
+ EXPECT_TRUE(wide_string != c_string2);
+ EXPECT_TRUE(wide_string != c_string3);
+ EXPECT_TRUE(c_string1 != wide_string);
+ EXPECT_TRUE(c_string2 != wide_string);
+ EXPECT_TRUE(c_string3 != wide_string);
}
#define ByteStringLiteral(str) CFX_ByteString(FX_BSTRC(str))
@@ -211,104 +312,104 @@
TEST(fxcrt, WideStringCOperatorEQ) {
CFX_WideStringC wide_string_c(L"hello");
- ASSERT_TRUE(wide_string_c == wide_string_c);
+ EXPECT_TRUE(wide_string_c == wide_string_c);
CFX_WideStringC wide_string_c_same1(L"hello");
- ASSERT_TRUE(wide_string_c == wide_string_c_same1);
- ASSERT_TRUE(wide_string_c_same1 == wide_string_c);
+ EXPECT_TRUE(wide_string_c == wide_string_c_same1);
+ EXPECT_TRUE(wide_string_c_same1 == wide_string_c);
CFX_WideStringC wide_string_c_same2(wide_string_c);
- ASSERT_TRUE(wide_string_c == wide_string_c_same2);
- ASSERT_TRUE(wide_string_c_same2 == wide_string_c);
+ EXPECT_TRUE(wide_string_c == wide_string_c_same2);
+ EXPECT_TRUE(wide_string_c_same2 == wide_string_c);
CFX_WideStringC wide_string_c1(L"he");
CFX_WideStringC wide_string_c2(L"hellp");
CFX_WideStringC wide_string_c3(L"hellod");
- ASSERT_FALSE(wide_string_c == wide_string_c1);
- ASSERT_FALSE(wide_string_c == wide_string_c2);
- ASSERT_FALSE(wide_string_c == wide_string_c3);
- ASSERT_FALSE(wide_string_c1 == wide_string_c);
- ASSERT_FALSE(wide_string_c2 == wide_string_c);
- ASSERT_FALSE(wide_string_c3 == wide_string_c);
+ EXPECT_FALSE(wide_string_c == wide_string_c1);
+ EXPECT_FALSE(wide_string_c == wide_string_c2);
+ EXPECT_FALSE(wide_string_c == wide_string_c3);
+ EXPECT_FALSE(wide_string_c1 == wide_string_c);
+ EXPECT_FALSE(wide_string_c2 == wide_string_c);
+ EXPECT_FALSE(wide_string_c3 == wide_string_c);
CFX_WideString wide_string_same1(L"hello");
- ASSERT_TRUE(wide_string_c == wide_string_same1);
- ASSERT_TRUE(wide_string_same1 == wide_string_c);
+ EXPECT_TRUE(wide_string_c == wide_string_same1);
+ EXPECT_TRUE(wide_string_same1 == wide_string_c);
CFX_WideString wide_string1(L"he");
CFX_WideString wide_string2(L"hellp");
CFX_WideString wide_string3(L"hellod");
- ASSERT_FALSE(wide_string_c == wide_string1);
- ASSERT_FALSE(wide_string_c == wide_string2);
- ASSERT_FALSE(wide_string_c == wide_string3);
- ASSERT_FALSE(wide_string1 == wide_string_c);
- ASSERT_FALSE(wide_string2 == wide_string_c);
- ASSERT_FALSE(wide_string3 == wide_string_c);
+ EXPECT_FALSE(wide_string_c == wide_string1);
+ EXPECT_FALSE(wide_string_c == wide_string2);
+ EXPECT_FALSE(wide_string_c == wide_string3);
+ EXPECT_FALSE(wide_string1 == wide_string_c);
+ EXPECT_FALSE(wide_string2 == wide_string_c);
+ EXPECT_FALSE(wide_string3 == wide_string_c);
const wchar_t* c_string_same1 = L"hello";
- ASSERT_TRUE(wide_string_c == c_string_same1);
- ASSERT_TRUE(c_string_same1 == wide_string_c);
+ EXPECT_TRUE(wide_string_c == c_string_same1);
+ EXPECT_TRUE(c_string_same1 == wide_string_c);
const wchar_t* c_string1 = L"he";
const wchar_t* c_string2 = L"hellp";
const wchar_t* c_string3 = L"hellod";
- ASSERT_FALSE(wide_string_c == c_string1);
- ASSERT_FALSE(wide_string_c == c_string2);
- ASSERT_FALSE(wide_string_c == c_string3);
+ EXPECT_FALSE(wide_string_c == c_string1);
+ EXPECT_FALSE(wide_string_c == c_string2);
+ EXPECT_FALSE(wide_string_c == c_string3);
- ASSERT_FALSE(c_string1 == wide_string_c);
- ASSERT_FALSE(c_string2 == wide_string_c);
- ASSERT_FALSE(c_string3 == wide_string_c);
+ EXPECT_FALSE(c_string1 == wide_string_c);
+ EXPECT_FALSE(c_string2 == wide_string_c);
+ EXPECT_FALSE(c_string3 == wide_string_c);
}
TEST(fxcrt, WideStringCOperatorNE) {
CFX_WideStringC wide_string_c(L"hello");
- ASSERT_FALSE(wide_string_c != wide_string_c);
+ EXPECT_FALSE(wide_string_c != wide_string_c);
CFX_WideStringC wide_string_c_same1(L"hello");
- ASSERT_FALSE(wide_string_c != wide_string_c_same1);
- ASSERT_FALSE(wide_string_c_same1 != wide_string_c);
+ EXPECT_FALSE(wide_string_c != wide_string_c_same1);
+ EXPECT_FALSE(wide_string_c_same1 != wide_string_c);
CFX_WideStringC wide_string_c_same2(wide_string_c);
- ASSERT_FALSE(wide_string_c != wide_string_c_same2);
- ASSERT_FALSE(wide_string_c_same2 != wide_string_c);
+ EXPECT_FALSE(wide_string_c != wide_string_c_same2);
+ EXPECT_FALSE(wide_string_c_same2 != wide_string_c);
CFX_WideStringC wide_string_c1(L"he");
CFX_WideStringC wide_string_c2(L"hellp");
CFX_WideStringC wide_string_c3(L"hellod");
- ASSERT_TRUE(wide_string_c != wide_string_c1);
- ASSERT_TRUE(wide_string_c != wide_string_c2);
- ASSERT_TRUE(wide_string_c != wide_string_c3);
- ASSERT_TRUE(wide_string_c1 != wide_string_c);
- ASSERT_TRUE(wide_string_c2 != wide_string_c);
- ASSERT_TRUE(wide_string_c3 != wide_string_c);
+ EXPECT_TRUE(wide_string_c != wide_string_c1);
+ EXPECT_TRUE(wide_string_c != wide_string_c2);
+ EXPECT_TRUE(wide_string_c != wide_string_c3);
+ EXPECT_TRUE(wide_string_c1 != wide_string_c);
+ EXPECT_TRUE(wide_string_c2 != wide_string_c);
+ EXPECT_TRUE(wide_string_c3 != wide_string_c);
CFX_WideString wide_string_same1(L"hello");
- ASSERT_FALSE(wide_string_c != wide_string_same1);
- ASSERT_FALSE(wide_string_same1 != wide_string_c);
+ EXPECT_FALSE(wide_string_c != wide_string_same1);
+ EXPECT_FALSE(wide_string_same1 != wide_string_c);
CFX_WideString wide_string1(L"he");
CFX_WideString wide_string2(L"hellp");
CFX_WideString wide_string3(L"hellod");
- ASSERT_TRUE(wide_string_c != wide_string1);
- ASSERT_TRUE(wide_string_c != wide_string2);
- ASSERT_TRUE(wide_string_c != wide_string3);
- ASSERT_TRUE(wide_string1 != wide_string_c);
- ASSERT_TRUE(wide_string2 != wide_string_c);
- ASSERT_TRUE(wide_string3 != wide_string_c);
+ EXPECT_TRUE(wide_string_c != wide_string1);
+ EXPECT_TRUE(wide_string_c != wide_string2);
+ EXPECT_TRUE(wide_string_c != wide_string3);
+ EXPECT_TRUE(wide_string1 != wide_string_c);
+ EXPECT_TRUE(wide_string2 != wide_string_c);
+ EXPECT_TRUE(wide_string3 != wide_string_c);
const wchar_t* c_string_same1 = L"hello";
- ASSERT_FALSE(wide_string_c != c_string_same1);
- ASSERT_FALSE(c_string_same1 != wide_string_c);
+ EXPECT_FALSE(wide_string_c != c_string_same1);
+ EXPECT_FALSE(c_string_same1 != wide_string_c);
const wchar_t* c_string1 = L"he";
const wchar_t* c_string2 = L"hellp";
const wchar_t* c_string3 = L"hellod";
- ASSERT_TRUE(wide_string_c != c_string1);
- ASSERT_TRUE(wide_string_c != c_string2);
- ASSERT_TRUE(wide_string_c != c_string3);
+ EXPECT_TRUE(wide_string_c != c_string1);
+ EXPECT_TRUE(wide_string_c != c_string2);
+ EXPECT_TRUE(wide_string_c != c_string3);
- ASSERT_TRUE(c_string1 != wide_string_c);
- ASSERT_TRUE(c_string2 != wide_string_c);
- ASSERT_TRUE(c_string3 != wide_string_c);
+ EXPECT_TRUE(c_string1 != wide_string_c);
+ EXPECT_TRUE(c_string2 != wide_string_c);
+ EXPECT_TRUE(c_string3 != wide_string_c);
}