-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·101 lines (81 loc) · 2.16 KB
/
test.sh
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
#!/usr/bin/env bash
# Author: Abid Sulaiman
# Title: Test Script for Sound Control
# Test Output Result ------------------------------------
# Test Get Input
re='^\[o(n)?(ff)?\]' # on or off
res=$(./sound-ctl.sh gi)
if [[ "$res" =~ $re ]]; then
echo "Test get input status OK"
else
echo "Test get input status failed."
echo "Consider running setup script or check the inputSource config."
exit 1
fi
# Test Get Output
re='^H?S?P$' # HP or SP
res=$(./sound-ctl.sh go)
if [[ "$res" =~ $re ]]; then
echo "Test get output status OK"
else
echo "Test get output status failed."
echo "Consider running setup script or check the outputSink, speakerPort and headphonePort config."
exit 1
fi
# Test Get Volume
re='^1?[0-9]{2}' # on or off
res=$(./sound-ctl.sh gv)
if [[ "$res" =~ $re ]]; then
echo "Test get volume OK"
else
echo "Test get volume failed."
echo "Consider running setup script or check the outputSink config."
exit 1
fi
echo # blank line
# Test Exit Code Function -------------------------------
test_exit_code_success() {
if [[ $? -eq 0 ]]; then
echo "Exit code set correctly"
else
echo "Exit code set incorrectly"
return 1
fi
return 0
}
test_exit_code_fail() {
if [[ $? -ne 0 ]]; then
echo "Exit code set correctly"
else
echo "Exit code set incorrectly"
return 1
fi
return 0
}
# Test Command ------------------------------------------
# with correct config -----------------------------------
options=("gi" "go" "gv" "i" "o" "sv 50")
echo "Test with correct config"
echo # blank line
for o in "${options[@]}"; do
echo "Test option" "$o"
./sound-ctl.sh $o
test_exit_code_success || exit 1
echo # blank line
done
# Test Command ------------------------------------------
# with incorrect config ---------------------------------
# Copy script and remove some word from config to cause error.
cp ./sound-ctl.sh ./sound-ctl-error.sh
sed -i '/outputSink=/,/headphonePort=/s/-.*/"/' ./sound-ctl-error.sh
echo "Test with incorrect config"
echo # blank line
for o in "${options[@]}"; do
echo "Test option" "$o"
./sound-ctl-error.sh $o
test_exit_code_fail || exit 1
echo # blank line
done
rm ./sound-ctl-error.sh
echo "Test finished successfully"
exit 0