diff options
author | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-14 01:25:32 +0000 |
---|---|---|
committer | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-14 01:25:32 +0000 |
commit | 44cd16fcc85697b5094250a89decaab5c692b392 (patch) | |
tree | 37e4fb0dbee34f2cc673c287b54515a71b1f9629 /base/string_util_unittest.cc | |
parent | 5f800edb90578f08b3462e1dc96b78bf0ec56d36 (diff) | |
download | chromium_src-44cd16fcc85697b5094250a89decaab5c692b392.zip chromium_src-44cd16fcc85697b5094250a89decaab5c692b392.tar.gz chromium_src-44cd16fcc85697b5094250a89decaab5c692b392.tar.bz2 |
DCHECK vswprintf format string cross-platform portability. Use %ls, not %s, for wchar_t* fields.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@849 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util_unittest.cc')
-rw-r--r-- | base/string_util_unittest.cc | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index 7cc9764..c286222 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -978,7 +978,7 @@ TEST(StringUtilTest, StringPrintfEmptyFormat) { TEST(StringUtilTest, StringPrintfMisc) { EXPECT_EQ("123hello w", StringPrintf("%3d%2s %1c", 123, "hello", 'w')); - EXPECT_EQ(L"123hello w", StringPrintf(L"%3d%2ls %1c", 123, L"hello", 'w')); + EXPECT_EQ(L"123hello w", StringPrintf(L"%3d%2ls %1lc", 123, L"hello", 'w')); } TEST(StringUtilTest, StringAppendfStringEmptyParam) { @@ -997,7 +997,7 @@ TEST(StringUtilTest, StringAppendfEmptyString) { EXPECT_EQ("Hello", value); std::wstring valuew(L"Hello"); - StringAppendF(&valuew, L"%s", L""); + StringAppendF(&valuew, L"%ls", L""); EXPECT_EQ(L"Hello", valuew); } @@ -1306,3 +1306,35 @@ TEST(StringUtilTest, LcpyTest) { EXPECT_EQ(0, memcmp(wdst, L"ab", sizeof(wchar_t) * 3)); } } + +TEST(StringUtilTest, WprintfFormatPortabilityTest) { + struct TestData { + const wchar_t* input; + bool portable; + } cases[] = { + { L"%ls", true }, + { L"%s", false }, + { L"%S", false }, + { L"%lS", false }, + { L"Hello, %s", false }, + { L"%lc", true }, + { L"%c", false }, + { L"%C", false }, + { L"%lC", false }, + { L"%ls %s", false }, + { L"%s %ls", false }, + { L"%s %ls %s", false }, + { L"%f", true }, + { L"%f %F", false }, + { L"%d %D", false }, + { L"%o %O", false }, + { L"%u %U", false }, + { L"%f %d %o %u", true }, + { L"%-8d (%02.1f%)", true }, + { L"% 10s", false }, + { L"% 10ls", true } + }; + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { + EXPECT_EQ(cases[i].portable, base::IsWprintfFormatPortable(cases[i].input)); + } +} |