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.
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/string16.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/url_canon_internal.h"
20 namespace test_utils {
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
27 inline base::string16 TruncateWStringToUTF16(const wchar_t* src) {
29 int length = static_cast<int>(wcslen(src));
30 for (int i = 0; i < length; ++i) {
31 str.push_back(static_cast<base::char16>(src[i]));
36 } // namespace test_utils
40 #endif // URL_URL_TEST_UTILS_H_