-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathxctest
executable file
·202 lines (178 loc) · 5.23 KB
/
xctest
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/sh -e
#
#
#
# xctest - shell script to test xclip
# Copyright (C) 2001 Kim Saunders
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
cleanup() {
# quietly remove temp files
rm "$tempi" "$tempo" 2>/dev/null || true
# Kill any remaining xclip processes
killall xclip 2>/dev/null || true
return 0
}
trap cleanup EXIT HUP INT
s() { [ "$1" != "1" ] && printf "s"; } # Plural(s)
# If terminal can show bold and standout (reverse), do so.
if tput bold >/dev/null 2>&1; then
PASS="$(tput bold)PASS$(tput sgr0)"
else
PASS=PASS
fi
if tput smso >/dev/null 2>&1; then
FAIL="$(tput smso)FAIL$(tput rmso)"
else
FAIL=FAIL
fi
delay=0.01 # seconds to wait before running xclip -o
if ! sleep $delay 2>/dev/null; then
delay=1
fi
# test to make sure ./xclip exists
if [ ! -x xclip ]; then
echo "Error: xclip doesn't exist in the current directory."
exit
fi
checker=""
for param in "$@"; do
case $param in
--valgrind) checker="valgrind --num-callers=8";;
esac
done
echo -n "Testing whether xclip exits correctly when the selection is lost: "
echo hello | ./xclip -q -i 2>/dev/null &
sleep "$delay"
echo goodbye | ./xclip -i
sleep "$delay"
if ps $! >/dev/null; then
echo "$FAIL"
echo "Zombie xclip yet lives! Killing."
killall xclip
exit 1
else
echo "$PASS"
fi
echo
echo "Testing whether xclip recognizes the advertised shorthand options"
echo -n "Trying: "
for opt in i o f "v -silent" c T r "t STRING" h V ; do
echo -n "-$opt, "
if ! ./xclip -$opt -out 2>/dev/null | ./xclip -$opt -in >/dev/null 2>&1
then
echo "$FAIL"
echo "./xclip -$opt returned an error."
killall xclip
exit 1
fi
done
printf "\t$PASS\n"
echo
# temp file names (in and out)
tempi=`mktemp` || exit 1
tempo=`mktemp` || exit 1
echo -n "Testing whether xclip can specify target with -t: "
echo hello | ./xclip -t xctest/datatype &
sleep $delay
if ! ./xclip -t TARGETS | grep -q xctest/datatype; then
echo "$FAIL"
killall xclip
exit 1
elif [ hello != "$(./xclip -t xctest/datatype)" ]; then
echo "$FAIL"
killall xclip
exit 1
fi
echo "$PASS"
# test xclip on different amounts of data (2^fold) to bring out any errors
c=0 # Number of folds completed.
lines=1 # Current file size (2 to the c power).
printf 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_+<>!@#$%%^&*() ' > "$tempi"
printf 'abcdefghijklmnopqrstuvwzyz-=,.1234567890\n' >> "$tempi"
for fold in 0 4 7 10 15; do
# double size of file by two (2 to the $fold power)
while [ "$c" -lt "$fold" ]; do
cat "$tempi" "$tempi" > "$tempo" && mv "$tempo" "$tempi"
lines=$(( 2 * lines ))
c=$(( c + 1 ))
done
# test sending the file to xclip, using all selections
nlines=$(printf "%d line%s" "$lines" $(s "$lines"))
printf "\nSending $nlines of text to xclip:"
for sel in PRIMARY SECONDARY CLIPBOARD BUFFERCUT; do
printf "\n\t$sel: "
printf "\tPipe "
cat "$tempi" | $checker ./xclip -sel "$sel" -i
sleep "$delay"
$checker ./xclip -sel $sel -o > $tempo
if ! diff $tempi $tempo; then
echo "$FAIL"
echo "Could not pipe $nlines of text into the $sel selection"
exit 1
fi
printf "$PASS"
# test xclip reading the file
printf "\tRead "
$checker ./xclip -sel $sel -i $tempi
sleep $delay
$checker ./xclip -sel $sel -o > $tempo
if ! diff $tempi $tempo; then
echo "$FAIL"
echo "Could not read a $lines-line file into the $sel selection"
exit 1
fi
printf "$PASS"
# test xclip filtering a file
printf "\tFilter "
$checker ./xclip -sel $sel -f < $tempi > $tempo
sleep "$delay"
if ! diff "$tempi" "$tempo"; then
echo "$FAIL"
echo "Could not filter $nlines of text through the $sel selection"
exit 1
fi
printf "$PASS"
done
echo
done
echo
# test xclip on files >1MB to force INCR mode.
echo
printf "Binary files large enough to force INCR mode\n"
for i in 1 4 16; do
dd if=/dev/zero bs=1024 count=$((i*1024)) of="$tempi" >/dev/null 2>&1
# Note: not testing "buffercut" because it cannot do INCR.
for sel in PRIMARY SECONDARY CLIPBOARD; do
printf "\t%10s ($i MiB)\t" $sel
$checker ./xclip -sel "$sel" -i -t image/jpeg < "$tempi"
sleep "$delay"
$checker ./xclip -sel "$sel" -o -t image/jpeg > "$tempo"
if ! diff "$tempi" "$tempo"; then
echo "$FAIL"
echo "xclip could not incrementally transfer $i MiB using the $sel selection"
exit 1
fi
echo "$PASS"
done
echo
done
echo
echo "All tests $PASS"
# quietly remove temp files
rm "$tempi" "$tempo" 2>/dev/null || true
# Kill any remaining xclip processes
killall xclip || true
# No errors
exit 0