-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_uploading_script.sh
executable file
·243 lines (196 loc) · 8.91 KB
/
test_uploading_script.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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/bash
set -e
upload_image="$1"
if [[ -z "$upload_image" ]]; then
upload_image="$(dirname "$0")/tupimage"
fi
echo "Testing the script $upload_image"
mkdir _data 2> /dev/null || true
[[ -f _data/wikipedia.png ]] || \
curl -o _data/wikipedia.png https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/440px-Wikipedia-logo-v2.svg.png
[[ -f _data/transparency.png ]] || \
curl -o _data/transparency.png https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png
[[ -f _data/tux.png ]] || \
curl -o _data/tux.png https://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png
[[ -f _data/earth.jpg ]] || \
curl -o _data/earth.jpg "https://upload.wikimedia.org/wikipedia/commons/thumb/c/cb/The_Blue_Marble_%28remastered%29.jpg/240px-The_Blue_Marble_%28remastered%29.jpg"
[[ -f _data/mars.jpg ]] || \
curl -o _data/mars.jpg "https://upload.wikimedia.org/wikipedia/commons/0/02/OSIRIS_Mars_true_color.jpg"
[[ -f _data/jupiter.jpg ]] || \
curl -o _data/jupiter.jpg "https://upload.wikimedia.org/wikipedia/commons/2/2b/Jupiter_and_its_shrunken_Great_Red_Spot.jpg"
[[ -f _data/saturn.jpg ]] || \
curl -o _data/saturn.jpg "https://upload.wikimedia.org/wikipedia/commons/c/c7/Saturn_during_Equinox.jpg"
[[ -f _data/sun.jpg ]] || \
curl -o _data/sun.jpg "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b4/The_Sun_by_the_Atmospheric_Imaging_Assembly_of_NASA%27s_Solar_Dynamics_Observatory_-_20100819.jpg/628px-The_Sun_by_the_Atmospheric_Imaging_Assembly_of_NASA%27s_Solar_Dynamics_Observatory_-_20100819.jpg"
[[ -f _data/butterfly.jpg ]] || \
curl -o _data/butterfly.jpg "https://upload.wikimedia.org/wikipedia/commons/a/a6/Peacock_butterfly_%28Aglais_io%29_2.jpg"
[[ -f _data/david.jpg ]] || \
curl -o _data/david.jpg "https://upload.wikimedia.org/wikipedia/commons/8/84/Michelangelo%27s_David_2015.jpg"
[[ -f _data/fern.jpg ]] || \
curl -o _data/fern.jpg "https://upload.wikimedia.org/wikipedia/commons/3/3d/Giant_fern_forest_7.jpg"
[[ -f _data/nebula.jpg ]] || \
curl -o _data/nebula.jpg "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/NGC7293_%282004%29.jpg/556px-NGC7293_%282004%29.jpg"
[[ -f _data/flake.jpg ]] || \
curl -o _data/flake.jpg "https://upload.wikimedia.org/wikipedia/commons/d/d7/Snowflake_macro_photography_1.jpg"
[[ -f _data/flower.jpg ]] || \
curl -o _data/flower.jpg "https://upload.wikimedia.org/wikipedia/commons/4/40/Sunflower_sky_backdrop.jpg"
[[ -f _data/a_panorama.jpg ]] || \
curl -o _data/a_panorama.jpg "https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/Kazbeg_Panorama.jpg/2560px-Kazbeg_Panorama.jpg"
[[ -f _data/column.png ]] || \
curl -o _data/column.png "https://upload.wikimedia.org/wikipedia/commons/9/95/Column6.png"
tmpdir="$(mktemp -d)"
if [[ -z "$tmpdir" ]]; then
exit 1
fi
cleanup() {
rm -r "$tmpdir"
}
trap cleanup EXIT TERM
echo "Just wikipedia logo"
$upload_image _data/wikipedia.png
echo "Wikipedia logo with enforced dpi=96"
$upload_image _data/wikipedia.png --override-dpi 96
echo "Wikipedia logo, less diacritics, 5 rows"
$upload_image _data/wikipedia.png -r 5 --less-diacritics
echo "Wikipedia logo, less diacritics, 1 column"
$upload_image _data/wikipedia.png -c 1 --less-diacritics
echo "Testing -r (5 images)"
for i in $(seq 1 5); do
$upload_image _data/wikipedia.png -r $i
done
echo "Testing -c (5 images)"
for i in $(seq 1 5); do
$upload_image _data/wikipedia.png -c $i
done
echo "Testing -r (-l) and -c and output to a file (4 x 6 images)"
for rows in $(seq 1 4); do
for cols in $(seq 1 6); do
$upload_image _data/tux.png -l $rows -c $cols -o "$tmpdir/cols_$cols"
done
paste -d "" "$tmpdir"/cols_*
rm "$tmpdir"/cols_*
done
echo "Testing appending to a file (4 images)"
for n in $(seq 2 5); do
$upload_image _data/tux.png --rows $n --columns $(( $n * 2 )) >> "$tmpdir/img"
done
cat "$tmpdir/img"
echo "Test saving id and showing id"
$upload_image _data/tux.png --lines 2 --save-info "$tmpdir/info" -o /dev/null
cat "$tmpdir/info"
image_id="$(grep id "$tmpdir/info" | cut -f 2)"
echo $image_id
$upload_image --show-id "$image_id"
echo "Test saving id and showing id for 256 bit IDs"
$upload_image _data/tux.png --256 -r 2 --save-info "$tmpdir/info" -o /dev/null
image_id="$(grep id "$tmpdir/info" | cut -f 2)"
echo $image_id
(( $image_id < 256 )) || exit 1
$upload_image --show-id "$image_id"
echo "Test saving id and showing id, the id is manually specified"
$upload_image _data/tux.png --id 9999 -r 2 --save-info "$tmpdir/info" -o /dev/null
image_id="$(grep id "$tmpdir/info" | cut -f 2)"
echo $image_id
(( $image_id == 9999 )) || exit 1
$upload_image --show-id "$image_id"
echo "Test saving id and showing id, the id is manually specified < 256"
$upload_image _data/tux.png --id 42 -r 2 --save-info "$tmpdir/info" -o /dev/null
image_id="$(grep id "$tmpdir/info" | cut -f 2)"
echo $image_id
(( $image_id == 42 )) || exit 1
$upload_image --show-id "$image_id"
echo "Testing being verbose (-V) but without status messages (-q)"
$upload_image _data/tux.png --rows 4 -V -q
echo "Testing one-way mode and forced uploading"
$upload_image _data/tux.png --rows 3 --one-way --force-upload
echo "Testing one-way mode"
$upload_image _data/tux.png --rows 3 --one-way
echo "Test overriding an existing id (the 9999 image above will change)"
$upload_image _data/tux.png --id 9999 -r 4
echo "Test showing part of an image with --show-id"
$upload_image --show-id 9999 --no-upload --rows 2
$upload_image --show-id 9999 --cols 4
echo "A jpeg image"
$upload_image _data/earth.jpg -r 10
echo "Uploading an image using direct method"
$upload_image _data/mars.jpg -r 10 -m direct
echo "Testing one-way mode with direct method"
$upload_image _data/tux.png --rows 3 --one-way -m direct --force-upload
echo "Testing one-way mode with a file instead of tty (may fail)"
echo "placeholder for the image:"
$upload_image _data/earth.jpg --tty "$tmpdir/tty" --one-way -c 11 -r 5 --force-upload
echo "waiting 1 s and uploading:"
sleep 1
cat "$tmpdir/tty"
echo "Showing an image without uploading"
$upload_image --clear-id 9998 || true
$upload_image _data/saturn.jpg --id 9998 -r 10 --no-upload
echo "Now reuploading the last image using direct method"
$upload_image --fix 9998 -m direct
echo "Deleting and reuploading it again"
$upload_image --clear-id 9998
$upload_image --fix 9998 -m direct
echo "A long image, should be fit to the terminal width"
$upload_image _data/a_panorama.jpg --save-info "$tmpdir/info" -r 20
cat "$tmpdir/info"
echo "A long image, without fitting to terminal width (will look bad)"
$upload_image _data/a_panorama.jpg --save-info "$tmpdir/info" -r 20 --max-cols 1000 -o "$tmpdir/tmp"
cat "$tmpdir/tmp" | head -4
echo "Testing max cols (should be fit to 50 columns)"
$upload_image _data/a_panorama.jpg --save-info "$tmpdir/info" --max-cols 50 -r 20
echo "Testing max rows (only one row)"
$upload_image _data/a_panorama.jpg --save-info "$tmpdir/info" --max-rows 1
echo "The rest of the test will use a temporary cache dir"
export TUPIMAGE_CACHE_DIR="$tmpdir/cache_dir"
draw_strips() {
local i=0
local total_cols=0
local max_cols="$(tput cols)"
local opts="$1"
shift
for file in "$@"; do
(( i++ )) || true
$upload_image "$file" $opts --save-info "$tmpdir/info" -o "$tmpdir/tmp"
cols="$(grep columns "$tmpdir/info" | cut -f 2)"
if (( $total_cols + $cols > $max_cols )); then
paste -d "" "$tmpdir/out_"*
rm "$tmpdir/out_"*
total_cols=0
fi
(( total_cols += cols )) || true
mv "$tmpdir/tmp" "$tmpdir/out_$(printf "%02d" $i)"
done
paste -d "" "$tmpdir/out_"*
rm "$tmpdir/out_"*
}
echo "Displaying all images in _data in horizontal strips"
echo "Images are uploaded immediately"
draw_strips "-r 9" _data/*.jpg _data/*.png
echo "Images are uploaded after creating placeholders using --fix"
draw_strips "-r 10 --no-upload" _data/*.jpg _data/*.png
$upload_image --fix
echo "Only 2 images are uploaded after creating placeholders using --fix --last 2"
draw_strips "-r 8 --no-upload" _data/*.png
$upload_image --fix --last 2
echo "Testing --ls, 2 rows per image"
$upload_image --ls --last 10 -r 2
export TUPIMAGE_CACHE_DIR="$tmpdir/cache_dir_test_limits"
export TUPIMAGE_CLEANUP_PROBABILITY=100
echo "Testing max ids limit"
export TUPIMAGE_IDS_LIMIT=2
draw_strips "-r 9" _data/*.jpg _data/*.png
$upload_image --status
ids_count="$(ls -1 $TUPIMAGE_CACHE_DIR/terminals/*-24bit_ids/ | wc -l)"
(( ids_count <= 2 )) || exit 1
echo "Testing max ids limit for 8-bit ids (will probably override old images)"
draw_strips "-r 9 --256" _data/*.jpg _data/*.png
$upload_image --status
ids_count="$(ls -1 $TUPIMAGE_CACHE_DIR/terminals/*-8bit_ids/ | wc -l)"
(( ids_count <= 2 )) || exit 1
echo "Testing max cache size limit"
export TUPIMAGE_IDS_LIMIT=
export TUPIMAGE_CACHE_SIZE_LIMIT=1000
draw_strips "-r 9" _data/*.jpg _data/*.png
$upload_image --status
cache_size="$(du -s $TUPIMAGE_CACHE_DIR/cache | cut -f1)"
(( $cache_size <= 1000 )) || exit 1