diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 03:45:37 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 03:45:37 +0000 |
commit | e6811ed52ec6c97dfb6d9073c8841d7f67bba082 (patch) | |
tree | 3d6a1abc880b89e94382f9f7c8e028d765f33508 /base/string_util_unittest.cc | |
parent | e486aef731a84a591451ec7e92e79724757a737d (diff) | |
download | chromium_src-e6811ed52ec6c97dfb6d9073c8841d7f67bba082.zip chromium_src-e6811ed52ec6c97dfb6d9073c8841d7f67bba082.tar.gz chromium_src-e6811ed52ec6c97dfb6d9073c8841d7f67bba082.tar.bz2 |
Move StringPrintf into its own file and use the base namespace. Currently this has using
directives for the functions so I don't have to change all files to use the namespace.
No code changes to logic.
TEST=it compiles + the included unit tests
BUG=none
Review URL: http://codereview.chromium.org/3181016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56299 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util_unittest.cc')
-rw-r--r-- | base/string_util_unittest.cc | 140 |
1 files changed, 0 insertions, 140 deletions
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index 4d3fc1c..9f72b1f 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -693,146 +693,6 @@ TEST(StringUtilTest, VAList) { VariableArgsFunc("%d %d %s %lf", 45, 92, "This is interesting", 9.21); } -TEST(StringUtilTest, StringPrintfEmpty) { - EXPECT_EQ("", StringPrintf("%s", "")); -} - -TEST(StringUtilTest, StringPrintfMisc) { - EXPECT_EQ("123hello w", StringPrintf("%3d%2s %1c", 123, "hello", 'w')); - EXPECT_EQ(L"123hello w", StringPrintf(L"%3d%2ls %1lc", 123, L"hello", 'w')); -} - -TEST(StringUtilTest, StringAppendfEmptyString) { - std::string value("Hello"); - StringAppendF(&value, "%s", ""); - EXPECT_EQ("Hello", value); - - std::wstring valuew(L"Hello"); - StringAppendF(&valuew, L"%ls", L""); - EXPECT_EQ(L"Hello", valuew); -} - -TEST(StringUtilTest, StringAppendfString) { - std::string value("Hello"); - StringAppendF(&value, " %s", "World"); - EXPECT_EQ("Hello World", value); - - std::wstring valuew(L"Hello"); - StringAppendF(&valuew, L" %ls", L"World"); - EXPECT_EQ(L"Hello World", valuew); -} - -TEST(StringUtilTest, StringAppendfInt) { - std::string value("Hello"); - StringAppendF(&value, " %d", 123); - EXPECT_EQ("Hello 123", value); - - std::wstring valuew(L"Hello"); - StringAppendF(&valuew, L" %d", 123); - EXPECT_EQ(L"Hello 123", valuew); -} - -// Make sure that lengths exactly around the initial buffer size are handled -// correctly. -TEST(StringUtilTest, StringPrintfBounds) { - const int kSrcLen = 1026; - char src[kSrcLen]; - for (size_t i = 0; i < arraysize(src); i++) - src[i] = 'A'; - - wchar_t srcw[kSrcLen]; - for (size_t i = 0; i < arraysize(srcw); i++) - srcw[i] = 'A'; - - for (int i = 1; i < 3; i++) { - src[kSrcLen - i] = 0; - std::string out; - SStringPrintf(&out, "%s", src); - EXPECT_STREQ(src, out.c_str()); - - srcw[kSrcLen - i] = 0; - std::wstring outw; - SStringPrintf(&outw, L"%ls", srcw); - EXPECT_STREQ(srcw, outw.c_str()); - } -} - -// Test very large sprintfs that will cause the buffer to grow. -TEST(StringUtilTest, Grow) { - char src[1026]; - for (size_t i = 0; i < arraysize(src); i++) - src[i] = 'A'; - src[1025] = 0; - - const char* fmt = "%sB%sB%sB%sB%sB%sB%s"; - - std::string out; - SStringPrintf(&out, fmt, src, src, src, src, src, src, src); - - const int kRefSize = 320000; - char* ref = new char[kRefSize]; -#if defined(OS_WIN) - sprintf_s(ref, kRefSize, fmt, src, src, src, src, src, src, src); -#elif defined(OS_POSIX) - snprintf(ref, kRefSize, fmt, src, src, src, src, src, src, src); -#endif - - EXPECT_STREQ(ref, out.c_str()); - 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) { - const int string_util_buf_len = 1024; - // Our buffer should be one larger than the size of StringAppendVT's stack - // buffer. - const int buf_len = string_util_buf_len + 1; - char src[buf_len + 1]; // Need extra one for NULL-terminator. - for (int i = 0; i < buf_len; ++i) - src[i] = 'a'; - src[buf_len] = 0; - - std::string out; - SStringPrintf(&out, "%s", src); - - EXPECT_STREQ(src, out.c_str()); -} - -// TODO(evanm): what's the proper cross-platform test here? -#if defined(OS_WIN) -// sprintf in Visual Studio fails when given U+FFFF. This tests that the -// failure case is gracefuly handled. -TEST(StringUtilTest, Invalid) { - wchar_t invalid[2]; - invalid[0] = 0xffff; - invalid[1] = 0; - - std::wstring out; - SStringPrintf(&out, L"%ls", invalid); - EXPECT_STREQ(L"", out.c_str()); -} -#endif - // Test for SplitString TEST(StringUtilTest, SplitString) { std::vector<std::wstring> r; |