url_test_utils.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. #ifndef URL_URL_TEST_UTILS_H_
  5. #define URL_URL_TEST_UTILS_H_
  6. // Convenience functions for string conversions.
  7. // These are mostly intended for use in unit tests.
  8. #include <string>
  9. #include "base/strings/utf_string_conversions.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. #include "url/url_canon_internal.h"
  12. namespace url {
  13. namespace test_utils {
  14. // Converts a UTF-16 string from native wchar_t format to char16 by
  15. // truncating the high 32 bits. This is different than the conversion function
  16. // in base bacause it passes invalid UTF-16 characters which is important for
  17. // test purposes. As a result, this is not meant to handle true UTF-32 encoded
  18. // strings.
  19. inline std::u16string TruncateWStringToUTF16(const wchar_t* src) {
  20. std::u16string str;
  21. int length = static_cast<int>(wcslen(src));
  22. for (int i = 0; i < length; ++i) {
  23. str.push_back(static_cast<char16_t>(src[i]));
  24. }
  25. return str;
  26. }
  27. } // namespace test_utils
  28. } // namespace url
  29. #endif // URL_URL_TEST_UTILS_H_