OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_utils.h" | 5 #include "net/quic/quic_utils.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
| 9 using base::StringPiece; |
| 10 using std::string; |
| 11 |
9 namespace net { | 12 namespace net { |
10 namespace test { | 13 namespace test { |
11 namespace { | 14 namespace { |
12 | 15 |
| 16 // A test string and a hex+ASCII dump of the same string. |
| 17 const unsigned char kString[] = { |
| 18 0x00, 0x90, 0x69, 0xbd, 0x54, 0x00, 0x00, 0x0d, |
| 19 0x61, 0x0f, 0x01, 0x89, 0x08, 0x00, 0x45, 0x00, |
| 20 0x00, 0x1c, 0xfb, 0x98, 0x40, 0x00, 0x40, 0x01, |
| 21 0x7e, 0x18, 0xd8, 0xef, 0x23, 0x01, 0x45, 0x5d, |
| 22 0x7f, 0xe2, 0x08, 0x00, 0x6b, 0xcb, 0x0b, 0xc6, |
| 23 0x80, 0x6e |
| 24 }; |
| 25 |
| 26 const unsigned char kHexDump[] = |
| 27 "0x0000: 0090 69bd 5400 000d 610f 0189 0800 4500 ..i.T...a.....E.\n" |
| 28 "0x0010: 001c fb98 4000 4001 7e18 d8ef 2301 455d ....@.@.~...#.E]\n" |
| 29 "0x0020: 7fe2 0800 6bcb 0bc6 806e ....k....n\n"; |
| 30 |
13 TEST(QuicUtilsTest, StreamErrorToString) { | 31 TEST(QuicUtilsTest, StreamErrorToString) { |
14 EXPECT_STREQ("QUIC_BAD_APPLICATION_PAYLOAD", | 32 EXPECT_STREQ("QUIC_BAD_APPLICATION_PAYLOAD", |
15 QuicUtils::StreamErrorToString(QUIC_BAD_APPLICATION_PAYLOAD)); | 33 QuicUtils::StreamErrorToString(QUIC_BAD_APPLICATION_PAYLOAD)); |
16 } | 34 } |
17 | 35 |
18 TEST(QuicUtilsTest, ErrorToString) { | 36 TEST(QuicUtilsTest, ErrorToString) { |
19 EXPECT_STREQ("QUIC_NO_ERROR", | 37 EXPECT_STREQ("QUIC_NO_ERROR", |
20 QuicUtils::ErrorToString(QUIC_NO_ERROR)); | 38 QuicUtils::ErrorToString(QUIC_NO_ERROR)); |
21 } | 39 } |
22 | 40 |
| 41 TEST(QuicUtilsTest, StringToHexASCIIDumpArgTypes) { |
| 42 // Verify that char*, string and StringPiece are all valid argument types. |
| 43 struct { |
| 44 const string input; |
| 45 const string expected; |
| 46 } tests[] = { |
| 47 { "", "", }, |
| 48 { "A", "0x0000: 41 A\n", }, |
| 49 { "AB", "0x0000: 4142 AB\n", }, |
| 50 { "ABC", "0x0000: 4142 43 ABC\n", }, |
| 51 { "original", |
| 52 "0x0000: 6f72 6967 696e 616c original\n", }, |
| 53 }; |
| 54 |
| 55 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 56 EXPECT_EQ(tests[i].expected, |
| 57 QuicUtils::StringToHexASCIIDump(tests[i].input.c_str())); |
| 58 EXPECT_EQ(tests[i].expected, |
| 59 QuicUtils::StringToHexASCIIDump(tests[i].input)); |
| 60 EXPECT_EQ(tests[i].expected, |
| 61 QuicUtils::StringToHexASCIIDump(StringPiece(tests[i].input))); |
| 62 } |
| 63 } |
| 64 |
| 65 TEST(QuicUtilsTest, StringToHexASCIIDumpSuccess) { |
| 66 EXPECT_EQ(string(reinterpret_cast<const char*>(kHexDump)), |
| 67 QuicUtils::StringToHexASCIIDump( |
| 68 string(reinterpret_cast<const char*>(kString), sizeof(kString)))); |
| 69 } |
| 70 |
23 } // namespace | 71 } // namespace |
24 } // namespace test | 72 } // namespace test |
25 } // namespace net | 73 } // namespace net |
OLD | NEW |