-
Notifications
You must be signed in to change notification settings - Fork 75
/
xctest
executable file
·152 lines (135 loc) · 4.3 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
#!/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
# Kill any remaining xclip processes
killall xclip 2>/dev/null
}
trap cleanup EXIT HUP INT
if sleep 0.1 2>/dev/null; then
delay=0.1 # seconds to wait before running xclip -o
else
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 "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: Zombie xclip yet lives! Killing."
killall xclip
exit 1
else
echo "PASS: xclip exited correctly after losing selection"
fi
# temp file names (in and out)
tempi=`mktemp` || exit 1
tempo=`mktemp` || exit 1
# 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 '%s' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_ ' > "$tempi"
printf '%s\n' 'abcdefghijklmnopqrstuvwzyz!@#$%^&*()' >> "$tempi"
for fold in 1 4 7 10 13; do
# double size of file by two
while [ "$c" -lt "$fold" ]; do
cat "$tempi" "$tempi" > "$tempo" && mv "$tempo" "$tempi"
lines=$(( 2 * lines ))
c=$(( c + 1 ))
done
# test piping the file to xclip, using all selections
echo "Piping a $lines line file to xclip"
for sel in primary secondary clipboard buffer; do
printf '%s' " Using the $sel selection "
cat "$tempi" | $checker ./xclip -sel "$sel" -i
sleep "$delay"
$checker ./xclip -sel "$sel" -o > "$tempo"
if diff "$tempi" "$tempo"; then
echo "PASS"
else
echo "FAIL"
exit 1
fi
done
echo
# test xclip reading the file
echo "Reading a $lines line file with xclip"
for sel in primary secondary clipboard buffer; do
printf '%s' " Using the $sel selection "
$checker ./xclip -sel "$sel" -i "$tempi"
sleep "$delay"
$checker ./xclip -sel "$sel" -o > "$tempo"
if diff "$tempi" "$tempo"; then
echo "PASS"
else
echo "FAIL"
exit 1
fi
done
echo
# test xclip filtering a file
echo "Filtering a $lines line file through xclip"
for sel in primary secondary clipboard buffer; do
printf '%s' " Using the $sel selection "
$checker ./xclip -sel "$sel" -f < "$tempi" > "$tempo"
sleep "$delay"
if diff "$tempi" "$tempo"; then
echo "PASS"
else
echo "FAIL"
exit 1
fi
done
echo
done
# test xclip on files >1MB to force INCR mode
for i in 1 2 16; do
dd if=/dev/zero bs=1024 count=$((i*1024)) of="$tempi" >/dev/null 2>&1
echo "Binary file large enough to force INCR mode ($i MB)"
for sel in primary secondary clipboard buffer; do
printf '%s' " Using the $sel selection "
$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 "PASS"
else
echo "FAIL"
exit 1
fi
done
done
# Kill any remain xclip processes
killall xclip
# quietly remove temp files
rm "$tempi" "$tempo" 2>/dev/null