1 // Copyright 2017 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.
4 
5 #include "net/base/hex_utils.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 
8 namespace net {
9 
10 namespace test {
11 
TEST(HexUtilsTest,HexDump)12 TEST(HexUtilsTest, HexDump) {
13   EXPECT_EQ("", HexDump(""));
14   EXPECT_EQ("0x0000:  4865 6c6c 6f20 776f 726c 6421            Hello.world!\n",
15             HexDump("Hello world!"));
16   EXPECT_EQ(
17       "0x0000:  5052 4920 2a20 4854 5450 2f32 2e30 0d0a  PRI.*.HTTP/2.0..\n"
18       "0x0010:  0d0a 534d 0d0a 0d0a                      ..SM....\n",
19       HexDump("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"));
20   // Verify that 0x21 and 0x7e are printable, 0x20 and 0x7f are not.
21   EXPECT_EQ("0x0000:  2021 7e7f                                .!~.\n",
22             HexDump("\x20\x21\x7e\x7f"));
23   // Verify that values above numeric_limits<unsigned char>::max() are cast
24   // properly on platforms where char is unsigned.
25   EXPECT_EQ("0x0000:  90aa ff                                  ...\n",
26             HexDump("\x90\xaa\xff"));
27 }
28 
29 }  // namespace test
30 
31 }  // namespace net
32