OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <errno.h> |
| 6 |
5 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
6 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
8 | 10 |
9 namespace base { | 11 namespace base { |
10 | 12 |
11 namespace { | 13 namespace { |
12 | 14 |
13 // A helper for the StringAppendV test that follows. | 15 // A helper for the StringAppendV test that follows. |
14 // | 16 // |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 SStringPrintf(&out, "%1$s %1$s", "test"); | 167 SStringPrintf(&out, "%1$s %1$s", "test"); |
166 EXPECT_STREQ("test test", out.c_str()); | 168 EXPECT_STREQ("test test", out.c_str()); |
167 | 169 |
168 #if defined(OS_WIN) | 170 #if defined(OS_WIN) |
169 std::wstring wout; | 171 std::wstring wout; |
170 SStringPrintf(&wout, L"%1$ls %1$ls", L"test"); | 172 SStringPrintf(&wout, L"%1$ls %1$ls", L"test"); |
171 EXPECT_STREQ(L"test test", wout.c_str()); | 173 EXPECT_STREQ(L"test test", wout.c_str()); |
172 #endif | 174 #endif |
173 } | 175 } |
174 | 176 |
| 177 // Test that StringPrintf and StringAppendV do not change errno. |
| 178 TEST(StringPrintfTest, StringPrintfErrno) { |
| 179 errno = 1; |
| 180 EXPECT_EQ("", StringPrintf("%s", "")); |
| 181 EXPECT_EQ(1, errno); |
| 182 std::string out; |
| 183 StringAppendVTestHelper(&out, "%d foo %s", 1, "bar"); |
| 184 EXPECT_EQ(1, errno); |
| 185 } |
| 186 |
175 } // namespace base | 187 } // namespace base |
OLD | NEW |