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