henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "rtc_base/string_utils.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 12 | |
| 13 | #include "test/gtest.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 14 | |
| 15 | namespace rtc { |
| 16 | |
Jonas Olsson | 7439534 | 2018-04-03 10:22:07 | [diff] [blame] | 17 | TEST(string_toHexTest, ToHex) { |
| 18 | EXPECT_EQ(ToHex(0), "0"); |
| 19 | EXPECT_EQ(ToHex(0X1243E), "1243e"); |
| 20 | EXPECT_EQ(ToHex(-20), "ffffffec"); |
| 21 | } |
| 22 | |
Noah Richards | 4ed5b08 | 2019-07-30 18:56:08 | [diff] [blame] | 23 | #if defined(WEBRTC_WIN) |
| 24 | |
| 25 | TEST(string_toutf, Empty) { |
| 26 | char empty_string[] = ""; |
| 27 | EXPECT_TRUE(ToUtf16(empty_string, 0u).empty()); |
| 28 | wchar_t empty_wchar[] = L""; |
| 29 | EXPECT_TRUE(ToUtf8(empty_wchar, 0u).empty()); |
| 30 | } |
| 31 | |
| 32 | #endif // WEBRTC_WIN |
| 33 | |
Markus Handell | 3d46d0b | 2021-05-27 19:42:57 | [diff] [blame] | 34 | TEST(CompileTimeString, MakeActsLikeAString) { |
| 35 | EXPECT_STREQ(MakeCompileTimeString("abc123"), "abc123"); |
| 36 | } |
| 37 | |
| 38 | TEST(CompileTimeString, ConvertibleToStdString) { |
| 39 | EXPECT_EQ(std::string(MakeCompileTimeString("abab")), "abab"); |
| 40 | } |
| 41 | |
| 42 | namespace detail { |
| 43 | constexpr bool StringEquals(const char* a, const char* b) { |
| 44 | while (*a && *a == *b) |
| 45 | a++, b++; |
| 46 | return *a == *b; |
| 47 | } |
| 48 | } // namespace detail |
| 49 | |
| 50 | static_assert(detail::StringEquals(MakeCompileTimeString("handellm"), |
| 51 | "handellm"), |
| 52 | "String should initialize."); |
| 53 | |
| 54 | static_assert(detail::StringEquals(MakeCompileTimeString("abc123").Concat( |
| 55 | MakeCompileTimeString("def456ghi")), |
| 56 | "abc123def456ghi"), |
| 57 | "Strings should concatenate."); |
| 58 | |
Jonas Olsson | 7439534 | 2018-04-03 10:22:07 | [diff] [blame] | 59 | } // namespace rtc |