]> wimlib.net Git - wimlib/blob - tests/win32-test-imagex-capture_and_apply.bat
win32-test-imagex-capture_and_apply improvements
[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 call :msg "empty directory"\r
26 call :do_test\r
27 if %errorlevel% neq 0 goto :fail\r
28 \r
29 call :msg "single file"\r
30 echo 1 > file\r
31 call :do_test\r
32 if %errorlevel% neq 0 goto :fail\r
33 \r
34 call :msg "different files"\r
35 echo 1 > file\r
36 echo 2 > anotherfile\r
37 call :do_test\r
38 if %errorlevel% neq 0 goto :fail\r
39 \r
40 call :msg "identical files"\r
41 echo 1 > file\r
42 echo 1 > identicalfile\r
43 call :do_test\r
44 if %errorlevel% neq 0 goto :fail\r
45 \r
46 call :msg "hard linked file"\r
47 echo 1 > file\r
48 mklink /h link file > nul\r
49 call :do_test\r
50 if %errorlevel% neq 0 goto :fail\r
51 \r
52 call :msg "hard linked file, with other identical files"\r
53 echo 1 > file\r
54 mklink /h link file > nul\r
55 echo 1 > identicalfile\r
56 call :do_test\r
57 if %errorlevel% neq 0 goto :fail\r
58 \r
59 call :msg "empty file"\r
60 type nul > emptyfile\r
61 call :do_test\r
62 if %errorlevel% neq 0 goto :fail\r
63 \r
64 call :msg "hard linked empty file"\r
65 type nul > file\r
66 mklink /h link file > nul\r
67 call :do_test\r
68 if %errorlevel% neq 0 goto :fail\r
69 \r
70 call :msg "various hard linked, identical, different, and empty files"\r
71 echo 1 > file\r
72 echo 5 > file\r
73 mklink /h link1 file > nul\r
74 mklink /h link2 file > nul\r
75 type nul > emptyfile\r
76 type nul > emptyfile2\r
77 mklink /h emptyfilelink emptyfile > nul\r
78 echo 5 > identicalfile\r
79 echo 1 > 1file\r
80 mklink /h 1filelink 1file > nul\r
81 call :do_test\r
82 if %errorlevel% neq 0 goto :fail\r
83 \r
84 call :msg "multiple subdirectories, some empty, some not"\r
85 md subdir1\r
86 md subdir2\r
87 md subdir3\r
88 echo 1 > subdir1\1\r
89 echo 5 > subdir1\5\r
90 mklink /h link subdir1\1 > nul\r
91 md subdir2\subdir2subdir\r
92 type nul > subdir2\emptyfile\r
93 call :do_test\r
94 if %errorlevel% neq 0 goto :fail\r
95 \r
96 call :msg "file with custom security descriptor"\r
97 echo hello > file\r
98 icacls file /deny Administrator:F > nul\r
99 call :do_test\r
100 if %errorlevel% neq 0 goto :fail\r
101 \r
102 call :msg "directory with custom security descriptor (inheritence enabled)"\r
103 md subdir\r
104 icacls subdir /inheritance:e > nul\r
105 call :do_test\r
106 if %errorlevel% neq 0 goto :fail\r
107 \r
108 call :msg "directory with custom security descriptor (inheritence disabled)"\r
109 md subdir\r
110 icacls subdir /inheritance:d > nul\r
111 call :do_test\r
112 if %errorlevel% neq 0 goto :fail\r
113 \r
114 REM            win32-tree-cmp can't handle this case.\r
115 REM\r
116 REM call :msg "file with custom security descriptor (all inherited ACEs removed)"\r
117 REM echo hello > file\r
118 REM icacls file /inheritance:r > nul\r
119 REM call :do_test\r
120 REM if %errorlevel% neq 0 goto :fail\r
121 \r
122 call :msg "file with custom integrity level"\r
123 echo hello > file\r
124 icacls file /setintegritylevel H > nul\r
125 call :do_test\r
126 if %errorlevel% neq 0 goto :fail\r
127 \r
128 call :msg "relative symlink"\r
129 mklink relink dest > nul\r
130 call :do_test\r
131 if %errorlevel% neq 0 goto :fail\r
132 \r
133 call :msg "absolute symlink, with drive letter"\r
134 mklink abslink C:\absolute\target > nul\r
135 call :do_test\r
136 if %errorlevel% neq 0 goto :fail\r
137 \r
138 call :msg "absolute symlink, without drive letter"\r
139 mklink abslink \absolute\target > nul\r
140 call :do_test\r
141 if %errorlevel% neq 0 goto :fail\r
142 \r
143 call :msg "relative symlink, with file target"\r
144 echo 1 > 1\r
145 mklink relink 1 > nul\r
146 call :do_test\r
147 if %errorlevel% neq 0 goto :fail\r
148 \r
149 call :msg "relative symlink, with directory target"\r
150 md subdir\r
151 mklink reldlink subdir > nul\r
152 call :do_test\r
153 if %errorlevel% neq 0 goto :fail\r
154 \r
155 call :msg "junction"\r
156 md subdir\r
157 mklink /j junction subdir > nul\r
158 call :do_test\r
159 if %errorlevel% neq 0 goto :fail\r
160 \r
161 call :msg "symlinks, junctions, files, subdirectories, etc."\r
162 echo 1 > 1\r
163 mklink relink 1 > nul\r
164 mklink rellinklink relink > nul\r
165 mklink /j junction . > nul\r
166 md subdir\r
167 mklink /h subdir\hardlink 1 > nul\r
168 echo "hello world!!!!" > hello\r
169 mklink subdir\hello hello > nul\r
170 mklink abslink C:\Users > nul\r
171 md subdir2\r
172 type nul > emptyfile\r
173 type nul > subdir2\emptyfile\r
174 md subdir2\s\r
175 md subdir2\s\s\r
176 md subdir2\s\s\s\r
177 echo "hello world!!!!" > subdir2\otherfile\r
178 call :do_test\r
179 if %errorlevel% neq 0 goto :fail\r
180 \r
181 call :msg "compressed file"\r
182 echo "test" > test\r
183 compact /C test > nul\r
184 call :do_test\r
185 if %errorlevel% neq 0 goto :fail\r
186 \r
187 call :msg "compressed directory"\r
188 md subdir\r
189 compact /C subdir > nul\r
190 call :do_test\r
191 if %errorlevel% neq 0 goto :fail\r
192 \r
193 call :msg "compressed directory with files in it"\r
194 md subdir\r
195 compact /C subdir > nul\r
196 echo 1 > subdir\file1\r
197 echo 2 > subdir\file2\r
198 echo 1 > subdir\file1\r
199 md subdir\subsubdir\r
200 mklink /h subdir\hardlink subdir\file1 > nul\r
201 mklink /j subdir\j subdir\subsubdir > nul\r
202 call :do_test\r
203 if %errorlevel% neq 0 goto :fail\r
204 \r
205 call :msg "compressed directory with some uncompressed files in it"\r
206 md subdir\r
207 compact /C subdir > nul\r
208 echo 1 > subdir\1\r
209 echo 5 > subdir\5\r
210 compact /U subdir\1 > nul\r
211 call :do_test\r
212 if %errorlevel% neq 0 goto :fail\r
213 \r
214 call :msg "file with alternate data stream"\r
215 echo 1 > file\r
216 echo 5 > file:ads\r
217 call :do_test\r
218 if %errorlevel% neq 0 goto :fail\r
219 \r
220 call :msg "file with multiple alternate data streams"\r
221 echo 1 > file\r
222 echo a > file:a\r
223 echo aa > file:aa\r
224 echo aaa > file:aaa\r
225 echo aaaa > file:aaaa\r
226 call :do_test\r
227 if %errorlevel% neq 0 goto :fail\r
228 \r
229 call :msg "file with multiple alternate data streams, with hard link"\r
230 echo 1 > file\r
231 echo a > file:a\r
232 echo aa > file:aa\r
233 echo aaa > file:aaa\r
234 echo aaaa > file:aaaa\r
235 mklink /h link file > nul\r
236 call :do_test\r
237 if %errorlevel% neq 0 goto :fail\r
238 \r
239 call :msg "files with multiple alternate data streams, some identical, with hard link"\r
240 echo 1 > file\r
241 echo 5 > file2\r
242 echo 1 > file:1\r
243 echo 1 > file:1again\r
244 echo aaa > file:aaa\r
245 echo 5 > file:5\r
246 mklink /h link file > nul\r
247 echo aaa > file2:aaa\r
248 call :do_test\r
249 if %errorlevel% neq 0 goto :fail\r
250 \r
251 call :msg "file with empty alternate data stream"\r
252 echo 1 > file\r
253 type nul > file:ads\r
254 call :do_test\r
255 if %errorlevel% neq 0 goto :fail\r
256 \r
257 call :msg "directory with empty alternate data stream"\r
258 md subdir\r
259 type nul > subdir:ads\r
260 call :do_test\r
261 if %errorlevel% neq 0 goto :fail\r
262 \r
263 call :msg "root directory with alternate data stream"\r
264 echo 1 > ..\in.dir:ads\r
265 call :do_test\r
266 if %errorlevel% neq 0 goto :fail\r
267 \r
268 call :msg "root directory with empty alternate data stream"\r
269 type nul > ..\in.dir:ads\r
270 call :do_test\r
271 if %errorlevel% neq 0 goto :fail\r
272 \r
273 call :msg "subdirectory with alternate data streams"\r
274 md subdir\r
275 echo 1 > subdir:1\r
276 echo 2 > subdir:2\r
277 echo 2 > subdir:2again\r
278 call :do_test\r
279 if %errorlevel% neq 0 goto :fail\r
280 \r
281 call :msg "subdirectories and files with alternate data streams"\r
282 md subdir\r
283 echo hello > hello\r
284 echo hello > subdir:hello\r
285 echo hello > subdir:helloagain\r
286 echo hello > helloagain\r
287 mklink /h hellolink hello > nul\r
288 echo 1 > helloagain:1\r
289 echo 8 > helloagain:8\r
290 echo 1 > 1\r
291 type nul > helloagain:dummy\r
292 call :do_test\r
293 if %errorlevel% neq 0 goto :fail\r
294 \r
295 call :msg "symbolic link and hard link, to file with alternate data streams"\r
296 echo 1 > 1\r
297 echo test > .\1:test\r
298 mklink symlink 1 > nul\r
299 mklink /h hardlink 1 > nul\r
300 call :do_test\r
301 if %errorlevel% neq 0 goto :fail\r
302 \r
303 call :msg "compressed file with alternate data streams"\r
304 echo 1 > 1\r
305 echo 1 > .\1:1\r
306 echo 2 > .\1:2\r
307 compact /C 1 > nul\r
308 call :do_test\r
309 if %errorlevel% neq 0 goto :fail\r
310 \r
311 call :msg "hidden file"\r
312 echo 1 > hidden\r
313 attrib +h hidden\r
314 call :do_test\r
315 if %errorlevel% neq 0 goto :fail\r
316 \r
317 call :msg "hidden system file"\r
318 echo 1 > file\r
319 attrib +h +s file\r
320 call :do_test\r
321 if %errorlevel% neq 0 goto :fail\r
322 \r
323 call :msg "hidden, readonly, system file"\r
324 echo 1 > file\r
325 attrib +h +r +s file\r
326 call :do_test\r
327 if %errorlevel% neq 0 goto :fail\r
328 \r
329 call :msg "hidden directory"\r
330 md subdir\r
331 attrib +h subdir\r
332 call :do_test\r
333 if %errorlevel% neq 0 goto :fail\r
334 \r
335 call :msg "hidden system directory"\r
336 md subdir\r
337 attrib +h +s subdir\r
338 call :do_test\r
339 if %errorlevel% neq 0 goto :fail\r
340 \r
341 call :msg "hidden, readonly, system directory"\r
342 md subdir\r
343 attrib +h +r +s subdir\r
344 call :do_test\r
345 if %errorlevel% neq 0 goto :fail\r
346 \r
347 call :msg "readonly directory with named data stream"\r
348 md subdir\r
349 echo foo > subdir:ads\r
350 attrib +r subdir\r
351 call :do_test\r
352 if %errorlevel% neq 0 goto :fail\r
353 \r
354 call :msg "encrypted file"\r
355 echo "hello" > encrypted\r
356 cipher /e encrypted > nul\r
357 call :do_test\r
358 if %errorlevel% neq 0 goto :fail\r
359 \r
360 call :msg "identical encrypted files"\r
361 echo "hello" > encrypted1\r
362 echo "hello" > encrypted2\r
363 cipher /e encrypted1 > nul\r
364 cipher /e encrypted2 > nul\r
365 call :do_test\r
366 if %errorlevel% neq 0 goto :fail\r
367 \r
368 call :msg "encrypted directory"\r
369 md subdir\r
370 cipher /e subdir > nul\r
371 call :do_test\r
372 if %errorlevel% neq 0 goto :fail\r
373 \r
374 call :msg "encrypted directory with encrypted file in it"\r
375 md subdir\r
376 echo 1 > subdir\1\r
377 cipher /e subdir > nul\r
378 cipher /e subdir\1 > nul\r
379 call :do_test\r
380 if %errorlevel% neq 0 goto :fail\r
381 \r
382 call :msg "encrypted directory with unencrypted file in it"\r
383 md subdir\r
384 echo 1 > subdir\1\r
385 cipher /e subdir > nul\r
386 cipher /d subdir\1 > nul\r
387 call :do_test\r
388 if %errorlevel% neq 0 goto :fail\r
389 \r
390 call :msg "encrypted root directory"\r
391 cd ..\r
392 cipher /e in.dir > nul\r
393 cd in.dir\r
394 echo "hello" > encrypted\r
395 call :do_test\r
396 if %errorlevel% neq 0 goto :fail\r
397 \r
398 call :msg "unencrypted file in encrypted directory in compressed directory"\r
399 md 1\r
400 md 1\2\r
401 compact /c 1 > nul\r
402 cipher /e 1\2 > nul\r
403 echo hello > 1\2\file\r
404 cipher /d 1\2\file > nul\r
405 call :do_test\r
406 if %errorlevel% neq 0 goto :fail\r
407 \r
408 call :msg "encrypted directory with alternate data streams"\r
409 md subdir\r
410 cipher /e subdir > nul\r
411 echo ads1 > subdir:ads1\r
412 echo ads2 > subdir:ads2\r
413 call :do_test\r
414 if %errorlevel% neq 0 goto :fail\r
415 \r
416 call :msg "hardlinked, encrypted file with alternate data streams"\r
417 echo hello > file\r
418 echo hello > file:ads\r
419 cipher /e file > nul\r
420 mklink /h link file > nul\r
421 call :do_test\r
422 if %errorlevel% neq 0 goto :fail\r
423 \r
424 :rpfix_tests\r
425 \r
426 echo Testing rpfix junction\r
427 md subdir\r
428 echo 1 > subdir\file\r
429 mklink /j junction subdir > nul\r
430 cd ..\r
431 %WIMLIB_IMAGEX% capture in.dir test.wim > nul\r
432 rd /s /q in.dir\r
433 %WIMLIB_IMAGEX% apply test.wim out.dir > nul\r
434 echo 1 > tmp1\r
435 type out.dir\junction\file > tmp2\r
436 fc tmp1 tmp2 > nul\r
437 if %errorlevel% neq 0 goto :fail\r
438 rd /s /q out.dir\r
439 del tmp1 tmp2\r
440 md in.dir\r
441 cd in.dir\r
442 \r
443 echo Testing rpfix relative\r
444 echo 1 > file\r
445 mklink relink file > nul\r
446 cd ..\r
447 %WIMLIB_IMAGEX% capture in.dir test.wim > nul\r
448 %WIMLIB_IMAGEX% apply test.wim out.dir > nul\r
449 type out.dir\relink > out.dir\tmp\r
450 if %errorlevel% neq 0 goto :fail\r
451 fc in.dir\file out.dir\tmp > nul\r
452 if %errorlevel% neq 0 goto :fail\r
453 rd /s /q in.dir out.dir\r
454 md in.dir\r
455 cd in.dir\r
456 \r
457 REM\r
458 REM END OF TESTS\r
459 REM\r
460 \r
461 cd ..\r
462 del test.wim\r
463 rd /s /q in.dir\r
464 exit /b 0\r
465 \r
466 :do_test\r
467 cd ..\r
468 %WIMLIB_IMAGEX% capture in.dir test.wim --norpfix > NUL\r
469 if %errorlevel% neq 0 goto :fail\r
470 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL\r
471 if %errorlevel% neq 0 goto :fail\r
472 %WIN32_TREE_CMP% in.dir out.dir\r
473 if %errorlevel% neq 0 goto :fail\r
474 \r
475 REM  apply a second time so we test the case where the files already exist\r
476 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL\r
477 if %errorlevel% neq 0 goto :fail\r
478 %WIN32_TREE_CMP% in.dir out.dir\r
479 if %errorlevel% neq 0 goto :fail\r
480 \r
481 REM Fun fact: Microsoft's WIMGAPI has bugs that make it fail some of our tests.\r
482 REM Even the Windows 8.1 version has incorrect behavior with empty files with\r
483 REM multiple links, or files with named data streams and multiple links.\r
484 rd /S /Q out.dir\r
485 md out.dir\r
486 REM dism /capture-image /capturedir:in.dir /imagefile:test.wim /name:"test" /norpfix > nul\r
487 REM if %errorlevel% neq 0 goto :fail\r
488 dism /apply-image /imagefile:test.wim /index:1 /applydir:out.dir > nul\r
489 if %errorlevel% neq 0 goto :fail\r
490 %WIN32_TREE_CMP% in.dir out.dir\r
491 \r
492 rd /S /Q in.dir out.dir\r
493 md in.dir\r
494 cd in.dir\r
495 goto :eof\r
496 \r
497 :msg\r
498 echo Testing capture and apply of %~1\r
499 goto :eof\r
500 \r
501 :fail\r
502 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
503 echo            TEST FAILED!!!!!!!\r
504 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
505 exit /b %errorlevel%\r