• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifdef UNSAFE_BUFFERS_BUILD
6 // TODO(crbug.com/350788890): Remove this and spanify to fix the errors.
7 #pragma allow_unsafe_buffers
8 #endif
9 
10 #ifndef URL_URL_TEST_UTILS_H_
11 #define URL_URL_TEST_UTILS_H_
12 
13 // Convenience functions for string conversions.
14 // These are mostly intended for use in unit tests.
15 
16 #include <string>
17 
18 #include "base/strings/utf_string_conversions.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "url/url_canon_internal.h"
21 
22 namespace url {
23 
24 namespace test_utils {
25 
26 // Converts a UTF-16 string from native wchar_t format to char16 by
27 // truncating the high 32 bits. This is different than the conversion function
28 // in base bacause it passes invalid UTF-16 characters which is important for
29 // test purposes. As a result, this is not meant to handle true UTF-32 encoded
30 // strings.
TruncateWStringToUTF16(const wchar_t * src)31 inline std::u16string TruncateWStringToUTF16(const wchar_t* src) {
32   std::u16string str;
33   int length = static_cast<int>(wcslen(src));
34   for (int i = 0; i < length; ++i) {
35     str.push_back(static_cast<char16_t>(src[i]));
36   }
37   return str;
38 }
39 
40 }  // namespace test_utils
41 
42 }  // namespace url
43 
44 #endif  // URL_URL_TEST_UTILS_H_
45