comparison testing/utp_1.1/utps/mfir/utp_mfir_update.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_UPDATE a set of UTPs for the mfir/update method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_mfir_update.m,v 1.14 2010/08/18 09:25:54 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The update method of the mfir class updates (replace) an LTPDA object
11 % in the repository with the given replacement object. It is only possible
12 % to update one object. This is the reason why the general UTPs are not
13 % possible.
14 %
15 % </MethodDescription>
16
17 function results = utp_mfir_update(varargin)
18
19 % Check the inputs
20 if nargin == 0
21
22 % Some keywords
23 class = 'mfir';
24 mthd = 'update';
25
26 results = [];
27 disp('******************************************************');
28 disp(['**** Running UTPs for ' class '/' mthd]);
29 disp('******************************************************');
30
31 obj = mfir(plist('type', 'bandreject', 'fc', [0.01 0.1]));
32 obj.setName();
33
34 plForAutoTest = plist('no dialog', true, 'use selector', false);
35 conn = utpGetConnection();
36 try
37
38 sinfo.conn = conn;
39 sinfo.experiment_title = 'utp_mfir_update: update mfir';
40 sinfo.experiment_description = 'utp_mfir_update: description';
41 sinfo.analysis_description = '<utp_mfir_update>';
42 sinfo.quantity = 'none';
43 sinfo.keywords = 'none';
44 sinfo.reference_ids = '';
45 sinfo.additional_comments = 'none';
46 sinfo.additional_authors = 'no one';
47
48 [ids, cids] = submit(obj, sinfo, plForAutoTest);
49
50 % Exception list for the UTPs:
51 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
52
53 % Run the tests
54 results = [results utp_01]; % getInfo call
55 results = [results utp_02]; % Test with conn
56 results = [results utp_03]; % Test with sinfo
57 results = [results utp_04]; % Test update of an binary file
58 results = [results utp_05]; % Test replace with other object
59 catch
60 end
61
62 % Close connection
63 utpCloseConnection(conn);
64
65 disp('Done.');
66 disp('******************************************************');
67
68 elseif nargin == 1 % Check for UTP functions
69 if strcmp(varargin{1}, 'isutp')
70 results = 1;
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 ~= 15, 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('binary'), atest = false; end
150 % Check default value
151 if ~isequal(io(3).plists.find('hostname'), hosts{1}), atest = false; end
152 if ~isEmptyChar(io(3).plists.find('database')), atest = false; end
153 if ~isEmptyChar(io(3).plists.find('username')), atest = false; end
154 if ~isEmptyChar(io(3).plists.find('password')), atest = false; end
155 if ~isEmptyChar(io(3).plists.find('experiment title')), atest = false; end
156 if ~isEmptyChar(io(3).plists.find('experiment description')), atest = false; end
157 if ~isEmptyChar(io(3).plists.find('analysis description')), atest = false; end
158 if ~isEmptyChar(io(3).plists.find('quantity')), atest = false; end
159 if ~isEmptyChar(io(3).plists.find('keywords')), atest = false; end
160 if ~isEmptyChar(io(3).plists.find('reference ids')), atest = false; end
161 if ~isEmptyChar(io(3).plists.find('additional comments')), atest = false; end
162 if ~isEmptyChar(io(3).plists.find('additional authors')), atest = false; end
163 if ~isequal(io(3).plists.find('no dialog'), false), atest = false; end
164 if ~isequal(io(3).plists.find('use selector'), true), atest = false; end
165 if ~isequal(io(3).plists.find('binary'), false), atest = false; end
166 end
167 % </AlgoCode>
168 else
169 atest = false;
170 end
171
172 % Return a result structure
173 result = utp_prepare_result(atest, stest, dbstack, mfilename);
174 end % END UTP_01
175
176 %% UTP_02
177
178 % <TestDescription>
179 %
180 % Tests that the update method updates the repository at the given
181 % position 'ids' with the new object.
182 %
183 % </TestDescription>
184 function result = utp_02
185
186 % <SyntaxDescription>
187 %
188 % Tests that the update method updates the repository at the given
189 % position 'ids' with the new object.
190 % Use a database object (conn) to establish the connection.
191 %
192 % </SyntaxDescription>
193
194 try
195 % <SyntaxCode>
196 % Make some changes to the object.
197 uobj = obj.setName('I was updated (conn)');
198 update(uobj, ids, conn, plForAutoTest);
199 % Retrieve the object from the repository position 'ids'
200 robj = ltpda_uo.retrieve(conn, ids);
201 % </SyntaxCode>
202 stest = true;
203 catch err
204 disp(err.message)
205 stest = false;
206 end
207
208 % <AlgoDescription>
209 %
210 % 1) Check that the updated object 'uobj' and the retrieved object
211 % 'robj' are the same.
212 %
213 % </AlgoDescription>
214
215 atest = true;
216 if stest
217 % <AlgoCode>
218 if ~eq(uobj, robj), atest = false; end
219 % </AlgoCode>
220 else
221 atest = false;
222 end
223
224 % Return a result structure
225 result = utp_prepare_result(atest, stest, dbstack, mfilename);
226 end % END UTP_02
227
228 %% UTP_03
229
230 % <TestDescription>
231 %
232 % Tests that the update method updates the repository at the given
233 % position 'ids' with the new object.
234 %
235 % </TestDescription>
236 function result = utp_03
237
238 % <SyntaxDescription>
239 %
240 % Tests that the update method updates the repository at the given
241 % position 'ids' with the new object.
242 % Use a database info structure (sinfo) to establish the connection.
243 %
244 % </SyntaxDescription>
245
246 try
247 % <SyntaxCode>
248 % Make some changes to the object.
249 uobj = obj.setName('I was updated (sinfo)');
250 update(uobj, ids, sinfo, plForAutoTest);
251 % Retrieve the object from the repository position 'ids'
252 robj = ltpda_uo.retrieve(conn, ids);
253 % </SyntaxCode>
254 stest = true;
255 catch err
256 disp(err.message)
257 stest = false;
258 end
259
260 % <AlgoDescription>
261 %
262 % 1) Check that the updated object 'uobj' and the retrieved object
263 % 'robj' are the same.
264 %
265 % </AlgoDescription>
266
267 atest = true;
268 if stest
269 % <AlgoCode>
270 if ~eq(uobj, robj), atest = false; end
271 % </AlgoCode>
272 else
273 atest = false;
274 end
275
276 % Return a result structure
277 result = utp_prepare_result(atest, stest, dbstack, mfilename);
278 end % END UTP_03
279
280 %% UTP_04
281
282 % <TestDescription>
283 %
284 % Tests that the update method updates the repository at the given
285 % position 'ids' with the new object.
286 %
287 % </TestDescription>
288 function result = utp_04
289
290 % <SyntaxDescription>
291 %
292 % Tests that the update method updates the repository at the given
293 % position 'ids' with the new object.
294 % Check that the update method also updates objects which are stored as
295 % a binary file.
296 %
297 % </SyntaxDescription>
298
299 try
300 % <SyntaxCode>
301 % Submit the object as a binary
302 [ids_bin, cids] = bsubmit(obj, sinfo, plForAutoTest);
303 % Make some changes to the object.
304 uobj = obj.setName('I was updated (sinfo)');
305 update(uobj, ids_bin, sinfo, plForAutoTest);
306 % Retrieve the object from the repository position 'ids_bin'
307 robj = ltpda_uo.retrieve(conn, ids_bin);
308 % </SyntaxCode>
309 stest = true;
310 catch err
311 disp(err.message)
312 stest = false;
313 end
314
315 % <AlgoDescription>
316 %
317 % 1) Check that the updated object 'uobj' and the retrieved object
318 % 'robj' are the same.
319 %
320 % </AlgoDescription>
321
322 atest = true;
323 if stest
324 % <AlgoCode>
325 if ~eq(uobj, robj), atest = false; end
326 % </AlgoCode>
327 else
328 atest = false;
329 end
330
331 % Return a result structure
332 result = utp_prepare_result(atest, stest, dbstack, mfilename);
333 end % END UTP_04
334
335 %% UTP_05
336
337 % <TestDescription>
338 %
339 % Tests that the update method replaces the object in the repository with
340 % a completely other object.
341 %
342 % </TestDescription>
343 function result = utp_05
344
345 % <SyntaxDescription>
346 %
347 % Tests that the update method replaces the object in the repository
348 % with a completely other object.
349 % Replace the mfir object with a filter object.
350 %
351 % </SyntaxDescription>
352
353 try
354 % <SyntaxCode>
355 % Make some changes to the object.
356 uobj = miir(plist('type', 'lowpass'));
357 update(uobj, ids, sinfo, plForAutoTest);
358 % Retrieve the object from the repository position 'ids'
359 robj = ltpda_uo.retrieve(conn, ids);
360 % </SyntaxCode>
361 stest = true;
362 catch err
363 disp(err.message)
364 stest = false;
365 end
366
367 % <AlgoDescription>
368 %
369 % 1) Check that the updated object 'uobj' and the retrieved object
370 % 'robj' are the same.
371 %
372 % </AlgoDescription>
373
374 atest = true;
375 if stest
376 % <AlgoCode>
377 if ~eq(uobj, robj), atest = false; 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 end