File: test.sh

package info (click to toggle)
uudeview 0.5.20%2B20250228-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,236 kB
  • sloc: ansic: 12,080; sh: 2,826; makefile: 360; awk: 13
file content (71 lines) | stat: -rwxr-xr-x 2,428 bytes parent folder | download
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
#!/bin/bash
set -euo pipefail

MYDIR="$(dirname "$0")"
TMPD="$(mktemp -d)"

# All test files ending with .good.msg contain the
# file doc/test.txt with various encodings.
for fn in "$MYDIR"/*.good.msg; do
	echo -e "\033[0;32mTesting good test case $fn\033[0m"
	env LD_LIBRARY_PATH="$MYDIR"/../uulib \
	"$MYDIR"/../unix/uudeview -i -p "$TMPD" "$fn"

	diff "$MYDIR"/../doc/test.txt "$TMPD"/test.txt

	rm "$TMPD"/test.txt
done

# The files ending with .bad.msg are sample files
# triggering bugs like memory safety violations. They
# do not contain valid data, thus we do not expect
# extracted files, we just do not want them to crash.
for fn in "$MYDIR"/*.bad.msg; do
	echo -e "\033[0;33mTesting bad test case $fn\033[0m"
	env LD_LIBRARY_PATH="$MYDIR"/../uulib \
	"$MYDIR"/../unix/uudeview -i -p "$TMPD" "$fn"
done

# Files ending with .fail.msg trigger memory safety bugs,
# they differ from .bad.msg fails that uudeview will try
# to decode input, so we expect them to return an error,
# still they should not crash.
for fn in "$MYDIR"/*.fail.msg; do
	echo -e "\033[1;33mTesting fail test case $fn\033[0m"
	# uudeview returns 2 on errors
	env LD_LIBRARY_PATH="$MYDIR"/../uulib \
	"$MYDIR"/../unix/uudeview -i -p "$TMPD" "$fn" && false || [ $? -eq 2 ]
done

# Test encoding and decoding of a random file of random size.
head -c $RANDOM /dev/urandom > "$TMPD/test.bin"
cp "$TMPD/test.bin" "$TMPD/_test.bin"
for enc in b u x y; do
	echo -e "\033[0;35mTesting uuenview -$enc\033[0m"
	echo -en "From:a\nTo:b\nSubject:test\n\n" | \
		env LD_LIBRARY_PATH="$MYDIR"/../uulib \
		"$MYDIR"/../unix/uuenview -$enc -a "$TMPD/test.bin" > \
		"$TMPD/test.$enc.msg"
	rm "$TMPD/test.bin"
	env LD_LIBRARY_PATH="$MYDIR"/../uulib \
	"$MYDIR"/../unix/uudeview -i -p "$TMPD" "$TMPD/test.$enc.msg"
	diff "$TMPD/_test.bin" "$TMPD/test.bin"
	rm "$TMPD/test.$enc.msg"
done

echo -e "\033[0;36mTesting split uuencoded file\033[0m"
env LD_LIBRARY_PATH="$MYDIR"/../uulib \
"$MYDIR"/../unix/uuenview -200 -od "$TMPD" "$TMPD/test.bin"
rm "$TMPD/test.bin"
env LD_LIBRARY_PATH="$MYDIR"/../uulib \
"$MYDIR"/../unix/uudeview "$TMPD"/test.* -p "$TMPD" -i
diff "$TMPD/_test.bin" "$TMPD/test.bin"

echo -e "\033[1;95mTesting invalid TMPDIR\033[0m"
env LD_LIBRARY_PATH="$MYDIR"/../uulib \
TMPDIR="/dev/null" "$MYDIR"/../unix/uudeview -i "$MYDIR"/mime-base64.good.msg && false || [ $? -eq 2 ]

rm -r "$TMPD"

echo
echo -e "\033[1;34mAll tests ran as expected\033[0m"