blob: cf9debef38a8bd86f5a7c9726187c25c7477cbd5 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_base/stringutils.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
25TEST(string_startsTest, StartsWith) {
26 EXPECT_TRUE(starts_with("foobar", "foo"));
27 EXPECT_TRUE(starts_with("foobar", "foobar"));
28 EXPECT_TRUE(starts_with("foobar", ""));
29 EXPECT_TRUE(starts_with("", ""));
30 EXPECT_FALSE(starts_with("foobar", "bar"));
31 EXPECT_FALSE(starts_with("foobar", "foobarbaz"));
32 EXPECT_FALSE(starts_with("", "f"));
33}
34
35TEST(string_endsTest, EndsWith) {
36 EXPECT_TRUE(ends_with("foobar", "bar"));
37 EXPECT_TRUE(ends_with("foobar", "foobar"));
38 EXPECT_TRUE(ends_with("foobar", ""));
39 EXPECT_TRUE(ends_with("", ""));
40 EXPECT_FALSE(ends_with("foobar", "foo"));
41 EXPECT_FALSE(ends_with("foobar", "foobarbaz"));
42 EXPECT_FALSE(ends_with("", "f"));
43}
44
Jonas Olsson74395342018-04-03 12:22:07 +020045TEST(string_toHexTest, ToHex) {
46 EXPECT_EQ(ToHex(0), "0");
47 EXPECT_EQ(ToHex(0X1243E), "1243e");
48 EXPECT_EQ(ToHex(-20), "ffffffec");
49}
50
51} // namespace rtc