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