comparison testing/utp_1.1/utps/time/utp_time_timeformat.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_TIME_TIMEFORMAT
2 %
3 % <MethodDescription>
4 %
5 % Tests time class 'timeformat' static property.
6 %
7 % </MethodDescription>
8 %
9 % NOTE: in this test we manipulate user preferences thus we should make
10 % sure we restore the original user preferences at the end of the testing
11 %
12 % $Id: utp_time_timeformat.m,v 1.3 2011/04/28 07:06:27 hewitson Exp $
13
14 function results = utp_time_timeformat(varargin)
15
16 % check inputs
17 if nargin == 0
18
19 % some keywords
20 class = 'time';
21 mthd = 'timeformat';
22
23 results = [];
24 disp('******************************************************');
25 disp(['**** Running UTPs for ' class '/' mthd]);
26 disp('******************************************************');
27
28 % get preferences
29 prefs = getappdata(0, 'LTPDApreferences');
30 oldTimezone = char(prefs.getTimePrefs.getTimeTimezone);
31 oldTimeformat = char(prefs.getTimePrefs.getTimestringFormat);
32
33 % get preferences
34 try
35 results = [results utp_901];
36 results = [results utp_902];
37 results = [results utp_903];
38 catch ex
39 % restore preferences
40 prefs.getTimePrefs.setTimeTimezone(oldTimezone);
41 prefs.getTimePrefs.setTimestringFormat(oldTimeformat);
42 rethrow(ex);
43 end
44
45 % restore preferences
46 prefs.getTimePrefs.setTimeTimezone(oldTimezone);
47 prefs.getTimePrefs.setTimestringFormat(oldTimeformat);
48
49 disp('Done.');
50 disp('******************************************************');
51
52 elseif nargin == 1
53 % check for UTP functions
54 if strcmp(varargin{1}, 'isutp')
55 results = 1;
56 else
57 results = 0;
58 end
59 else
60 error('### Incorrect inputs')
61 end
62
63 %% UTP_901
64
65 % <TestDescription>
66 %
67 % Tests that the method really returns what is in the user preferences.
68 %
69 % </TestDescription>
70 function result = utp_901
71
72 % <SyntaxDescription>
73 % Check that the timeformat method runs without error.
74 % </SyntaxDescription>
75 stest = false;
76 try
77 % <SyntaxCode>
78 frmt = time.timeformat;
79 % </SyntaxCode>
80 stest = true;
81 end
82
83 atest = true;
84 try
85 % do not run algorithm tests if sintax tests failed
86 assert(stest);
87
88 % <AlgoDescription>
89 % Check that the returned value is the same as the one set in the
90 % user preferences.
91 % </AlgoDescription>
92
93 % <AlgoCode>
94 assert(strcmp(frmt, char(prefs.getTimePrefs.getTimestringFormat)));
95 % </AlgoCode>
96 catch ex
97 atest = false;
98 % rethrow(ex)
99 end
100
101 % return a result structure
102 result = utp_prepare_result(atest, stest, dbstack, mfilename);
103 end
104
105
106 %% UTP_902
107
108 % <TestDescription>
109 %
110 % Change user preferences and do it again.
111 %
112 % </TestDescription>
113 function result = utp_902
114
115 % <SyntaxDescription>
116 % Set the time string format in the preferences and check that the
117 % timeformat method runs without error.
118 % </SyntaxDescription>
119 stest = false;
120 try
121 % <SyntaxCode>
122 prefs.getTimePrefs.setTimestringFormat('HH:MM:SS');
123 frmt = time.timeformat;
124 % </SyntaxCode>
125 stest = true;
126 end
127
128 atest = true;
129 try
130 % do not run algorithm tests if sintax tests failed
131 assert(stest);
132
133 % <AlgoDescription>
134 % Check that the returned value is the same as the one set in the
135 % user preferences.
136 % </AlgoDescription>
137
138 % <AlgoCode>
139 assert(strcmp(frmt, char(prefs.getTimePrefs.getTimestringFormat)));
140 % </AlgoCode>
141 catch ex
142 atest = false;
143 % rethrow(ex)
144 end
145
146 % return a result structure
147 result = utp_prepare_result(atest, stest, dbstack, mfilename);
148 end
149
150
151 %% UTP_903
152
153 % <TestDescription>
154 %
155 % Change user preferences and do it again.
156 %
157 % </TestDescription>
158 function result = utp_903
159
160 % <SyntaxDescription>
161 % Set the time string format in the preferences and check that the
162 % timeformat method runs without error.
163 % </SyntaxDescription>
164 stest = false;
165 try
166 % <SyntaxCode>
167 prefs.getTimePrefs.setTimestringFormat('yyyy-mm-dd');
168 frmt = time.timeformat;
169 % </SyntaxCode>
170 stest = true;
171 end
172
173 atest = true;
174 try
175 % do not run algorithm tests if sintax tests failed
176 assert(stest);
177 % <AlgoDescription>
178 % Check that the returned value is the same as the one set in the
179 % user preferences.
180 % </AlgoDescription>
181
182 % <AlgoCode>
183 assert(strcmp(frmt, char(prefs.getTimePrefs.getTimestringFormat)));
184 % </AlgoCode>
185 catch ex
186 atest = false;
187 % rethrow(ex);
188 end
189
190 % return a result structure
191 result = utp_prepare_result(atest, stest, dbstack, mfilename);
192 end
193
194 end