| Index: core/src/fxcrt/fx_basic_bstring_unittest.cpp
|
| diff --git a/core/src/fxcrt/fx_basic_bstring_unittest.cpp b/core/src/fxcrt/fx_basic_bstring_unittest.cpp
|
| index 9f37cbcf194a2bc8bc6e8e69b65db675ba9c0147..e506f9ddd20081bf78db93dc6499471e0fee2fb5 100644
|
| --- a/core/src/fxcrt/fx_basic_bstring_unittest.cpp
|
| +++ b/core/src/fxcrt/fx_basic_bstring_unittest.cpp
|
| @@ -6,6 +6,32 @@
|
| #include "../../../testing/fx_string_testhelpers.h"
|
| #include "../../include/fxcrt/fx_basic.h"
|
|
|
| +TEST(fxcrt, ByteStringNotNull) {
|
| + CFX_ByteString string3("abc");
|
| + CFX_ByteString string6("abcdef");
|
| + CFX_ByteString alternate_string3("abcdef", 3);
|
| + CFX_ByteStringC illegal_string7("abcdef", 7);
|
| + EXPECT_EQ(3, string3.GetLength());
|
| + EXPECT_EQ(6, string6.GetLength());
|
| + EXPECT_EQ(3, alternate_string3.GetLength());
|
| + EXPECT_EQ(7, illegal_string7.GetLength());
|
| +
|
| + // Prove constructor uses sizeof(), not strlen() against literals.
|
| + CFX_ByteString literal_string("abc\0def");
|
| + EXPECT_EQ(7, literal_string.GetLength());
|
| +
|
| + // Prove constructor uses strlen(), not sizeof() against mutable arrays.
|
| + char array[32];
|
| + memcpy(array, "abc\0def", 7);
|
| + CFX_ByteString array_string(array);
|
| + EXPECT_EQ(3, array_string.GetLength());
|
| +
|
| + // Prove constructor uses strlen(), not sizeof() against pointers.
|
| + const char* ptr = "abc\0def";
|
| + CFX_ByteString pointer_string(ptr);
|
| + EXPECT_EQ(3, pointer_string.GetLength());
|
| +}
|
| +
|
| TEST(fxcrt, ByteStringOperatorSubscript) {
|
| // CFX_ByteString includes the NUL terminator for non-empty strings.
|
| CFX_ByteString abc("abc");
|
| @@ -192,13 +218,27 @@ TEST(fxcrt, ByteStringCNotNull) {
|
| CFX_ByteStringC alternate_string3("abcdef", 3);
|
| CFX_ByteStringC embedded_nul_string7("abc\0def", 7);
|
| CFX_ByteStringC illegal_string7("abcdef", 7);
|
| -
|
| EXPECT_EQ(3, string3.GetLength());
|
| EXPECT_EQ(6, string6.GetLength());
|
| EXPECT_EQ(3, alternate_string3.GetLength());
|
| EXPECT_EQ(7, embedded_nul_string7.GetLength());
|
| EXPECT_EQ(7, illegal_string7.GetLength());
|
|
|
| + // Prove constructor uses sizeof(), not strlen() against literals.
|
| + CFX_ByteStringC literal_string("abc\0def");
|
| + EXPECT_EQ(7, literal_string.GetLength());
|
| +
|
| + // Prove constructor uses strlen(), not sizeof() against mutable arrays.
|
| + char array[32];
|
| + memcpy(array, "abc\0def", 7);
|
| + CFX_ByteStringC array_string(array);
|
| + EXPECT_EQ(3, array_string.GetLength());
|
| +
|
| + // Prove constructor uses strlen(), not sizeof() against pointers.
|
| + const char* ptr = "abc\0def";
|
| + CFX_ByteStringC pointer_string(ptr);
|
| + EXPECT_EQ(3, pointer_string.GetLength());
|
| +
|
| EXPECT_NE(string3, string6);
|
| EXPECT_EQ(string3, alternate_string3);
|
| EXPECT_NE(string3, embedded_nul_string7);
|
|
|