Upload upstream chromium 67.0.3396
[platform/framework/web/chromium-efl.git] / url / url_test_utils.h
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.
4
5 #ifndef URL_URL_TEST_UTILS_H_
6 #define URL_URL_TEST_UTILS_H_
7
8 // Convenience functions for string conversions.
9 // These are mostly intended for use in unit tests.
10
11 #include <string>
12
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"
17
18 namespace url {
19
20 namespace test_utils {
21
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) {
28   base::string16 str;
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]));
32   }
33   return str;
34 }
35
36 }  // namespace test_utils
37
38 }  // namespace url
39
40 #endif  // URL_URL_TEST_UTILS_H_