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