-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·300 lines (228 loc) · 7.07 KB
/
test.sh
File metadata and controls
executable file
·300 lines (228 loc) · 7.07 KB
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/bin/bash
# Copyright (c) 2020 gyselroth GmbH
# Licensed under the MIT License - https://opensource.org/licenses/MIT
################################################################################
# Run functional tests written with bats - https://github.com/sstephenson/bats #
# #
# Install bats on Linux: sudo apt-get install bats #
# Install bats on Mac: brew install bats #
################################################################################
IS_ERROR=false
AMOUNT_ERRORS=0
IS_VALGRIND_TEST=false
export DOCXBOX_BINARY
run_single_case() {
START_TIME=$SECONDS
export IS_VALGRIND_TEST=false
bats ./test/functional/"$1".bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
}
run_all_cases() {
export IS_VALGRIND_TEST=$IS_VALGRIND_TEST
START_TIME=$SECONDS
# Meta commands
printf "\033[4mTest display of help (h)\033[0m\n"
bats ./test/functional/help.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest display of version number (v)\033[0m\n"
bats ./test/functional/version.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
# List DOCX contents:
printf "\n\033[4mTest listing files in DOCX (ls)\033[0m\n"
bats ./test/functional/ls.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest listing files in DOCX as JSON (lsj)\033[0m\n"
bats ./test/functional/lsj.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest listing fields in DOCX (lsd)\033[0m\n"
bats ./test/functional/lsd.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest listing fields in DOCX as JSON (lsdj)\033[0m\n"
bats ./test/functional/lsdj.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest listing referenced fonts in DOCX (lsf)\033[0m\n"
bats ./test/functional/lsf.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest listing referenced fonts in DOCX as JSON (lsfj)\033[0m\n"
bats ./test/functional/lsfj.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest listing images in DOCX (lsi)\033[0m\n"
bats ./test/functional/lsi.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest listing images in DOCX as JSON (lsij)\033[0m\n"
bats ./test/functional/lsij.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest listing files containing given string (lsl)\033[0m\n"
bats ./test/functional/lsl.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest listing files containing given string as JSON (lslj)\033[0m\n"
bats ./test/functional/lslj.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest listing metadata in DOCX (lsm)\033[0m\n"
bats ./test/functional/lsm.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest listing metadata in DOCX as JSON (lsmj)\033[0m\n"
bats ./test/functional/lsmj.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
# Convert and compare DOCX:
printf "\n\033[4mTest output XML document (cat)\033[0m\n"
bats ./test/functional/cat.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest output DOCX document as plaintext (txt)\033[0m\n"
bats ./test/functional/txt.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest side-by-side comparison from two DOCX archives (diff)\033[0m\n"
bats ./test/functional/diff.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
# Manipulate DOCX:
printf "\n\033[4mTest replacing text with dummy text in DOCX (lorem)\033[0m\n"
bats ./test/functional/lorem.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest replacing image in DOCX (rpi)\033[0m\n"
bats ./test/functional/rpi.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest replacing text in DOCX (rpt)\033[0m\n"
bats ./test/functional/rpt.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest modifying or setting metadata in DOCX (mm)\033[0m\n"
bats ./test/functional/mm.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest removing DOCX contens between given strings (rmt)\033[0m\n"
bats ./test/functional/rmt.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest setting field value in DOCX (sfv)\033[0m\n"
bats ./test/functional/sfv.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
# Batch processing
printf "\n\033[4mTest processing multiple docxBox commands (batch)\033[0m\n"
bats ./test/functional/batch.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
# Extract and create DOCX:
printf "\n\033[4mTest unziping files from DOCX (uz)\033[0m\n"
bats ./test/functional/uz.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest unziping files from DOCX and indenting XML files (uzi)\033[0m\n"
bats ./test/functional/uzi.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest unziping only media files from DOCX (uzm)\033[0m\n"
bats ./test/functional/uzm.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest creating (zp) DOCX from files (zp)\033[0m\n"
bats ./test/functional/zp.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
printf "\n\033[4mTest creating DOCX from indented files (zpc)\033[0m\n"
bats ./test/functional/zpc.bats.sh
if [ $? -ne 0 ]; then
IS_ERROR=true
((AMOUNT_ERRORS=AMOUNT_ERRORS+1))
fi
}
init_valgrind() {
export IS_VALGRIND_TEST=true
}
if [ "$1" != "" ]; then
if [ "$1" == "valgrind" ]; then
init_valgrind
run_all_cases
else
run_single_case $1
fi
else
run_all_cases
fi
ELAPSED_TIME=$(($SECONDS - $START_TIME))
printf "\nDone. Bats tests ran for $ELAPSED_TIME seconds.\n\n"
if $IS_ERROR;
then
printf "\n${AMOUNT_ERRORS} error(s) while executing tests\n\n"
exit 1
else
exit 0
fi