1 | // ================================================================= // |
---|
2 | // // |
---|
3 | // File : AWT_hexdump.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in September 2011 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // ================================================================= // |
---|
11 | |
---|
12 | #include "awt_hexdump.hxx" |
---|
13 | |
---|
14 | #ifdef UNIT_TESTS |
---|
15 | #ifndef TEST_UNIT_H |
---|
16 | #include <test_unit.h> |
---|
17 | #endif |
---|
18 | |
---|
19 | #define DO_HEXDUMP(off,hex,ascii,width,gap,space) \ |
---|
20 | str.erase(); \ |
---|
21 | MemDump(off, hex, ascii, width, gap,space) \ |
---|
22 | .dump_to(str, buf, len) |
---|
23 | |
---|
24 | #define TEST_HEXDUMP_EQUAL(width,gap,off,hex,ascii,space,expected) do { \ |
---|
25 | DO_HEXDUMP(off,hex,ascii,width,gap,space); \ |
---|
26 | TEST_EXPECT_EQUAL(str.get_data(), expected); \ |
---|
27 | } while(0) |
---|
28 | |
---|
29 | #define TEST_HEXDUMP_EQUAL__BROKEN(width,gap,off,hex,ascii,space,expected) do { \ |
---|
30 | DO_HEXDUMP(off,hex,ascii,width,gap,space); \ |
---|
31 | TEST_EXPECT_EQUAL__BROKEN(str.get_data(), expected); \ |
---|
32 | } while(0) |
---|
33 | |
---|
34 | void TEST_hexdump() { |
---|
35 | GBS_strstruct str(200); |
---|
36 | { |
---|
37 | char buf[] = { 0x11, 0x47, 0, 0}; |
---|
38 | int len = 4; |
---|
39 | |
---|
40 | TEST_HEXDUMP_EQUAL(0, 0, false, true, false, true, "11 47 00 00\n"); // unwrapped hexdump |
---|
41 | TEST_HEXDUMP_EQUAL(0, 0, false, true, false, false, "11470000\n"); // unwrapped hexdump (unspaced) |
---|
42 | TEST_HEXDUMP_EQUAL(0, 0, false, false, true, true, ".G..\n"); // unwrapped ascii |
---|
43 | TEST_HEXDUMP_EQUAL(0, 0, false, true, true, true, "11 47 00 00 | .G..\n"); // unwrapped hex+ascii |
---|
44 | |
---|
45 | TEST_HEXDUMP_EQUAL(0, 0, true, false, true, true, "0000 | .G..\n"); // unwrapped ascii |
---|
46 | TEST_HEXDUMP_EQUAL(0, 0, true, true, false, true, "0000 | 11 47 00 00\n"); // unwrapped hex |
---|
47 | TEST_HEXDUMP_EQUAL(0, 0, true, true, true, true, "0000 | 11 47 00 00 | .G..\n"); // unwrapped hex+ascii |
---|
48 | |
---|
49 | TEST_HEXDUMP_EQUAL(4, 0, false, true, false, true, "11 47 00 00\n"); |
---|
50 | TEST_HEXDUMP_EQUAL(4, 0, true, true, false, true, "0000 | 11 47 00 00\n"); |
---|
51 | TEST_HEXDUMP_EQUAL(4, 0, true, true, true, true, "0000 | 11 47 00 00 | .G..\n"); |
---|
52 | |
---|
53 | TEST_HEXDUMP_EQUAL(3, 0, false, true, false, true, "11 47 00\n00\n"); |
---|
54 | TEST_HEXDUMP_EQUAL(3, 0, true, true, false, true, "0000 | 11 47 00\n0003 | 00\n"); |
---|
55 | TEST_HEXDUMP_EQUAL(3, 0, true, true, true, true, "0000 | 11 47 00 | .G.\n0003 | 00 | .\n"); |
---|
56 | |
---|
57 | TEST_HEXDUMP_EQUAL(2, 0, false, true, false, true, "11 47\n00 00\n"); |
---|
58 | TEST_HEXDUMP_EQUAL(2, 0, true, true, false, true, "0000 | 11 47\n0002 | 00 00\n"); |
---|
59 | TEST_HEXDUMP_EQUAL(2, 0, true, true, true, true, "0000 | 11 47 | .G\n0002 | 00 00 | ..\n"); |
---|
60 | |
---|
61 | TEST_HEXDUMP_EQUAL(1, 0, false, true, false, true, "11\n47\n00\n00\n"); |
---|
62 | TEST_HEXDUMP_EQUAL(1, 0, true, true, false, true, "0000 | 11\n0001 | 47\n0002 | 00\n0003 | 00\n"); |
---|
63 | TEST_HEXDUMP_EQUAL(1, 0, true, true, true, true, "0000 | 11 | .\n0001 | 47 | G\n0002 | 00 | .\n0003 | 00 | .\n"); |
---|
64 | } |
---|
65 | |
---|
66 | { |
---|
67 | char buf[] = "\1Smarkerline\1Sposvar_full_all\1Sp"; |
---|
68 | int len = strlen(buf); |
---|
69 | TEST_HEXDUMP_EQUAL(16, 0, true, true, true, true, |
---|
70 | "0000 | 01 53 6D 61 72 6B 65 72 6C 69 6E 65 01 53 70 6F | .Smarkerline.Spo\n" |
---|
71 | "0010 | 73 76 61 72 5F 66 75 6C 6C 5F 61 6C 6C 01 53 70 | svar_full_all.Sp\n"); |
---|
72 | TEST_HEXDUMP_EQUAL(16, 4, true, true, true, true, |
---|
73 | "0000 | 01 53 6D 61 72 6B 65 72 6C 69 6E 65 01 53 70 6F | .Sma rker line .Spo\n" |
---|
74 | "0010 | 73 76 61 72 5F 66 75 6C 6C 5F 61 6C 6C 01 53 70 | svar _ful l_al l.Sp\n"); |
---|
75 | TEST_HEXDUMP_EQUAL(13, 4, true, true, true, true, |
---|
76 | "0000 | 01 53 6D 61 72 6B 65 72 6C 69 6E 65 01 | .Sma rker line .\n" |
---|
77 | "000D | 53 70 6F 73 76 61 72 5F 66 75 6C 6C 5F | Spos var_ full _\n" |
---|
78 | "001A | 61 6C 6C 01 53 70 | all. Sp\n" |
---|
79 | ); |
---|
80 | TEST_HEXDUMP_EQUAL(13, 4, true, false, true, true, |
---|
81 | "0000 | .Sma rker line .\n" |
---|
82 | "000D | Spos var_ full _\n" |
---|
83 | "001A | all. Sp\n" |
---|
84 | ); |
---|
85 | } |
---|
86 | } |
---|
87 | TEST_PUBLISH(TEST_hexdump); |
---|
88 | |
---|
89 | #endif // UNIT_TESTS |
---|
90 | |
---|
91 | |
---|
92 | |
---|