henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "rtc_base/stringutils.h" |
| 12 | #include "rtc_base/gunit.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 13 | |
| 14 | namespace rtc { |
| 15 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 16 | TEST(string_trim_Test, Trimming) { |
| 17 | EXPECT_EQ("temp", string_trim("\n\r\t temp \n\r\t")); |
| 18 | EXPECT_EQ("temp\n\r\t temp", string_trim(" temp\n\r\t temp ")); |
| 19 | EXPECT_EQ("temp temp", string_trim("temp temp")); |
| 20 | EXPECT_EQ("", string_trim(" \r\n\t")); |
| 21 | EXPECT_EQ("", string_trim("")); |
| 22 | } |
| 23 | |
| 24 | TEST(string_startsTest, StartsWith) { |
| 25 | EXPECT_TRUE(starts_with("foobar", "foo")); |
| 26 | EXPECT_TRUE(starts_with("foobar", "foobar")); |
| 27 | EXPECT_TRUE(starts_with("foobar", "")); |
| 28 | EXPECT_TRUE(starts_with("", "")); |
| 29 | EXPECT_FALSE(starts_with("foobar", "bar")); |
| 30 | EXPECT_FALSE(starts_with("foobar", "foobarbaz")); |
| 31 | EXPECT_FALSE(starts_with("", "f")); |
| 32 | } |
| 33 | |
| 34 | TEST(string_endsTest, EndsWith) { |
| 35 | EXPECT_TRUE(ends_with("foobar", "bar")); |
| 36 | EXPECT_TRUE(ends_with("foobar", "foobar")); |
| 37 | EXPECT_TRUE(ends_with("foobar", "")); |
| 38 | EXPECT_TRUE(ends_with("", "")); |
| 39 | EXPECT_FALSE(ends_with("foobar", "foo")); |
| 40 | EXPECT_FALSE(ends_with("foobar", "foobarbaz")); |
| 41 | EXPECT_FALSE(ends_with("", "f")); |
| 42 | } |
| 43 | |
Jonas Olsson | 7439534 | 2018-04-03 12:22:07 +0200 | [diff] [blame] | 44 | TEST(string_toHexTest, ToHex) { |
| 45 | EXPECT_EQ(ToHex(0), "0"); |
| 46 | EXPECT_EQ(ToHex(0X1243E), "1243e"); |
| 47 | EXPECT_EQ(ToHex(-20), "ffffffec"); |
| 48 | } |
| 49 | |
| 50 | } // namespace rtc |