comparison testing/utp_1.1/utps/time/utp_time_timezone.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_TIMEZONE
2 %
3 % <MethodDescription>
4 %
5 % Tests time class 'timezone' 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_timezone.m,v 1.3 2011/04/28 07:06:27 hewitson Exp $
13
14 function results = utp_time_timezone(varargin)
15
16 % check inputs
17 if nargin == 0
18
19 % some keywords
20 class = 'time';
21 mthd = 'timezone';
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 % Call the static timezone method.
74 % </SyntaxDescription>
75 stest = false;
76 try
77 % <SyntaxCode>
78 tz = time.timezone;
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 the resulting timezone object against the one in the user
90 % preferences.
91 % </AlgoDescription>
92 % <AlgoCode>
93 assert(strcmp(tz.getID(), char(prefs.getTimePrefs.getTimeTimezone)));
94 % </AlgoCode>
95 catch ex
96 atest = false;
97 % rethrow(ex)
98 end
99
100 % return a result structure
101 result = utp_prepare_result(atest, stest, dbstack, mfilename);
102 end
103
104
105 %% UTP_902
106
107 % <TestDescription>
108 %
109 % Change user preferences and do it again.
110 %
111 % </TestDescription>
112 function result = utp_902
113
114 % <SyntaxDescription>
115 % Set the timezone in the preferences then call the static timezone method.
116 % </SyntaxDescription>
117 stest = false;
118 try
119 % <SyntaxCode>
120 prefs.getTimePrefs.setTimeTimezone('GMT-12:00');
121 tz = time.timezone;
122 % </SyntaxCode>
123 stest = true;
124 end
125
126 atest = true;
127 try
128 % do not run algorithm tests if sintax tests failed
129 assert(stest);
130
131 % <AlgoDescription>
132 % Check the resulting timezone object against the one in the user
133 % preferences.
134 % </AlgoDescription>
135 % <AlgoCode>
136 assert(strcmp(tz.getID(), char(prefs.getTimePrefs.getTimeTimezone)));
137 % </AlgoCode>
138 catch ex
139 atest = false;
140 % rethrow(ex)
141 end
142
143 % return a result structure
144 result = utp_prepare_result(atest, stest, dbstack, mfilename);
145 end
146
147
148 %% UTP_903
149
150 % <TestDescription>
151 %
152 % Change user preferences and do it again.
153 %
154 % </TestDescription>
155 function result = utp_903
156
157 % <SyntaxDescription>
158 % Set the timezone in the preferences then call the static timezone method.
159 % </SyntaxDescription>
160 stest = false;
161 try
162 % <SyntaxCode>
163 prefs.getTimePrefs.setTimeTimezone('GMT+06:00');
164 tz = time.timezone;
165 % </SyntaxCode>
166 stest = true;
167 end
168
169 atest = true;
170 try
171 % do not run algorithm tests if sintax tests failed
172 assert(stest);
173
174 % <AlgoDescription>
175 % Check the resulting timezone object against the one in the user
176 % preferences.
177 % </AlgoDescription>
178 % <AlgoCode>
179 assert(strcmp(tz.getID(), char(prefs.getTimePrefs.getTimeTimezone)));
180 % </AlgoCode>
181 catch
182 atest = false;
183 end
184
185 % return a result structure
186 result = utp_prepare_result(atest, stest, dbstack, mfilename);
187 end
188
189 end