blob: d9509612136af7b97aa037ff8fd43be609869524 [file] [log] [blame]
Ian Rogers43b2e0f2014-01-30 16:58:39 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "hex_dump.h"
18
19#include "globals.h"
20
21#include "gtest/gtest.h"
22
23#include <stdint.h>
24
25namespace art {
26
27TEST(HexDump, OneLine) {
28 const char* test_text = "0123456789abcdef";
29 std::ostringstream oss;
30 oss << HexDump(test_text, strlen(test_text), false, "");
31 EXPECT_STREQ(oss.str().c_str(),
32 "00000000: 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 0123456789abcdef");
33}
34
35TEST(HexDump, MultiLine) {
36 const char* test_text = "0123456789abcdef0123456789ABCDEF";
37 std::ostringstream oss;
38 oss << HexDump(test_text, strlen(test_text), false, "");
39 EXPECT_STREQ(oss.str().c_str(),
40 "00000000: 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 0123456789abcdef\n"
41 "00000010: 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 0123456789ABCDEF");
42}
43
44uint64_t g16byte_aligned_number __attribute__ ((aligned(16))); // NOLINT(whitespace/parens)
45TEST(HexDump, ShowActualAddresses) {
46 g16byte_aligned_number = 0x6162636465666768;
47 std::ostringstream oss;
48 oss << HexDump(&g16byte_aligned_number, 8, true, "");
49 // Compare ignoring pointer.
50 EXPECT_STREQ(oss.str().c_str() + (kBitsPerWord / 4),
51 ": 68 67 66 65 64 63 62 61 hgfedcba ");
52}
53
54TEST(HexDump, Prefix) {
55 const char* test_text = "0123456789abcdef";
56 std::ostringstream oss;
57 oss << HexDump(test_text, strlen(test_text), false, "test prefix: ");
58 EXPECT_STREQ(oss.str().c_str(),
59 "test prefix: 00000000: 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 "
60 "0123456789abcdef");
61}
62
63} // namespace art