xref: /aosp_15_r20/external/ltp/testcases/commands/unzip/unzip01.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) International Business Machines Corp., 2001
4# Copyright (c) Cyril Hrubis <[email protected]>
5# Author: Manoj Iyer <[email protected]>
6#
7# Tests basic functionality of unzip command.
8
9TST_SETUP=setup
10TST_TESTFUNC=do_test
11TST_NEEDS_TMPDIR=1
12TST_NEEDS_CMDS="unzip"
13
14EXTRACT_MATCH="extracting"
15
16if unzip 2>&1 | grep -q 'BusyBox'; then
17	EXTRACT_MATCH="inflating"
18fi
19
20setup()
21{
22	cat > unzip_exp.out <<EOF
23Archive:  $TST_DATAROOT/test.zip
24   creating: dir/
25   creating: dir/d1/
26   creating: dir/d2/
27   creating: dir/d3/
28   creating: dir/d4/
29 $EXTRACT_MATCH: dir/d1/f1
30 $EXTRACT_MATCH: dir/d1/f2
31 $EXTRACT_MATCH: dir/d1/f3
32   creating: dir/d2/d1/
33   creating: dir/d2/d2/
34   creating: dir/d2/d3/
35 $EXTRACT_MATCH: dir/d2/f1
36 $EXTRACT_MATCH: dir/d2/f2
37 $EXTRACT_MATCH: dir/d2/f3
38   creating: dir/d3/d1/
39   creating: dir/d3/d2/
40   creating: dir/d3/d3/
41EOF
42}
43
44stable_ls()
45{
46	local i
47
48	for i in $(echo "$1/*" | sort); do
49
50		if ! [ -e "$i" ]; then
51			return
52		fi
53
54		echo "$i"
55
56		if [ -d "$i" ]; then
57			stable_ls "$i"
58		fi
59	done
60}
61
62do_test()
63{
64	EXPECT_PASS unzip "$TST_DATAROOT/test.zip" \> unzip.out
65
66	if diff -w unzip_exp.out unzip.out; then
67		tst_res TPASS "Unzip output is correct"
68	else
69		tst_res TFAIL "Unzip output is incorrect"
70		cat unzip.out
71	fi
72
73	stable_ls "dir" > dir.out
74
75	if diff "$TST_DATAROOT/dir.out" dir.out; then
76		tst_res TPASS "Files unzipped correctly"
77	else
78		tst_res TFAIL "Files unzipped incorrectly"
79		cat dir.out
80	fi
81
82	ROD rm -rf "dir/"
83}
84
85. tst_test.sh
86tst_run
87