OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_split.h" | 5 #include "base/string_split.h" |
| 6 |
| 7 #include "base/utf_string_conversions.h" |
6 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
8 | 10 |
9 using ::testing::ElementsAre; | 11 using ::testing::ElementsAre; |
10 | 12 |
11 namespace base { | 13 namespace base { |
12 | 14 |
| 15 namespace { |
| 16 |
| 17 #if !defined(WCHAR_T_IS_UTF16) |
| 18 // Overload SplitString with a wide-char version to make it easier to |
| 19 // test the string16 version with wide character literals. |
| 20 void SplitString(const std::wstring& str, |
| 21 wchar_t c, |
| 22 std::vector<std::wstring>* result) { |
| 23 std::vector<string16> result16; |
| 24 SplitString(WideToUTF16(str), c, &result16); |
| 25 for (size_t i = 0; i < result16.size(); ++i) |
| 26 result->push_back(UTF16ToWide(result16[i])); |
| 27 } |
| 28 #endif |
| 29 |
| 30 } // anonymous namespace |
| 31 |
13 class SplitStringIntoKeyValuesTest : public testing::Test { | 32 class SplitStringIntoKeyValuesTest : public testing::Test { |
14 protected: | 33 protected: |
15 std::string key; | 34 std::string key; |
16 std::vector<std::string> values; | 35 std::vector<std::string> values; |
17 }; | 36 }; |
18 | 37 |
19 TEST_F(SplitStringIntoKeyValuesTest, EmptyInputMultipleValues) { | 38 TEST_F(SplitStringIntoKeyValuesTest, EmptyInputMultipleValues) { |
20 EXPECT_FALSE(SplitStringIntoKeyValues("", // Empty input | 39 EXPECT_FALSE(SplitStringIntoKeyValues("", // Empty input |
21 '\t', // Key separators | 40 '\t', // Key separators |
22 &key, &values)); | 41 &key, &values)); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 SplitStringAlongWhitespace(data[i].input, &results); | 307 SplitStringAlongWhitespace(data[i].input, &results); |
289 ASSERT_EQ(data[i].expected_result_count, results.size()); | 308 ASSERT_EQ(data[i].expected_result_count, results.size()); |
290 if (data[i].expected_result_count > 0) | 309 if (data[i].expected_result_count > 0) |
291 ASSERT_EQ(data[i].output1, results[0]); | 310 ASSERT_EQ(data[i].output1, results[0]); |
292 if (data[i].expected_result_count > 1) | 311 if (data[i].expected_result_count > 1) |
293 ASSERT_EQ(data[i].output2, results[1]); | 312 ASSERT_EQ(data[i].output2, results[1]); |
294 } | 313 } |
295 } | 314 } |
296 | 315 |
297 } // namespace base | 316 } // namespace base |
OLD | NEW |