| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 wchar_t invalid[2]; | 156 wchar_t invalid[2]; |
| 157 invalid[0] = 0xffff; | 157 invalid[0] = 0xffff; |
| 158 invalid[1] = 0; | 158 invalid[1] = 0; |
| 159 | 159 |
| 160 std::wstring out; | 160 std::wstring out; |
| 161 SStringPrintf(&out, L"%ls", invalid); | 161 SStringPrintf(&out, L"%ls", invalid); |
| 162 EXPECT_STREQ(L"", out.c_str()); | 162 EXPECT_STREQ(L"", out.c_str()); |
| 163 } | 163 } |
| 164 #endif | 164 #endif |
| 165 | 165 |
| 166 // Test that the positional parameters work. | |
| 167 TEST(StringPrintfTest, PositionalParameters) { | |
| 168 std::string out; | |
| 169 SStringPrintf(&out, "%1$s %1$s", "test"); | |
| 170 EXPECT_STREQ("test test", out.c_str()); | |
| 171 | |
| 172 #if defined(OS_WIN) | |
| 173 std::wstring wout; | |
| 174 SStringPrintf(&wout, L"%1$ls %1$ls", L"test"); | |
| 175 EXPECT_STREQ(L"test test", wout.c_str()); | |
| 176 #endif | |
| 177 } | |
| 178 | |
| 179 // Test that StringPrintf and StringAppendV do not change errno. | 166 // Test that StringPrintf and StringAppendV do not change errno. |
| 180 TEST(StringPrintfTest, StringPrintfErrno) { | 167 TEST(StringPrintfTest, StringPrintfErrno) { |
| 181 errno = 1; | 168 errno = 1; |
| 182 EXPECT_EQ("", StringPrintf("%s", "")); | 169 EXPECT_EQ("", StringPrintf("%s", "")); |
| 183 EXPECT_EQ(1, errno); | 170 EXPECT_EQ(1, errno); |
| 184 std::string out; | 171 std::string out; |
| 185 StringAppendVTestHelper(&out, "%d foo %s", 1, "bar"); | 172 StringAppendVTestHelper(&out, "%d foo %s", 1, "bar"); |
| 186 EXPECT_EQ(1, errno); | 173 EXPECT_EQ(1, errno); |
| 187 } | 174 } |
| 188 | 175 |
| 189 } // namespace base | 176 } // namespace base |
| OLD | NEW |