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