1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef URL_URL_TEST_UTILS_H_
6 #define URL_URL_TEST_UTILS_H_
8 // Convenience functions for string conversions.
9 // These are mostly intended for use in unit tests.
13 #include "base/strings/utf_string_conversions.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/url_canon_internal.h"
19 namespace test_utils {
21 // Converts a UTF-16 string from native wchar_t format to char16 by
22 // truncating the high 32 bits. This is different than the conversion function
23 // in base bacause it passes invalid UTF-16 characters which is important for
24 // test purposes. As a result, this is not meant to handle true UTF-32 encoded
26 inline std::u16string TruncateWStringToUTF16(const wchar_t* src) {
28 int length = static_cast<int>(wcslen(src));
29 for (int i = 0; i < length; ++i) {
30 str.push_back(static_cast<char16_t>(src[i]));
35 } // namespace test_utils
39 #endif // URL_URL_TEST_UTILS_H_