Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_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 | 7d2e2e065cf1 |
comparison
equal
deleted
inserted
replaced
43:bc767aaa99a8 | 44:409a22968d5e |
---|---|
1 % UTP_AO_UPDATE a set of UTPs for the ao/update method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_update.m,v 1.16 2010/08/18 09:25:55 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The update method of the ao 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_ao_update(varargin) | |
18 | |
19 % Check the inputs | |
20 if nargin == 0 | |
21 | |
22 % Some keywords | |
23 class = 'ao'; | |
24 mthd = 'update'; | |
25 | |
26 results = []; | |
27 disp('******************************************************'); | |
28 disp(['**** Running UTPs for ' class '/' mthd]); | |
29 disp('******************************************************'); | |
30 | |
31 x = 1:100; | |
32 y = exp(x.^.5/2); | |
33 obj = ao(x,y, plist('type', 'xydata')); | |
34 obj.setName(); | |
35 | |
36 plForAutoTest = plist('no dialog', true, 'use selector', false); | |
37 connPl = utpGetConnectionPlist(); | |
38 rm = LTPDARepositoryManager(); | |
39 conn = rm.getConnection(connPl); | |
40 | |
41 try | |
42 | |
43 experiment_title = 'utp_ao_update: update ao'; | |
44 experiment_description = 'utp_ao_update: description'; | |
45 analysis_description = '<utp_ao_update>'; | |
46 quantity = 'none'; | |
47 keywords = 'none'; | |
48 reference_ids = ''; | |
49 additional_comments = 'none'; | |
50 additional_authors = 'no one'; | |
51 | |
52 plSinfo = plist(... | |
53 'experiment_title', experiment_title, ... | |
54 'experiment_description', experiment_description, ... | |
55 'analysis_description', analysis_description, ... | |
56 'quantity', quantity, ... | |
57 'keywords', keywords, ... | |
58 'reference_ids', reference_ids, ... | |
59 'additional_comments', additional_comments, ... | |
60 'additional_authors', additional_authors); | |
61 | |
62 [ids, cids] = submit(obj, connPl, plSinfo, plForAutoTest); | |
63 | |
64 % Exception list for the UTPs: | |
65 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
66 | |
67 % Run the tests | |
68 results = [results utp_01]; % getInfo call | |
69 results = [results utp_02]; % Test with conn | |
70 results = [results utp_03]; % Test with sinfo | |
71 results = [results utp_04]; % Test update of an binary file | |
72 results = [results utp_05]; % Test replace with other object | |
73 catch | |
74 end | |
75 | |
76 % Close connection | |
77 utpCloseConnection(conn); | |
78 | |
79 disp('Done.'); | |
80 disp('******************************************************'); | |
81 | |
82 elseif nargin == 1 % Check for UTP functions | |
83 if strcmp(varargin{1}, 'isutp') | |
84 results = 1; | |
85 else | |
86 results = 0; | |
87 end | |
88 else | |
89 error('### Incorrect inputs') | |
90 end | |
91 | |
92 %% UTP_01 | |
93 | |
94 % <TestDescription> | |
95 % | |
96 % Tests that the getInfo call works for this method. | |
97 % | |
98 % </TestDescription> | |
99 function result = utp_01 | |
100 | |
101 | |
102 % <SyntaxDescription> | |
103 % | |
104 % Test that the getInfo call works for no sets, all sets, and each set | |
105 % individually. | |
106 % | |
107 % </SyntaxDescription> | |
108 | |
109 try | |
110 % <SyntaxCode> | |
111 % Call for no sets | |
112 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
113 % Call for all sets | |
114 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
115 % Call for each set | |
116 for kk=1:numel(io(2).sets) | |
117 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
118 end | |
119 % </SyntaxCode> | |
120 stest = true; | |
121 catch err | |
122 disp(err.message) | |
123 stest = false; | |
124 end | |
125 | |
126 % <AlgoDescription> | |
127 % | |
128 % 1) Check that getInfo call returned an minfo object in all cases. | |
129 % 2) Check that all plists have the correct parameters. | |
130 % | |
131 % </AlgoDescription> | |
132 | |
133 atest = true; | |
134 if stest | |
135 % <AlgoCode> | |
136 % check we have minfo objects | |
137 if isa(io, 'minfo') | |
138 prefs = getappdata(0, 'LTPDApreferences'); | |
139 hosts = utils.helper.jArrayList2CellArray(prefs.getRepoPrefs.getHostnames()); | |
140 % SET 'None' | |
141 if ~isempty(io(1).sets), atest = false; end | |
142 if ~isempty(io(1).plists), atest = false; end | |
143 % Check all Sets | |
144 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
145 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
146 % SET 'Default' | |
147 % Check key | |
148 if io(3).plists.nparams ~= 15, atest = false; end | |
149 if ~io(3).plists.isparam('hostname'), atest = false; end | |
150 if ~io(3).plists.isparam('database'), atest = false; end | |
151 if ~io(3).plists.isparam('username'), atest = false; end | |
152 if ~io(3).plists.isparam('password'), atest = false; end | |
153 if ~io(3).plists.isparam('experiment title'), atest = false; end | |
154 if ~io(3).plists.isparam('experiment description'), atest = false; end | |
155 if ~io(3).plists.isparam('analysis description'), atest = false; end | |
156 if ~io(3).plists.isparam('quantity'), atest = false; end | |
157 if ~io(3).plists.isparam('keywords'), atest = false; end | |
158 if ~io(3).plists.isparam('reference ids'), atest = false; end | |
159 if ~io(3).plists.isparam('additional comments'), atest = false; end | |
160 if ~io(3).plists.isparam('additional authors'), atest = false; end | |
161 if ~io(3).plists.isparam('no dialog'), atest = false; end | |
162 if ~io(3).plists.isparam('use selector'), atest = false; end | |
163 if ~io(3).plists.isparam('binary'), atest = false; end | |
164 % Check default value | |
165 if ~isequal(io(3).plists.find('hostname'), hosts{1}), atest = false; end | |
166 if ~isEmptyChar(io(3).plists.find('database')), atest = false; end | |
167 if ~isEmptyChar(io(3).plists.find('username')), atest = false; end | |
168 if ~isEmptyChar(io(3).plists.find('password')), atest = false; end | |
169 if ~isEmptyChar(io(3).plists.find('experiment title')), atest = false; end | |
170 if ~isEmptyChar(io(3).plists.find('experiment description')), atest = false; end | |
171 if ~isEmptyChar(io(3).plists.find('analysis description')), atest = false; end | |
172 if ~isEmptyChar(io(3).plists.find('quantity')), atest = false; end | |
173 if ~isEmptyChar(io(3).plists.find('keywords')), atest = false; end | |
174 if ~isEmptyChar(io(3).plists.find('reference ids')), atest = false; end | |
175 if ~isEmptyChar(io(3).plists.find('additional comments')), atest = false; end | |
176 if ~isEmptyChar(io(3).plists.find('additional authors')), atest = false; end | |
177 if ~isequal(io(3).plists.find('no dialog'), false), atest = false; end | |
178 if ~isequal(io(3).plists.find('use selector'), true), atest = false; end | |
179 if ~isequal(io(3).plists.find('binary'), false), atest = false; end | |
180 end | |
181 % </AlgoCode> | |
182 else | |
183 atest = false; | |
184 end | |
185 | |
186 % Return a result structure | |
187 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
188 end % END UTP_01 | |
189 | |
190 %% UTP_02 | |
191 | |
192 % <TestDescription> | |
193 % | |
194 % Tests that the update method updates the repository at the given | |
195 % position 'ids' with the new object. | |
196 % | |
197 % </TestDescription> | |
198 function result = utp_02 | |
199 | |
200 % <SyntaxDescription> | |
201 % | |
202 % Tests that the update method updates the repository at the given | |
203 % position 'ids' with the new object. | |
204 % Use a database object (conn) to establish the connection. | |
205 % | |
206 % </SyntaxDescription> | |
207 | |
208 try | |
209 % <SyntaxCode> | |
210 % Make some changes to the object. | |
211 uobj = obj.setName('I was updated (conn)'); | |
212 update(uobj, ids, connPl, plForAutoTest); | |
213 % Retrieve the object from the repository position 'ids' | |
214 robj = ltpda_uo.retrieve(conn, ids); | |
215 % </SyntaxCode> | |
216 stest = true; | |
217 catch err | |
218 disp(err.message) | |
219 stest = false; | |
220 end | |
221 | |
222 % <AlgoDescription> | |
223 % | |
224 % 1) Check that the updated object 'uobj' and the retrieved object | |
225 % 'robj' are the same. | |
226 % | |
227 % </AlgoDescription> | |
228 | |
229 atest = true; | |
230 if stest | |
231 % <AlgoCode> | |
232 if ~eq(uobj, robj), 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 update method updates the repository at the given | |
247 % position 'ids' with the new object. | |
248 % | |
249 % </TestDescription> | |
250 function result = utp_03 | |
251 | |
252 % <SyntaxDescription> | |
253 % | |
254 % Tests that the update method updates the repository at the given | |
255 % position 'ids' with the new object. | |
256 % Use a database info structure (sinfo) to establish the connection. | |
257 % | |
258 % </SyntaxDescription> | |
259 | |
260 try | |
261 % <SyntaxCode> | |
262 % Make some changes to the object. | |
263 uobj = obj.setName('I was updated (sinfo)'); | |
264 update(uobj, ids, connPl, plSinfo, plForAutoTest); | |
265 % Retrieve the object from the repository position 'ids' | |
266 robj = ltpda_uo.retrieve(conn, ids); | |
267 % </SyntaxCode> | |
268 stest = true; | |
269 catch err | |
270 disp(err.message) | |
271 stest = false; | |
272 end | |
273 | |
274 % <AlgoDescription> | |
275 % | |
276 % 1) Check that the updated object 'uobj' and the retrieved object | |
277 % 'robj' are the same. | |
278 % | |
279 % </AlgoDescription> | |
280 | |
281 atest = true; | |
282 if stest | |
283 % <AlgoCode> | |
284 if ~eq(uobj, robj), atest = false; end | |
285 % </AlgoCode> | |
286 else | |
287 atest = false; | |
288 end | |
289 | |
290 % Return a result structure | |
291 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
292 end % END UTP_03 | |
293 | |
294 %% UTP_04 | |
295 | |
296 % <TestDescription> | |
297 % | |
298 % Tests that the update method updates the repository at the given | |
299 % position 'ids' with the new object. | |
300 % | |
301 % </TestDescription> | |
302 function result = utp_04 | |
303 | |
304 % <SyntaxDescription> | |
305 % | |
306 % Tests that the update method updates the repository at the given | |
307 % position 'ids' with the new object. | |
308 % Check that the update method also updates objects which are stored as | |
309 % a binary file. | |
310 % | |
311 % </SyntaxDescription> | |
312 | |
313 try | |
314 % <SyntaxCode> | |
315 % Submit the object as a binary | |
316 [ids_bin, cids] = bsubmit(obj, connPl, plSinfo, plForAutoTest); | |
317 % Make some changes to the object. | |
318 uobj = obj.setName('I was updated (sinfo)'); | |
319 update(uobj, ids_bin, plSinfo, plForAutoTest); | |
320 % Retrieve the object from the repository position 'ids_bin' | |
321 robj = ltpda_uo.retrieve(conn, ids_bin); | |
322 % </SyntaxCode> | |
323 stest = true; | |
324 catch err | |
325 disp(err.message) | |
326 stest = false; | |
327 end | |
328 | |
329 % <AlgoDescription> | |
330 % | |
331 % 1) Check that the updated object 'uobj' and the retrieved object | |
332 % 'robj' are the same. | |
333 % | |
334 % </AlgoDescription> | |
335 | |
336 atest = true; | |
337 if stest | |
338 % <AlgoCode> | |
339 if ~eq(uobj, robj), atest = false; end | |
340 % </AlgoCode> | |
341 else | |
342 atest = false; | |
343 end | |
344 | |
345 % Return a result structure | |
346 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
347 end % END UTP_04 | |
348 | |
349 %% UTP_05 | |
350 | |
351 % <TestDescription> | |
352 % | |
353 % Tests that the update method replaces the object in the repository with | |
354 % a completely other object. | |
355 % | |
356 % </TestDescription> | |
357 function result = utp_05 | |
358 | |
359 % <SyntaxDescription> | |
360 % | |
361 % Tests that the update method replaces the object in the repository | |
362 % with a completely other object. | |
363 % Replace the analysis object with a filter object. | |
364 % | |
365 % </SyntaxDescription> | |
366 | |
367 try | |
368 % <SyntaxCode> | |
369 % Make some changes to the object. | |
370 uobj = miir(plist('type', 'lowpass')); | |
371 update(uobj, ids, connPl, plSinfo, plForAutoTest); | |
372 % Retrieve the object from the repository position 'ids' | |
373 robj = ltpda_uo.retrieve(conn, ids); | |
374 % </SyntaxCode> | |
375 stest = true; | |
376 catch err | |
377 disp(err.message) | |
378 stest = false; | |
379 end | |
380 | |
381 % <AlgoDescription> | |
382 % | |
383 % 1) Check that the updated object 'uobj' and the retrieved object | |
384 % 'robj' are the same. | |
385 % | |
386 % </AlgoDescription> | |
387 | |
388 atest = true; | |
389 if stest | |
390 % <AlgoCode> | |
391 if ~eq(uobj, robj), atest = false; end | |
392 % </AlgoCode> | |
393 else | |
394 atest = false; | |
395 end | |
396 | |
397 % Return a result structure | |
398 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
399 end % END UTP_05 | |
400 | |
401 end |