Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_md5.m @ 44:409a22968d5e default
Add unit tests
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 18:42:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
43:bc767aaa99a8 | 44:409a22968d5e |
---|---|
1 % UTP_AO_MD5 a set of UTPs for the ao/md5 method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_md5.m,v 1.4 2010/05/06 07:22:05 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The md5 method of the ao class computes an MD5 checksum from an analysis | |
11 % objects which is first converted into a XML document. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_md5(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'md5'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Test AOs | |
30 [at1,at2,at3,at4,at5,at6,atvec,atmat] = get_test_objects_ao; | |
31 | |
32 % Exception list for the UTPs: | |
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
34 | |
35 % Run the tests | |
36 results = [results utp_01]; % getInfo call | |
37 results = [results utp_02]; % Vector input | |
38 results = [results utp_03]; % Matrix input | |
39 results = [results utp_04]; % List input | |
40 results = [results utp_05]; % Test with mixed input | |
41 results = [results utp_06]; % Spcial case: one AO retruns a string | |
42 | |
43 disp('Done.'); | |
44 disp('******************************************************'); | |
45 | |
46 elseif nargin == 1 % Check for UTP functions | |
47 if strcmp(varargin{1}, 'isutp') | |
48 results = 1; | |
49 else | |
50 results = 0; | |
51 end | |
52 else | |
53 error('### Incorrect inputs') | |
54 end | |
55 | |
56 %% UTP_01 | |
57 | |
58 % <TestDescription> | |
59 % | |
60 % Tests that the getInfo call works for this method. | |
61 % | |
62 % </TestDescription> | |
63 function result = utp_01 | |
64 | |
65 | |
66 % <SyntaxDescription> | |
67 % | |
68 % Test that the getInfo call works for no sets, all sets, and each set | |
69 % individually. | |
70 % | |
71 % </SyntaxDescription> | |
72 | |
73 try | |
74 % <SyntaxCode> | |
75 % Call for no sets | |
76 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
77 % Call for all sets | |
78 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
79 % Call for each set | |
80 for kk=1:numel(io(2).sets) | |
81 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
82 end | |
83 % </SyntaxCode> | |
84 stest = true; | |
85 catch err | |
86 disp(err.message) | |
87 stest = false; | |
88 end | |
89 | |
90 % <AlgoDescription> | |
91 % | |
92 % 1) Check that getInfo call returned an minfo object in all cases. | |
93 % 2) Check that all plists have the correct parameters. | |
94 % | |
95 % </AlgoDescription> | |
96 | |
97 atest = true; | |
98 if stest | |
99 % <AlgoCode> | |
100 % check we have minfo objects | |
101 if isa(io, 'minfo') | |
102 % SET 'None' | |
103 if ~isempty(io(1).sets), atest = false; end | |
104 if ~isempty(io(1).plists), atest = false; end | |
105 % Check all Sets | |
106 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
107 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
108 % SET 'Default' | |
109 if io(3).plists.nparams ~= 0, atest = false; end | |
110 % Check key | |
111 % Check default value | |
112 % Check options | |
113 end | |
114 % </AlgoCode> | |
115 else | |
116 atest = false; | |
117 end | |
118 | |
119 % Return a result structure | |
120 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
121 end % END UTP_01 | |
122 | |
123 %% UTP_02 | |
124 | |
125 % <TestDescription> | |
126 % | |
127 % Tests that the md5 method works with a vector of AOs as input. | |
128 % | |
129 % </TestDescription> | |
130 function result = utp_02 | |
131 | |
132 % <SyntaxDescription> | |
133 % | |
134 % Test that the md5 method works for a vector of AOs as input. | |
135 % | |
136 % </SyntaxDescription> | |
137 | |
138 try | |
139 % <SyntaxCode> | |
140 out = md5(atvec); | |
141 % </SyntaxCode> | |
142 stest = true; | |
143 catch err | |
144 disp(err.message) | |
145 stest = false; | |
146 end | |
147 | |
148 % <AlgoDescription> | |
149 % | |
150 % 1) Check that the number of elements in 'out' are the same as in 'atvec' | |
151 % 2) Check that each output AO contains the correct data. | |
152 % | |
153 % </AlgoDescription> | |
154 | |
155 atest = true; | |
156 if stest | |
157 % <AlgoCode> | |
158 % Check we have the correct number of outputs | |
159 if ~isequal(size(out), size(atvec)), atest = false; end | |
160 % Check each output against the md5 of the XML document | |
161 for kk=1:numel(out) | |
162 % Create XML document | |
163 xml = com.mathworks.xml.XMLUtils.createDocument('ltpda_object'); | |
164 parent = xml.getDocumentElement; | |
165 utils.xml.xmlwrite(atvec(kk), xml, parent, ''); | |
166 xml_txt = xmlwrite(xml); | |
167 xml_txt = uint8(xml_txt); | |
168 xml_txt = xml_txt(:); | |
169 | |
170 % Compute java md5 | |
171 md5_java = java.security.MessageDigest.getInstance('MD5'); | |
172 md5_java.update(xml_txt); | |
173 | |
174 md5_hex = typecast(md5_java.digest, 'uint8'); | |
175 md5_hex = dec2hex(md5_hex)'; | |
176 | |
177 if ~strcmpi(out{kk}, md5_hex(:)'), atest = false; end | |
178 end | |
179 % </AlgoCode> | |
180 else | |
181 atest = false; | |
182 end | |
183 | |
184 % Return a result structure | |
185 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
186 end % END UTP_02 | |
187 | |
188 %% UTP_03 | |
189 | |
190 % <TestDescription> | |
191 % | |
192 % Tests that the md5 method works with a matrix of AOs as input. | |
193 % | |
194 % </TestDescription> | |
195 function result = utp_03 | |
196 | |
197 % <SyntaxDescription> | |
198 % | |
199 % Tests that the md5 method works with a matrix of AOs as input. | |
200 % | |
201 % </SyntaxDescription> | |
202 | |
203 try | |
204 % <SyntaxCode> | |
205 out = md5(atmat); | |
206 % </SyntaxCode> | |
207 stest = true; | |
208 catch err | |
209 disp(err.message) | |
210 stest = false; | |
211 end | |
212 | |
213 % <AlgoDescription> | |
214 % | |
215 % 1) Check that the number of elements in 'out' are the same as in 'atmat' | |
216 % 2) Check that each output AO contains the correct data. | |
217 % | |
218 % </AlgoDescription> | |
219 | |
220 atest = true; | |
221 if stest | |
222 % <AlgoCode> | |
223 % Check we have the correct number of outputs | |
224 if ~isequal(size(out), size(atmat)), atest = false; end | |
225 % Check each output against the md5 of the XML document | |
226 for kk=1:numel(out) | |
227 % Create XML document | |
228 xml = com.mathworks.xml.XMLUtils.createDocument('ltpda_object'); | |
229 parent = xml.getDocumentElement; | |
230 utils.xml.xmlwrite(atmat(kk), xml, parent, ''); | |
231 xml_txt = xmlwrite(xml); | |
232 xml_txt = uint8(xml_txt); | |
233 xml_txt = xml_txt(:); | |
234 | |
235 % Compute java md5 | |
236 md5_java = java.security.MessageDigest.getInstance('MD5'); | |
237 md5_java.update(xml_txt); | |
238 | |
239 md5_hex = typecast(md5_java.digest, 'uint8'); | |
240 md5_hex = dec2hex(md5_hex)'; | |
241 | |
242 if ~strcmpi(out{kk}, md5_hex(:)'), atest = false; end | |
243 end | |
244 % </AlgoCode> | |
245 else | |
246 atest = false; | |
247 end | |
248 | |
249 % Return a result structure | |
250 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
251 end % END UTP_03 | |
252 | |
253 %% UTP_04 | |
254 | |
255 % <TestDescription> | |
256 % | |
257 % Tests that the md5 method works with a list of AOs as input. | |
258 % | |
259 % </TestDescription> | |
260 function result = utp_04 | |
261 | |
262 % <SyntaxDescription> | |
263 % | |
264 % Tests that the md5 method works with a list of AOs as input. | |
265 % | |
266 % </SyntaxDescription> | |
267 | |
268 try | |
269 % <SyntaxCode> | |
270 out = md5(at1, at2, at3); | |
271 % </SyntaxCode> | |
272 stest = true; | |
273 catch err | |
274 disp(err.message) | |
275 stest = false; | |
276 end | |
277 | |
278 % <AlgoDescription> | |
279 % | |
280 % 1) Check that the number of elements in 'out' are the same as in the input | |
281 % 2) Check that each output AO contains the correct data. | |
282 % | |
283 % </AlgoDescription> | |
284 | |
285 atest = true; | |
286 aoin = [at1, at2, at3]; | |
287 if stest | |
288 % <AlgoCode> | |
289 % Check we have the correct number of outputs | |
290 if ~isequal(size(out), size(aoin)), atest = false; end | |
291 % Check each output against the md5 of the XML document | |
292 for kk=1:numel(out) | |
293 % Create XML document | |
294 xml = com.mathworks.xml.XMLUtils.createDocument('ltpda_object'); | |
295 parent = xml.getDocumentElement; | |
296 utils.xml.xmlwrite(aoin(kk), xml, parent, ''); | |
297 xml_txt = xmlwrite(xml); | |
298 xml_txt = uint8(xml_txt); | |
299 xml_txt = xml_txt(:); | |
300 | |
301 % Compute java md5 | |
302 md5_java = java.security.MessageDigest.getInstance('MD5'); | |
303 md5_java.update(xml_txt); | |
304 | |
305 md5_hex = typecast(md5_java.digest, 'uint8'); | |
306 md5_hex = dec2hex(md5_hex)'; | |
307 | |
308 if ~strcmpi(out{kk}, md5_hex(:)'), atest = false; end | |
309 end | |
310 % </AlgoCode> | |
311 else | |
312 atest = false; | |
313 end | |
314 | |
315 % Return a result structure | |
316 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
317 end % END UTP_04 | |
318 | |
319 %% UTP_05 | |
320 | |
321 % <TestDescription> | |
322 % | |
323 % Tests that the md5 method works with a mix of different shaped AOs as | |
324 % input. | |
325 % | |
326 % </TestDescription> | |
327 function result = utp_05 | |
328 | |
329 % <SyntaxDescription> | |
330 % | |
331 % Tests that the md5 method works with a mix of different shaped AOs as | |
332 % input. | |
333 % | |
334 % </SyntaxDescription> | |
335 | |
336 try | |
337 % <SyntaxCode> | |
338 out = md5(atvec, at2, atmat); | |
339 % </SyntaxCode> | |
340 stest = true; | |
341 catch err | |
342 disp(err.message) | |
343 stest = false; | |
344 end | |
345 | |
346 % <AlgoDescription> | |
347 % | |
348 % 1) Check that the number of elements in 'out' are the same as in the input | |
349 % 2) Check that each output AO contains the correct data. | |
350 % | |
351 % </AlgoDescription> | |
352 | |
353 atest = true; | |
354 aoin = [reshape(atvec,1,[]), at2, reshape(atmat,1,[])]; | |
355 if stest | |
356 % <AlgoCode> | |
357 % Check we have the correct number of outputs | |
358 if ~isequal(size(out), size(aoin)), atest = false; end | |
359 % Check each output against the md5 of the XML document | |
360 for kk=1:numel(out) | |
361 % Create XML document | |
362 xml = com.mathworks.xml.XMLUtils.createDocument('ltpda_object'); | |
363 parent = xml.getDocumentElement; | |
364 utils.xml.xmlwrite(aoin(kk), xml, parent, ''); | |
365 xml_txt = xmlwrite(xml); | |
366 xml_txt = uint8(xml_txt); | |
367 xml_txt = xml_txt(:); | |
368 | |
369 % Compute java md5 | |
370 md5_java = java.security.MessageDigest.getInstance('MD5'); | |
371 md5_java.update(xml_txt); | |
372 | |
373 md5_hex = typecast(md5_java.digest, 'uint8'); | |
374 md5_hex = dec2hex(md5_hex)'; | |
375 | |
376 if ~strcmpi(out{kk}, md5_hex(:)'), atest = false; end | |
377 end | |
378 % </AlgoCode> | |
379 else | |
380 atest = false; | |
381 end | |
382 | |
383 % Return a result structure | |
384 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
385 end % END UTP_05 | |
386 | |
387 %% UTP_06 | |
388 | |
389 % <TestDescription> | |
390 % | |
391 % Tests that the md5 method retruns for one input a string and not a cell | |
392 % of a string | |
393 % | |
394 % </TestDescription> | |
395 function result = utp_06 | |
396 | |
397 % <SyntaxDescription> | |
398 % | |
399 % Special case for one input because in this case retruns md5 a string | |
400 % and not a cell. | |
401 % | |
402 % </SyntaxDescription> | |
403 | |
404 try | |
405 % <SyntaxCode> | |
406 out = md5(at4); | |
407 % </SyntaxCode> | |
408 stest = true; | |
409 catch err | |
410 disp(err.message) | |
411 stest = false; | |
412 end | |
413 | |
414 % <AlgoDescription> | |
415 % | |
416 % 1) Check that the output is a string | |
417 % 2) Check that each output AO contains the correct data. | |
418 % | |
419 % </AlgoDescription> | |
420 | |
421 atest = true; | |
422 if stest | |
423 % <AlgoCode> | |
424 % Check that the output is a string | |
425 if~ischar(out), atest = false; end | |
426 % Check each output against the md5 of the XML document | |
427 % Create XML document | |
428 xml = com.mathworks.xml.XMLUtils.createDocument('ltpda_object'); | |
429 parent = xml.getDocumentElement; | |
430 utils.xml.xmlwrite(at4, xml, parent, ''); | |
431 xml_txt = xmlwrite(xml); | |
432 xml_txt = uint8(xml_txt); | |
433 xml_txt = xml_txt(:); | |
434 | |
435 % Compute java md5 | |
436 md5_java = java.security.MessageDigest.getInstance('MD5'); | |
437 md5_java.update(xml_txt); | |
438 | |
439 md5_hex = typecast(md5_java.digest, 'uint8'); | |
440 md5_hex = dec2hex(md5_hex)'; | |
441 | |
442 if ~strcmpi(out, md5_hex(:)'), atest = false; end | |
443 % </AlgoCode> | |
444 else | |
445 atest = false; | |
446 end | |
447 | |
448 % Return a result structure | |
449 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
450 end % END UTP_06 | |
451 | |
452 end |