| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/base/arraysize.h" | 11 #include "webrtc/base/arraysize.h" |
| 12 #include "webrtc/base/gunit.h" | 12 #include "webrtc/base/gunit.h" |
| 13 #include "webrtc/base/stringencode.h" | 13 #include "webrtc/base/stringencode.h" |
| 14 #include "webrtc/base/stringutils.h" | 14 #include "webrtc/base/stringutils.h" |
| 15 | 15 |
| 16 namespace rtc { | 16 namespace rtc { |
| 17 | 17 |
| 18 TEST(Utf8EncodeTest, EncodeDecode) { | 18 TEST(Utf8EncodeTest, EncodeDecode) { |
| 19 const struct Utf8Test { | 19 const struct Utf8Test { |
| 20 const char* encoded; | 20 const char* encoded; |
| 21 size_t encsize, enclen; | 21 size_t encsize, enclen; |
| 22 unsigned long decoded; | 22 unsigned long decoded; |
| 23 } kTests[] = { | 23 } kTests[] = { |
| 24 { "a ", 5, 1, 'a' }, | 24 {"a ", 5, 1, 'a'}, |
| 25 { "\x7F ", 5, 1, 0x7F }, | 25 {"\x7F ", 5, 1, 0x7F}, |
| 26 { "\xC2\x80 ", 5, 2, 0x80 }, | 26 {"\xC2\x80 ", 5, 2, 0x80}, |
| 27 { "\xDF\xBF ", 5, 2, 0x7FF }, | 27 {"\xDF\xBF ", 5, 2, 0x7FF}, |
| 28 { "\xE0\xA0\x80 ", 5, 3, 0x800 }, | 28 {"\xE0\xA0\x80 ", 5, 3, 0x800}, |
| 29 { "\xEF\xBF\xBF ", 5, 3, 0xFFFF }, | 29 {"\xEF\xBF\xBF ", 5, 3, 0xFFFF}, |
| 30 { "\xF0\x90\x80\x80 ", 5, 4, 0x10000 }, | 30 {"\xF0\x90\x80\x80 ", 5, 4, 0x10000}, |
| 31 { "\xF0\x90\x80\x80 ", 3, 0, 0x10000 }, | 31 {"\xF0\x90\x80\x80 ", 3, 0, 0x10000}, |
| 32 { "\xF0\xF0\x80\x80 ", 5, 0, 0 }, | 32 {"\xF0\xF0\x80\x80 ", 5, 0, 0}, |
| 33 { "\xF0\x90\x80 ", 5, 0, 0 }, | 33 {"\xF0\x90\x80 ", 5, 0, 0}, |
| 34 { "\x90\x80\x80 ", 5, 0, 0 }, | 34 {"\x90\x80\x80 ", 5, 0, 0}, |
| 35 { NULL, 0, 0 }, | 35 {nullptr, 0, 0}, |
| 36 }; | 36 }; |
| 37 for (size_t i = 0; kTests[i].encoded; ++i) { | 37 for (size_t i = 0; kTests[i].encoded; ++i) { |
| 38 unsigned long val = 0; | 38 unsigned long val = 0; |
| 39 ASSERT_EQ(kTests[i].enclen, utf8_decode(kTests[i].encoded, | 39 ASSERT_EQ(kTests[i].enclen, utf8_decode(kTests[i].encoded, |
| 40 kTests[i].encsize, | 40 kTests[i].encsize, |
| 41 &val)); | 41 &val)); |
| 42 unsigned long result = (kTests[i].enclen == 0) ? 0 : kTests[i].decoded; | 42 unsigned long result = (kTests[i].enclen == 0) ? 0 : kTests[i].decoded; |
| 43 ASSERT_EQ(result, val); | 43 ASSERT_EQ(result, val); |
| 44 | 44 |
| 45 if (kTests[i].decoded == 0) { | 45 if (kTests[i].decoded == 0) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // Extra spaces should be ignored. | 241 // Extra spaces should be ignored. |
| 242 tokenize(" find middle one ", ' ', &fields); | 242 tokenize(" find middle one ", ' ', &fields); |
| 243 ASSERT_EQ(3ul, fields.size()); | 243 ASSERT_EQ(3ul, fields.size()); |
| 244 ASSERT_STREQ("middle", fields.at(1).c_str()); | 244 ASSERT_STREQ("middle", fields.at(1).c_str()); |
| 245 fields.clear(); | 245 fields.clear(); |
| 246 tokenize(" ", ' ', &fields); | 246 tokenize(" ", ' ', &fields); |
| 247 ASSERT_EQ(0ul, fields.size()); | 247 ASSERT_EQ(0ul, fields.size()); |
| 248 } | 248 } |
| 249 | 249 |
| 250 TEST(TokenizeTest, TokenizeAppend) { | 250 TEST(TokenizeTest, TokenizeAppend) { |
| 251 ASSERT_EQ(0ul, tokenize_append("A B C", ' ', NULL)); | 251 ASSERT_EQ(0ul, tokenize_append("A B C", ' ', nullptr)); |
| 252 | 252 |
| 253 std::vector<std::string> fields; | 253 std::vector<std::string> fields; |
| 254 | 254 |
| 255 tokenize_append("A B C", ' ', &fields); | 255 tokenize_append("A B C", ' ', &fields); |
| 256 ASSERT_EQ(3ul, fields.size()); | 256 ASSERT_EQ(3ul, fields.size()); |
| 257 ASSERT_STREQ("B", fields.at(1).c_str()); | 257 ASSERT_STREQ("B", fields.at(1).c_str()); |
| 258 | 258 |
| 259 tokenize_append("D E", ' ', &fields); | 259 tokenize_append("D E", ' ', &fields); |
| 260 ASSERT_EQ(5ul, fields.size()); | 260 ASSERT_EQ(5ul, fields.size()); |
| 261 ASSERT_STREQ("B", fields.at(1).c_str()); | 261 ASSERT_STREQ("B", fields.at(1).c_str()); |
| 262 ASSERT_STREQ("E", fields.at(4).c_str()); | 262 ASSERT_STREQ("E", fields.at(4).c_str()); |
| 263 } | 263 } |
| 264 | 264 |
| 265 TEST(TokenizeTest, TokenizeWithMarks) { | 265 TEST(TokenizeTest, TokenizeWithMarks) { |
| 266 ASSERT_EQ(0ul, tokenize("D \"A B", ' ', '(', ')', NULL)); | 266 ASSERT_EQ(0ul, tokenize("D \"A B", ' ', '(', ')', nullptr)); |
| 267 | 267 |
| 268 std::vector<std::string> fields; | 268 std::vector<std::string> fields; |
| 269 tokenize("A B C", ' ', '"', '"', &fields); | 269 tokenize("A B C", ' ', '"', '"', &fields); |
| 270 ASSERT_EQ(3ul, fields.size()); | 270 ASSERT_EQ(3ul, fields.size()); |
| 271 ASSERT_STREQ("C", fields.at(2).c_str()); | 271 ASSERT_STREQ("C", fields.at(2).c_str()); |
| 272 | 272 |
| 273 tokenize("\"A B\" C", ' ', '"', '"', &fields); | 273 tokenize("\"A B\" C", ' ', '"', '"', &fields); |
| 274 ASSERT_EQ(2ul, fields.size()); | 274 ASSERT_EQ(2ul, fields.size()); |
| 275 ASSERT_STREQ("A B", fields.at(0).c_str()); | 275 ASSERT_STREQ("A B", fields.at(0).c_str()); |
| 276 | 276 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 439 |
| 440 TEST(BoolTest, RoundTrip) { | 440 TEST(BoolTest, RoundTrip) { |
| 441 bool value; | 441 bool value; |
| 442 EXPECT_TRUE(FromString(ToString(true), &value)); | 442 EXPECT_TRUE(FromString(ToString(true), &value)); |
| 443 EXPECT_TRUE(value); | 443 EXPECT_TRUE(value); |
| 444 EXPECT_TRUE(FromString(ToString(false), &value)); | 444 EXPECT_TRUE(FromString(ToString(false), &value)); |
| 445 EXPECT_FALSE(value); | 445 EXPECT_FALSE(value); |
| 446 } | 446 } |
| 447 | 447 |
| 448 } // namespace rtc | 448 } // namespace rtc |
| OLD | NEW |