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
3 // found in the LICENSE file.
5 #include "net/quic/quic_utils.h"
7 #include "net/quic/crypto/crypto_protocol.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using base::StringPiece
;
17 // A test string and a hex+ASCII dump of the same string.
18 const unsigned char kString
[] = {
19 0x00, 0x90, 0x69, 0xbd, 0x54, 0x00, 0x00, 0x0d,
20 0x61, 0x0f, 0x01, 0x89, 0x08, 0x00, 0x45, 0x00,
21 0x00, 0x1c, 0xfb, 0x98, 0x40, 0x00, 0x40, 0x01,
22 0x7e, 0x18, 0xd8, 0xef, 0x23, 0x01, 0x45, 0x5d,
23 0x7f, 0xe2, 0x08, 0x00, 0x6b, 0xcb, 0x0b, 0xc6,
27 const unsigned char kHexDump
[] =
28 "0x0000: 0090 69bd 5400 000d 610f 0189 0800 4500 ..i.T...a.....E.\n"
29 "0x0010: 001c fb98 4000 4001 7e18 d8ef 2301 455d ....@.@.~...#.E]\n"
30 "0x0020: 7fe2 0800 6bcb 0bc6 806e ....k....n\n";
32 TEST(QuicUtilsTest
, StreamErrorToString
) {
33 EXPECT_STREQ("QUIC_BAD_APPLICATION_PAYLOAD",
34 QuicUtils::StreamErrorToString(QUIC_BAD_APPLICATION_PAYLOAD
));
37 TEST(QuicUtilsTest
, ErrorToString
) {
38 EXPECT_STREQ("QUIC_NO_ERROR",
39 QuicUtils::ErrorToString(QUIC_NO_ERROR
));
42 TEST(QuicUtilsTest
, StringToHexASCIIDumpArgTypes
) {
43 // Verify that char*, string and StringPiece are all valid argument types.
46 const string expected
;
49 { "A", "0x0000: 41 A\n", },
50 { "AB", "0x0000: 4142 AB\n", },
51 { "ABC", "0x0000: 4142 43 ABC\n", },
53 "0x0000: 6f72 6967 696e 616c original\n", },
56 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(tests
); ++i
) {
57 EXPECT_EQ(tests
[i
].expected
,
58 QuicUtils::StringToHexASCIIDump(tests
[i
].input
.c_str()));
59 EXPECT_EQ(tests
[i
].expected
,
60 QuicUtils::StringToHexASCIIDump(tests
[i
].input
));
61 EXPECT_EQ(tests
[i
].expected
,
62 QuicUtils::StringToHexASCIIDump(StringPiece(tests
[i
].input
)));
66 TEST(QuicUtilsTest
, StringToHexASCIIDumpSuccess
) {
67 EXPECT_EQ(string(reinterpret_cast<const char*>(kHexDump
)),
68 QuicUtils::StringToHexASCIIDump(
69 string(reinterpret_cast<const char*>(kString
), sizeof(kString
))));
72 TEST(QuicUtilsTest
, TagToString
) {
74 QuicUtils::TagToString(kSCFG
));
76 QuicUtils::TagToString(kServerNonceTag
));
78 QuicUtils::TagToString(kCertificateTag
));
80 QuicUtils::TagToString(MakeQuicTag('C', 'H', 'L', 'O')));
81 // A tag that contains a non-printing character will be printed as a decimal
83 EXPECT_EQ("525092931",
84 QuicUtils::TagToString(MakeQuicTag('C', 'H', 'L', '\x1f')));