blob: e1be7fc5087b617adfd13d051604aae2602c75e6 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2013 The Chromium Authors
[email protected]51bcc5d2013-04-24 01:41:372// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]e7bba5f82013-04-10 20:10:524
[email protected]318076b2013-04-18 21:19:455#ifndef URL_URL_TEST_UTILS_H_
6#define URL_URL_TEST_UTILS_H_
7
[email protected]e7bba5f82013-04-10 20:10:528// Convenience functions for string conversions.
9// These are mostly intended for use in unit tests.
10
[email protected]e7bba5f82013-04-10 20:10:5211#include <string>
12
brettw1b8582f2016-11-03 20:37:1713#include "base/strings/utf_string_conversions.h"
[email protected]e7bba5f82013-04-10 20:10:5214#include "testing/gtest/include/gtest/gtest.h"
[email protected]318076b2013-04-18 21:19:4515#include "url/url_canon_internal.h"
[email protected]e7bba5f82013-04-10 20:10:5216
[email protected]0318f922014-04-22 00:09:2317namespace url {
18
19namespace test_utils {
[email protected]e7bba5f82013-04-10 20:10:5220
brettw1b8582f2016-11-03 20:37:1721// 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
25// strings.
Jan Wilken Dörrie739ccc212021-03-11 18:13:0526inline std::u16string TruncateWStringToUTF16(const wchar_t* src) {
27 std::u16string str;
[email protected]e7bba5f82013-04-10 20:10:5228 int length = static_cast<int>(wcslen(src));
29 for (int i = 0; i < length; ++i) {
Jan Wilken Dörrie5aad5c22021-03-08 21:44:1230 str.push_back(static_cast<char16_t>(src[i]));
[email protected]e7bba5f82013-04-10 20:10:5231 }
32 return str;
33}
34
[email protected]0318f922014-04-22 00:09:2335} // namespace test_utils
36
37} // namespace url
[email protected]e7bba5f82013-04-10 20:10:5238
[email protected]318076b2013-04-18 21:19:4539#endif // URL_URL_TEST_UTILS_H_