]> git.ipfire.org Git - thirdparty/cups.git/blob - everywhere/bonjour-tests.bat
6f109f2dcb09bb7497cb844504a181b30aaddeb5
[thirdparty/cups.git] / everywhere / bonjour-tests.bat
1 @echo off
2 ::
3 :: "$Id$"
4 ::
5 :: IPP Everywhere Printer Self-Certification Manual 1.0: Section 5: Bonjour Tests.
6 ::
7 :: Copyright 2014 by The Printer Working Group.
8 ::
9 :: This program may be copied and furnished to others, and derivative works
10 :: that comment on, or otherwise explain it or assist in its implementation may
11 :: be prepared, copied, published and distributed, in whole or in part, without
12 :: restriction of any kind, provided that the above copyright notice and this
13 :: paragraph are included on all such copies and derivative works.
14 ::
15 :: The IEEE-ISTO and the Printer Working Group DISCLAIM ANY AND ALL WARRANTIES,
16 :: WHETHER EXPRESS OR IMPLIED INCLUDING (WITHOUT LIMITATION) ANY IMPLIED
17 :: WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18 ::
19 :: Usage:
20 ::
21 :: bonjour-tests.bat 'Printer Name'
22 ::
23
24 set PLIST="%1 Bonjour Results.plist"
25
26 :: Special case "_failN" name to show bad/missing TXT keys
27 if not "%2" == "" {
28 echo "FAIL"
29 echo "<key>Errors</key><array>" >>"%PLIST%"
30 if not defined IPPFIND_TXT_ADMINURL {
31 echo " adminurl is not set."
32 echo "<string>adminurl is not set.</string>" >>"%PLIST%"
33 } else {
34 if test "%2" == "_values" {
35 if not %IPPFIND_TXT_ADMINURL:~0,7% == "http://" {
36 if not %IPPFIND_TXT_ADMINURL:~0,8% == "https://" {
37 echo " adminurl has bad value '%IPPFIND_TXT_ADMINURL%'."
38 echo "<string>adminurl has bad value '%IPPFIND_TXT_ADMINURL%'.</string>" >>"%PLIST%"
39 }
40 }
41 }
42 }
43
44 if not defined IPPFIND_TXT_PDL {
45 echo " pdl is not set."
46 echo "<string>pdl is not set.</string>" >>"%PLIST%"
47 } else {
48 if "%2" == "_values" {
49 set temp=%IPPFIND_TXT_PDL:image/jpeg=%
50 if "%temp%" == "%IPPFIND_TXT_PDL%" {
51 echo " pdl is missing image/jpeg: '%IPPFIND_TXT_PDL%'"
52 echo "<string>pdl is missing image/jpeg: '%IPPFIND_TXT_PDL%'.</string>" >>"%PLIST%"
53 }
54
55 set temp=%IPPFIND_TXT_PDL:image/pwg-raster=%
56 if "%temp%" == "%IPPFIND_TXT_PDL%" {
57 echo " pdl is missing image/pwg-raster: '%IPPFIND_TXT_PDL%'"
58 echo "<string>pdl is missing image/pwg-raster: '%IPPFIND_TXT_PDL%'.</string>" >>"%PLIST%"
59 }
60 }
61 }
62
63 if not defined IPPFIND_TXT_RP {
64 echo " rp is not set."
65 echo "<string>rp is not set.</string>" >>"%PLIST%"
66 } else {
67 if "%2" == "_values" {
68 if not "%IPPFIND_TXT_RP%" == "ipp/print" {
69 if not "%IPPFIND_TXT_RP:~0,10%" == "ipp/print/" {
70 echo " rp has bad value '%IPPFIND_TXT_RP%'"
71 echo "<string>rp has bad value '%IPPFIND_TXT_RP%'.</string>" >>"%PLIST%"
72 }
73 }
74 }
75 }
76
77 if not defined IPPFIND_TXT_UUID {
78 echo " UUID is not set."
79 echo "<string>UUID is not set.</string>" >>"%PLIST%"
80 } else {
81 if "%2" == "_values" {
82 :: This isn't as effective as the test in bonjour-tests.sh...
83 if "%IPPFIND_TXT_UUID:~0,9%" == "urn:uuid:" {
84 echo " UUID has bad value '%IPPFIND_TXT_UUID%'"
85 echo "<string>UUID has bad value '%IPPFIND_TXT_UUID%'.</string>" >>"%PLIST%"
86 }
87 }
88 }
89
90 if "%2" == "_values" {
91 ipptool -t -d "ADMINURL=%IPPFIND_TXT_ADMINURL%" -d "UUID=%IPPFIND_TXT_UUID%" %IPPFIND_SERVICE_URI% bonjour-value-tests.test
92 echo "<string>" >>"%PLIST%"
93 $IPPTOOL -t -d "ADMINURL=$IPPFIND_TXT_ADMINURL" -d "UUID=$IPPFIND_TXT_UUID" $IPPFIND_SERVICE_URI bonjour-value-tests.test | findstr /r '[TD]:' >>"%PLIST%"
94 echo "</string>" >>"%PLIST%"
95 }
96
97 echo "</array>" >>"%PLIST%"
98 echo "<key>Successful</key><false />" >>"%PLIST%"
99 echo "</dict>" >>"%PLIST%"
100
101 exit
102 }
103
104
105 :: Write the standard XML plist header...
106 echo '<?xml version="1.0" encoding="UTF-8"?>' >"%PLIST%"
107 echo '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >>"%PLIST%"
108 echo '<plist version="1.0">' >>"%PLIST%"
109 echo '<dict>' >>"%PLIST%"
110 echo '<key>Tests</key><array>' >>"%PLIST%"
111
112 set total=0
113 set pass=0
114 set fail=0
115 set skip=0
116
117 :: B-1. IPP Browse test: Printers appear in a search for "_ipp._tcp,_print" services?
118 call :start_test "B-1. IPP Browse test"
119 set result=FAIL
120 ippfind _ipp._tcp,_print.local. --name "%1" --quiet && set result=PASS
121 if "%result%" == "PASS" {
122 set /a pass=pass+1
123 call :end_test PASS
124 } else {
125 set /a fail=fail+1
126 call :end_test FAIL
127 }
128
129 :: B-2. IPP TXT keys test: The IPP TXT record contains all required keys.
130 call :start_test "B-2. IPP TXT keys test"
131 set result=FAIL
132 ippfind "%1._ipp._tcp.local." --txt adminurl --txt pdl --txt rp --txt UUID --quiet && set result=PASS
133 if "%result%" == "PASS" {
134 set /a pass=pass+1
135 call :end_test PASS
136 } else {
137 set /a fail=fail+1
138 ippfind "$1._ipp._tcp.local." -x bonjour-tests.bat '{service_name}' _keys \;
139 }
140
141 :: B-3. IPP Resolve test: Printer responds to an IPP Get-Printer-Attributes request using the resolved hostname, port, and resource path.
142 call :start_test "B-3. IPP Resolve test"
143 set result=FAIL
144 ippfind "%1._ipp._tcp.local." --ls >/dev/null && set result=PASS
145 if "%result%" == "PASS" {
146 set /a pass=pass+1
147 call :end_test PASS
148 } else {
149 set /a fail=fail+1
150 echo "<key>Errors</key><array><string>" >>"%PLIST%"
151 ippfind "$1._ipp._tcp.local." --ls >>"%PLIST%"
152 echo "</string></array>" >>"%PLIST%"
153 call :end_test FAIL
154 }
155
156 :: B-4. IPP TXT values test: The IPP TXT record values match the reported IPP attribute values.
157 call :start_test "B-4. IPP TXT values test"
158 set result=FAIL
159 ippfind "%1._ipp._tcp.local." --txt-adminurl '^(http:|https:)//' --txt-pdl 'image/pwg-raster' --txt-pdl 'image/jpeg' --txt-rp '^ipp/(print|print/[^/]+)$' --txt-UUID '^[0-9a-fA-F]{8,8}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{12,12}$' -x $IPPTOOL -q -d 'ADMINURL={txt_adminurl}' -d 'UUID={txt_uuid}' '{}' bonjour-value-tests.test \; && set result=PASS
160 if "%result%" == "PASS" {
161 set /a pass=pass+1
162 call :end_test PASS
163 } else {
164 set /a fail=fail+1
165 ippfind "%1._ipp._tcp.local." -x bonjour-tests.bat '{service_name}' _values \;
166 fi
167
168 :: B-5. TLS tests: Performed only if TLS is supported
169 call :start_test "B-5. TLS tests"
170 set result=FAIL
171 find "$1._ipp._tcp.local." --txt tls --quiet && set result=PASS
172 if "%result%" == "PASS" {
173 set /a pass=pass+1
174 set HAVE_TLS=1
175 call :end_test PASS
176 } else {
177 set /a skip=skip+1
178 set HAVE_TLS=0
179 call :end_test SKIP
180 }
181
182 :: B-5.1 HTTP Upgrade test: Printer responds to an IPP Get-Printer-Attributes request after doing an HTTP Upgrade to TLS.
183 call :start_test "B-5.1 HTTP Upgrade test"
184 if %HAVE_TLS% == 1 {
185 set result=FAIL
186 ippfind "%1._ipp._tcp.local." -x ipptool -E -q '{}' bonjour-access-tests.test \; && set result=PASS
187 if "%result%" == "PASS" {
188 set /a pass=pass+1
189 call :end_test PASS
190 } else {
191 set /a fail=fail+1
192 echo "<key>Errors</key><array><string>" >>"%PLIST"
193 ippfind "%1._ipp._tcp.local." -x ipptool -E -q '{}' bonjour-access-tests.test \; >>"%PLIST%"
194 echo "</string></array>" >>"%PLIST%"
195 call :end_test FAIL
196 }
197 } else {
198 set /a skip=skip+1
199 call :end_test SKIP
200 }
201
202 :: B-5.2 IPPS Browse test: Printer appears in a search for "_ipps._tcp,_print" services.
203 start_test "B-5.2 IPPS Browse test"
204 if test $HAVE_TLS = 1; then
205 $IPPFIND _ipps._tcp,_print.local. --name "$1" --quiet
206 if test $? = 0; then
207 pass=`expr $pass + 1`
208 end_test PASS
209 else
210 fail=`expr $fail + 1`
211 end_test FAIL
212 fi
213 else
214 skip=`expr $skip + 1`
215 end_test SKIP
216 fi
217
218 :: B-5.3 IPPS TXT keys test: The TXT record for IPPS contains all required keys
219 start_test "B-5.3 IPPS TXT keys test"
220 if test $HAVE_TLS = 1; then
221 $IPPFIND "$1._ipps._tcp.local." --txt adminurl --txt pdl --txt rp --txt TLS --txt UUID --quiet
222 if test $? = 0; then
223 pass=`expr $pass + 1`
224 end_test PASS
225 else
226 fail=`expr $fail + 1`
227 $IPPFIND "$1._ipps._tcp.local." -x ./bonjour-tests.sh '{service_name}' _fail5.3 \;
228 fi
229 else
230 skip=`expr $skip + 1`
231 end_test SKIP
232 fi
233
234 :: B-5.4 IPPS Resolve test: Printer responds to an IPPS Get-Printer-Attributes request using the resolved hostname, port, and resource path.
235 start_test "B-5.4 IPPS Resolve test"
236 if test $HAVE_TLS = 1; then
237 $IPPFIND "$1._ipps._tcp.local." --ls >/dev/null
238 if test $? = 0; then
239 pass=`expr $pass + 1`
240 end_test PASS
241 else
242 fail=`expr $fail + 1`
243 echo "<key>Errors</key><array>" >>"%PLIST%"
244 $IPPFIND "$1._ipps._tcp.local." --ls | awk '{ print "<string>" $0 "</string>" }' >>"%PLIST%"
245 echo "</array>" >>"%PLIST%"
246 end_test FAIL
247 fi
248 else
249 skip=`expr $skip + 1`
250 end_test SKIP
251 fi
252
253 :: B-5.5 IPPS TXT values test: The TXT record values for IPPS match the reported IPPS attribute values.
254 start_test "B-5.5 IPPS TXT values test"
255 if test $HAVE_TLS = 1; then
256 $IPPFIND "$1._ipps._tcp.local." --txt-adminurl '^(http:|https:)//' --txt-pdl 'image/pwg-raster' --txt-pdl 'image/jpeg' --txt-rp '^ipp/(print|print/[^/]+)$' --txt-UUID '^[0-9a-fA-F]{8,8}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{12,12}$' -x $IPPTOOL -q -d 'ADMINURL={txt_adminurl}' -d 'UUID={txt_uuid}' '{}' bonjour-value-tests.test \;
257 if test $? = 0; then
258 pass=`expr $pass + 1`
259 end_test PASS
260 else
261 fail=`expr $fail + 1`
262 $IPPFIND "$1._ipps._tcp.local." -x ./bonjour-tests.sh '{service_name}' _fail5.5 \;
263 fi
264 else
265 skip=`expr $skip + 1`
266 end_test SKIP
267 fi
268
269 :: Finish up...
270 if test $fail -gt 0; then
271 cat >>"%PLIST%" <<EOF
272 </array>
273 <key>Successful</key>
274 <false />
275 EOF
276 else
277 cat >>"%PLIST%" <<EOF
278 </array>
279 <key>Successful</key>
280 <true />
281 EOF
282 fi
283
284 cat >>"%PLIST%" <<EOF
285 </dict>
286 </plist>
287 EOF
288
289 score=`expr $pass + $skip`
290 score=`expr 100 \* $score / $total`
291 echo "Summary: $total tests, $pass passed, $fail failed, $skip skipped"
292 echo "Score: ${score}%"
293
294 exit
295
296 :: call :start_test "name"
297 :start_test
298 setlocal
299 set /a total=total+1
300 set <NUL /p="%1: "
301 echo "<dict><key>Name</key><string>$1</string>" >>"%PLIST%"
302 echo "<key>FileId</key><string>org.pwg.ipp-everywhere.20140826.bonjour</string>" >>"%PLIST%"
303 endlocal
304 goto :eof
305
306 :: call :end_test PASS/FAIL/SKIP
307 :end_test
308 setlocal
309 echo %1
310 if "%1" == "FAIL" {
311 echo "<key>Successful</key><false />" >>"%PLIST%"
312 } else {
313 if "%1" == "SKIP" {
314 echo "<key>Successful</key><true />" >>"%PLIST%"
315 echo "<key>Skipped</key><true />" >>"%PLIST%"
316 } else {
317 echo "<key>Successful</key><true />" >>"%PLIST%"
318 }
319 }
320 echo "</dict>" >>"%PLIST%"
321 endlocal
322 goto :eof
323
324 ::
325 :: End of "$Id$".
326 ::