1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# $NetBSD: t_pr_19722.sh,v 1.4 2022/05/22 21:39:44 rillig Exp $
#
# Copyright (c) 2022 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
atf_test_case 'compress_small_file'
compress_small_file_body()
{
# If the compressed version of a file would be larger than the
# original file, the original file is kept.
echo 'hello' > file
atf_check compress file
atf_check -o 'inline:hello\n' cat file
atf_check test ! -f file.Z
}
atf_test_case 'compress_small_file_force'
compress_small_file_force_body()
{
# The option '-f' forces compression to happen, even if the resulting
# file becomes larger than the original.
echo 'hello' > file
atf_check compress -f file
atf_check test ! -f file
atf_check \
-o 'inline:0000000 1f 9d 90 68 ca b0 61 f3 46 01 \n000000a\n' \
od -Ax -tx1 file.Z
}
atf_test_case 'roundtrip'
roundtrip_body()
{
# Compressing and decompressing a file must preserve every byte.
atf_check -e 'ignore' dd if=/dev/urandom of=file bs=4k count=10
atf_check cp file original
atf_check compress -f file
atf_check uncompress file.Z
atf_check cmp file original
}
atf_test_case 'uncompress_basename'
uncompress_basename_body()
{
# To uncompress a file, it suffices to specify the basename of the
# file, the filename extension '.Z' is optional.
atf_check sh -c "echo 'hello' > file"
atf_check compress -f file
atf_check uncompress file
atf_check -o 'inline:hello\n' cat file
atf_check test ! -f file.Z
}
atf_test_case 'uncompress_no_source_no_target'
uncompress_no_source_no_target_body()
{
# PR 19722: uncompressing a missing source creates empty target
#
# Before compress.c 1.28 from 2022-05-22, uncompress created an empty
# target file and didn't clean it up.
atf_check \
-s 'not-exit:0' \
-e 'inline:uncompress: file.Z: No such file or directory\n' \
uncompress -f file
atf_check test ! -f file
atf_check test ! -f file.Z
}
atf_test_case 'uncompress_no_source_existing_target'
uncompress_no_source_existing_target_body()
{
# PR 19722: uncompressing a missing source truncates target
#
# Before compress.c 1.28 from 2022-05-22, uncompress truncated the
# target.
atf_check sh -c "echo 'hello' > file"
atf_check \
-s 'not-exit:0' \
-e 'inline:uncompress: file.Z: No such file or directory\n' \
uncompress -f file
atf_check -o 'inline:hello\n' cat file
atf_check test ! -f file.Z
}
atf_test_case 'uncompress_broken_source_no_target'
uncompress_broken_source_no_target_body()
{
# When trying to uncompress a broken source, the target is created
# temporarily but deleted again, as part of the cleanup.
echo 'broken' > file.Z
atf_check \
-s 'not-exit:0' \
-e 'inline:uncompress: file.Z: Inappropriate file type or format\n' \
uncompress -f file
atf_check test ! -f file
atf_check test -f file.Z
}
atf_test_case 'uncompress_broken_source_existing_target'
uncompress_broken_source_existing_target_body()
{
# PR 19722: uncompressing a broken source removes existing target
#
# Before compress.c 1.29 from 2022-05-22, uncompress removed an
# existing target before checking that the source has the correct
# format.
echo 'broken' > file.Z
echo 'before' > file
atf_check \
-s 'not-exit:0' \
-e 'inline:uncompress: file.Z: Inappropriate file type or format\n' \
uncompress -f file.Z
atf_check -o 'inline:broken\n' cat file.Z
atf_check -o 'inline:before\n' cat file
}
atf_init_test_cases()
{
atf_add_test_case compress_small_file
atf_add_test_case compress_small_file_force
atf_add_test_case roundtrip
atf_add_test_case uncompress_basename
atf_add_test_case uncompress_no_source_no_target
atf_add_test_case uncompress_no_source_existing_target
atf_add_test_case uncompress_broken_source_no_target
atf_add_test_case uncompress_broken_source_existing_target
}
|