OSDN Git Service

Merge tag 'android-8.1.0_r1' into oreo-x86
[android-x86/external-toybox.git] / tests / xxd.test
1 #!/bin/bash
2
3 [ -f testing.sh ] && . testing.sh
4
5 #testing "name" "command" "result" "infile" "stdin"
6
7 echo "this is some text" > file1
8 echo -n > file2
9
10 # Note that the xxd in vim-common on Ubuntu 14 uses %07x for the file offset.
11
12 testing "file1" "xxd file1" \
13     "00000000: 7468 6973 2069 7320 736f 6d65 2074 6578  this is some tex\n00000010: 740a                                     t.\n" \
14     "" ""
15 testing "file1 -l" "xxd -l 2 file1" \
16     "00000000: 7468                                     th\n" \
17     "" ""
18 testing "file2" "xxd file2" "" "" ""
19 testing "-" "xxd -" \
20     "00000000: 6865 6c6c 6f                             hello\n" "" "hello"
21 testing "xxd" "xxd" \
22     "00000000: 776f 726c 64                             world\n" "" "world"
23 testing "-c 8 -g 4 file1" "xxd -c 8 -g 4 file1" \
24     "00000000: 74686973 20697320  this is \n00000008: 736f6d65 20746578  some tex\n00000010: 740a               t.\n" "" ""
25 testing "-c 8 -g 3 file1" "xxd -c 8 -g 3 file1" \
26     "00000000: 746869 732069 7320 this is \n00000008: 736f6d 652074 6578 some tex\n00000010: 740a               t.\n" "" ""
27
28 testing "-p" "xxd -p file1" "7468697320697320736f6d6520746578740a\n" "" ""
29
30 testing "-s" "xxd -s 13 file1" "0000000d: 7465 7874 0a                             text.\n" "" ""
31
32 testing "-r" "xxd file1 | xxd -r" "this is some text\n" "" ""
33 testing "-r -p" "xxd -p file1 | xxd -r -p" "this is some text\n" "" ""
34
35 testing "-r garbage" "echo '0000: 68 65 6c6c 6fxxxx' | xxd -r -" "hello" "" ""
36
37 # -r will only read -c bytes (default 16) before skipping to the next line,
38 # ignoring the rest.
39 testing "-r long" \
40     "echo '0000: 40404040404040404040404040404040404040404040404040404040404040404040404040404040' | xxd -r -" \
41     "@@@@@@@@@@@@@@@@" "" ""
42
43 # -r -p ignores the usual -p 30-byte/line limit (or any limit set by -c) and
44 # will take as many bytes as you give it.
45 testing "-r -p long" \
46     "echo '40404040404040404040404040404040404040404040404040404040404040404040404040404040' | xxd -r -p -" \
47     "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" "" ""
48
49 rm file1 file2