diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-20 06:53:28 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-20 06:53:28 +0000 |
commit | 34b2b007db875a6acb853c5cd2a247fbb32c0f88 (patch) | |
tree | 6dc39bc9f10d6e8eedcdf14821ba9e96b5ccab51 /base/string_util_unittest.cc | |
parent | 24b857793e27aded8d804a112a5fe6c77e28b081 (diff) | |
download | chromium_src-34b2b007db875a6acb853c5cd2a247fbb32c0f88.zip chromium_src-34b2b007db875a6acb853c5cd2a247fbb32c0f88.tar.gz chromium_src-34b2b007db875a6acb853c5cd2a247fbb32c0f88.tar.bz2 |
Add compiler-specific "examine printf format" attributes to printfs.
Functions that take a printf-style format get a new annotation, which
produces a bunch of compiler warnings when you use printf impoperly.
This change adds the annotations and fixes the warnings.
We now must use PRId64 for 64-bit numbers and the PRIsz for size_t.
Review URL: http://codereview.chromium.org/339059
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32600 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util_unittest.cc')
-rw-r--r-- | base/string_util_unittest.cc | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index d691003..c586ff4 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -827,9 +827,7 @@ TEST(StringUtilTest, VAList) { VariableArgsFunc("%d %d %s %lf", 45, 92, "This is interesting", 9.21); } -TEST(StringUtilTest, StringPrintfEmptyFormat) { - const char* empty = ""; - EXPECT_EQ("", StringPrintf(empty)); +TEST(StringUtilTest, StringPrintfEmpty) { EXPECT_EQ("", StringPrintf("%s", "")); } @@ -838,16 +836,6 @@ TEST(StringUtilTest, StringPrintfMisc) { EXPECT_EQ(L"123hello w", StringPrintf(L"%3d%2ls %1lc", 123, L"hello", 'w')); } -TEST(StringUtilTest, StringAppendfStringEmptyParam) { - std::string value("Hello"); - StringAppendF(&value, ""); - EXPECT_EQ("Hello", value); - - std::wstring valuew(L"Hello"); - StringAppendF(&valuew, L""); - EXPECT_EQ(L"Hello", valuew); -} - TEST(StringUtilTest, StringAppendfEmptyString) { std::string value("Hello"); StringAppendF(&value, "%s", ""); @@ -926,6 +914,25 @@ TEST(StringUtilTest, Grow) { delete[] ref; } +// A helper for the StringAppendV test that follows. +// Just forwards its args to StringAppendV. +static void StringAppendVTestHelper(std::string* out, + const char* format, + ...) PRINTF_FORMAT(2, 3); + +static void StringAppendVTestHelper(std::string* out, const char* format, ...) { + va_list ap; + va_start(ap, format); + StringAppendV(out, format, ap); + va_end(ap); +} + +TEST(StringUtilTest, StringAppendV) { + std::string out; + StringAppendVTestHelper(&out, "%d foo %s", 1, "bar"); + EXPECT_EQ("1 foo bar", out); +} + // Test the boundary condition for the size of the string_util's // internal buffer. TEST(StringUtilTest, GrowBoundary) { |