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/common.h" | 12 #include "webrtc/base/common.h" |
12 #include "webrtc/base/gunit.h" | 13 #include "webrtc/base/gunit.h" |
13 #include "webrtc/base/stringencode.h" | 14 #include "webrtc/base/stringencode.h" |
14 #include "webrtc/base/stringutils.h" | 15 #include "webrtc/base/stringutils.h" |
15 | 16 |
16 namespace rtc { | 17 namespace rtc { |
17 | 18 |
18 TEST(Utf8EncodeTest, EncodeDecode) { | 19 TEST(Utf8EncodeTest, EncodeDecode) { |
19 const struct Utf8Test { | 20 const struct Utf8Test { |
20 const char* encoded; | 21 const char* encoded; |
(...skipping 20 matching lines...) Expand all Loading... |
41 &val)); | 42 &val)); |
42 unsigned long result = (kTests[i].enclen == 0) ? 0 : kTests[i].decoded; | 43 unsigned long result = (kTests[i].enclen == 0) ? 0 : kTests[i].decoded; |
43 ASSERT_EQ(result, val); | 44 ASSERT_EQ(result, val); |
44 | 45 |
45 if (kTests[i].decoded == 0) { | 46 if (kTests[i].decoded == 0) { |
46 // Not an interesting encoding test case | 47 // Not an interesting encoding test case |
47 continue; | 48 continue; |
48 } | 49 } |
49 | 50 |
50 char buffer[5]; | 51 char buffer[5]; |
51 memset(buffer, 0x01, ARRAY_SIZE(buffer)); | 52 memset(buffer, 0x01, arraysize(buffer)); |
52 ASSERT_EQ(kTests[i].enclen, utf8_encode(buffer, | 53 ASSERT_EQ(kTests[i].enclen, utf8_encode(buffer, |
53 kTests[i].encsize, | 54 kTests[i].encsize, |
54 kTests[i].decoded)); | 55 kTests[i].decoded)); |
55 ASSERT_TRUE(memcmp(buffer, kTests[i].encoded, kTests[i].enclen) == 0); | 56 ASSERT_TRUE(memcmp(buffer, kTests[i].encoded, kTests[i].enclen) == 0); |
56 // Make sure remainder of buffer is unchanged | 57 // Make sure remainder of buffer is unchanged |
57 ASSERT_TRUE(memory_check(buffer + kTests[i].enclen, | 58 ASSERT_TRUE(memory_check(buffer + kTests[i].enclen, |
58 0x1, | 59 0x1, |
59 ARRAY_SIZE(buffer) - kTests[i].enclen)); | 60 arraysize(buffer) - kTests[i].enclen)); |
60 } | 61 } |
61 } | 62 } |
62 | 63 |
63 class HexEncodeTest : public testing::Test { | 64 class HexEncodeTest : public testing::Test { |
64 public: | 65 public: |
65 HexEncodeTest() : enc_res_(0), dec_res_(0) { | 66 HexEncodeTest() : enc_res_(0), dec_res_(0) { |
66 for (size_t i = 0; i < sizeof(data_); ++i) { | 67 for (size_t i = 0; i < sizeof(data_); ++i) { |
67 data_[i] = (i + 128) & 0xff; | 68 data_[i] = (i + 128) & 0xff; |
68 } | 69 } |
69 memset(decoded_, 0x7f, sizeof(decoded_)); | 70 memset(decoded_, 0x7f, sizeof(decoded_)); |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 | 440 |
440 TEST(BoolTest, RoundTrip) { | 441 TEST(BoolTest, RoundTrip) { |
441 bool value; | 442 bool value; |
442 EXPECT_TRUE(FromString(ToString(true), &value)); | 443 EXPECT_TRUE(FromString(ToString(true), &value)); |
443 EXPECT_TRUE(value); | 444 EXPECT_TRUE(value); |
444 EXPECT_TRUE(FromString(ToString(false), &value)); | 445 EXPECT_TRUE(FromString(ToString(false), &value)); |
445 EXPECT_FALSE(value); | 446 EXPECT_FALSE(value); |
446 } | 447 } |
447 | 448 |
448 } // namespace rtc | 449 } // namespace rtc |
OLD | NEW |