xref: /freebsd/usr.bin/hexdump/tests/hexdump_test.sh (revision bca9d05fdb058aa709621661c2feccae8940d94b)
1#
2# Copyright (c) 2017 Kyle Evans <kevans@FreeBSD.org>
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24# SUCH DAMAGE.
25#
26# $FreeBSD$
27
28atf_test_case b_flag
29b_flag_head()
30{
31	atf_set "descr" "Verify -b output"
32}
33b_flag_body()
34{
35	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_a.out" \
36	    hexdump -b "$(atf_get_srcdir)/d_hexdump_a.in"
37	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_b.out" \
38	    hexdump -b "$(atf_get_srcdir)/d_hexdump_b.in"
39	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_c.out" \
40	    hexdump -b "$(atf_get_srcdir)/d_hexdump_c.in"
41}
42
43atf_test_case c_flag
44c_flag_head()
45{
46	atf_set "descr" "Verify -c output"
47}
48c_flag_body()
49{
50	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_a.out" \
51	    hexdump -c "$(atf_get_srcdir)/d_hexdump_a.in"
52	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_b.out" \
53	    hexdump -c "$(atf_get_srcdir)/d_hexdump_b.in"
54	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_c.out" \
55	    hexdump -c "$(atf_get_srcdir)/d_hexdump_c.in"
56}
57
58atf_test_case C_flag
59C_flag_head()
60{
61	atf_set "descr" "Verify -C output"
62}
63C_flag_body()
64{
65	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_a.out" \
66	    hexdump -C "$(atf_get_srcdir)/d_hexdump_a.in"
67	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_b.out" \
68	    hexdump -C "$(atf_get_srcdir)/d_hexdump_b.in"
69	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \
70	    hexdump -C "$(atf_get_srcdir)/d_hexdump_c.in"
71}
72
73atf_test_case hd_name
74hd_name_head()
75{
76	atf_set "descr" "Verify hd output matching -C output"
77}
78hd_name_body()
79{
80	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_a.out" \
81	    hd "$(atf_get_srcdir)/d_hexdump_a.in"
82	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_b.out" \
83	    hd "$(atf_get_srcdir)/d_hexdump_b.in"
84	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \
85	    hd "$(atf_get_srcdir)/d_hexdump_c.in"
86}
87
88atf_test_case d_flag
89d_flag_head()
90{
91	atf_set "descr" "Verify -d output"
92}
93d_flag_body()
94{
95	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_a.out" \
96	    hexdump -d "$(atf_get_srcdir)/d_hexdump_a.in"
97	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_b.out" \
98	    hexdump -d "$(atf_get_srcdir)/d_hexdump_b.in"
99	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_c.out" \
100	    hexdump -d "$(atf_get_srcdir)/d_hexdump_c.in"
101}
102
103atf_test_case n_flag
104n_flag_head()
105{
106	atf_set "descr" "Check -n functionality"
107}
108n_flag_body()
109{
110	atf_check -o empty hexdump -bn 0 "$(atf_get_srcdir)/d_hexdump_a.in"
111	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_nflag_a.out" \
112	    hexdump -bn 1 "$(atf_get_srcdir)/d_hexdump_a.in"
113}
114
115atf_test_case o_flag
116o_flag_head()
117{
118	atf_set "descr" "Verify -o output"
119}
120o_flag_body()
121{
122	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_a.out" \
123	    hexdump -o "$(atf_get_srcdir)/d_hexdump_a.in"
124	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_b.out" \
125	    hexdump -o "$(atf_get_srcdir)/d_hexdump_b.in"
126	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_c.out" \
127	    hexdump -o "$(atf_get_srcdir)/d_hexdump_c.in"
128}
129
130atf_test_case s_flag
131s_flag_head()
132{
133	atf_set "descr" "Verify -s output"
134}
135s_flag_body()
136{
137	atf_expect_fail "-s option is currently broken due to capsicum (PR 219173)"
138	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_sflag_a.out" \
139	    hexdump -bs 4 "$(atf_get_srcdir)/d_hexdump_a.in"
140
141	atf_check -o not-empty hexdump -n 100 -s 1024 /dev/random
142}
143
144atf_test_case v_flag
145v_flag_head()
146{
147	atf_set "descr" "Verify -v functionality"
148}
149v_flag_body()
150{
151	atf_expect_fail "-s option is currently broken due to capsicum (PR 219173)"
152	for i in $(seq 0 7); do
153		atf_check -o match:"^\*$" \
154		    hexdump -s ${i} "$(atf_get_srcdir)/d_hexdump_c.in"
155		atf_check -o not-match:"^\*$" \
156		    hexdump -vs ${i} "$(atf_get_srcdir)/d_hexdump_c.in"
157	done
158
159	atf_check -o not-match:"^\*$" \
160	    hexdump -s 8 "$(atf_get_srcdir)/d_hexdump_c.in"
161	atf_check -o not-match:"^\*$" \
162	    hexdump -vs 8 "$(atf_get_srcdir)/d_hexdump_c.in"
163}
164
165atf_test_case x_flag
166x_flag_head()
167{
168	atf_set "descr" "Verify -x output"
169}
170x_flag_body()
171{
172	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_a.out" \
173	    hexdump -x "$(atf_get_srcdir)/d_hexdump_a.in"
174	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_b.out" \
175	    hexdump -x "$(atf_get_srcdir)/d_hexdump_b.in"
176	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_c.out" \
177	    hexdump -x "$(atf_get_srcdir)/d_hexdump_c.in"
178}
179
180atf_init_test_cases()
181{
182	atf_add_test_case b_flag
183	atf_add_test_case c_flag
184	atf_add_test_case C_flag
185	atf_add_test_case hd_name
186	atf_add_test_case d_flag
187	atf_add_test_case n_flag
188	atf_add_test_case o_flag
189	atf_add_test_case s_flag
190	atf_add_test_case v_flag
191	atf_add_test_case x_flag
192}
193