Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_bsubmit.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 | 7d2e2e065cf1 |
comparison
equal
deleted
inserted
replaced
43:bc767aaa99a8 | 44:409a22968d5e |
---|---|
1 % UTP_AO_BSUBMIT a set of UTPs for the ao/bsubmit method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_bsubmit.m,v 1.15 2010/08/18 09:25:55 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The bsubmit method of the ao class submits a collection of objects in | |
11 % binary form to an LTPDA Repository. The type of the objects are | |
12 % independent. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_ao_bsubmit(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'ao'; | |
23 mthd = 'bsubmit'; | |
24 | |
25 results = []; | |
26 disp('******************************************************'); | |
27 disp(['**** Running UTPs for ' class '/' mthd]); | |
28 disp('******************************************************'); | |
29 | |
30 [at1,at2,at3,at4,at5,at6,atvec,atmat] = get_test_objects_ao; | |
31 plForAutoTest = plist('no dialog', true, 'use selector', false); | |
32 | |
33 connPl = utpGetConnectionPlist(); | |
34 rm = LTPDARepositoryManager(); | |
35 conn = rm.getConnection(connPl); | |
36 try | |
37 | |
38 experiment_title = 'utp_ao_bsubmit: submit ao'; | |
39 experiment_description = 'utp_ao_bsubmit: description'; | |
40 analysis_description = '<utp_ao_bsubmit>'; | |
41 quantity = 'none'; | |
42 keywords = 'none'; | |
43 reference_ids = ''; | |
44 additional_comments = 'none'; | |
45 additional_authors = 'no one'; | |
46 | |
47 plSinfo = plist(... | |
48 'experiment_title', experiment_title, ... | |
49 'experiment_description', experiment_description, ... | |
50 'analysis_description', analysis_description, ... | |
51 'quantity', quantity, ... | |
52 'keywords', keywords, ... | |
53 'reference_ids', reference_ids, ... | |
54 'additional_comments', additional_comments, ... | |
55 'additional_authors', additional_authors); | |
56 | |
57 % Exception list for the UTPs: | |
58 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
59 | |
60 % Run the tests | |
61 results = [results utp_01]; % getInfo call | |
62 results = [results utp_02]; % Vector input | |
63 results = [results utp_03]; % Matrix input | |
64 results = [results utp_04]; % List input | |
65 results = [results utp_05]; % Test with mixed input | |
66 results = [results utp_06]; % Test history is working | |
67 results = [results utp_07]; % Test output of the data | |
68 catch | |
69 end | |
70 | |
71 % Close connection | |
72 utpCloseConnection(conn); | |
73 | |
74 disp('Done.'); | |
75 disp('******************************************************'); | |
76 | |
77 elseif nargin == 1 % Check for UTP functions | |
78 if strcmp(varargin{1}, 'isutp') | |
79 results = 1; | |
80 elseif strcmpi(varargin{1}, 'needs repository') | |
81 results = 2; | |
82 else | |
83 results = 0; | |
84 end | |
85 else | |
86 error('### Incorrect inputs') | |
87 end | |
88 | |
89 %% UTP_01 | |
90 | |
91 % <TestDescription> | |
92 % | |
93 % Tests that the getInfo call works for this method. | |
94 % | |
95 % </TestDescription> | |
96 function result = utp_01 | |
97 | |
98 | |
99 % <SyntaxDescription> | |
100 % | |
101 % Test that the getInfo call works for no sets, all sets, and each set | |
102 % individually. | |
103 % | |
104 % </SyntaxDescription> | |
105 | |
106 try | |
107 % <SyntaxCode> | |
108 % Call for no sets | |
109 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
110 % Call for all sets | |
111 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
112 % Call for each set | |
113 for kk=1:numel(io(2).sets) | |
114 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
115 end | |
116 % </SyntaxCode> | |
117 stest = true; | |
118 catch err | |
119 disp(err.message) | |
120 stest = false; | |
121 end | |
122 | |
123 % <AlgoDescription> | |
124 % | |
125 % 1) Check that getInfo call returned an minfo object in all cases. | |
126 % 2) Check that all plists have the correct parameters. | |
127 % | |
128 % </AlgoDescription> | |
129 | |
130 atest = true; | |
131 if stest | |
132 % <AlgoCode> | |
133 % check we have minfo objects | |
134 if isa(io, 'minfo') | |
135 prefs = getappdata(0, 'LTPDApreferences'); | |
136 hosts = utils.helper.jArrayList2CellArray(prefs.getRepoPrefs.getHostnames()); | |
137 % SET 'None' | |
138 if ~isempty(io(1).sets), atest = false; end | |
139 if ~isempty(io(1).plists), atest = false; end | |
140 % Check all Sets | |
141 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
142 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
143 % SET 'Default' | |
144 % Check key | |
145 if io(3).plists.nparams ~= 15, atest = false; end | |
146 if ~io(3).plists.isparam('hostname'), atest = false; end | |
147 if ~io(3).plists.isparam('database'), atest = false; end | |
148 if ~io(3).plists.isparam('username'), atest = false; end | |
149 if ~io(3).plists.isparam('password'), atest = false; end | |
150 if ~io(3).plists.isparam('experiment title'), atest = false; end | |
151 if ~io(3).plists.isparam('experiment description'), atest = false; end | |
152 if ~io(3).plists.isparam('analysis description'), atest = false; end | |
153 if ~io(3).plists.isparam('quantity'), atest = false; end | |
154 if ~io(3).plists.isparam('keywords'), atest = false; end | |
155 if ~io(3).plists.isparam('reference ids'), atest = false; end | |
156 if ~io(3).plists.isparam('additional comments'), atest = false; end | |
157 if ~io(3).plists.isparam('additional authors'), atest = false; end | |
158 if ~io(3).plists.isparam('no dialog'), atest = false; end | |
159 if ~io(3).plists.isparam('use selector'), atest = false; end | |
160 if ~io(3).plists.isparam('sinfo filename'), atest = false; end | |
161 % Check default value | |
162 if ~isequal(io(3).plists.find('hostname'), hosts{1}), atest = false; end | |
163 if ~isEmptyChar(io(3).plists.find('database')), atest = false; end | |
164 if ~isEmptyChar(io(3).plists.find('username')), atest = false; end | |
165 if ~isEmptyChar(io(3).plists.find('password')), atest = false; end | |
166 if ~isEmptyChar(io(3).plists.find('experiment title')), atest = false; end | |
167 if ~isEmptyChar(io(3).plists.find('experiment description')), atest = false; end | |
168 if ~isEmptyChar(io(3).plists.find('analysis description')), atest = false; end | |
169 if ~isEmptyChar(io(3).plists.find('quantity')), atest = false; end | |
170 if ~isEmptyChar(io(3).plists.find('keywords')), atest = false; end | |
171 if ~isEmptyChar(io(3).plists.find('reference ids')), atest = false; end | |
172 if ~isEmptyChar(io(3).plists.find('additional comments')), atest = false; end | |
173 if ~isEmptyChar(io(3).plists.find('additional authors')), atest = false; end | |
174 if ~isequal(io(3).plists.find('no dialog'), false), atest = false; end | |
175 if ~isequal(io(3).plists.find('use selector'), true), atest = false; end | |
176 if ~isEmptyChar(io(3).plists.find('sinfo filename')), atest = false; end | |
177 end | |
178 % </AlgoCode> | |
179 else | |
180 atest = false; | |
181 end | |
182 | |
183 % Return a result structure | |
184 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
185 end % END UTP_01 | |
186 | |
187 %% UTP_02 | |
188 | |
189 % <TestDescription> | |
190 % | |
191 % Tests that the bsubmit method works with a vector of AOs as input. | |
192 % | |
193 % </TestDescription> | |
194 function result = utp_02 | |
195 | |
196 % <SyntaxDescription> | |
197 % | |
198 % Test that the bsubmit method works for a vector of AOs as input. | |
199 % | |
200 % </SyntaxDescription> | |
201 | |
202 try | |
203 % <SyntaxCode> | |
204 [ids, cids] = bsubmit(atvec, connPl, plSinfo, plForAutoTest); | |
205 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
206 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids); | |
207 robjs3 = ltpda_uo.retrieve(conn, 'binary', ids(1), ids(2), ids(3)); | |
208 % </SyntaxCode> | |
209 stest = true; | |
210 catch err | |
211 disp(err.message) | |
212 stest = false; | |
213 end | |
214 | |
215 % <AlgoDescription> | |
216 % | |
217 % 1) Check the number of retrieved objects. | |
218 % 2) Check that the retrieved object is the same as the submitted | |
219 % | |
220 % </AlgoDescription> | |
221 | |
222 atest = true; | |
223 if stest | |
224 % <AlgoCode> | |
225 % Check we have the correct number of outputs | |
226 if numel(robjs1) ~= numel(atvec), atest = false; end | |
227 if numel(robjs2) ~= numel(atvec), atest = false; end | |
228 if numel(robjs3) ~= numel(atvec), atest = false; end | |
229 % Check the retrieved object against the submitted | |
230 if ~eq(atvec, [robjs1{:}]), atest = false; end | |
231 if ~eq(atvec, [robjs2{:}]), atest = false; end | |
232 if ~eq(atvec, [robjs3{:}]), atest = false; end | |
233 % </AlgoCode> | |
234 else | |
235 atest = false; | |
236 end | |
237 | |
238 % Return a result structure | |
239 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
240 end % END UTP_02 | |
241 | |
242 %% UTP_03 | |
243 | |
244 % <TestDescription> | |
245 % | |
246 % Tests that the bsubmit method works with a matrix of AOs as input. | |
247 % | |
248 % </TestDescription> | |
249 function result = utp_03 | |
250 | |
251 % <SyntaxDescription> | |
252 % | |
253 % Tests that the bsubmit method works with a matrix of AOs as input. | |
254 % | |
255 % </SyntaxDescription> | |
256 | |
257 try | |
258 % <SyntaxCode> | |
259 [ids, cids] = bsubmit(atmat, connPl, plSinfo, plForAutoTest); | |
260 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
261 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids); | |
262 robjs3 = ltpda_uo.retrieve(conn, 'binary', ids(1), ids(2), ids(3), ids(4), ids(5), ids(6)); | |
263 % </SyntaxCode> | |
264 stest = true; | |
265 catch err | |
266 disp(err.message) | |
267 stest = false; | |
268 end | |
269 | |
270 % <AlgoDescription> | |
271 % | |
272 % 1) Check the number of retrieved objects. | |
273 % 2) Check that the retrieved object is the same as the submitted | |
274 % | |
275 % </AlgoDescription> | |
276 | |
277 atest = true; | |
278 if stest | |
279 % <AlgoCode> | |
280 % Check we have the correct number of outputs | |
281 if numel(robjs1) ~= numel(atmat), atest = false; end | |
282 if numel(robjs2) ~= numel(atmat), atest = false; end | |
283 if numel(robjs3) ~= numel(atmat), atest = false; end | |
284 % Check the retrieved object against the submitted | |
285 if ~eq(atmat, reshape([robjs1{:}], size(atmat))), atest = false; end | |
286 if ~eq(atmat, reshape([robjs2{:}], size(atmat))), atest = false; end | |
287 if ~eq(atmat, reshape([robjs3{:}], size(atmat))), atest = false; end | |
288 % </AlgoCode> | |
289 else | |
290 atest = false; | |
291 end | |
292 | |
293 % Return a result structure | |
294 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
295 end % END UTP_03 | |
296 | |
297 %% UTP_04 | |
298 | |
299 % <TestDescription> | |
300 % | |
301 % Tests that the bsubmit method works with a list of AOs as input. | |
302 % | |
303 % </TestDescription> | |
304 function result = utp_04 | |
305 | |
306 % <SyntaxDescription> | |
307 % | |
308 % Tests that the bsubmit method works with a list of AOs as input. Use | |
309 % for this a mix of different object types. | |
310 % | |
311 % </SyntaxDescription> | |
312 | |
313 try | |
314 % <SyntaxCode> | |
315 pl = smodel('a'); | |
316 iir = miir(plist('type', 'highpass')); | |
317 [ids, cids] = bsubmit(at1, pl, iir, connPl, plSinfo, plForAutoTest); | |
318 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
319 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids); | |
320 robjs3 = ltpda_uo.retrieve(conn, 'binary', ids(1), ids(2), ids(3)); | |
321 % </SyntaxCode> | |
322 stest = true; | |
323 catch err | |
324 disp(err.message) | |
325 stest = false; | |
326 end | |
327 | |
328 % <AlgoDescription> | |
329 % | |
330 % 1) Check the number of retrieved objects. | |
331 % 2) Check that the retrieved object is the same as the submitted | |
332 % | |
333 % </AlgoDescription> | |
334 | |
335 atest = true; | |
336 if stest | |
337 % <AlgoCode> | |
338 % Check we have the correct number of outputs | |
339 if numel(robjs1) ~= 3, atest = false; end | |
340 if numel(robjs2) ~= 3, atest = false; end | |
341 if numel(robjs3) ~= 3, atest = false; end | |
342 % Check the retrieved object against the submitted | |
343 % Check robjs1 | |
344 if ~eq(robjs1{1}, at1), atest = false; end | |
345 if ~eq(robjs1{2}, pl), atest = false; end | |
346 if ~eq(robjs1{3}, iir), atest = false; end | |
347 % Check robjs2 | |
348 if ~eq(robjs2{1}, at1), atest = false; end | |
349 if ~eq(robjs2{2}, pl), atest = false; end | |
350 if ~eq(robjs2{3}, iir), atest = false; end | |
351 % Check robjs3 | |
352 if ~eq(robjs3{1}, at1), atest = false; end | |
353 if ~eq(robjs3{2}, pl), atest = false; end | |
354 if ~eq(robjs3{3}, iir), atest = false; end | |
355 % </AlgoCode> | |
356 else | |
357 atest = false; | |
358 end | |
359 | |
360 % Return a result structure | |
361 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
362 end % END UTP_04 | |
363 | |
364 %% UTP_05 | |
365 | |
366 % <TestDescription> | |
367 % | |
368 % Tests that the abs method works with a mix of different shaped AOs as | |
369 % input. | |
370 % | |
371 % </TestDescription> | |
372 function result = utp_05 | |
373 | |
374 % <SyntaxDescription> | |
375 % | |
376 % Tests that the bsubmit method works with a list of AOs as input. Use | |
377 % for this a mix of different object types. | |
378 % | |
379 % </SyntaxDescription> | |
380 | |
381 try | |
382 % <SyntaxCode> | |
383 pl = plist('key1', 'val', 'key2', 2); | |
384 iir = miir(plist('type', 'highpass')); | |
385 [ids, cids] = bsubmit(pl, atmat, iir, atvec, connPl, plSinfo, plForAutoTest); | |
386 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
387 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids); | |
388 % </SyntaxCode> | |
389 stest = true; | |
390 catch err | |
391 disp(err.message) | |
392 stest = false; | |
393 end | |
394 | |
395 % <AlgoDescription> | |
396 % | |
397 % 1) Check the number of retrieved objects. | |
398 % 2) Check that the retrieved object is the same as the submitted | |
399 % | |
400 % </AlgoDescription> | |
401 | |
402 atest = true; | |
403 if stest | |
404 % <AlgoCode> | |
405 % Check we have the correct number of outputs | |
406 if numel(robjs1) ~= 2 + numel(atmat) + numel(atvec), atest = false; end | |
407 if numel(robjs2) ~= 2 + numel(atmat) + numel(atvec), atest = false; end | |
408 % Check the retrieved object against the submitted | |
409 % Check robjs1 | |
410 if ~eq(robjs1{1}, atmat(1)), atest = false; end | |
411 if ~eq(robjs1{2}, atmat(2)), atest = false; end | |
412 if ~eq(robjs1{3}, atmat(3)), atest = false; end | |
413 if ~eq(robjs1{4}, atmat(4)), atest = false; end | |
414 if ~eq(robjs1{5}, atmat(5)), atest = false; end | |
415 if ~eq(robjs1{6}, atmat(6)), atest = false; end | |
416 if ~eq(robjs1{7}, iir), atest = false; end | |
417 if ~eq(robjs1{8}, atvec(1)), atest = false; end | |
418 if ~eq(robjs1{9}, atvec(2)), atest = false; end | |
419 if ~eq(robjs1{10}, atvec(3)), atest = false; end | |
420 if ~eq(robjs1{11}, pl), atest = false; end | |
421 % Check robjs2 | |
422 if ~eq(robjs2{1}, atmat(1)), atest = false; end | |
423 if ~eq(robjs2{2}, atmat(2)), atest = false; end | |
424 if ~eq(robjs2{3}, atmat(3)), atest = false; end | |
425 if ~eq(robjs2{4}, atmat(4)), atest = false; end | |
426 if ~eq(robjs2{5}, atmat(5)), atest = false; end | |
427 if ~eq(robjs2{6}, atmat(6)), atest = false; end | |
428 if ~eq(robjs2{7}, iir), atest = false; end | |
429 if ~eq(robjs2{8}, atvec(1)), atest = false; end | |
430 if ~eq(robjs2{9}, atvec(2)), atest = false; end | |
431 if ~eq(robjs2{10}, atvec(3)), atest = false; end | |
432 if ~eq(robjs2{11}, pl), atest = false; end | |
433 % </AlgoCode> | |
434 else | |
435 atest = false; | |
436 end | |
437 | |
438 % Return a result structure | |
439 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
440 end % END UTP_05 | |
441 | |
442 %% UTP_06 | |
443 | |
444 % <TestDescription> | |
445 % | |
446 % Tthe bsubmit method properly applies history. | |
447 % | |
448 % </TestDescription> | |
449 function result = utp_06 | |
450 | |
451 % <SyntaxDescription> | |
452 % | |
453 % Tthe bsubmit method properly applies history. | |
454 % | |
455 % </SyntaxDescription> | |
456 | |
457 try | |
458 % <SyntaxCode> | |
459 % </SyntaxCode> | |
460 stest = true; | |
461 catch err | |
462 disp(err.message) | |
463 stest = false; | |
464 end | |
465 | |
466 % <AlgoDescription> | |
467 % | |
468 % 1) Nothing to test. | |
469 % | |
470 % </AlgoDescription> | |
471 | |
472 atest = true; | |
473 if stest | |
474 % <AlgoCode> | |
475 % </AlgoCode> | |
476 else | |
477 atest = false; | |
478 end | |
479 | |
480 % Return a result structure | |
481 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
482 end % END UTP_06 | |
483 | |
484 %% UTP_07 | |
485 | |
486 % <TestDescription> | |
487 % | |
488 % Check that the bsubmit method pass back the output objects to a list of | |
489 % output variables or to a single variable. | |
490 % | |
491 % </TestDescription> | |
492 function result = utp_07 | |
493 | |
494 % <SyntaxDescription> | |
495 % | |
496 % Call the method with a list of output variables and with a single | |
497 % output variable. Additionaly check that the rebuild method works on | |
498 % the output. | |
499 % | |
500 % </SyntaxDescription> | |
501 | |
502 try | |
503 % <SyntaxCode> | |
504 [ids, cids] = bsubmit(at1, at2, connPl, plSinfo, plForAutoTest); | |
505 | |
506 [o1, o2] = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
507 o3 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
508 % </SyntaxCode> | |
509 stest = true; | |
510 catch err | |
511 disp(err.message) | |
512 stest = false; | |
513 end | |
514 | |
515 % <AlgoDescription> | |
516 % | |
517 % 1) Check that the output contains the right number of objects | |
518 % | |
519 % </AlgoDescription> | |
520 | |
521 atest = true; | |
522 if stest | |
523 % <AlgoCode> | |
524 % Check the number of outputs | |
525 if numel(o1) ~=1, atest = false; end | |
526 if numel(o2) ~=1, atest = false; end | |
527 if numel(o3) ~=2, atest = false; end | |
528 % Check the output | |
529 if ~eq(o1, at1), atest = false; end | |
530 if ~eq(o2, at2), atest = false; end | |
531 if ~eq(o3{1}, at1), atest = false; end | |
532 if ~eq(o3{2}, at2), atest = false; end | |
533 % </AlgoCode> | |
534 else | |
535 atest = false; | |
536 end | |
537 | |
538 % Return a result structure | |
539 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
540 end % END UTP_07 | |
541 | |
542 end |