]> wimlib.net Git - wimlib/blob - tests/win32-test-imagex-capture_and_apply.bat
Document handling of invalid filenames
[wimlib] / tests / win32-test-imagex-capture_and_apply.bat
1 @echo off\r
2 \r
3 REM\r
4 REM win32-test-imagex-capture_and_apply.bat\r
5 REM\r
6 REM Run some tests on the Windows version of wimlib-imagex.\r
7 REM\r
8 REM This must be run on Windows Vista or later in a clean directory, with\r
9 REM Administrator privileges.  wimlib-imagex and win32-tree-cmp must be\r
10 REM executable using the paths set below.\r
11 \r
12 setlocal EnableDelayedExpansion\r
13 set WIN32_TREE_CMP=win32-tree-cmp\r
14 set WIMLIB_IMAGEX=wimlib-imagex\r
15 \r
16 if exist in.dir rd /S /Q in.dir\r
17 if exist out.dir rd /S /Q out.dir\r
18 md in.dir\r
19 cd in.dir\r
20 \r
21 REM\r
22 REM BEGIN TESTS\r
23 REM\r
24 \r
25 REM goto :rpfix_tests\r
26 \r
27 call :msg "empty directory"\r
28 call :do_test\r
29 if %errorlevel% neq 0 exit /b %errorlevel%\r
30 \r
31 call :msg "single file"\r
32 echo 1 > file\r
33 call :do_test\r
34 if %errorlevel% neq 0 exit /b %errorlevel%\r
35 \r
36 call :msg "different files"\r
37 echo 1 > file\r
38 echo 2 > anotherfile\r
39 call :do_test\r
40 if %errorlevel% neq 0 exit /b %errorlevel%\r
41 \r
42 call :msg "identical files"\r
43 echo 1 > file\r
44 echo 1 > identicalfile\r
45 call :do_test\r
46 if %errorlevel% neq 0 exit /b %errorlevel%\r
47 \r
48 call :msg "hard linked file"\r
49 echo 1 > file\r
50 mklink /h link file > nul\r
51 call :do_test\r
52 if %errorlevel% neq 0 exit /b %errorlevel%\r
53 \r
54 call :msg "hard linked file, with other identical files"\r
55 echo 1 > file\r
56 mklink /h link file > nul\r
57 echo 1 > identicalfile\r
58 call :do_test\r
59 if %errorlevel% neq 0 exit /b %errorlevel%\r
60 \r
61 call :msg "empty file"\r
62 type nul > emptyfile\r
63 call :do_test\r
64 if %errorlevel% neq 0 exit /b %errorlevel%\r
65 \r
66 call :msg "various hard linked, identical, different, and empty files"\r
67 echo 1 > file\r
68 echo 5 > file\r
69 mklink /h link1 file > nul\r
70 mklink /h link2 file > nul\r
71 type nul > emptyfile\r
72 type nul > emptyfile2\r
73 mklink /h emptyfilelink emptyfile > nul\r
74 echo 5 > identicalfile\r
75 echo 1 > 1file\r
76 mklink /h 1filelink 1file > nul\r
77 call :do_test\r
78 if %errorlevel% neq 0 exit /b %errorlevel%\r
79 \r
80 call :msg "multiple subdirectories, some empty, some not"\r
81 md subdir1\r
82 md subdir2\r
83 md subdir3\r
84 echo 1 > subdir1\1\r
85 echo 5 > subdir1\5\r
86 mklink /h link subdir1\1 > nul\r
87 md subdir2\subdir2subdir\r
88 type nul > subdir2\emptyfile\r
89 call :do_test\r
90 if %errorlevel% neq 0 exit /b %errorlevel%\r
91 \r
92 call :msg "relative symlink"\r
93 mklink relink dest > nul\r
94 call :do_test\r
95 if %errorlevel% neq 0 exit /b %errorlevel%\r
96 \r
97 call :msg "absolute symlink, with drive letter"\r
98 mklink abslink C:\absolute\target > nul\r
99 call :do_test\r
100 if %errorlevel% neq 0 exit /b %errorlevel%\r
101 \r
102 call :msg "absolute symlink, without drive letter"\r
103 mklink abslink \absolute\target > nul\r
104 call :do_test\r
105 if %errorlevel% neq 0 exit /b %errorlevel%\r
106 \r
107 call :msg "relative symlink, with file target"\r
108 echo 1 > 1\r
109 mklink relink 1 > nul\r
110 call :do_test\r
111 if %errorlevel% neq 0 exit /b %errorlevel%\r
112 \r
113 call :msg "relative symlink, with directory target"\r
114 md subdir\r
115 mklink reldlink subdir > nul\r
116 call :do_test\r
117 if %errorlevel% neq 0 exit /b %errorlevel%\r
118 \r
119 call :msg "junction"\r
120 md subdir\r
121 mklink /j junction subdir > nul\r
122 call :do_test\r
123 if %errorlevel% neq 0 exit /b %errorlevel%\r
124 \r
125 call :msg "symlinks, junctions, files, subdirectories, etc."\r
126 echo 1 > 1\r
127 mklink relink 1 > nul\r
128 mklink rellinklink relink > nul\r
129 mklink /j junction . > nul\r
130 md subdir\r
131 mklink /h subdir\hardlink 1 > nul\r
132 echo "hello world!!!!" > hello\r
133 mklink subdir\hello hello > nul\r
134 mklink abslink C:\Users > nul\r
135 md subdir2\r
136 type nul > emptyfile\r
137 type nul > subdir2\emptyfile\r
138 md subdir2\s\r
139 md subdir2\s\s\r
140 md subdir2\s\s\s\r
141 echo "hello world!!!!" > subdir2\otherfile\r
142 call :do_test\r
143 if %errorlevel% neq 0 exit /b %errorlevel%\r
144 \r
145 call :msg "compressed file"\r
146 echo "test" > test\r
147 compact /C test > nul\r
148 call :do_test\r
149 if %errorlevel% neq 0 exit /b %errorlevel%\r
150 \r
151 call :msg "compressed directory"\r
152 md subdir\r
153 compact /C subdir > nul\r
154 call :do_test\r
155 if %errorlevel% neq 0 exit /b %errorlevel%\r
156 \r
157 call :msg "compressed directory with files in it"\r
158 md subdir\r
159 compact /C subdir > nul\r
160 echo 1 > subdir\file1\r
161 echo 2 > subdir\file2\r
162 echo 1 > subdir\file1\r
163 md subdir\subsubdir\r
164 mklink /h subdir\hardlink subdir\file1 > nul\r
165 mklink /j subdir\j subdir\subsubdir > nul\r
166 call :do_test\r
167 if %errorlevel% neq 0 exit /b %errorlevel%\r
168 \r
169 call :msg "compressed directory with some uncompressed files in it"\r
170 md subdir\r
171 compact /C subdir > nul\r
172 echo 1 > subdir\1\r
173 echo 5 > subdir\5\r
174 compact /U subdir\1 > nul\r
175 call :do_test\r
176 if %errorlevel% neq 0 exit /b %errorlevel%\r
177 \r
178 call :msg "file with alternate data stream"\r
179 echo 1 > file\r
180 echo 5 > file:ads\r
181 call :do_test\r
182 if %errorlevel% neq 0 exit /b %errorlevel%\r
183 \r
184 call :msg "file with multiple alternate data streams"\r
185 echo 1 > file\r
186 echo a > file:a\r
187 echo aa > file:aa\r
188 echo aaa > file:aaa\r
189 echo aaaa > file:aaaa\r
190 call :do_test\r
191 if %errorlevel% neq 0 exit /b %errorlevel%\r
192 \r
193 call :msg "file with multiple alternate data streams, with hard link"\r
194 echo 1 > file\r
195 echo a > file:a\r
196 echo aa > file:aa\r
197 echo aaa > file:aaa\r
198 echo aaaa > file:aaaa\r
199 mklink /h link file > nul\r
200 call :do_test\r
201 if %errorlevel% neq 0 exit /b %errorlevel%\r
202 \r
203 call :msg "files with multiple alternate data streams, some identical, with hard link"\r
204 echo 1 > file\r
205 echo 5 > file2\r
206 echo 1 > file:1\r
207 echo 1 > file:1again\r
208 echo aaa > file:aaa\r
209 echo 5 > file:5\r
210 mklink /h link file > nul\r
211 echo aaa > file2:aaa\r
212 call :do_test\r
213 if %errorlevel% neq 0 exit /b %errorlevel%\r
214 \r
215 call :msg "root directory with alternate data stream"\r
216 echo 1 > ..\in.dir:ads\r
217 call :do_test\r
218 if %errorlevel% neq 0 exit /b %errorlevel%\r
219 \r
220 call :msg "subdirectory with alternate data streams"\r
221 md subdir\r
222 echo 1 > subdir:1\r
223 echo 2 > subdir:2\r
224 echo 2 > subdir:2again\r
225 call :do_test\r
226 if %errorlevel% neq 0 exit /b %errorlevel%\r
227 \r
228 call :msg "subdirectories and files with alternate data streams"\r
229 md subdir\r
230 echo hello > hello\r
231 echo hello > subdir:hello\r
232 echo hello > subdir:helloagain\r
233 echo hello > helloagain\r
234 mklink /h hellolink hello > nul\r
235 echo 1 > helloagain:1\r
236 echo 8 > helloagain:8\r
237 echo 1 > 1\r
238 type nul > helloagain:dummy\r
239 call :do_test\r
240 if %errorlevel% neq 0 exit /b %errorlevel%\r
241 \r
242 call :msg "symbolic link and hard link, to file with alternate data streams"\r
243 echo 1 > 1\r
244 echo test > .\1:test\r
245 mklink symlink 1 > nul\r
246 mklink /h hardlink 1 > nul\r
247 call :do_test\r
248 if %errorlevel% neq 0 exit /b %errorlevel%\r
249 \r
250 call :msg "compressed file with alternate data streams"\r
251 echo 1 > 1\r
252 echo 1 > .\1:1\r
253 echo 2 > .\1:2\r
254 compact /C 1 > nul\r
255 call :do_test\r
256 if %errorlevel% neq 0 exit /b %errorlevel%\r
257 \r
258 call :msg "hidden file"\r
259 echo 1 > hidden\r
260 attrib +h hidden\r
261 call :do_test\r
262 if %errorlevel% neq 0 exit /b %errorlevel%\r
263 \r
264 call :msg "hidden directory"\r
265 md subdir\r
266 attrib +h subdir\r
267 call :do_test\r
268 if %errorlevel% neq 0 exit /b %errorlevel%\r
269 \r
270 call :msg "encrypted file"\r
271 echo "hello" > encrypted\r
272 cipher /e encrypted > nul\r
273 call :do_test\r
274 if %errorlevel% neq 0 exit /b %errorlevel%\r
275 \r
276 call :msg "identical encrypted files"\r
277 echo "hello" > encrypted1\r
278 echo "hello" > encrypted2\r
279 cipher /e encrypted1 > nul\r
280 cipher /e encrypted2 > nul\r
281 call :do_test\r
282 if %errorlevel% neq 0 exit /b %errorlevel%\r
283 \r
284 call :msg "encrypted directory"\r
285 md subdir\r
286 cipher /e subdir > nul\r
287 call :do_test\r
288 if %errorlevel% neq 0 exit /b %errorlevel%\r
289 \r
290 call :msg "encrypted directory with encrypted file in it"\r
291 md subdir\r
292 echo 1 > subdir\1\r
293 cipher /e subdir > nul\r
294 cipher /e subdir\1 > nul\r
295 call :do_test\r
296 if %errorlevel% neq 0 exit /b %errorlevel%\r
297 \r
298 call :msg "encrypted directory with unencrypted file in it"\r
299 md subdir\r
300 echo 1 > subdir\1\r
301 cipher /e subdir > nul\r
302 cipher /d subdir\1 > nul\r
303 call :do_test\r
304 if %errorlevel% neq 0 exit /b %errorlevel%\r
305 \r
306 call :msg "hardlinked, encrypted file with alternate data streams"\r
307 echo hello > file\r
308 echo hello > file:ads\r
309 cipher /e file > nul\r
310 mklink /h link file > nul\r
311 call :do_test\r
312 if %errorlevel% neq 0 exit /b %errorlevel%\r
313 \r
314 :rpfix_tests\r
315 \r
316 echo Testing rpfix junction\r
317 md subdir\r
318 echo 1 > subdir\file\r
319 mklink /j junction subdir > nul\r
320 cd ..\r
321 %WIMLIB_IMAGEX% capture in.dir test.wim > nul\r
322 rd /s /q in.dir\r
323 %WIMLIB_IMAGEX% apply test.wim out.dir > nul\r
324 echo 1 > tmp1\r
325 type out.dir\junction\file > tmp2\r
326 fc tmp1 tmp2 > nul\r
327 if %errorlevel% neq 0 exit /b %errorlevel%\r
328 rd /s /q out.dir\r
329 del tmp1 tmp2\r
330 md in.dir\r
331 cd in.dir\r
332 \r
333 echo Testing rpfix exclude\r
334 mklink otherlink c:\some\other\directory > nul\r
335 cd ..\r
336 %WIMLIB_IMAGEX% capture in.dir test.wim > nul\r
337 %WIMLIB_IMAGEX% apply test.wim out.dir > nul\r
338 rd out.dir\r
339 if %errorlevel% neq 0 exit /b %errorlevel%\r
340 rd /s /q in.dir\r
341 md in.dir\r
342 cd in.dir\r
343 \r
344 echo Testing rpfix relative\r
345 echo 1 > file\r
346 mklink relink file > nul\r
347 cd ..\r
348 %WIMLIB_IMAGEX% capture in.dir test.wim > nul\r
349 %WIMLIB_IMAGEX% apply test.wim out.dir > nul\r
350 fc in.dir\file out.dir\relink > nul\r
351 if %errorlevel% neq 0 exit /b %errorlevel%\r
352 rd /s /q in.dir out.dir\r
353 md in.dir\r
354 cd in.dir\r
355 \r
356 REM\r
357 REM END OF TESTS\r
358 REM\r
359 \r
360 cd ..\r
361 del test.wim\r
362 rd /s /q in.dir\r
363 exit /b 0\r
364 \r
365 :do_test\r
366 cd ..\r
367 %WIMLIB_IMAGEX% capture in.dir test.wim --norpfix > NUL\r
368 if %errorlevel% neq 0 exit /b %errorlevel%\r
369 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL\r
370 if %errorlevel% neq 0 exit /b %errorlevel%\r
371 %WIN32_TREE_CMP% in.dir out.dir\r
372 if %errorlevel% neq 0 (\r
373         echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
374         echo            TEST FAILED!!!!!!!\r
375         echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
376         exit /b %errorlevel%\r
377 )\r
378 \r
379 REM Fun fact:  There are bugs in Microsoft's imagex.exe that make it fail some\r
380 REM of our tests.\r
381 REM\r
382 REM rd /S /Q out.dir\r
383 REM md out.dir\r
384 REM imagex /capture in.dir test.wim "test" /norpfix > nul\r
385 REM if %errorlevel% neq 0 exit /b %errorlevel%\r
386 REM imagex /apply test.wim 1 out.dir > nul\r
387 REM if %errorlevel% neq 0 exit /b %errorlevel%\r
388 REM %WIN32_TREE_CMP% in.dir out.dir\r
389 REM if %errorlevel% neq 0 (\r
390         REM echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
391         REM echo            TEST FAILED!!!!!!! ^(imagex^)\r
392         REM echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
393         REM exit /b %errorlevel%\r
394 REM )\r
395 \r
396 rd /S /Q in.dir out.dir\r
397 md in.dir\r
398 cd in.dir\r
399 goto :eof\r
400 \r
401 :msg\r
402 echo Testing capture and apply of %~1\r
403 goto :eof\r