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 <chrubis@suse.cz>
5# Author: Manoj Iyer <manjo@mail.utexas.edu>
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. tst_test.sh
14
15setup()
16{
17	cat > unzip_exp.out <<EOF
18Archive:  $TST_DATAROOT/test.zip
19   creating: dir/
20   creating: dir/d1/
21   creating: dir/d2/
22   creating: dir/d3/
23   creating: dir/d4/
24 extracting: dir/d1/f1
25 extracting: dir/d1/f2
26 extracting: dir/d1/f3
27   creating: dir/d2/d1/
28   creating: dir/d2/d2/
29   creating: dir/d2/d3/
30 extracting: dir/d2/f1
31 extracting: dir/d2/f2
32 extracting: dir/d2/f3
33   creating: dir/d3/d1/
34   creating: dir/d3/d2/
35   creating: dir/d3/d3/
36EOF
37}
38
39stable_ls()
40{
41	local i
42
43	for i in $(echo "$1/*" | sort); do
44
45		if ! [ -e "$i" ]; then
46			return
47		fi
48
49		echo "$i"
50
51		if [ -d "$i" ]; then
52			stable_ls "$i"
53		fi
54	done
55}
56
57do_test()
58{
59	EXPECT_PASS unzip "$TST_DATAROOT/test.zip" \> unzip.out
60
61	if diff -w unzip_exp.out unzip.out; then
62		tst_res TPASS "Unzip output is correct"
63	else
64		tst_res TFAIL "Unzip output is incorrect"
65		cat unzip.out
66	fi
67
68	stable_ls "dir" > dir.out
69
70	if diff "$TST_DATAROOT/dir.out" dir.out; then
71		tst_res TPASS "Files unzipped correctly"
72	else
73		tst_res TFAIL "Files unzipped incorrectly"
74		cat dir.out
75	fi
76
77	ROD rm -rf "dir/"
78}
79
80tst_run
81