[email protected] | 51bcc5d | 2013-04-24 01:41:37 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
[email protected] | e7bba5f8 | 2013-04-10 20:10:52 | [diff] [blame] | 4 | |
[email protected] | 318076b | 2013-04-18 21:19:45 | [diff] [blame] | 5 | #ifndef URL_URL_TEST_UTILS_H_ |
6 | #define URL_URL_TEST_UTILS_H_ | ||||
7 | |||||
[email protected] | e7bba5f8 | 2013-04-10 20:10:52 | [diff] [blame] | 8 | // Convenience functions for string conversions. |
9 | // These are mostly intended for use in unit tests. | ||||
10 | |||||
[email protected] | e7bba5f8 | 2013-04-10 20:10:52 | [diff] [blame] | 11 | #include <string> |
12 | |||||
[email protected] | 516f018 | 2013-06-11 22:51:56 | [diff] [blame] | 13 | #include "base/strings/string16.h" |
brettw | 1b8582f | 2016-11-03 20:37:17 | [diff] [blame] | 14 | #include "base/strings/utf_string_conversions.h" |
[email protected] | e7bba5f8 | 2013-04-10 20:10:52 | [diff] [blame] | 15 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 318076b | 2013-04-18 21:19:45 | [diff] [blame] | 16 | #include "url/url_canon_internal.h" |
[email protected] | e7bba5f8 | 2013-04-10 20:10:52 | [diff] [blame] | 17 | |
[email protected] | 0318f92 | 2014-04-22 00:09:23 | [diff] [blame] | 18 | namespace url { |
19 | |||||
20 | namespace test_utils { | ||||
[email protected] | e7bba5f8 | 2013-04-10 20:10:52 | [diff] [blame] | 21 | |
brettw | 1b8582f | 2016-11-03 20:37:17 | [diff] [blame] | 22 | // Converts a UTF-16 string from native wchar_t format to char16 by |
23 | // truncating the high 32 bits. This is different than the conversion function | ||||
24 | // in base bacause it passes invalid UTF-16 characters which is important for | ||||
25 | // test purposes. As a result, this is not meant to handle true UTF-32 encoded | ||||
26 | // strings. | ||||
27 | inline base::string16 TruncateWStringToUTF16(const wchar_t* src) { | ||||
[email protected] | 3774f83 | 2013-06-11 21:21:57 | [diff] [blame] | 28 | base::string16 str; |
[email protected] | e7bba5f8 | 2013-04-10 20:10:52 | [diff] [blame] | 29 | int length = static_cast<int>(wcslen(src)); |
30 | for (int i = 0; i < length; ++i) { | ||||
[email protected] | c84c479 | 2013-12-25 21:57:26 | [diff] [blame] | 31 | str.push_back(static_cast<base::char16>(src[i])); |
[email protected] | e7bba5f8 | 2013-04-10 20:10:52 | [diff] [blame] | 32 | } |
33 | return str; | ||||
34 | } | ||||
35 | |||||
[email protected] | 0318f92 | 2014-04-22 00:09:23 | [diff] [blame] | 36 | } // namespace test_utils |
37 | |||||
38 | } // namespace url | ||||
[email protected] | e7bba5f8 | 2013-04-10 20:10:52 | [diff] [blame] | 39 | |
[email protected] | 318076b | 2013-04-18 21:19:45 | [diff] [blame] | 40 | #endif // URL_URL_TEST_UTILS_H_ |