blob: 120f7e60f5b787d43a72e788351d55934a6a4e11 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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 Anton10542f22019-01-11 09:11:00 -080011#include "rtc_base/string_utils.h"
Yves Gerey3e707812018-11-28 16:47:49 +010012
13#include "test/gtest.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000014
15namespace rtc {
16
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000017TEST(string_trim_Test, Trimming) {
18 EXPECT_EQ("temp", string_trim("\n\r\t temp \n\r\t"));
19 EXPECT_EQ("temp\n\r\t temp", string_trim(" temp\n\r\t temp "));
20 EXPECT_EQ("temp temp", string_trim("temp temp"));
21 EXPECT_EQ("", string_trim(" \r\n\t"));
22 EXPECT_EQ("", string_trim(""));
23}
24
Jonas Olsson74395342018-04-03 12:22:07 +020025TEST(string_toHexTest, ToHex) {
26 EXPECT_EQ(ToHex(0), "0");
27 EXPECT_EQ(ToHex(0X1243E), "1243e");
28 EXPECT_EQ(ToHex(-20), "ffffffec");
29}
30
Noah Richards4ed5b082019-07-30 11:56:08 -070031#if defined(WEBRTC_WIN)
32
33TEST(string_toutf, Empty) {
34 char empty_string[] = "";
35 EXPECT_TRUE(ToUtf16(empty_string, 0u).empty());
36 wchar_t empty_wchar[] = L"";
37 EXPECT_TRUE(ToUtf8(empty_wchar, 0u).empty());
38}
39
40#endif // WEBRTC_WIN
41
Markus Handell3d46d0b2021-05-27 21:42:57 +020042TEST(CompileTimeString, MakeActsLikeAString) {
43 EXPECT_STREQ(MakeCompileTimeString("abc123"), "abc123");
44}
45
46TEST(CompileTimeString, ConvertibleToStdString) {
47 EXPECT_EQ(std::string(MakeCompileTimeString("abab")), "abab");
48}
49
50namespace detail {
51constexpr bool StringEquals(const char* a, const char* b) {
52 while (*a && *a == *b)
53 a++, b++;
54 return *a == *b;
55}
56} // namespace detail
57
58static_assert(detail::StringEquals(MakeCompileTimeString("handellm"),
59 "handellm"),
60 "String should initialize.");
61
62static_assert(detail::StringEquals(MakeCompileTimeString("abc123").Concat(
63 MakeCompileTimeString("def456ghi")),
64 "abc123def456ghi"),
65 "Strings should concatenate.");
66
Jonas Olsson74395342018-04-03 12:22:07 +020067} // namespace rtc