Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Unified Diff: core/src/fxcrt/fx_basic_wstring_unittest.cpp

Issue 1114313006: Make constructors recognize char[n] vs. char* and avoid strlen calls. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Delegated constructors everywhere. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/src/fxcrt/fx_basic_wstring_unittest.cpp
diff --git a/core/src/fxcrt/fx_basic_wstring_unittest.cpp b/core/src/fxcrt/fx_basic_wstring_unittest.cpp
index 3b15006d655f8019f6906406d8147d09bd271af7..ee010f281898e02d773c2d3fa61bc382c41517c5 100644
--- a/core/src/fxcrt/fx_basic_wstring_unittest.cpp
+++ b/core/src/fxcrt/fx_basic_wstring_unittest.cpp
@@ -6,6 +6,23 @@
#include "../../../testing/fx_string_testhelpers.h"
#include "../../include/fxcrt/fx_basic.h"
+TEST(fxcrt, WideStringNotNull) {
+ // Prove constructor uses sizeof(), not strlen() against literals.
+ CFX_WideString literal_string(L"ab\0c");
+ EXPECT_EQ(4, literal_string.GetLength());
+
+ // Prove constructor uses strlen(), not sizeof() against mutable arrays.
+ wchar_t array[32];
+ memcpy(array, L"ab\0c", 5 * sizeof(wchar_t));
+ CFX_WideString array_string(array);
+ EXPECT_EQ(2, array_string.GetLength());
+
+ // Prove constructor uses strlen(), not sizeof() against pointers.
+ const wchar_t* ptr = L"ab\0c";
+ CFX_WideString pointer_string(ptr);
+ EXPECT_EQ(2, pointer_string.GetLength());
+}
+
TEST(fxcrt, WideStringOperatorSubscript) {
// CFX_WideString includes the NUL terminator for non-empty strings.
CFX_WideString abc(L"abc");
@@ -170,6 +187,23 @@ TEST(fxcrt, WideStringUTF16LE_Encode) {
}
}
+TEST(fxcrt, WideStringCNotNull) {
+ // Prove constructor uses sizeof(), not strlen() against literals.
+ CFX_WideStringC literal_string(L"ab\0c");
+ EXPECT_EQ(4, literal_string.GetLength());
+
+ // Prove constructor uses strlen(), not sizeof() against mutable arrays.
+ wchar_t array[32];
+ memcpy(array, L"ab\0c", 5 * sizeof(wchar_t));
+ CFX_WideStringC array_string(array);
+ EXPECT_EQ(2, array_string.GetLength());
+
+ // Prove constructor uses strlen(), not sizeof() against pointers.
+ const wchar_t* ptr = L"ab\0c";
+ CFX_WideStringC pointer_string(ptr);
+ EXPECT_EQ(2, pointer_string.GetLength());
+}
+
TEST(fxcrt, WideStringCOperatorSubscript) {
// CFX_WideStringC includes the NUL terminator for non-empty strings.
CFX_WideStringC abc(L"abc");
« core/include/fxcrt/fx_string.h ('K') | « core/src/fxcrt/fx_basic_bstring_unittest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698