author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 11 May 2010 17:28:22 +0300 | |
branch | RCL_3 |
changeset 26 | c734af59ce98 |
parent 4 | 56f325a607ea |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32test\datetime\t_time.cpp |
|
15 |
// Overview: |
|
16 |
// Date & time tests |
|
17 |
// API Information: |
|
18 |
// TDateTime, TTimeInterval... |
|
19 |
// Details: |
|
20 |
// - Set various locale settings to known values. |
|
21 |
// - Test the TDateTime class by checking year, month, day, hour, minute, |
|
22 |
// second and microsecond ranges then verify setting individual ranges. |
|
23 |
// - Test TTimeIntervalMicroSeconds class: verify construction and initialization. |
|
24 |
// Verify the "=", "<", ">", "!=", ">=" and "<=" operators. |
|
25 |
// - Test TTimeIntervalSeconds class: verify construction and initialization. |
|
26 |
// Verify the "=", "<", ">", "!=", ">=" and "<=" operators. |
|
27 |
// - Test TTimeIntervalMinutes, TTimeIntervalHours, TTimeIntervalDays, |
|
28 |
// TTimeIntervalMonths and TTimeIntervalYears classes: verify construction, |
|
29 |
// initialization and "=" operator. |
|
30 |
// - Test conversions between TDateTime and TTime objects. |
|
31 |
// - Test adding and differencing between TDateTime and TTime objects. Including |
|
32 |
// the methods: YearsFrom, MonthsFrom, DaysFrom, HoursFrom, MinutesFrom, |
|
33 |
// SecondsFrom and MicroSecondsFrom. Also specific tests for adding months, |
|
34 |
// adding days, adding hours, adding minutes, adding seconds, adding microseconds |
|
35 |
// and invalid differences. |
|
36 |
// - Test adding and subtracting different TTimeIntervals and verify the results. |
|
37 |
// - Test TTime's date property functions. Verify results are as expected. |
|
38 |
// - Test different date formats and string parsing. Verify results are as expected. |
|
39 |
// - Test a variety of time change scenarios and verify results are as expected. |
|
40 |
// - Test the TTime::Set() method with different combinations of data, verify the |
|
41 |
// results are as expected. |
|
42 |
// - Test a variety of operations involving negative times. Verify results are |
|
43 |
// as expected. |
|
44 |
// - Test year 2000 and print the results. |
|
45 |
// - Test secure clock is not affected by changes |
|
46 |
// Platforms/Drives/Compatibility: |
|
47 |
// All. |
|
48 |
// Assumptions/Requirement/Pre-requisites: |
|
49 |
// Failures and causes: |
|
50 |
// Base Port information: |
|
51 |
// |
|
52 |
// |
|
53 |
||
54 |
#define __E32TEST_EXTENSION__ |
|
55 |
#include <e32test.h> |
|
56 |
#include <e32debug.h> |
|
57 |
#include <hal.h> |
|
58 |
||
59 |
LOCAL_D RTest test(_L("T_TIME")); |
|
60 |
||
61 |
// |
|
62 |
// duplication of local variable in UC_TIME |
|
63 |
LOCAL_D const TInt8 mTab[2][12]= |
|
64 |
{ |
|
65 |
{31,28,31,30,31,30,31,31,30,31,30,31}, // 28 days in Feb |
|
66 |
{31,29,31,30,31,30,31,31,30,31,30,31} // 29 days in Feb |
|
67 |
}; |
|
68 |
const TInt64 KDaysToMicroSeconds(MAKE_TINT64(20,500654080)); |
|
69 |
const TInt64 KHoursToMicroSeconds(3600000000u); |
|
70 |
const TInt KSecondsToMicroSeconds=1000000; |
|
71 |
||
72 |
class TestTTime |
|
73 |
{ |
|
74 |
public: |
|
75 |
void Test1(void); |
|
76 |
void Test2(void); |
|
77 |
void Test3(void); |
|
78 |
void Test4(void); |
|
79 |
void Test5(void); |
|
80 |
void Test6(void); |
|
81 |
void Test7(void); |
|
82 |
void Test8(void); |
|
83 |
void Test9(void); |
|
84 |
void Test10(void); |
|
85 |
void Test11(void); |
|
86 |
void Test12(void); |
|
87 |
void Test13(void); |
|
88 |
void TestSecureClock(void); |
|
89 |
}; |
|
90 |
||
91 |
||
92 |
void PrintTime(char* sz, TTime& t) |
|
93 |
{ |
|
94 |
TDateTime dateTime(t.DateTime()); |
|
95 |
RDebug::Printf("%s%+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d", sz, dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
96 |
} |
|
97 |
||
98 |
void TestTTime::Test1(void) |
|
99 |
// |
|
100 |
// Tests for TDateTime |
|
101 |
// |
|
102 |
{ |
|
103 |
TInt year=1980; //leap year |
|
104 |
TMonth month=EJanuary; |
|
105 |
TInt day=0; |
|
106 |
TInt hour=0; |
|
107 |
TInt minute=0; |
|
108 |
TInt second=0; |
|
109 |
TInt microSecond=10; |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
110 |
|
0 | 111 |
TDateTime dateTime(year,month,day,hour,minute,second,microSecond); |
112 |
||
113 |
test.Next(_L("Testing year ranges")); |
|
114 |
TInt ii; |
|
115 |
for (ii=1970; ii<2100; ii++) |
|
116 |
{ |
|
117 |
test(dateTime.Set(ii,ENovember,day,hour,minute,second,microSecond)==KErrNone); |
|
118 |
TTime time(dateTime); |
|
119 |
TDateTime dateTime2(time.DateTime()); |
|
120 |
test(dateTime2.Year()==ii); |
|
121 |
test(dateTime2.Month()==ENovember); |
|
122 |
test(dateTime2.Day()==day); |
|
123 |
test(dateTime2.Hour()==hour); |
|
124 |
test(dateTime2.Minute()==minute); |
|
125 |
test(dateTime2.Second()==second); |
|
126 |
test(dateTime2.MicroSecond()==microSecond); |
|
127 |
} |
|
128 |
||
129 |
test.Next(_L("Testing month ranges")); |
|
130 |
for (ii=0; ii<12; ii++) |
|
131 |
test(dateTime.Set(year,TMonth(ii),day,hour,minute,second,microSecond)==0); |
|
132 |
test(dateTime.Set(year,TMonth(12),day,hour,minute,second,microSecond)!=0); |
|
133 |
||
134 |
test.Next(_L("Testing day ranges")); |
|
135 |
for (ii=0; ii<12; ii++) |
|
136 |
{ |
|
137 |
test(dateTime.Set(year,TMonth(ii),(mTab[1][ii]-1),hour,minute,second,microSecond)==0); |
|
138 |
test(dateTime.Set(year+1,TMonth(ii),(mTab[0][ii]-1),hour,minute,second,microSecond)==0); |
|
139 |
test(dateTime.Set(year+1,TMonth(ii),(mTab[0][ii]),hour,minute,second,microSecond)!=0); |
|
140 |
} |
|
141 |
test(dateTime.Set(year,month,-1,hour,minute,second,microSecond)!=0); |
|
142 |
||
143 |
test.Next(_L("Testing hour ranges")); |
|
144 |
for (ii=0; ii<24; ii++) |
|
145 |
test(dateTime.Set(year,EMarch,10,ii,minute,second,microSecond)==0); |
|
146 |
test(dateTime.Set(year,EMarch,10,-1,minute,second,microSecond)!=0); |
|
147 |
test(dateTime.Set(year,EMarch,10,24,minute,second,microSecond)!=0); |
|
148 |
||
149 |
test.Next(_L("Testing minute ranges")); |
|
150 |
for (ii=0; ii<60; ii++) |
|
151 |
test(dateTime.Set(year,EMarch,0,0,ii,second,microSecond)==0); |
|
152 |
test(dateTime.Set(year,EMarch,0,0,-1,second,microSecond)!=0); |
|
153 |
test(dateTime.Set(year,EMarch,0,0,60,second,microSecond)!=0); |
|
154 |
||
155 |
test.Next(_L("Testing second ranges")); |
|
156 |
for (ii=0; ii<60; ii++) |
|
157 |
test(dateTime.Set(year,EMarch,0,0,0,ii,microSecond)==0); |
|
158 |
test(dateTime.Set(year,EMarch,0,0,0,-1,microSecond)!=0); |
|
159 |
test(dateTime.Set(year,EMarch,0,0,0,60,microSecond)!=0); |
|
160 |
||
161 |
test.Next(_L("Testing microsecond ranges")); |
|
162 |
for (ii=0; ii<100; ii++) |
|
163 |
test(dateTime.Set(year,EMarch,0,0,0,0,ii)==0); |
|
164 |
test(dateTime.Set(year,EMarch,0,0,0,0,-1)!=0); |
|
165 |
test(dateTime.Set(year,EMarch,0,0,0,0,1000000)!=0); |
|
166 |
||
167 |
test.Next(_L("Testing setting individual ranges")); |
|
168 |
||
169 |
dateTime.Set(year,month,day,hour,minute,second,microSecond); |
|
170 |
year=1984; |
|
171 |
test(dateTime.SetYear(year)==0); |
|
172 |
test(dateTime.Year()==year); |
|
173 |
test(dateTime.Month()==month); |
|
174 |
test(dateTime.Day()==day); |
|
175 |
test(dateTime.Hour()==hour); |
|
176 |
test(dateTime.Minute()==minute); |
|
177 |
test(dateTime.Second()==second); |
|
178 |
test(dateTime.MicroSecond()==microSecond); |
|
179 |
month=EFebruary; |
|
180 |
test(dateTime.SetMonth(month)==0); |
|
181 |
test(dateTime.SetYear(year)==0); |
|
182 |
test(dateTime.Year()==year); |
|
183 |
test(dateTime.Month()==month); |
|
184 |
test(dateTime.Day()==day); |
|
185 |
test(dateTime.Hour()==hour); |
|
186 |
test(dateTime.Minute()==minute); |
|
187 |
test(dateTime.Second()==second); |
|
188 |
test(dateTime.MicroSecond()==microSecond); |
|
189 |
day=28; |
|
190 |
test(dateTime.SetDay(day)==0); |
|
191 |
test(dateTime.SetYear(year)==0); |
|
192 |
test(dateTime.Year()==year); |
|
193 |
test(dateTime.Month()==month); |
|
194 |
test(dateTime.Day()==day); |
|
195 |
test(dateTime.Hour()==hour); |
|
196 |
test(dateTime.Minute()==minute); |
|
197 |
test(dateTime.Second()==second); |
|
198 |
test(dateTime.MicroSecond()==microSecond); |
|
199 |
hour=12; |
|
200 |
test(dateTime.SetHour(hour)==0); |
|
201 |
test(dateTime.SetYear(year)==0); |
|
202 |
test(dateTime.Year()==year); |
|
203 |
test(dateTime.Month()==month); |
|
204 |
test(dateTime.Day()==day); |
|
205 |
test(dateTime.Hour()==hour); |
|
206 |
test(dateTime.Minute()==minute); |
|
207 |
test(dateTime.Second()==second); |
|
208 |
test(dateTime.MicroSecond()==microSecond); |
|
209 |
minute=57; |
|
210 |
test(dateTime.SetMinute(minute)==0); |
|
211 |
test(dateTime.SetYear(year)==0); |
|
212 |
test(dateTime.Year()==year); |
|
213 |
test(dateTime.Month()==month); |
|
214 |
test(dateTime.Day()==day); |
|
215 |
test(dateTime.Hour()==hour); |
|
216 |
test(dateTime.Minute()==minute); |
|
217 |
test(dateTime.Second()==second); |
|
218 |
test(dateTime.MicroSecond()==microSecond); |
|
219 |
second=2; |
|
220 |
test(dateTime.SetSecond(second)==0); |
|
221 |
test(dateTime.SetYear(year)==0); |
|
222 |
test(dateTime.Year()==year); |
|
223 |
test(dateTime.Month()==month); |
|
224 |
test(dateTime.Day()==day); |
|
225 |
test(dateTime.Hour()==hour); |
|
226 |
test(dateTime.Minute()==minute); |
|
227 |
test(dateTime.Second()==second); |
|
228 |
test(dateTime.MicroSecond()==microSecond); |
|
229 |
microSecond=99999; |
|
230 |
test(dateTime.SetMicroSecond(microSecond)==0); |
|
231 |
test(dateTime.SetYear(year)==0); |
|
232 |
test(dateTime.Year()==year); |
|
233 |
test(dateTime.Month()==month); |
|
234 |
test(dateTime.Day()==day); |
|
235 |
test(dateTime.Hour()==hour); |
|
236 |
test(dateTime.Minute()==minute); |
|
237 |
test(dateTime.Second()==second); |
|
238 |
test(dateTime.MicroSecond()==microSecond); |
|
239 |
||
240 |
test(dateTime.SetYear(1981)!=0); |
|
241 |
test(dateTime.SetMonth((TMonth)15)!=0); |
|
242 |
test(dateTime.SetDay(-1)!=0); |
|
243 |
test(dateTime.SetHour(100)!=0); |
|
244 |
test(dateTime.SetMinute(-15)!=0); |
|
245 |
test(dateTime.SetSecond(60)!=0); |
|
246 |
test(dateTime.SetMicroSecond(-2)!=0); |
|
247 |
test(dateTime.Year()==year); |
|
248 |
test(dateTime.Month()==month); |
|
249 |
test(dateTime.Day()==day); |
|
250 |
test(dateTime.Hour()==hour); |
|
251 |
test(dateTime.Minute()==minute); |
|
252 |
test(dateTime.Second()==second); |
|
253 |
test(dateTime.MicroSecond()==microSecond); |
|
254 |
} |
|
255 |
||
256 |
void TestTTime::Test2(void) |
|
257 |
// |
|
258 |
// Tests for TTimeIntervalMicroSeconds |
|
259 |
// |
|
260 |
{ |
|
261 |
test.Next(_L("Construction")); |
|
262 |
TTimeIntervalMicroSeconds t1; // uninitialised |
|
263 |
TTimeIntervalMicroSeconds t2(0); |
|
264 |
test(t2.Int64()==0 ); |
|
265 |
TTimeIntervalMicroSeconds t3(1000000); |
|
266 |
test(t3.Int64()==1000000 ); |
|
267 |
TTimeIntervalMicroSeconds t4(-452); |
|
268 |
test(t4.Int64()==-452 ); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
|
0 | 270 |
TTimeIntervalMicroSeconds t5(MAKE_TINT64(0x7fffffff,0xffffffff)); |
271 |
t5.Int64(); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
|
0 | 273 |
test.Next(_L("operator =")); |
274 |
TInt num(1234); |
|
275 |
t1=num; |
|
276 |
t2=t1; |
|
277 |
test(t1.Int64()==t2.Int64()); |
|
278 |
||
279 |
test.Next(_L("operator <")); |
|
280 |
test((t4<t1)!=0); |
|
281 |
test((t3<t2)==0); |
|
282 |
test((t2<t3)!=0); |
|
283 |
||
284 |
test.Next(_L("operator >")); |
|
285 |
test((t1>t4)!=0); |
|
286 |
test((t2>t3)==0); |
|
287 |
test((t2>t1)==0); |
|
288 |
||
289 |
test.Next(_L("operator !=")); |
|
290 |
test((t1!=t3)!=0); |
|
291 |
test((t1!=t2)==0); |
|
292 |
||
293 |
test.Next(_L("operator >=")); |
|
294 |
test((t3>=t4)!=0); |
|
295 |
test((t1>=t2)!=0); |
|
296 |
test((t1>=t3)==0); |
|
297 |
||
298 |
test.Next(_L("operator <=")); |
|
299 |
test((t4<=t3)!=0); |
|
300 |
test((t1<=t2)!=0); |
|
301 |
test((t3<=t2)==0); |
|
302 |
} |
|
303 |
||
304 |
void TestTTime::Test3(void) |
|
305 |
// |
|
306 |
// Tests for TTimeIntervaSeconds (and therefore TTimeIntervalBase) |
|
307 |
// |
|
308 |
{ |
|
309 |
test.Next(_L("Construction")); |
|
310 |
TTimeIntervalSeconds s1; // uninitialised |
|
311 |
TTimeIntervalSeconds s2(0); |
|
312 |
test(s2.Int()==0 ); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
|
0 | 314 |
TTimeIntervalSeconds s3(1); |
315 |
test(s3.Int()==1 ); |
|
316 |
test(s3.Int()!=0 ); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
|
0 | 318 |
TTimeIntervalSeconds s4(-1); |
319 |
test(s4.Int()==-1 ); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
|
0 | 321 |
TTimeIntervalSeconds s8(2147483647); |
322 |
test(s8.Int()== 2147483647); |
|
323 |
||
324 |
test.Next(_L("operator =")); |
|
325 |
s1=0; |
|
326 |
test(s1.Int()==0 ); |
|
327 |
TTimeIntervalSeconds s5(5),s6; |
|
328 |
s6=s5; |
|
329 |
test(s5.Int()==s6.Int()); |
|
330 |
s6=3; |
|
331 |
test(s5.Int()!=s6.Int()); |
|
332 |
||
333 |
test.Next(_L("operator <")); |
|
334 |
test((s6<s3)==0); |
|
335 |
test((s3<s5)!=0); |
|
336 |
test((s4<s1)!=0); |
|
337 |
||
338 |
test.Next(_L("operator >")); |
|
339 |
test((s3>s6)==0); |
|
340 |
test((s5>s3)!=0); |
|
341 |
test((s1>s4)!=0); |
|
342 |
||
343 |
test.Next(_L("operator !=")); |
|
344 |
s6=s5; |
|
345 |
test((s6!=s5)==0); |
|
346 |
test((s3!=s4)!=0); |
|
347 |
test((s1!=s2)==0); |
|
348 |
||
349 |
test.Next(_L("operator >=")); |
|
350 |
test((s1>=s6)==0); |
|
351 |
test((s3>=s5)==0); |
|
352 |
test((s5>=s3)!=0); |
|
353 |
test((s6>=s5)!=0); |
|
354 |
test((s1>=s2)!=0); |
|
355 |
||
356 |
test.Next(_L("operator <=")); |
|
357 |
test((s6<=s1)==0); |
|
358 |
test((s5<=s3)==0); |
|
359 |
test((s3<=s5)!=0); |
|
360 |
test((s6<=s5)!=0); |
|
361 |
test((s1<=s2)!=0); |
|
362 |
} |
|
363 |
||
364 |
void TestTTime::Test4() |
|
365 |
// |
|
366 |
// Tests for all other time intervals |
|
367 |
// |
|
368 |
{ |
|
369 |
test.Next(_L("TTimeIntervalMinutes")); |
|
370 |
test.Next(_L("Construction")); |
|
371 |
TTimeIntervalMinutes m1; // uninitialised |
|
372 |
TTimeIntervalMinutes m2(0); |
|
373 |
test(m2.Int()==0 ); |
|
374 |
TTimeIntervalMinutes m3(1); |
|
375 |
test(m3.Int()==1 ); |
|
376 |
test(m3.Int()!=0 ); |
|
377 |
TTimeIntervalMinutes m4a(-1); |
|
378 |
test(m4a.Int()==-1 ); |
|
379 |
TTimeIntervalMinutes m4(0xffffffff); |
|
380 |
test((TUint)m4.Int()==0xffffffff); |
|
381 |
test.Next(_L("operator =")); |
|
382 |
m1=0; |
|
383 |
test(m1.Int()==0 ); |
|
384 |
TTimeIntervalMinutes m5(5),m6; |
|
385 |
m6=m5; |
|
386 |
test(m5.Int()==m6.Int()); |
|
387 |
m6=3; |
|
388 |
m5=m6; |
|
389 |
test(m5.Int()==m6.Int()); |
|
390 |
||
391 |
test.Next(_L("TTimeIntervalHours")); |
|
392 |
test.Next(_L("Construction")); |
|
393 |
TTimeIntervalHours h1; // uninitialised |
|
394 |
TTimeIntervalHours h2(0); |
|
395 |
test(h2.Int()==0 ); |
|
396 |
TTimeIntervalHours h3(1); |
|
397 |
test(h3.Int()==1 ); |
|
398 |
test(h3.Int()!=0 ); |
|
399 |
TTimeIntervalHours h4a(-1); |
|
400 |
test(h4a.Int()==-1 ); |
|
401 |
TTimeIntervalHours h4(0xffffffff); |
|
402 |
test((TUint)h4.Int()==0xffffffff); |
|
403 |
test.Next(_L("operator =")); |
|
404 |
h1=0; |
|
405 |
test(h1.Int()==0 ); |
|
406 |
TTimeIntervalHours h5(5),h6; |
|
407 |
h6=h5; |
|
408 |
test(h5.Int()==h6.Int()); |
|
409 |
||
410 |
test.Next(_L("TTImeIntervalDays")); |
|
411 |
test.Next(_L("Construction")); |
|
412 |
TTimeIntervalDays d1; // uninitialised |
|
413 |
TTimeIntervalDays d2(0); |
|
414 |
test(d2.Int()==0 ); |
|
415 |
TTimeIntervalDays d3(1); |
|
416 |
test(d3.Int()==1 ); |
|
417 |
test(d3.Int()!=0 ); |
|
418 |
TTimeIntervalDays d4a(-1); |
|
419 |
test(d4a.Int()==-1 ); |
|
420 |
TTimeIntervalDays d4(0xffffffff); |
|
421 |
test((TUint)d4.Int()==0xffffffff); |
|
422 |
test.Next(_L("operator =")); |
|
423 |
d1=0; |
|
424 |
test(d1.Int()==0 ); |
|
425 |
TTimeIntervalDays d5(5),d6; |
|
426 |
d6=d5; |
|
427 |
test(d5.Int()==d6.Int()); |
|
428 |
||
429 |
test.Next(_L("TTimeIntervalMonths")); |
|
430 |
test.Next(_L("Construction")); |
|
431 |
TTimeIntervalMonths mo1; // uninitialised |
|
432 |
TTimeIntervalMonths mo2(0); |
|
433 |
test(mo2.Int()==0 ); |
|
434 |
TTimeIntervalMonths mo3(1); |
|
435 |
test(mo3.Int()==1 ); |
|
436 |
test(mo3.Int()!=0 ); |
|
437 |
TTimeIntervalMonths mo4a(-1); |
|
438 |
test(mo4a.Int()==-1 ); |
|
439 |
TTimeIntervalMonths mo4(0xffffffff); |
|
440 |
test((TUint)mo4.Int()==0xffffffff); |
|
441 |
test.Next(_L("operator =")); |
|
442 |
mo1=0; |
|
443 |
test(mo1.Int()==0 ); |
|
444 |
TTimeIntervalMonths mo5(5),mo6; |
|
445 |
mo6=mo5; |
|
446 |
test(mo5.Int()==mo6.Int()); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
447 |
|
0 | 448 |
test.Next(_L("TTimeIntervalYears")); |
449 |
test.Next(_L("Construction")); |
|
450 |
TTimeIntervalYears y1; // uninitialised |
|
451 |
TTimeIntervalYears y2(0); |
|
452 |
test(y2.Int()==0 ); |
|
453 |
TTimeIntervalYears y3(1); |
|
454 |
test(y3.Int()==1 ); |
|
455 |
test(y3.Int()!=0 ); |
|
456 |
TTimeIntervalYears y4a(-1); |
|
457 |
test(y4a.Int()==-1 ); |
|
458 |
TTimeIntervalYears y4(0xffffffff); |
|
459 |
test((TUint)y4.Int()==0xffffffff); |
|
460 |
test.Next(_L("operator =")); |
|
461 |
y1=0; |
|
462 |
test(y1.Int()==0 ); |
|
463 |
TTimeIntervalYears y5(17),y6; |
|
464 |
y6=y5; |
|
465 |
test(y5.Int()==y6.Int()); |
|
466 |
y6=16; |
|
467 |
test(y5.Int()!=y6.Int()); |
|
468 |
y5=16; |
|
469 |
test(y5.Int()==y6.Int()); |
|
470 |
} |
|
471 |
||
472 |
||
473 |
void TestTTime::Test5() |
|
474 |
// |
|
475 |
// TDateTime to TTime convertions and vice versa, very large loop, so in own function for easy removal |
|
476 |
// |
|
477 |
{ |
|
478 |
TInt microSecond=500000; |
|
479 |
TDateTime dateTime(0,EJanuary,0,0,0,0,microSecond); |
|
480 |
TInt year; |
|
481 |
for(year=1590;year<1710;year+=2) |
|
482 |
{ |
|
483 |
dateTime.SetYear(year); |
|
484 |
for(TInt m=0;m<6;m++) |
|
485 |
{ |
|
486 |
static TInt months[]={0,1,2,8,9,11}; |
|
487 |
TInt month=months[m]; |
|
488 |
dateTime.SetDay(0); // to make sure next line always suceeds |
|
489 |
dateTime.SetMonth((TMonth)month); |
|
490 |
for(TInt d=0;d<6;d++) |
|
491 |
{ |
|
492 |
static TInt days[]={0,1,27,28,29,30}; |
|
493 |
TInt day=days[d]; |
|
494 |
if (day>=mTab[Time::IsLeapYear(year)][month]) |
|
495 |
break; |
|
496 |
dateTime.SetDay(day); |
|
497 |
for(TInt h=0;h<4;h++) |
|
498 |
{ |
|
499 |
static TInt hours[]={0,11,12,23}; |
|
500 |
TInt hour=hours[h]; |
|
501 |
dateTime.SetHour(hour); |
|
502 |
for(TInt minute=0;minute<60;minute+=59) |
|
503 |
{ |
|
504 |
dateTime.SetMinute(minute); |
|
505 |
for(TInt second=0;second<60;second+=59) |
|
506 |
{ |
|
507 |
dateTime.SetSecond(second); |
|
508 |
TTime tim(dateTime); |
|
509 |
dateTime = tim.DateTime(); |
|
510 |
test(dateTime.Year()==year); |
|
511 |
test(dateTime.Month()==(TMonth)month); |
|
512 |
test(dateTime.Day()==day); |
|
513 |
test(dateTime.Hour()==hour); |
|
514 |
test(dateTime.Minute()==minute); |
|
515 |
test(dateTime.Second()==second); |
|
516 |
test(dateTime.MicroSecond()==microSecond); |
|
517 |
} |
|
518 |
} |
|
519 |
} |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
523 |
||
524 |
// smaller loop for -ve dates |
|
525 |
for (year=-150; year<5; year+=15) |
|
526 |
{ |
|
527 |
dateTime.SetYear(year); |
|
528 |
for(TInt month=0; month<12; month+=5) |
|
529 |
{ |
|
530 |
dateTime.SetDay(0); // to make sure next line always suceeds |
|
531 |
dateTime.SetMonth((TMonth)month); |
|
532 |
for(TInt day=0; day<30; day+=7) |
|
533 |
{ |
|
534 |
if (day>=mTab[Time::IsLeapYear(year)][month]) |
|
535 |
break; |
|
536 |
dateTime.SetDay(day); |
|
537 |
for(TInt hour=0; hour<24; hour+=6) |
|
538 |
{ |
|
539 |
dateTime.SetHour(hour); |
|
540 |
for(TInt minute=0; minute<60; minute+=15) |
|
541 |
{ |
|
542 |
dateTime.SetMinute(minute); |
|
543 |
for(TInt second=0; second<60; second+=20) |
|
544 |
{ |
|
545 |
dateTime.SetSecond(second); |
|
546 |
TTime tim(dateTime); |
|
547 |
dateTime = tim.DateTime(); |
|
548 |
test(dateTime.Year()==year); |
|
549 |
test(dateTime.Month()==(TMonth)month); |
|
550 |
test(dateTime.Day()==day); |
|
551 |
test(dateTime.Hour()==hour); |
|
552 |
test(dateTime.Minute()==minute); |
|
553 |
test(dateTime.Second()==second); |
|
554 |
test(dateTime.MicroSecond()==microSecond); |
|
555 |
} |
|
556 |
} |
|
557 |
} |
|
558 |
} |
|
559 |
} |
|
560 |
} |
|
561 |
||
562 |
TTime tim(MAKE_TINT64(0x7fffffff,0xffffffff)); |
|
563 |
dateTime = tim.DateTime(); |
|
564 |
tim = dateTime; |
|
565 |
test(tim.Int64()==MAKE_TINT64(0x7fffffff,0xffffffff)); |
|
566 |
} |
|
567 |
||
568 |
void TestTTime::Test6() |
|
569 |
// |
|
570 |
// Adding and differencing |
|
571 |
// |
|
572 |
{ |
|
573 |
TDateTime dateTime(4,EJanuary,30,0,0,0,0); |
|
574 |
||
575 |
test.Next(_L("TTimeIntervalYears")); |
|
576 |
TTime base=dateTime; |
|
577 |
TTimeIntervalYears year(1); |
|
578 |
TTime result=base+year; |
|
579 |
dateTime=result.DateTime(); |
|
580 |
test(dateTime.Year()==5); |
|
581 |
test(dateTime.Month()==EJanuary); |
|
582 |
test(dateTime.Day()==30); |
|
583 |
test(result.YearsFrom(base)==year); |
|
584 |
year=2000; |
|
585 |
result+=year; |
|
586 |
dateTime=result.DateTime(); |
|
587 |
test(dateTime.Year()==2005); |
|
588 |
test(dateTime.Month()==EJanuary); |
|
589 |
test(dateTime.Day()==30); |
|
590 |
test(result.YearsFrom(base)==TTimeIntervalYears(2001)); |
|
591 |
test(base.YearsFrom(result)==TTimeIntervalYears(-2001)); |
|
592 |
||
593 |
test.Next(_L("YearsFrom")); |
|
594 |
TTime timeNow; |
|
595 |
timeNow.HomeTime(); |
|
596 |
TTime timeFuture=timeNow+TTimeIntervalYears(10); |
|
597 |
test(timeFuture.YearsFrom(timeNow).Int()==10); |
|
598 |
test(timeNow.YearsFrom(timeFuture).Int()==-10); |
|
599 |
TTime mintime = Time::MinTTime(); |
|
600 |
test(timeNow.YearsFrom(mintime).Int()>0);//must be positive value |
|
601 |
test(mintime.YearsFrom(timeNow).Int()<0);//must be negative value |
|
602 |
TTime maxtime = Time::MaxTTime(); |
|
603 |
test(timeNow.YearsFrom(maxtime).Int()<0);//must be negative value |
|
604 |
test(maxtime.YearsFrom(timeNow).Int()>0);//must be positive value |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
605 |
|
0 | 606 |
test.Next(_L("Adding months")); |
607 |
TTimeIntervalMonths month(1); |
|
608 |
result=base+month; |
|
609 |
dateTime=result.DateTime(); |
|
610 |
test(dateTime.Year()==4); |
|
611 |
test(dateTime.Month()==EFebruary); |
|
612 |
test(dateTime.Day()==28); // leap year |
|
613 |
test(result.YearsFrom(base)==TTimeIntervalYears(0)); |
|
614 |
test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
|
615 |
test(result.MonthsFrom(base)==month); |
|
616 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(-month.Int())); |
|
617 |
month=12; |
|
618 |
result+=month; |
|
619 |
dateTime=result.DateTime(); |
|
620 |
test(dateTime.Year()==5); |
|
621 |
test(dateTime.Month()==EFebruary); |
|
622 |
test(dateTime.Day()==27); // not aleap year |
|
623 |
test(result.YearsFrom(base)==TTimeIntervalYears(1)); |
|
624 |
test(base.YearsFrom(result)==TTimeIntervalYears(-1)); |
|
625 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(13)); |
|
626 |
test(base.MonthsFrom(result)==TTimeIntervalYears(-13)); |
|
627 |
||
628 |
test.Next(_L("MonthsFrom")); |
|
629 |
timeNow.HomeTime(); |
|
630 |
timeFuture=timeNow+TTimeIntervalMonths(10); |
|
631 |
test(timeFuture.MonthsFrom(timeNow).Int()==10); |
|
632 |
test(timeNow.MonthsFrom(timeFuture).Int()==-10); |
|
633 |
test(timeNow.MonthsFrom(mintime).Int()>0);//must be positive value |
|
634 |
test(mintime.MonthsFrom(timeNow).Int()<0);//must be negative value |
|
635 |
test(timeNow.MonthsFrom(maxtime).Int()<0);//must be negative value |
|
636 |
test(maxtime.MonthsFrom(timeNow).Int()>0);//must be positive value |
|
637 |
||
638 |
test.Next(_L("Adding days")); |
|
639 |
TTimeIntervalDays day(1); |
|
640 |
result=base+day; |
|
641 |
dateTime=result.DateTime(); |
|
642 |
test(dateTime.Year()==4); |
|
643 |
test(dateTime.Month()==EFebruary); |
|
644 |
test(dateTime.Day()==0); |
|
645 |
test(result.YearsFrom(base)==TTimeIntervalYears(0)); |
|
646 |
test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
|
647 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
|
648 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
|
649 |
test(result.DaysFrom(base)==day); |
|
650 |
test(base.DaysFrom(result)==TTimeIntervalDays(-day.Int())); |
|
651 |
day=60; |
|
652 |
result+=day; |
|
653 |
dateTime=result.DateTime(); |
|
654 |
test(dateTime.Year()==4); |
|
655 |
test(dateTime.Month()==EApril); |
|
656 |
test(dateTime.Day()==0); |
|
657 |
test(result.YearsFrom(base)==TTimeIntervalYears(0)); |
|
658 |
test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
|
659 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(2)); |
|
660 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(-2)); |
|
661 |
test(result.DaysFrom(base)==TTimeIntervalDays(61)); |
|
662 |
test(base.DaysFrom(result)==TTimeIntervalDays(-61)); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
663 |
|
0 | 664 |
test.Next(_L("DaysFrom")); |
665 |
timeNow.HomeTime(); |
|
666 |
timeFuture=timeNow+TTimeIntervalDays(10); |
|
667 |
test(timeFuture.DaysFrom(timeNow).Int()==10); |
|
668 |
test(timeNow.DaysFrom(timeFuture).Int()==-10); |
|
669 |
test(timeNow.DaysFrom(mintime).Int()>0);//must be positive value |
|
670 |
test(mintime.DaysFrom(timeNow).Int()<0);//must be negative value |
|
671 |
test(timeNow.DaysFrom(maxtime).Int()<0);//must be negative value |
|
672 |
test(maxtime.DaysFrom(timeNow).Int()>0);//must be positive value |
|
673 |
||
674 |
test.Next(_L("Adding hours")); |
|
675 |
TTimeIntervalHours hour(6); |
|
676 |
result=base+hour; |
|
677 |
dateTime=result.DateTime(); |
|
678 |
test(dateTime.Year()==4); |
|
679 |
test(dateTime.Month()==EJanuary); |
|
680 |
test(dateTime.Day()==30); |
|
681 |
test(dateTime.Hour()==6); |
|
682 |
test(result.YearsFrom(base)==TTimeIntervalYears(0)); |
|
683 |
test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
|
684 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
|
685 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
|
686 |
test(result.DaysFrom(base)==TTimeIntervalDays(0)); |
|
687 |
test(base.DaysFrom(result)==TTimeIntervalDays(0)); |
|
688 |
TInt ret=result.HoursFrom(base,hour); |
|
689 |
test(ret==0); |
|
690 |
test(hour==TTimeIntervalHours(6)); |
|
691 |
ret=base.HoursFrom(result,hour); |
|
692 |
test(ret==0); |
|
693 |
test(hour==TTimeIntervalHours(-6)); |
|
694 |
hour=20; |
|
695 |
result+=hour; |
|
696 |
dateTime=result.DateTime(); |
|
697 |
test(dateTime.Year()==4); |
|
698 |
test(dateTime.Month()==EFebruary); |
|
699 |
test(dateTime.Day()==0); |
|
700 |
test(dateTime.Hour()==2); |
|
701 |
test(result.YearsFrom(base)==TTimeIntervalYears(0)); |
|
702 |
test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
|
703 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
|
704 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
|
705 |
test(result.DaysFrom(base)==TTimeIntervalDays(1)); |
|
706 |
test(base.DaysFrom(result)==TTimeIntervalDays(-1)); |
|
707 |
ret=result.HoursFrom(base,hour); |
|
708 |
test(ret==0); |
|
709 |
test(hour==TTimeIntervalHours(26)); |
|
710 |
ret=base.HoursFrom(result,hour); |
|
711 |
test(ret==0); |
|
712 |
test(hour==TTimeIntervalHours(-26)); |
|
713 |
||
714 |
test.Next(_L("HoursFrom")); |
|
715 |
timeNow.HomeTime(); |
|
716 |
timeFuture=timeNow+TTimeIntervalHours(10); |
|
717 |
test(timeFuture.HoursFrom(timeNow,hour)==KErrNone); |
|
718 |
test(hour.Int()==10); |
|
719 |
test(timeNow.HoursFrom(timeFuture,hour)==KErrNone); |
|
720 |
test(hour.Int()==-10); // fails this in 059 |
|
721 |
timeFuture=timeNow+TTimeIntervalHours(KMaxTInt); |
|
722 |
test(timeFuture.HoursFrom(timeNow,hour)==KErrNone); |
|
723 |
test(hour.Int()==KMaxTInt); |
|
724 |
test(timeNow.HoursFrom(timeFuture,hour)==KErrNone); |
|
725 |
test(hour.Int()==-KMaxTInt); |
|
726 |
timeFuture=timeFuture+TTimeIntervalHours(1); |
|
727 |
test(timeFuture.HoursFrom(timeNow,hour)==KErrOverflow); |
|
728 |
test(timeNow.HoursFrom(timeFuture,hour)==KErrNone); |
|
729 |
test(hour.Int()==KMinTInt); |
|
730 |
timeFuture=timeFuture+TTimeIntervalHours(1); |
|
731 |
test(timeFuture.HoursFrom(timeNow,hour)==KErrOverflow); |
|
732 |
test(timeNow.HoursFrom(timeFuture,hour)==KErrOverflow); |
|
733 |
||
734 |
test.Next(_L("Adding minutes")); |
|
735 |
TTimeIntervalMinutes minute(73); |
|
736 |
result=base+minute; |
|
737 |
dateTime=result.DateTime(); |
|
738 |
test(dateTime.Year()==4); |
|
739 |
test(dateTime.Month()==EJanuary); |
|
740 |
test(dateTime.Day()==30); |
|
741 |
test(dateTime.Hour()==1); |
|
742 |
test(dateTime.Minute()==13); |
|
743 |
test(result.YearsFrom(base)==TTimeIntervalYears(0)); |
|
744 |
test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
|
745 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
|
746 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
|
747 |
test(result.DaysFrom(base)==TTimeIntervalDays(0)); |
|
748 |
test(base.DaysFrom(result)==TTimeIntervalDays(0)); |
|
749 |
ret=result.HoursFrom(base,hour); |
|
750 |
test(ret==0); |
|
751 |
test(hour==TTimeIntervalHours(1)); |
|
752 |
ret=base.HoursFrom(result,hour); |
|
753 |
test(ret==0); |
|
754 |
test(hour==TTimeIntervalHours(-1)); |
|
755 |
ret=result.MinutesFrom(base,minute); |
|
756 |
test(ret==0); |
|
757 |
test(minute==TTimeIntervalMinutes(73)); |
|
758 |
ret=base.MinutesFrom(result,minute); |
|
759 |
test(ret==0); |
|
760 |
test(minute==TTimeIntervalMinutes(-73)); |
|
761 |
minute=1367; |
|
762 |
result+=minute; |
|
763 |
dateTime=result.DateTime(); |
|
764 |
test(dateTime.Year()==4); |
|
765 |
test(dateTime.Month()==EFebruary); |
|
766 |
test(dateTime.Day()==0); |
|
767 |
test(dateTime.Hour()==0); |
|
768 |
test(dateTime.Minute()==0); |
|
769 |
test(result.YearsFrom(base)==TTimeIntervalYears(0)); |
|
770 |
test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
|
771 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
|
772 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
|
773 |
test(result.DaysFrom(base)==TTimeIntervalDays(1)); |
|
774 |
test(base.DaysFrom(result)==TTimeIntervalDays(-1)); |
|
775 |
ret=result.HoursFrom(base,hour); |
|
776 |
test(ret==0); |
|
777 |
test(hour==TTimeIntervalHours(24)); |
|
778 |
ret=base.HoursFrom(result,hour); |
|
779 |
test(ret==0); |
|
780 |
test(hour==TTimeIntervalHours(-24)); |
|
781 |
ret=result.MinutesFrom(base,minute); |
|
782 |
test(ret==0); |
|
783 |
test(minute==TTimeIntervalMinutes(1440)); |
|
784 |
ret=base.MinutesFrom(result,minute); |
|
785 |
test(ret==0); |
|
786 |
test(minute==TTimeIntervalMinutes(-1440)); |
|
787 |
||
788 |
test.Next(_L("MinutesFrom")); |
|
789 |
timeNow.HomeTime(); |
|
790 |
timeFuture=timeNow+TTimeIntervalMinutes(10); |
|
791 |
test(timeFuture.MinutesFrom(timeNow,minute)==KErrNone); |
|
792 |
test(minute.Int()==10); |
|
793 |
test(timeNow.MinutesFrom(timeFuture,minute)==KErrNone); |
|
794 |
test(minute.Int()==-10); // fails this in 059 |
|
795 |
timeFuture=timeNow+TTimeIntervalMinutes(KMaxTInt); |
|
796 |
test(timeFuture.MinutesFrom(timeNow,minute)==KErrNone); |
|
797 |
test(minute.Int()==KMaxTInt); |
|
798 |
test(timeNow.MinutesFrom(timeFuture,minute)==KErrNone); |
|
799 |
test(minute.Int()==-KMaxTInt); |
|
800 |
timeFuture=timeFuture+TTimeIntervalMinutes(1); |
|
801 |
test(timeFuture.MinutesFrom(timeNow,minute)==KErrOverflow); |
|
802 |
test(timeNow.MinutesFrom(timeFuture,minute)==KErrNone); |
|
803 |
test(minute.Int()==KMinTInt); |
|
804 |
timeFuture=timeFuture+TTimeIntervalMinutes(1); |
|
805 |
test(timeFuture.MinutesFrom(timeNow,minute)==KErrOverflow); |
|
806 |
test(timeNow.MinutesFrom(timeFuture,minute)==KErrOverflow); |
|
807 |
||
808 |
test.Next(_L("Adding seconds")); |
|
809 |
TTimeIntervalSeconds second(305222); |
|
810 |
result=base+second; |
|
811 |
dateTime=result.DateTime(); |
|
812 |
test(dateTime.Year()==4); |
|
813 |
test(dateTime.Month()==EFebruary); |
|
814 |
test(dateTime.Day()==2); |
|
815 |
test(dateTime.Hour()==12); |
|
816 |
test(dateTime.Minute()==47); |
|
817 |
test(dateTime.Second()==2); |
|
818 |
test(result.YearsFrom(base)==TTimeIntervalYears(0)); |
|
819 |
test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
|
820 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
|
821 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
|
822 |
test(result.DaysFrom(base)==TTimeIntervalDays(3)); |
|
823 |
test(base.DaysFrom(result)==TTimeIntervalDays(-3)); |
|
824 |
ret=result.HoursFrom(base,hour); |
|
825 |
test(ret==0); |
|
826 |
test(hour==TTimeIntervalHours(84)); |
|
827 |
ret=base.HoursFrom(result,hour); |
|
828 |
test(ret==0); |
|
829 |
test(hour==TTimeIntervalHours(-84)); |
|
830 |
ret=result.MinutesFrom(base,minute); |
|
831 |
test(ret==0); |
|
832 |
test(minute==TTimeIntervalMinutes(5087)); |
|
833 |
ret=base.MinutesFrom(result,minute); |
|
834 |
test(ret==0); |
|
835 |
test(minute==TTimeIntervalMinutes(-5087)); |
|
836 |
ret=result.SecondsFrom(base,second); |
|
837 |
test(ret==0); |
|
838 |
test(second==TTimeIntervalSeconds(305222)); |
|
839 |
ret=base.SecondsFrom(result,second); |
|
840 |
test(ret==0); |
|
841 |
test(second==TTimeIntervalSeconds(-305222)); |
|
842 |
second=58; |
|
843 |
result+=second; |
|
844 |
dateTime=result.DateTime(); |
|
845 |
test(dateTime.Year()==4); |
|
846 |
test(dateTime.Month()==EFebruary); |
|
847 |
test(dateTime.Day()==2); |
|
848 |
test(dateTime.Hour()==12); |
|
849 |
test(dateTime.Minute()==48); |
|
850 |
test(dateTime.Second()==0); |
|
851 |
test(result.YearsFrom(base)==TTimeIntervalYears(0)); |
|
852 |
test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
|
853 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
|
854 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
|
855 |
test(result.DaysFrom(base)==TTimeIntervalDays(3)); |
|
856 |
test(base.DaysFrom(result)==TTimeIntervalDays(-3)); |
|
857 |
ret=result.HoursFrom(base,hour); |
|
858 |
test(ret==0); |
|
859 |
test(hour==TTimeIntervalHours(84)); |
|
860 |
ret=base.HoursFrom(result,hour); |
|
861 |
test(ret==0); |
|
862 |
test(hour==TTimeIntervalHours(-84)); |
|
863 |
ret=result.MinutesFrom(base,minute); |
|
864 |
test(ret==0); |
|
865 |
test(minute==TTimeIntervalMinutes(5088)); |
|
866 |
ret=base.MinutesFrom(result,minute); |
|
867 |
test(ret==0); |
|
868 |
test(minute==TTimeIntervalMinutes(-5088)); |
|
869 |
ret=result.SecondsFrom(base,second); |
|
870 |
test(ret==0); |
|
871 |
test(second==TTimeIntervalSeconds(305280)); |
|
872 |
ret=base.SecondsFrom(result,second); |
|
873 |
test(ret==0); |
|
874 |
test(second==TTimeIntervalSeconds(-305280)); |
|
875 |
||
876 |
test.Next(_L("SecondsFrom")); |
|
877 |
timeNow.HomeTime(); |
|
878 |
timeFuture=timeNow+TTimeIntervalSeconds(10); |
|
879 |
test(timeFuture.SecondsFrom(timeNow,second)==KErrNone); |
|
880 |
test(second.Int()==10); |
|
881 |
test(timeNow.SecondsFrom(timeFuture,second)==KErrNone); |
|
882 |
test(second.Int()==-10); |
|
883 |
timeFuture=timeNow+TTimeIntervalSeconds(KMaxTInt); |
|
884 |
test(timeFuture.SecondsFrom(timeNow,second)==KErrNone); |
|
885 |
test(second.Int()==KMaxTInt); |
|
886 |
test(timeNow.SecondsFrom(timeFuture,second)==KErrNone); |
|
887 |
test(second.Int()==-KMaxTInt); |
|
888 |
timeFuture=timeFuture+TTimeIntervalSeconds(1); |
|
889 |
test(timeFuture.SecondsFrom(timeNow,second)==KErrOverflow); |
|
890 |
test(timeNow.SecondsFrom(timeFuture,second)==KErrNone); |
|
891 |
test(second.Int()==KMinTInt); |
|
892 |
timeFuture=timeFuture+TTimeIntervalSeconds(1); |
|
893 |
test(timeFuture.SecondsFrom(timeNow,second)==KErrOverflow); |
|
894 |
test(timeNow.SecondsFrom(timeFuture,second)==KErrOverflow); |
|
895 |
||
896 |
test.Next(_L("Adding microseconds")); |
|
897 |
TTimeIntervalMicroSeconds microsecond=KDaysToMicroSeconds+KHoursToMicroSeconds+MAKE_TINT64(0,5000); |
|
898 |
result=base+microsecond; |
|
899 |
dateTime=result.DateTime(); |
|
900 |
test(dateTime.Year()==4); |
|
901 |
test(dateTime.Month()==EFebruary); |
|
902 |
test(dateTime.Day()==0); |
|
903 |
test(dateTime.Hour()==1); |
|
904 |
test(dateTime.Minute()==0); |
|
905 |
test(dateTime.Second()==0); |
|
906 |
test(dateTime.MicroSecond()==5000); |
|
907 |
test(result.YearsFrom(base)==TTimeIntervalYears(0)); |
|
908 |
test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
|
909 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
|
910 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
|
911 |
test(result.DaysFrom(base)==TTimeIntervalDays(1)); |
|
912 |
test(base.DaysFrom(result)==TTimeIntervalDays(-1)); |
|
913 |
ret=result.HoursFrom(base,hour); |
|
914 |
test(ret==0); |
|
915 |
test(hour==TTimeIntervalHours(25)); |
|
916 |
ret=base.HoursFrom(result,hour); |
|
917 |
test(ret==0); |
|
918 |
test(hour==TTimeIntervalHours(-25)); |
|
919 |
ret=result.MinutesFrom(base,minute); |
|
920 |
test(ret==0); |
|
921 |
test(minute==TTimeIntervalMinutes(1500)); |
|
922 |
ret=base.MinutesFrom(result,minute); |
|
923 |
test(ret==0); |
|
924 |
test(minute==TTimeIntervalMinutes(-1500)); |
|
925 |
ret=result.SecondsFrom(base,second); |
|
926 |
test(ret==0); |
|
927 |
test(second==TTimeIntervalSeconds(90000)); |
|
928 |
ret=base.SecondsFrom(result,second); |
|
929 |
test(ret==0); |
|
930 |
test(second==TTimeIntervalSeconds(-90000)); |
|
931 |
test(result.MicroSecondsFrom(base)==microsecond); |
|
932 |
microsecond=5008; |
|
933 |
result+=microsecond; |
|
934 |
dateTime=result.DateTime(); |
|
935 |
test(dateTime.Year()==4); |
|
936 |
test(dateTime.Month()==EFebruary); |
|
937 |
test(dateTime.Day()==0); |
|
938 |
test(dateTime.Hour()==1); |
|
939 |
test(dateTime.Minute()==0); |
|
940 |
test(dateTime.Second()==0); |
|
941 |
test(dateTime.MicroSecond()==10008); |
|
942 |
||
943 |
test.Next(_L("MicroSecondsFrom")); |
|
944 |
timeNow.HomeTime(); |
|
945 |
timeFuture=timeNow+TTimeIntervalMicroSeconds(10); |
|
946 |
test(timeFuture.MicroSecondsFrom(timeNow).Int64()==10); |
|
947 |
test(timeNow.MicroSecondsFrom(timeFuture).Int64()==-10); |
|
948 |
||
949 |
test.Next(_L("Testing invalid differences")); |
|
950 |
TInt64 overflow(KMaxTInt); |
|
951 |
overflow++; |
|
952 |
overflow*=KSecondsToMicroSeconds; |
|
953 |
result=base+TTimeIntervalMicroSeconds(overflow); |
|
954 |
ret=result.SecondsFrom(base,second); |
|
955 |
test(ret==KErrOverflow); |
|
956 |
overflow*=60; |
|
957 |
result=base+TTimeIntervalMicroSeconds(overflow); |
|
958 |
ret=result.MinutesFrom(base,minute); |
|
959 |
test(ret==KErrOverflow); |
|
960 |
overflow*=60; |
|
961 |
result=base+TTimeIntervalMicroSeconds(overflow); |
|
962 |
ret=result.HoursFrom(base,hour); |
|
963 |
test(ret==KErrOverflow); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
964 |
|
0 | 965 |
test.Next(_L("Specific MonthsFrom() tests")); |
966 |
||
967 |
base=TDateTime(1995,EJanuary,30,0,0,0,0); |
|
968 |
result=TDateTime(1995,EFebruary,27,0,0,0,0); |
|
969 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
|
970 |
||
971 |
base=TDateTime(1995,EJanuary,27,0,0,0,0); |
|
972 |
result=TDateTime(1995,EFebruary,27,0,0,0,0); |
|
973 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
974 |
|
0 | 975 |
base=TDateTime(1995,EJanuary,29,0,0,0,0); |
976 |
result=TDateTime(1995,EFebruary,27,0,0,0,0); |
|
977 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
|
978 |
||
979 |
base=TDateTime(1995,EJanuary,30,0,0,0,0); |
|
980 |
result=TDateTime(1995,EFebruary,27,0,0,0,0); |
|
981 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
|
982 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
|
983 |
||
984 |
base=TDateTime(1995,EJanuary,27,0,0,0,0); |
|
985 |
result=TDateTime(1995,EFebruary,27,0,0,0,0); |
|
986 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
|
987 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
988 |
|
0 | 989 |
base=TDateTime(1995,EJanuary,29,0,0,0,0); |
990 |
result=TDateTime(1995,EFebruary,27,0,0,0,0); |
|
991 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
|
992 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
993 |
|
0 | 994 |
base=TDateTime(1995,EJanuary,26,0,0,0,0); |
995 |
result=TDateTime(1995,EFebruary,27,0,0,0,0); |
|
996 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
|
997 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
998 |
|
0 | 999 |
base=TDateTime(1995,EFebruary,27,0,0,0,0); |
1000 |
result=TDateTime(1995,EMarch,29,0,0,0,0); |
|
1001 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
|
1002 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1003 |
|
0 | 1004 |
base=TDateTime(1995,EFebruary,27,0,0,0,0); |
1005 |
result=TDateTime(1995,EMarch,30,0,0,0,0); |
|
1006 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
|
1007 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1008 |
|
0 | 1009 |
base=TDateTime(1995,EFebruary,27,13,0,0,0); |
1010 |
result=TDateTime(1995,EJanuary,29,12,0,0,0); |
|
1011 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(1)); |
|
1012 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(-1)); |
|
1013 |
||
1014 |
base=TDateTime(1995,EFebruary,27,12,0,0,0); |
|
1015 |
result=TDateTime(1995,EJanuary,29,13,0,0,0); |
|
1016 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
|
1017 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
|
1018 |
||
1019 |
base=TDateTime(1995,EJanuary,27,12,0,0,0); |
|
1020 |
result=TDateTime(1995,EJanuary,29,13,0,0,0); |
|
1021 |
test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
|
1022 |
test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1023 |
|
0 | 1024 |
test.Next(_L("Looped MonthsFrom() test")); |
1025 |
const TTime endBase=MAKE_TINT64(74334524,25422354); |
|
1026 |
const TTime endResult=MAKE_TINT64(154334524,25422354); |
|
1027 |
const TTimeIntervalMicroSeconds plus=MAKE_TINT64(1234567,23453452); |
|
1028 |
for (base=MAKE_TINT64(3563656,3456235623u);base<endBase;base+=plus) |
|
1029 |
for (result=MAKE_TINT64(3563656,3456235623u);result<endResult;result+=plus) |
|
1030 |
test(base.MonthsFrom(result).Int()==-result.MonthsFrom(base).Int()); |
|
1031 |
} |
|
1032 |
||
1033 |
void TestTTime::Test7() |
|
1034 |
// |
|
1035 |
// subtracting |
|
1036 |
// |
|
1037 |
{ |
|
1038 |
TDateTime dateTime(1996,EApril,3,0,0,0,0); |
|
1039 |
TTime base(dateTime); |
|
1040 |
TTime tim(base); |
|
1041 |
||
1042 |
tim+=TTimeIntervalYears(7); |
|
1043 |
tim+=TTimeIntervalMonths(3); |
|
1044 |
tim+=TTimeIntervalDays(40); |
|
1045 |
tim+=TTimeIntervalHours(-3); |
|
1046 |
tim+=TTimeIntervalMinutes(1234); |
|
1047 |
tim+=TTimeIntervalSeconds(666); |
|
1048 |
tim+=TTimeIntervalMicroSeconds(-876540); |
|
1049 |
tim-=TTimeIntervalMicroSeconds(-876540); |
|
1050 |
tim-=TTimeIntervalSeconds(666); |
|
1051 |
tim-=TTimeIntervalMinutes(1234); |
|
1052 |
tim-=TTimeIntervalHours(-3); |
|
1053 |
tim-=TTimeIntervalDays(40); |
|
1054 |
tim-=TTimeIntervalMonths(3); |
|
1055 |
tim-=TTimeIntervalYears(7); |
|
1056 |
test (base==tim); |
|
1057 |
||
1058 |
tim-=TTimeIntervalMicroSeconds(9999999); |
|
1059 |
tim-=TTimeIntervalSeconds(52); |
|
1060 |
tim-=TTimeIntervalMinutes(-13); |
|
1061 |
tim-=TTimeIntervalHours(-337); |
|
1062 |
tim-=TTimeIntervalDays(1010); |
|
1063 |
tim-=TTimeIntervalMonths(-150); |
|
1064 |
tim-=TTimeIntervalYears(337); |
|
1065 |
tim+=TTimeIntervalYears(337); |
|
1066 |
tim+=TTimeIntervalMonths(-150); |
|
1067 |
tim+=TTimeIntervalDays(1010); |
|
1068 |
tim+=TTimeIntervalHours(-337); |
|
1069 |
tim+=TTimeIntervalMinutes(-13); |
|
1070 |
tim+=TTimeIntervalSeconds(52); |
|
1071 |
tim+=TTimeIntervalMicroSeconds(9999999); |
|
1072 |
test (base==tim); |
|
1073 |
||
1074 |
tim=TDateTime(-50,EMarch,6,14,45,3,100); |
|
1075 |
dateTime=tim.DateTime(); |
|
1076 |
test(dateTime.Year()==-50); |
|
1077 |
test(dateTime.Month()==EMarch); |
|
1078 |
test(dateTime.Day()==6); |
|
1079 |
test(dateTime.Hour()==14); |
|
1080 |
test(dateTime.Minute()==45); |
|
1081 |
test(dateTime.Second()==3); |
|
1082 |
test(dateTime.MicroSecond()==100); |
|
1083 |
||
1084 |
tim=TDateTime(-241,EJanuary,0,0,0,0,0); |
|
1085 |
tim-=TTimeIntervalMicroSeconds(1); |
|
1086 |
dateTime=tim.DateTime(); |
|
1087 |
test(dateTime.Year()==-242); |
|
1088 |
test(dateTime.Month()==EDecember); |
|
1089 |
test(dateTime.Day()==30); |
|
1090 |
test(dateTime.Hour()==23); |
|
1091 |
test(dateTime.Minute()==59); |
|
1092 |
test(dateTime.Second()==59); |
|
1093 |
test(dateTime.MicroSecond()==999999); |
|
1094 |
||
1095 |
tim=Time::MaxTTime(); |
|
1096 |
dateTime=tim.DateTime(); |
|
1097 |
tim=dateTime; |
|
1098 |
test(tim==Time::MaxTTime()); |
|
1099 |
||
1100 |
tim=Time::MinTTime(); |
|
1101 |
dateTime=tim.DateTime(); |
|
1102 |
tim=dateTime; |
|
1103 |
test(tim==Time::MinTTime()); |
|
1104 |
} |
|
1105 |
||
1106 |
void TestTTime::Test8() |
|
1107 |
// |
|
1108 |
// Test TTime's date property functions |
|
1109 |
// this implicitly tests Time's date property functions. |
|
1110 |
// |
|
1111 |
{ |
|
1112 |
test.Next(_L("Thorough Test with 4 day week rule")); |
|
1113 |
||
1114 |
TInt year=4; |
|
1115 |
TMonth month=EJanuary; |
|
1116 |
TInt day=30; |
|
1117 |
TInt hour=0; |
|
1118 |
TInt minute=0; |
|
1119 |
TInt second=0; |
|
1120 |
TInt microSecond=0; |
|
1121 |
TDateTime dateTime(year,month,day,hour,minute,second,microSecond); |
|
1122 |
TTime tim(dateTime); |
|
1123 |
||
1124 |
test(tim.DayNoInWeek()==0); |
|
1125 |
test(tim.DayNoInYear()==31); |
|
1126 |
test(tim.WeekNoInYear()==5); |
|
1127 |
||
1128 |
dateTime.SetDay(29); |
|
1129 |
tim=dateTime; |
|
1130 |
test(tim.DayNoInWeek()==6); |
|
1131 |
test(tim.DayNoInYear()==30); |
|
1132 |
test(tim.WeekNoInYear()==4); |
|
1133 |
||
1134 |
dateTime.SetMonth(EJanuary); |
|
1135 |
dateTime.SetDay(0); |
|
1136 |
TInt y; |
|
1137 |
for (y=1990;y<2020;y++) |
|
1138 |
{ |
|
1139 |
dateTime.SetYear(y); |
|
1140 |
tim=dateTime; |
|
1141 |
test(tim.DayNoInYear()==1); |
|
1142 |
TInt r=tim.WeekNoInYear(); |
|
1143 |
if (tim.DayNoInWeek()<=3) |
|
1144 |
test(r==1); |
|
1145 |
else |
|
1146 |
test(r==52 || r==53); |
|
1147 |
} |
|
1148 |
||
1149 |
dateTime.SetMonth(EDecember); |
|
1150 |
dateTime.SetDay(30); |
|
1151 |
TInt m(0); |
|
1152 |
TInt d(0); |
|
1153 |
TInt dn(0); |
|
1154 |
TInt wkn(0); |
|
1155 |
TInt wk(0); |
|
1156 |
for (y=1900;y<1921;y++) // MUST BEGIN 0N 1900 (been run to 2500) |
|
1157 |
{ |
|
1158 |
dateTime.SetYear(y); |
|
1159 |
for (m=0;m<12;m++) |
|
1160 |
{ |
|
1161 |
dateTime.SetMonth(TMonth(m)); |
|
1162 |
for (d=0;d<Time::DaysInMonth(y,TMonth(m));d++) |
|
1163 |
{ |
|
1164 |
dateTime.SetDay(d); |
|
1165 |
tim=dateTime; |
|
1166 |
wk=tim.WeekNoInYear(); |
|
1167 |
dn++; |
|
1168 |
if (dn>6) |
|
1169 |
dn=0; |
|
1170 |
if (dn==1) |
|
1171 |
{ |
|
1172 |
wkn++; |
|
1173 |
if((m==11 && d>=28) | (m==0 && d<=3)) |
|
1174 |
wkn=1; |
|
1175 |
} |
|
1176 |
test(wkn==wk); |
|
1177 |
} |
|
1178 |
dateTime.SetDay(0); |
|
1179 |
} |
|
1180 |
} |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1181 |
|
0 | 1182 |
test.Next(_L("Testing wk53 in a year with 4 days in last week")); |
1183 |
dateTime.SetYear(2009); |
|
1184 |
dateTime.SetMonth(EDecember); |
|
1185 |
dateTime.SetDay(27); // 28th, day is 0-based |
|
1186 |
dateTime.SetHour(8); // Ensure the remaining days are 3.somefraction to test rounding |
|
1187 |
tim=dateTime; |
|
1188 |
test(tim.DayNoInWeek()==0); |
|
1189 |
test(tim.DayNoInMonth()==27); |
|
1190 |
test(tim.DayNoInYear()==362); |
|
1191 |
test(tim.WeekNoInYear()==53); |
|
1192 |
dateTime.SetYear(2010); |
|
1193 |
dateTime.SetMonth(EJanuary); |
|
1194 |
dateTime.SetDay(3); // 4th, day is 0-based |
|
1195 |
tim=dateTime; |
|
1196 |
test(tim.DayNoInWeek()==0); |
|
1197 |
test(tim.DayNoInMonth()==3); |
|
1198 |
test(tim.DayNoInYear()==4); |
|
1199 |
test(tim.WeekNoInYear()==1); |
|
1200 |
dateTime.SetHour(0); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1201 |
|
0 | 1202 |
test.Next(_L("Testing other week no. rules")); |
1203 |
dateTime.SetYear(1995); |
|
1204 |
dateTime.SetDay(14); |
|
1205 |
dateTime.SetMonth(ENovember); |
|
1206 |
tim=dateTime; |
|
1207 |
test(tim.DayNoInWeek()==2); |
|
1208 |
test(tim.DayNoInYear()==319); |
|
1209 |
test(tim.WeekNoInYear()==46); |
|
1210 |
||
1211 |
// Different First Week rules |
|
1212 |
test.Next(_L("Test week no in year by different rules")); |
|
1213 |
test(tim.WeekNoInYear(EFirstFullWeek)==46); |
|
1214 |
test(tim.WeekNoInYear(EFirstWeek)==47); |
|
1215 |
test(tim.WeekNoInYear(EFirstFourDayWeek)==46); |
|
1216 |
||
1217 |
dateTime.SetYear(1997); |
|
1218 |
dateTime.SetMonth(EJanuary); |
|
1219 |
dateTime.SetDay(6); |
|
1220 |
tim=dateTime; |
|
1221 |
test(tim.WeekNoInYear()==2); |
|
1222 |
test(tim.WeekNoInYear(EFirstFullWeek)==1); |
|
1223 |
test(tim.WeekNoInYear(EFirstWeek)==2); |
|
1224 |
test(tim.WeekNoInYear(EFirstFourDayWeek)==2); |
|
1225 |
||
1226 |
||
1227 |
dateTime.SetYear(1999); |
|
1228 |
tim=dateTime; |
|
1229 |
test(tim.WeekNoInYear()==1); |
|
1230 |
test(tim.WeekNoInYear(EFirstFullWeek)==1); |
|
1231 |
test(tim.WeekNoInYear(EFirstWeek)==2); |
|
1232 |
test(tim.WeekNoInYear(EFirstFourDayWeek)==1); |
|
1233 |
||
1234 |
// Year start dates different from jan 1st |
|
1235 |
dateTime.SetYear(1995); |
|
1236 |
dateTime.SetMonth(ENovember); |
|
1237 |
dateTime.SetDay(14); |
|
1238 |
TTime tim2(dateTime); // cTime |
|
1239 |
dateTime.SetMonth(EJune); |
|
1240 |
tim=dateTime; //dTime |
|
1241 |
||
1242 |
test(tim2.DayNoInYear(tim)==154); |
|
1243 |
test(tim2.WeekNoInYear(tim)==23); |
|
1244 |
test(tim2.WeekNoInYear(tim,EFirstFullWeek)==22); |
|
1245 |
test(tim.DayNoInYear(tim2)==213); |
|
1246 |
test(tim.WeekNoInYear(tim2)==31); |
|
1247 |
test(tim.WeekNoInYear(tim2,EFirstFullWeek)==30); |
|
1248 |
||
1249 |
dateTime.SetYear(1999); |
|
1250 |
dateTime.SetMonth(EJanuary); |
|
1251 |
dateTime.SetDay(6); |
|
1252 |
tim2=dateTime; |
|
1253 |
test(tim2.WeekNoInYear(tim,EFirstFullWeek)==30); |
|
1254 |
test(tim2.WeekNoInYear(tim,EFirstWeek)==30); |
|
1255 |
test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==30); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1256 |
|
0 | 1257 |
dateTime.SetYear(1904); |
1258 |
dateTime.SetMonth(EFebruary); |
|
1259 |
dateTime.SetDay(28); |
|
1260 |
tim=dateTime; |
|
1261 |
dateTime.SetYear(1955); |
|
1262 |
dateTime.SetMonth(EJanuary); |
|
1263 |
tim2=dateTime; |
|
1264 |
test(tim2.WeekNoInYear(tim,EFirstFullWeek)==48); |
|
1265 |
test(tim2.WeekNoInYear(tim,EFirstWeek)==49); |
|
1266 |
test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==48); |
|
1267 |
dateTime.SetMonth(EMarch); |
|
1268 |
tim2=dateTime; |
|
1269 |
test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==5); |
|
1270 |
test(tim2.WeekNoInYear(tim,EFirstFullWeek)==5); |
|
1271 |
dateTime.SetYear(1994); |
|
1272 |
dateTime.SetMonth(EMarch); |
|
1273 |
dateTime.SetDay(0); |
|
1274 |
dateTime.SetHour(12); |
|
1275 |
tim2=dateTime; |
|
1276 |
test(tim2.WeekNoInYear(tim,EFirstFullWeek)==1); |
|
1277 |
test(tim2.WeekNoInYear(tim,EFirstWeek)==1); |
|
1278 |
test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==1); |
|
1279 |
dateTime.SetYear(1991); |
|
1280 |
dateTime.SetMonth(EMarch); |
|
1281 |
dateTime.SetDay(0); |
|
1282 |
dateTime.SetHour(12); |
|
1283 |
tim2=dateTime; |
|
1284 |
test(tim2.WeekNoInYear(tim,EFirstFullWeek)==52); |
|
1285 |
test(tim2.WeekNoInYear(tim,EFirstWeek)==1); |
|
1286 |
test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==1); |
|
1287 |
} |
|
1288 |
||
1289 |
||
1290 |
void TestTTime::Test9() |
|
1291 |
// |
|
1292 |
// string handling |
|
1293 |
// |
|
1294 |
{ |
|
1295 |
TInt lyear =1993; |
|
1296 |
TInt lmonth =6; |
|
1297 |
TInt lday =3; |
|
1298 |
TInt lhour =13; |
|
1299 |
TInt lminute =53; |
|
1300 |
TInt lsecond =20; |
|
1301 |
TInt lmicroSecond =12345; |
|
1302 |
TDateTime aDate(lyear,TMonth(lmonth),lday,lhour,lminute,lsecond,lmicroSecond); |
|
1303 |
test.Next(_L("Different DateFormats")); |
|
1304 |
TTime aTime(aDate); |
|
1305 |
TBuf<0x80> testString; |
|
1306 |
TDateTime aDateTime=aTime.DateTime(); |
|
1307 |
aDateTime.Month(); |
|
1308 |
aTime.FormatL(testString,(_L("%E"))); |
|
1309 |
if (testString.Compare(_L("Sunday"))) |
|
1310 |
test.Panic(_L("%%E")); |
|
1311 |
aTime.FormatL(testString,(_L("%*E"))); |
|
1312 |
if (testString.Compare(_L("Sun"))) |
|
1313 |
test.Panic(_L("%%*E")); |
|
1314 |
TLocale local; |
|
1315 |
local.SetDateFormat(EDateEuropean); |
|
1316 |
local.Set(); |
|
1317 |
aTime.FormatL(testString,(_L("%D%M%Y%/0%1%/1%2%/2%3%/3"))); |
|
1318 |
if (testString.Compare(_L("04/07/1993"))) |
|
1319 |
test.Panic(_L("%%D%%M%%Y")); |
|
1320 |
local.SetDateFormat(EDateAmerican); |
|
1321 |
local.Set(); |
|
1322 |
aTime.FormatL(testString,(_L("%*D%X%N%Y%1 %2 '%*3"))); |
|
1323 |
if (testString.Compare(_L("July 4th '93"))) |
|
1324 |
test.Panic(_L("%%*D%%X%%N'%%*Y, American")); |
|
1325 |
local.SetDateFormat(EDateJapanese); |
|
1326 |
local.Set(); |
|
1327 |
aTime.FormatL(testString,(_L("%*D%*N%4 %5"))); |
|
1328 |
if (testString.Compare(_L("Jul 4"))) |
|
1329 |
test.Panic(_L("%%*D%%*N, Japanese")); |
|
1330 |
aTime.FormatL(testString,(_L("%F%Y %D%X %N"))); |
|
1331 |
if (testString.Compare(_L("1993 04th July"))) |
|
1332 |
test.Panic(_L("%%F%%Y %%D%%X %%N")); |
|
1333 |
test.Next(_L("Times")); |
|
1334 |
aTime.FormatL(testString,(_L("%*I%:1%T%A"))); |
|
1335 |
if (testString.Compare(_L("1:53 pm"))) |
|
1336 |
test.Panic(_L("%%*I%%:1%%T%%A")); |
|
1337 |
local.SetAmPmSymbolPosition(ELocaleBefore); |
|
1338 |
local.Set(); |
|
1339 |
aTime.FormatL(testString,(_L("%*I%:1%T%A"))); |
|
1340 |
if (testString.Compare(_L("1:53pm "))) |
|
1341 |
test.Panic(_L("%%*I%%:1%%T%%A Bef")); |
|
1342 |
local.SetAmPmSpaceBetween(EFalse); |
|
1343 |
local.Set(); |
|
1344 |
aTime.FormatL(testString,(_L("%*I%:1%T%A"))); |
|
1345 |
if (testString.Compare(_L("1:53pm"))) |
|
1346 |
test.Panic(_L("%%*I%%:1%%T%%A Bef NoSp")); |
|
1347 |
local.SetAmPmSymbolPosition(ELocaleAfter); |
|
1348 |
local.Set(); |
|
1349 |
aTime.FormatL(testString,(_L("%*I%:1%T%A"))); |
|
1350 |
if (testString.Compare(_L("1:53pm"))) |
|
1351 |
test.Panic(_L("%%*I%%:1%%T%%A NoSp")); |
|
1352 |
||
1353 |
aTime.FormatL(testString,(_L("%-A%*I%:1%T%+A"))); |
|
1354 |
if (testString.Compare(_L("1:53pm"))) |
|
1355 |
test.Panic(_L("%%-A%%*I%%:1%%T%%+A NoSp")); |
|
1356 |
local.SetAmPmSymbolPosition(ELocaleBefore); |
|
1357 |
local.Set(); |
|
1358 |
aTime.FormatL(testString,(_L("%-A%*I%:1%T%+A"))); |
|
1359 |
if (testString.Compare(_L("pm1:53"))) |
|
1360 |
test.Panic(_L("%%-A%%*I%%:1%%T%%+A Bef NoSp")); |
|
1361 |
local.SetAmPmSpaceBetween(ETrue); |
|
1362 |
local.Set(); |
|
1363 |
aTime.FormatL(testString,(_L("%-A%*I%:1%T%+A"))); |
|
1364 |
if (testString.Compare(_L("pm 1:53"))) |
|
1365 |
test.Panic(_L("%%-A%%*I%%:1%%T%%+A Bef")); |
|
1366 |
local.SetAmPmSymbolPosition(ELocaleAfter); |
|
1367 |
local.Set(); |
|
1368 |
aTime.FormatL(testString,(_L("%-A%*I%:1%T%+A"))); |
|
1369 |
if (testString.Compare(_L("1:53 pm"))) |
|
1370 |
test.Panic(_L("%%-A%%*I%%:1%%T%%+A")); |
|
1371 |
||
1372 |
aTime.FormatL(testString,(_L("%:0%H%:1%T%:2%S%.%C%:3"))); |
|
1373 |
if (testString.Compare(_L("13:53:20.012345"))) |
|
1374 |
test.Panic(_L("%%:0%%H%%:1%%T%%:2%%S%%.%%C%%:3 1")); |
|
1375 |
local.SetDecimalSeparator(','); |
|
1376 |
local.Set(); |
|
1377 |
aTime.FormatL(testString,(_L("%:0%H%:1%T%:2%S%.%C%:3"))); |
|
1378 |
if (testString.Compare(_L("13:53:20,012345"))) |
|
1379 |
test.Panic(_L("%%:0%%H%%:1%%T%%:2%%S%%.%%C%%:3 2")); |
|
1380 |
local.SetDecimalSeparator('.'); |
|
1381 |
local.Set(); |
|
1382 |
||
1383 |
aTime.FormatL(testString,(_L("%T%:2%S%.%*C0"))); |
|
1384 |
if (testString.Compare(_L("53:20."))) |
|
1385 |
test.Panic(_L("%%T%%:2%%S.%%*C0")); |
|
1386 |
aTime.FormatL(testString,(_L("%S%.%*C1"))); |
|
1387 |
if (testString.Compare(_L("20.0"))) |
|
1388 |
test.Panic(_L("%%S.%%*C1")); |
|
1389 |
aTime.FormatL(testString,(_L(".%*C3"))); |
|
1390 |
if (testString.Compare(_L(".012"))) |
|
1391 |
test.Panic(_L(".%%*C3")); |
|
1392 |
aTime.FormatL(testString,(_L("%*C6"))); |
|
1393 |
if (testString.Compare(_L("012345"))) |
|
1394 |
test.Panic(_L("%%*C6")); |
|
1395 |
aTime.FormatL(testString,(_L(".%*CZTest"))); |
|
1396 |
if (testString.Compare(_L(".012345Test"))) |
|
1397 |
test.Panic(_L("%%*C6")); |
|
1398 |
aTime.FormatL(testString,(_L("%J%:1%T%B"))); |
|
1399 |
if (testString.Compare(_L("1:53 pm"))) |
|
1400 |
test.Panic(_L("%%J%%:1%%T%%B")); |
|
1401 |
aTime.FormatL(testString,(_L("%J%:1%T%*B"))); |
|
1402 |
if (testString.Compare(_L("1:53pm"))) |
|
1403 |
test.Panic(_L("%%J%%:1%%T%%*B")); |
|
1404 |
local.SetTimeFormat(ETime24); |
|
1405 |
local.Set(); |
|
1406 |
aTime.FormatL(testString,(_L("%J%:1%T%B"))); |
|
1407 |
if (testString.Compare(_L("13:53"))) |
|
1408 |
test.Panic(_L("%%J%%:1%%T%%B, ETime24")); |
|
1409 |
aTime.FormatL(testString,(_L("%J%:1%T%*B"))); |
|
1410 |
if (testString.Compare(_L("13:53"))) |
|
1411 |
test.Panic(_L("%%J%%:1%%T%%*B, ETime24")); |
|
1412 |
test.Next(_L("Miscellaneous")); |
|
1413 |
aTime.FormatL(testString,(_L("%W"))); |
|
1414 |
if (testString.Compare(_L("26"))) |
|
1415 |
test.Panic(_L("%%W")); |
|
1416 |
aTime.FormatL(testString,(_L("%*Z"))); |
|
1417 |
if (testString.Compare(_L("185"))) |
|
1418 |
test.Panic(_L("%%*Z")); |
|
1419 |
test.Next(_L("Junk strings")); |
|
1420 |
aTime.FormatL(testString,(_L("%F %M%O%N%D%A%Y"))); |
|
1421 |
if (testString.Compare(_L(" 07OJuly04 pm1993"))) |
|
1422 |
test.Panic(_L(" MONDAY")); |
|
1423 |
aTime.FormatL(testString,(_L("%*D%X %N '%*Y"))); |
|
1424 |
if (testString.Compare(_L(" '"))) |
|
1425 |
test.Panic(_L(" '")); |
|
1426 |
aTime.FormatL(testString,(_L("%G%K%L%O%P%Q%R%U%V%%"))); |
|
1427 |
if (testString.Compare(_L("GKLOPQRUV%"))) |
|
1428 |
test.Panic(_L("GKLOPQRUV%%")); |
|
1429 |
aDate.Set(1993,TMonth(6),3,0,0,0,0); |
|
1430 |
aTime=aDate; |
|
1431 |
aTime.FormatL(testString,(_L("%*I%:1%T%A"))); |
|
1432 |
if (testString.Compare(_L("12:00 am"))) |
|
1433 |
test.Panic(_L("testDate->time")); |
|
1434 |
aTime.FormatL(testString,(_L("%*I%:1%T%*A"))); |
|
1435 |
if (testString.Compare(_L("12:00am"))) |
|
1436 |
test.Panic(_L("testDate->time 2")); |
|
1437 |
aTime.FormatL(testString,(_L("unformatted string"))); // test added 25/08/95 |
|
1438 |
if (testString.Compare(_L("unformatted string"))) |
|
1439 |
test.Panic(_L("unformatted string")); |
|
1440 |
TBuf<8> buf; |
|
1441 |
TRAPD(r,aTime.FormatL(buf,_L("%F %M%O%N%D%A%Y"))); |
|
1442 |
test(r==KErrOverflow); |
|
1443 |
TRAP(r,aTime.FormatL(buf,_L("qwertyuiop"))); |
|
1444 |
test(r==KErrOverflow); |
|
1445 |
TRAP(r,aTime.FormatL(testString,_L("%:4"))); |
|
1446 |
test(r==KErrGeneral); |
|
1447 |
TRAP(r,aTime.FormatL(testString,_L("%/4"))); |
|
1448 |
test(r==KErrGeneral); |
|
1449 |
TRAP(r,aTime.FormatL(testString,_L("%:/"))); |
|
1450 |
test(r==KErrGeneral); |
|
1451 |
TRAP(r,aTime.FormatL(testString,_L("%//"))); |
|
1452 |
test(r==KErrGeneral); |
|
1453 |
TRAP(r,aTime.FormatL(testString,_L("%:z"))); |
|
1454 |
test(r==KErrGeneral); |
|
1455 |
TRAP(r,aTime.FormatL(testString,_L("%/z"))); |
|
1456 |
test(r==KErrGeneral); |
|
1457 |
TRAP(r,aTime.FormatL(testString,_L("%: "))); |
|
1458 |
test(r==KErrGeneral); |
|
1459 |
TRAP(r,aTime.FormatL(testString,_L("%/ "))); |
|
1460 |
test(r==KErrGeneral); |
|
1461 |
TRAP(r,aTime.FormatL(testString,_L("%- "))); |
|
1462 |
test(r==KErrGeneral); |
|
1463 |
TRAP(r,aTime.FormatL(testString,_L("%+ "))); |
|
1464 |
test(r==KErrGeneral); |
|
1465 |
||
1466 |
// HA - 258 |
|
1467 |
aTime.Set(_L("19991231:000000.0000")); |
|
1468 |
local.SetTimeFormat(ETime24); |
|
1469 |
local.Set(); |
|
1470 |
aTime.FormatL(testString, _L("%*J%BX")); |
|
1471 |
test(testString==_L("0X")); |
|
1472 |
local.SetTimeFormat(ETime12); |
|
1473 |
local.Set(); |
|
1474 |
aTime.FormatL(testString, _L("%*J%BX")); |
|
1475 |
test(testString==_L("12 amX")); |
|
1476 |
aTime.FormatL(testString, _L("%IX")); |
|
1477 |
test(testString==_L("12X")); |
|
1478 |
aTime.FormatL(testString, _L("%HX")); |
|
1479 |
test(testString==_L("00X")); |
|
1480 |
||
1481 |
//Reset so it can be run twice |
|
1482 |
local.SetDateFormat(EDateEuropean); |
|
1483 |
local.SetTimeFormat(ETime12); |
|
1484 |
local.Set(); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1485 |
|
0 | 1486 |
// Test for overload of TTime::FormatL(TDes& aDes,const TDesC& aFormat,const TLocale& aLocale); |
1487 |
// Reset Time and dates |
|
1488 |
aDate.Set(lyear,TMonth(lmonth),lday,lhour,lminute,lsecond,lmicroSecond); |
|
1489 |
test.Next(_L("Different DateFormats with specified locale")); |
|
1490 |
TTime aTimeLocale(aDate); |
|
1491 |
||
1492 |
local.SetDateFormat(EDateAmerican); |
|
1493 |
aTimeLocale.FormatL(testString,(_L("%*D%X%N%Y%1 %2 '%*3")),local); |
|
1494 |
if (testString.Compare(_L("July 4th '93"))) |
|
1495 |
test.Panic(_L("%%*D%%X%%N'%%*Y, American")); |
|
1496 |
local.SetDateFormat(EDateJapanese); |
|
1497 |
aTimeLocale.FormatL(testString,(_L("%*D%*N%4 %5")),local); |
|
1498 |
if (testString.Compare(_L("Jul 4"))) |
|
1499 |
test.Panic(_L("%%*D%%*N, Japanese")); |
|
1500 |
aTimeLocale.FormatL(testString,(_L("%F%Y %D%X %N")),local); |
|
1501 |
if (testString.Compare(_L("1993 04th July"))) |
|
1502 |
test.Panic(_L("%%F%%Y %%D%%X %%N")); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1503 |
|
0 | 1504 |
test.Next(_L("Times with specified locale")); |
1505 |
aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local); |
|
1506 |
if (testString.Compare(_L("1:53 pm"))) |
|
1507 |
test.Panic(_L("%%*I%%:1%%T%%A")); |
|
1508 |
local.SetAmPmSymbolPosition(ELocaleBefore); |
|
1509 |
aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local); |
|
1510 |
if (testString.Compare(_L("1:53pm "))) |
|
1511 |
test.Panic(_L("%%*I%%:1%%T%%A Bef")); |
|
1512 |
local.SetAmPmSpaceBetween(EFalse); |
|
1513 |
aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local); |
|
1514 |
if (testString.Compare(_L("1:53pm"))) |
|
1515 |
test.Panic(_L("%%*I%%:1%%T%%A Bef NoSp")); |
|
1516 |
local.SetAmPmSymbolPosition(ELocaleAfter); |
|
1517 |
aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local); |
|
1518 |
if (testString.Compare(_L("1:53pm"))) |
|
1519 |
test.Panic(_L("%%*I%%:1%%T%%A NoSp")); |
|
1520 |
aTimeLocale.FormatL(testString,(_L("%-A%*I%:1%T%+A")),local); |
|
1521 |
if (testString.Compare(_L("1:53pm"))) |
|
1522 |
test.Panic(_L("%%-A%%*I%%:1%%T%%+A NoSp")); |
|
1523 |
local.SetAmPmSymbolPosition(ELocaleBefore); |
|
1524 |
aTimeLocale.FormatL(testString,(_L("%-A%*I%:1%T%+A")),local); |
|
1525 |
if (testString.Compare(_L("pm1:53"))) |
|
1526 |
test.Panic(_L("%%-A%%*I%%:1%%T%%+A Bef NoSp")); |
|
1527 |
local.SetAmPmSpaceBetween(ETrue); |
|
1528 |
aTimeLocale.FormatL(testString,(_L("%-A%*I%:1%T%+A")),local); |
|
1529 |
if (testString.Compare(_L("pm 1:53"))) |
|
1530 |
test.Panic(_L("%%-A%%*I%%:1%%T%%+A Bef")); |
|
1531 |
local.SetAmPmSymbolPosition(ELocaleAfter); |
|
1532 |
aTimeLocale.FormatL(testString,(_L("%-A%*I%:1%T%+A")),local); |
|
1533 |
if (testString.Compare(_L("1:53 pm"))) |
|
1534 |
test.Panic(_L("%%-A%%*I%%:1%%T%%+A")); |
|
1535 |
aTimeLocale.FormatL(testString,(_L("%:0%H%:1%T%:2%S%.%C%:3")),local); |
|
1536 |
if (testString.Compare(_L("13:53:20.012345"))) |
|
1537 |
test.Panic(_L("%%:0%%H%%:1%%T%%:2%%S%%.%%C%%:3 1")); |
|
1538 |
local.SetDecimalSeparator(','); |
|
1539 |
aTimeLocale.FormatL(testString,(_L("%:0%H%:1%T%:2%S%.%C%:3")),local); |
|
1540 |
if (testString.Compare(_L("13:53:20,012345"))) |
|
1541 |
test.Panic(_L("%%:0%%H%%:1%%T%%:2%%S%%.%%C%%:3 2")); |
|
1542 |
local.SetDecimalSeparator('.'); |
|
1543 |
aTimeLocale.FormatL(testString,(_L("%T%:2%S%.%*C0")),local); |
|
1544 |
if (testString.Compare(_L("53:20."))) |
|
1545 |
test.Panic(_L("%%T%%:2%%S.%%*C0")); |
|
1546 |
aTimeLocale.FormatL(testString,(_L("%S%.%*C1")),local); |
|
1547 |
if (testString.Compare(_L("20.0"))) |
|
1548 |
test.Panic(_L("%%S.%%*C1")); |
|
1549 |
aTimeLocale.FormatL(testString,(_L(".%*C3")),local); |
|
1550 |
if (testString.Compare(_L(".012"))) |
|
1551 |
test.Panic(_L(".%%*C3")); |
|
1552 |
aTimeLocale.FormatL(testString,(_L("%*C6")),local); |
|
1553 |
if (testString.Compare(_L("012345"))) |
|
1554 |
test.Panic(_L("%%*C6")); |
|
1555 |
aTimeLocale.FormatL(testString,(_L(".%*CZTest")),local); |
|
1556 |
if (testString.Compare(_L(".012345Test"))) |
|
1557 |
test.Panic(_L("%%*C6")); |
|
1558 |
aTimeLocale.FormatL(testString,(_L("%J%:1%T%B")),local); |
|
1559 |
if (testString.Compare(_L("1:53 pm"))) |
|
1560 |
test.Panic(_L("%%J%%:1%%T%%B")); |
|
1561 |
aTimeLocale.FormatL(testString,(_L("%J%:1%T%*B")),local); |
|
1562 |
if (testString.Compare(_L("1:53pm"))) |
|
1563 |
test.Panic(_L("%%J%%:1%%T%%*B")); |
|
1564 |
local.SetTimeFormat(ETime24); |
|
1565 |
aTimeLocale.FormatL(testString,(_L("%J%:1%T%B")),local); |
|
1566 |
if (testString.Compare(_L("13:53"))) |
|
1567 |
test.Panic(_L("%%J%%:1%%T%%B, ETime24")); |
|
1568 |
aTimeLocale.FormatL(testString,(_L("%J%:1%T%*B")),local); |
|
1569 |
if (testString.Compare(_L("13:53"))) |
|
1570 |
test.Panic(_L("%%J%%:1%%T%%*B, ETime24")); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1571 |
|
0 | 1572 |
test.Next(_L("Miscellaneous with specified locale")); |
1573 |
aTimeLocale.FormatL(testString,(_L("%W")),local); |
|
1574 |
if (testString.Compare(_L("26"))) |
|
1575 |
test.Panic(_L("%%W")); |
|
1576 |
aTimeLocale.FormatL(testString,(_L("%*Z")),local); |
|
1577 |
if (testString.Compare(_L("185"))) |
|
1578 |
test.Panic(_L("%%*Z")); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1579 |
|
0 | 1580 |
test.Next(_L("Junk strings with specified locale")); |
1581 |
aTimeLocale.FormatL(testString,(_L("%F %M%O%N%D%A%Y")),local); |
|
1582 |
if (testString.Compare(_L(" 07OJuly04 pm1993"))) |
|
1583 |
test.Panic(_L(" MONDAY")); |
|
1584 |
aTimeLocale.FormatL(testString,(_L("%*D%X %N '%*Y")),local); |
|
1585 |
if (testString.Compare(_L(" '"))) |
|
1586 |
test.Panic(_L(" '")); |
|
1587 |
aTimeLocale.FormatL(testString,(_L("%G%K%L%O%P%Q%R%U%V%%")),local); |
|
1588 |
if (testString.Compare(_L("GKLOPQRUV%"))) |
|
1589 |
test.Panic(_L("GKLOPQRUV%%")); |
|
1590 |
aDate.Set(1993,TMonth(6),3,0,0,0,0); |
|
1591 |
aTimeLocale=aDate; |
|
1592 |
aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local); |
|
1593 |
if (testString.Compare(_L("12:00 am"))) |
|
1594 |
test.Panic(_L("testDate->time")); |
|
1595 |
aTimeLocale.FormatL(testString,(_L("%*I%:1%T%*A")),local); |
|
1596 |
if (testString.Compare(_L("12:00am"))) |
|
1597 |
test.Panic(_L("testDate->time 2")); |
|
1598 |
aTimeLocale.FormatL(testString,(_L("unformatted string")),local); // test added 25/08/95 |
|
1599 |
if (testString.Compare(_L("unformatted string"))) |
|
1600 |
test.Panic(_L("unformatted string")); |
|
1601 |
TRAP(r,aTimeLocale.FormatL(buf,_L("%F %M%O%N%D%A%Y"),local)); |
|
1602 |
test(r==KErrOverflow); |
|
1603 |
TRAP(r,aTimeLocale.FormatL(buf,_L("qwertyuiop"),local)); |
|
1604 |
test(r==KErrOverflow); |
|
1605 |
TRAP(r,aTimeLocale.FormatL(testString,_L("%:4"),local)); |
|
1606 |
test(r==KErrGeneral); |
|
1607 |
TRAP(r,aTimeLocale.FormatL(testString,_L("%/4"),local)); |
|
1608 |
test(r==KErrGeneral); |
|
1609 |
TRAP(r,aTimeLocale.FormatL(testString,_L("%:/"),local)); |
|
1610 |
test(r==KErrGeneral); |
|
1611 |
TRAP(r,aTimeLocale.FormatL(testString,_L("%//"),local)); |
|
1612 |
test(r==KErrGeneral); |
|
1613 |
TRAP(r,aTimeLocale.FormatL(testString,_L("%:z"),local)); |
|
1614 |
test(r==KErrGeneral); |
|
1615 |
TRAP(r,aTimeLocale.FormatL(testString,_L("%/z"),local)); |
|
1616 |
test(r==KErrGeneral); |
|
1617 |
TRAP(r,aTimeLocale.FormatL(testString,_L("%: "),local)); |
|
1618 |
test(r==KErrGeneral); |
|
1619 |
TRAP(r,aTimeLocale.FormatL(testString,_L("%/ "),local)); |
|
1620 |
test(r==KErrGeneral); |
|
1621 |
TRAP(r,aTimeLocale.FormatL(testString,_L("%- "),local)); |
|
1622 |
test(r==KErrGeneral); |
|
1623 |
TRAP(r,aTimeLocale.FormatL(testString,_L("%+ "),local)); |
|
1624 |
test(r==KErrGeneral); |
|
1625 |
aTimeLocale.Set(_L("19991231:000000.0000")); |
|
1626 |
local.SetTimeFormat(ETime24); |
|
1627 |
aTimeLocale.FormatL(testString, _L("%*J%BX"),local); |
|
1628 |
test(testString==_L("0X")); |
|
1629 |
local.SetTimeFormat(ETime12); |
|
1630 |
aTimeLocale.FormatL(testString, _L("%*J%BX"),local); |
|
1631 |
test(testString==_L("12 amX")); |
|
1632 |
aTimeLocale.FormatL(testString, _L("%IX"),local); |
|
1633 |
test(testString==_L("12X")); |
|
1634 |
aTimeLocale.FormatL(testString, _L("%HX"),local); |
|
1635 |
test(testString==_L("00X")); |
|
1636 |
} |
|
1637 |
||
1638 |
||
1639 |
void TestTTime::Test10() |
|
1640 |
// |
|
1641 |
// The Time functions that aren't called/tested above. |
|
1642 |
// |
|
1643 |
{ |
|
1644 |
test.Next(_L("IsLeapYear()")); |
|
1645 |
TDateTime date; |
|
1646 |
date.Set(1200,EFebruary,28,13,58,59,245322); |
|
1647 |
test(date.SetYear(1980)==KErrNone); |
|
1648 |
TBool isLeap = Time::IsLeapYear(1580); |
|
1649 |
TInt noUpTo = Time::LeapYearsUpTo(1580); |
|
1650 |
test(isLeap==1); |
|
1651 |
test(noUpTo==395); |
|
1652 |
isLeap = Time::IsLeapYear(1750); |
|
1653 |
noUpTo = Time::LeapYearsUpTo(1750); |
|
1654 |
test(isLeap==0); |
|
1655 |
test(noUpTo==437); |
|
1656 |
isLeap = Time::IsLeapYear(1980); |
|
1657 |
noUpTo = Time::LeapYearsUpTo(1980); |
|
1658 |
test(isLeap==1); |
|
1659 |
test(noUpTo==492); |
|
1660 |
isLeap = Time::IsLeapYear(2000); |
|
1661 |
noUpTo = Time::LeapYearsUpTo(2000); |
|
1662 |
test(isLeap==1); |
|
1663 |
test(noUpTo==497); |
|
1664 |
isLeap = Time::IsLeapYear(25000); |
|
1665 |
noUpTo = Time::LeapYearsUpTo(25000); |
|
1666 |
test(isLeap==0); |
|
1667 |
test(noUpTo==6075); |
|
1668 |
||
1669 |
test.Next(_L("TTime::RoundUpToNextMinute()")); |
|
1670 |
TTime time; |
|
1671 |
time.RoundUpToNextMinute(); |
|
1672 |
TDateTime dateTime=time.DateTime(); |
|
1673 |
test(dateTime.MicroSecond()==0); |
|
1674 |
test(dateTime.Second()==0); |
|
1675 |
||
1676 |
TDateTime dateTime2(2004,EFebruary,28,12,48,59,999999); |
|
1677 |
time=dateTime2; |
|
1678 |
time.RoundUpToNextMinute(); |
|
1679 |
dateTime=time.DateTime(); |
|
1680 |
test(dateTime.MicroSecond()==0); |
|
1681 |
test(dateTime.Second()==0); |
|
1682 |
test(dateTime.Minute()==dateTime2.Minute()+1); |
|
1683 |
test(dateTime.Hour()==dateTime2.Hour()); |
|
1684 |
test(dateTime.Day()==dateTime2.Day()); |
|
1685 |
test(dateTime.Month()==dateTime2.Month()); |
|
1686 |
test(dateTime.Year()==dateTime2.Year()); |
|
1687 |
||
1688 |
dateTime2.Set(2004,EFebruary,28,12,48,0,0); |
|
1689 |
time=dateTime2; |
|
1690 |
time.RoundUpToNextMinute(); |
|
1691 |
dateTime=time.DateTime(); |
|
1692 |
test(dateTime.MicroSecond()==0); |
|
1693 |
test(dateTime.Second()==0); |
|
1694 |
test(dateTime.MicroSecond()==dateTime2.MicroSecond()); |
|
1695 |
test(dateTime.Second()==dateTime2.Second()); |
|
1696 |
test(dateTime.Minute()==dateTime2.Minute()); |
|
1697 |
test(dateTime.Hour()==dateTime2.Hour()); |
|
1698 |
test(dateTime.Day()==dateTime2.Day()); |
|
1699 |
test(dateTime.Month()==dateTime2.Month()); |
|
1700 |
test(dateTime.Year()==dateTime2.Year()); |
|
1701 |
||
1702 |
dateTime2.Set(2004,EFebruary,28,12,48,0,1); |
|
1703 |
time=dateTime2; |
|
1704 |
time.RoundUpToNextMinute(); |
|
1705 |
dateTime=time.DateTime(); |
|
1706 |
test(dateTime.MicroSecond()==0); |
|
1707 |
test(dateTime.Second()==0); |
|
1708 |
test(dateTime.Minute()==dateTime2.Minute()+1); |
|
1709 |
test(dateTime.Hour()==dateTime2.Hour()); |
|
1710 |
test(dateTime.Day()==dateTime2.Day()); |
|
1711 |
test(dateTime.Month()==dateTime2.Month()); |
|
1712 |
test(dateTime.Year()==dateTime2.Year()); |
|
1713 |
||
1714 |
dateTime2.Set(2037,EDecember,30,23,59,1,45341); |
|
1715 |
time=dateTime2; |
|
1716 |
time.RoundUpToNextMinute(); |
|
1717 |
dateTime=time.DateTime(); |
|
1718 |
test(dateTime.MicroSecond()==0); |
|
1719 |
test(dateTime.Second()==0); |
|
1720 |
test(dateTime.Minute()==0); |
|
1721 |
test(dateTime.Hour()==0); |
|
1722 |
test(dateTime.Day()==0); |
|
1723 |
test(dateTime.Month()==EJanuary); |
|
1724 |
test(dateTime.Year()==dateTime2.Year()+1); |
|
1725 |
||
1726 |
test.Next(_L("HomeTime and UniversalTime")); |
|
1727 |
time.HomeTime(); |
|
1728 |
dateTime=time.DateTime(); |
|
1729 |
test.Printf(_L(" Local Time is - %+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d\n"),dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
1730 |
time.UniversalTime(); |
|
1731 |
dateTime=time.DateTime(); |
|
1732 |
test.Printf(_L(" Universal Time is - %+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d\n"),dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
1733 |
||
1734 |
test.Next(_L("SetUTCTime")); |
|
1735 |
time.UniversalTime(); |
|
1736 |
time+=TTimeIntervalMinutes(30); |
|
1737 |
TInt r=User::SetUTCTime(time); |
|
1738 |
test(r==KErrNone); |
|
1739 |
time.HomeTime(); |
|
1740 |
dateTime=time.DateTime(); |
|
1741 |
test.Printf(_L(" Local Time is - %+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d\n"),dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
1742 |
time.UniversalTime(); |
|
1743 |
dateTime=time.DateTime(); |
|
1744 |
test.Printf(_L(" Universal Time is - %+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d\n"),dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
1745 |
||
1746 |
r=User::SetUTCTime(TTime(TDateTime(2090,EJanuary,0,0,0,0,0))); |
|
1747 |
//#if defined (__MARM__) |
|
1748 |
test(r==KErrOverflow); |
|
1749 |
//#else |
|
1750 |
// test(r==KErrNone); |
|
1751 |
// time.HomeTime(); |
|
1752 |
// test(time.DateTime().Second()==0); |
|
1753 |
// test(time.DateTime().Minute()==0); |
|
1754 |
// test(time.DateTime().Day()==0); |
|
1755 |
// test(time.DateTime().Month()==EJanuary); |
|
1756 |
// test(time.DateTime().Year()==2090); |
|
1757 |
// test(time.DateTime().Hour()==0); |
|
1758 |
//#endif |
|
1759 |
||
1760 |
time.UniversalTime(); |
|
1761 |
time-=TTimeIntervalMinutes(30); |
|
1762 |
r=User::SetUTCTime(time); |
|
1763 |
test(r==KErrNone); |
|
1764 |
time.HomeTime(); |
|
1765 |
dateTime=time.DateTime(); |
|
1766 |
test.Printf(_L(" Local Time is - %+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d\n"),dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
1767 |
time.UniversalTime(); |
|
1768 |
dateTime=time.DateTime(); |
|
1769 |
test.Printf(_L(" Universal Time is - %+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d\n"),dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
1770 |
test.Printf(_L("does this come out")); |
|
1771 |
} |
|
1772 |
||
1773 |
void TestTTime::Test11() |
|
1774 |
// |
|
1775 |
// |
|
1776 |
// |
|
1777 |
{ |
|
1778 |
TTime now; |
|
1779 |
now.UniversalTime(); |
|
1780 |
TTimeIntervalSeconds offset; |
|
1781 |
offset = User::UTCOffset(); |
|
1782 |
RTimer timer[5]; |
|
1783 |
TRequestStatus stat[5]; |
|
1784 |
||
1785 |
test.Start(_L("Create timers")); |
|
1786 |
TInt i; |
|
1787 |
for (i=0; i<5; i++) |
|
1788 |
test(timer[i].CreateLocal()==KErrNone); |
|
1789 |
||
1790 |
test.Next(_L("Change the time")); |
|
1791 |
TInt r=User::SetUTCTime(now-TTimeIntervalMinutes(120)); |
|
1792 |
test_Equal(r, KErrNone); |
|
1793 |
||
1794 |
test.Next(_L("Start an absolute timer")); |
|
1795 |
timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(60)); |
|
1796 |
test.Next(_L("Change the system time")); |
|
1797 |
r=User::SetUTCTime(now-TTimeIntervalMinutes(120)); |
|
1798 |
test(r==KErrNone); |
|
1799 |
User::WaitForRequest(stat[0]); |
|
1800 |
test.Next(_L("Test timer aborted")); |
|
1801 |
test(stat[0]==KErrAbort); |
|
1802 |
||
1803 |
test.Next(_L("Set UTC offset to zero")); |
|
1804 |
User::SetUTCOffset(0); |
|
1805 |
test.Next(_L("Start an absolute timer")); |
|
1806 |
timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(120)); |
|
1807 |
test.Next(_L("Change the UTC offset to +1 hour")); |
|
1808 |
User::SetUTCOffset(3600); |
|
1809 |
User::WaitForRequest(stat[0]); |
|
1810 |
test.Next(_L("Test timer aborted")); |
|
1811 |
test(stat[0]==KErrAbort); |
|
1812 |
test.Next(_L("Start another absolute timer")); |
|
1813 |
timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(120)); |
|
1814 |
test.Next(_L("Re-set the UTC offset to +1 hour")); |
|
1815 |
User::SetUTCOffset(3600); |
|
1816 |
test.Next(_L("Test timer NOT aborted (no actual time change)")); |
|
1817 |
test(stat[0]==KRequestPending); |
|
1818 |
test.Next(_L("Cancel timer")); |
|
1819 |
timer[0].Cancel(); |
|
1820 |
User::WaitForRequest(stat[0]); |
|
1821 |
test(stat[0]==KErrCancel); |
|
1822 |
||
1823 |
/* |
|
1824 |
// This code fails intermitantly |
|
1825 |
FOREVER |
|
1826 |
{ |
|
1827 |
timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(60)); |
|
1828 |
test(stat[0]==KRequestPending); |
|
1829 |
timer[1].AtUTC(stat[1], now+TTimeIntervalMinutes(30)); |
|
1830 |
test(stat[1]==KRequestPending); |
|
1831 |
test.Next(_L("ABCDEFGHIJKLMNOPQRS D FD FDDFGDF ABCDEFGHIJ ABCDEFGHIJKGL")); |
|
1832 |
timer[1].Cancel(); |
|
1833 |
timer[0].Cancel(); |
|
1834 |
User::WaitForRequest(stat[0]); |
|
1835 |
User::WaitForRequest(stat[1]); |
|
1836 |
test.Next(_L("ABCDEFGH")); |
|
1837 |
test(stat[0]==KErrCancel); |
|
1838 |
test(stat[1]==KErrCancel); |
|
1839 |
} |
|
1840 |
*/ |
|
1841 |
||
1842 |
test.Next(_L("Start 3 absolute timers and a relative timer")); |
|
1843 |
timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(60)); |
|
1844 |
test_Equal(KRequestPending, stat[0].Int()); |
|
1845 |
timer[1].AtUTC(stat[1], now+TTimeIntervalMinutes(30)); |
|
1846 |
test_Equal(KRequestPending, stat[1].Int()); |
|
1847 |
timer[2].After(stat[2], 9000000); |
|
1848 |
test_Equal(KRequestPending, stat[2].Int()); |
|
1849 |
timer[3].AtUTC(stat[3], now+TTimeIntervalMinutes(10)); |
|
1850 |
test_Equal(KRequestPending, stat[3].Int()); |
|
1851 |
TInt s=stat[2].Int(); |
|
1852 |
test.Next(_L("Change system time")); |
|
1853 |
r=User::SetUTCTime(now-TTimeIntervalMinutes(100)); |
|
1854 |
test(r==KErrNone); |
|
1855 |
User::WaitForRequest(stat[0]); |
|
1856 |
User::WaitForRequest(stat[1]); |
|
1857 |
User::WaitForRequest(stat[3]); |
|
1858 |
test.Next(_L("Test absolute timers aborted")); |
|
1859 |
test(stat[0]==KErrAbort); |
|
1860 |
test(stat[1]==KErrAbort); |
|
1861 |
test(stat[3]==KErrAbort); |
|
1862 |
test(stat[2]==s); |
|
1863 |
test.Next(_L("Cancel relative timer")); |
|
1864 |
timer[2].Cancel(); |
|
1865 |
User::WaitForRequest(stat[2]); |
|
1866 |
test(stat[2]==KErrCancel); |
|
1867 |
||
1868 |
test.Next(_L("Start 3 relative timers and 1 absolute timer")); |
|
1869 |
timer[0].After(stat[0], 10000); |
|
1870 |
timer[1].After(stat[1], 20000); |
|
1871 |
timer[2].After(stat[2], 20100); |
|
1872 |
timer[3].AtUTC(stat[3], now+TTimeIntervalMinutes(10)); |
|
1873 |
test.Next(_L("Wait for 1 relative timer to complete")); |
|
1874 |
User::WaitForRequest(stat[0]); |
|
1875 |
test(stat[0]==KErrNone); |
|
1876 |
test.Next(_L("Change the time")); |
|
1877 |
r=User::SetUTCTime(now-TTimeIntervalMinutes(100)); |
|
1878 |
test(r==KErrNone); |
|
1879 |
User::WaitForRequest(stat[3]); |
|
1880 |
test(stat[3]==KErrAbort); |
|
1881 |
stat[3]=-999; |
|
1882 |
test.Next(_L("Change the time again")); |
|
1883 |
r=User::SetUTCTime(now-TTimeIntervalMinutes(110)); |
|
1884 |
test(r==KErrNone); |
|
1885 |
test.Next(_L("Wait for other relative timers to complete")); |
|
1886 |
User::WaitForRequest(stat[1]); |
|
1887 |
User::WaitForRequest(stat[2]); |
|
1888 |
test(stat[1]==KErrNone); |
|
1889 |
test(stat[2]==KErrNone); |
|
1890 |
test(stat[3]==-999); |
|
1891 |
||
1892 |
test.Next(_L("Start 2 absolute timers")); |
|
1893 |
timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(60)); |
|
1894 |
timer[1].AtUTC(stat[1], now+TTimeIntervalMinutes(30)); |
|
1895 |
test.Next(_L("Cancel one")); |
|
1896 |
timer[0].Cancel(); |
|
1897 |
User::WaitForRequest(stat[0]); |
|
1898 |
test(stat[0]==KErrCancel); |
|
1899 |
test.Next(_L("Change the time")); |
|
1900 |
r=User::SetUTCTime(now-TTimeIntervalMinutes(110)); |
|
1901 |
test(r==KErrNone); |
|
1902 |
User::WaitForRequest(stat[1]); |
|
1903 |
test(stat[1]==KErrAbort); |
|
1904 |
test(stat[0]==KErrCancel); |
|
1905 |
||
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1906 |
// The platform may or may not support SecureTime, and even if it does, |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1907 |
// it may not have a secure time set. So we start this test by making |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1908 |
// sure that the NonSecureOffset is set (which may fail, if it's not |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1909 |
// supported OR if it's already set); then read and write the secure |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1910 |
// time, to make sure that it's supported and we have permission. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1911 |
User::SetUTCTime(now); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1912 |
HAL::Set(HAL::ETimeNonSecureOffset, 0); |
0 | 1913 |
test.Next(_L("Test absolute timers with secure time change")); |
1914 |
TTime securetime; |
|
1915 |
if ((r = securetime.UniversalTimeSecure()) == KErrNone) |
|
1916 |
r = User::SetUTCTimeSecure(securetime); |
|
1917 |
if (r != KErrNone) |
|
1918 |
{ |
|
1919 |
RDebug::Printf("WARNING: Secure clock change test skipped because secure time could not be changed!"); |
|
1920 |
} |
|
1921 |
else |
|
1922 |
{ |
|
1923 |
timer[0].AtUTC(stat[0], now+TTimeIntervalSeconds(5)); |
|
1924 |
r = User::SetUTCTimeSecure(securetime+TTimeIntervalSeconds(30)); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1925 |
test_Equal(KErrNone, r); |
0 | 1926 |
r = User::SetUTCTimeSecure(securetime-TTimeIntervalSeconds(30)); |
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1927 |
test_Equal(KErrNone, r); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1928 |
// The absolute timer should not have been aborted by the secure time change, |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1929 |
test_Equal(KRequestPending, stat[0].Int()); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1930 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1931 |
// The outstanding absolute timer should complete before this new relative timer |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1932 |
timer[1].After(stat[1], 20000000); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1933 |
User::WaitForRequest(stat[0], stat[1]); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1934 |
timer[1].Cancel(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1935 |
test_Equal(KErrNone, stat[0].Int()); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1936 |
test_Equal(KErrCancel, stat[1].Int()); |
0 | 1937 |
User::SetUTCTimeSecure(securetime+TTimeIntervalSeconds(5)); |
1938 |
} |
|
1939 |
||
1940 |
test.Next(_L("Close the timers")); |
|
1941 |
for (i=0; i<5; i++) |
|
1942 |
timer[i].Close(); |
|
1943 |
||
1944 |
r=User::SetUTCTimeAndOffset(now,offset); |
|
1945 |
test(r==KErrNone); |
|
1946 |
test.End(); |
|
1947 |
} |
|
1948 |
||
1949 |
void TestTTime::Test12() |
|
1950 |
{ |
|
1951 |
||
1952 |
TInt err; |
|
1953 |
TDateTime dateTime; |
|
1954 |
test.Start(_L("Setting date using YYYYMMDD:HHMMSS.MMMMMM")); |
|
1955 |
TTime now(_L("19960201:122341.1234")); |
|
1956 |
dateTime=now.DateTime(); |
|
1957 |
test(dateTime.MicroSecond()==1234); |
|
1958 |
test(dateTime.Second()==41); |
|
1959 |
test(dateTime.Minute()==23); |
|
1960 |
test(dateTime.Hour()==12); |
|
1961 |
test(dateTime.Day()==1); |
|
1962 |
test(dateTime.Month()==2); |
|
1963 |
test(dateTime.Year()==1996); |
|
1964 |
test.Next(_L("Setting date using YYYYMMDD:")); |
|
1965 |
err=now.Set(_L("19901129:")); // Just set the date |
|
1966 |
dateTime=now.DateTime(); |
|
1967 |
test(err==KErrNone); |
|
1968 |
test(dateTime.MicroSecond()==0); |
|
1969 |
test(dateTime.Second()==0); |
|
1970 |
test(dateTime.Minute()==0); |
|
1971 |
test(dateTime.Hour()==0); |
|
1972 |
test(dateTime.Day()==29); |
|
1973 |
test(dateTime.Month()==11); |
|
1974 |
test(dateTime.Year()==1990); |
|
1975 |
test.Next(_L("Setting date using :HHMMSS.")); |
|
1976 |
err=now.Set(_L(":105614.")); // Just the time |
|
1977 |
dateTime=now.DateTime(); |
|
1978 |
test(err==KErrNone); |
|
1979 |
test(dateTime.MicroSecond()==0); |
|
1980 |
test(dateTime.Second()==14); |
|
1981 |
test(dateTime.Minute()==56); |
|
1982 |
test(dateTime.Hour()==10); |
|
1983 |
test(dateTime.Day()==0); |
|
1984 |
test(dateTime.Month()==0); |
|
1985 |
test(dateTime.Year()==0); |
|
1986 |
test.Next(_L("Setting date using .MMMMMM")); |
|
1987 |
err=now.Set(_L(".999999")); // Just the microseconds |
|
1988 |
dateTime=now.DateTime(); |
|
1989 |
test(err==KErrNone); |
|
1990 |
test(dateTime.MicroSecond()==999999); |
|
1991 |
test(dateTime.Second()==0); |
|
1992 |
test(dateTime.Minute()==0); |
|
1993 |
test(dateTime.Hour()==0); |
|
1994 |
test(dateTime.Day()==0); |
|
1995 |
test(dateTime.Month()==0); |
|
1996 |
test(dateTime.Year()==0); |
|
1997 |
test.Next(_L("Setting date using HHMMSS should fail")); |
|
1998 |
err=now.Set(_L("104520")); // Invalid - no separator |
|
1999 |
dateTime=now.DateTime(); |
|
2000 |
test(err==KErrGeneral); |
|
2001 |
test(dateTime.MicroSecond()==999999); |
|
2002 |
test(dateTime.Second()==0); |
|
2003 |
test(dateTime.Minute()==0); |
|
2004 |
test(dateTime.Hour()==0); |
|
2005 |
test(dateTime.Day()==0); |
|
2006 |
test(dateTime.Month()==0); |
|
2007 |
test(dateTime.Year()==0); |
|
2008 |
test.Next(_L("Setting date using :HHMMSS")); |
|
2009 |
err=now.Set(_L(":054531")); // Set time with no dot |
|
2010 |
dateTime=now.DateTime(); |
|
2011 |
test(err==KErrNone); |
|
2012 |
test(dateTime.MicroSecond()==0); |
|
2013 |
test(dateTime.Second()==31); |
|
2014 |
test(dateTime.Minute()==45); |
|
2015 |
test(dateTime.Hour()==5); |
|
2016 |
test(dateTime.Day()==0); |
|
2017 |
test(dateTime.Month()==0); |
|
2018 |
test(dateTime.Year()==0); |
|
2019 |
test.Next(_L("Setting invalid date using YYYYMMSS:HHMMSS.MMMM")); |
|
2020 |
err=now.Set(_L("19910130:023210.1234")); // invalid date |
|
2021 |
dateTime=now.DateTime(); |
|
2022 |
test(err==KErrGeneral); |
|
2023 |
test(dateTime.MicroSecond()==0); |
|
2024 |
test(dateTime.Second()==31); |
|
2025 |
test(dateTime.Minute()==45); |
|
2026 |
test(dateTime.Hour()==5); |
|
2027 |
test(dateTime.Day()==0); |
|
2028 |
test(dateTime.Month()==0); |
|
2029 |
test(dateTime.Year()==0); |
|
2030 |
test.Next(_L("Setting date using YYYYMMDD:.MMMM")); |
|
2031 |
err=now.Set(_L("19960730:.123456")); // Set date and microseconds |
|
2032 |
dateTime=now.DateTime(); |
|
2033 |
test(err==KErrNone); |
|
2034 |
test(dateTime.MicroSecond()==123456); |
|
2035 |
test(dateTime.Second()==0); |
|
2036 |
test(dateTime.Minute()==0); |
|
2037 |
test(dateTime.Hour()==0); |
|
2038 |
test(dateTime.Day()==30); |
|
2039 |
test(dateTime.Month()==7); |
|
2040 |
test(dateTime.Year()==1996); |
|
2041 |
test.Next(_L("Setting date using .")); |
|
2042 |
err=now.Set(_L(".")); |
|
2043 |
dateTime=now.DateTime(); |
|
2044 |
test(err==KErrNone); |
|
2045 |
test(dateTime.MicroSecond()==0); |
|
2046 |
test(dateTime.Second()==0); |
|
2047 |
test(dateTime.Minute()==0); |
|
2048 |
test(dateTime.Hour()==0); |
|
2049 |
test(dateTime.Day()==0); |
|
2050 |
test(dateTime.Month()==0); |
|
2051 |
test(dateTime.Year()==0); |
|
2052 |
test.Next(_L("Setting date using :.")); |
|
2053 |
err=now.Set(_L(":.")); |
|
2054 |
dateTime=now.DateTime(); |
|
2055 |
test(err==KErrNone); |
|
2056 |
test(dateTime.MicroSecond()==0); |
|
2057 |
test(dateTime.Second()==0); |
|
2058 |
test(dateTime.Minute()==0); |
|
2059 |
test(dateTime.Hour()==0); |
|
2060 |
test(dateTime.Day()==0); |
|
2061 |
test(dateTime.Month()==0); |
|
2062 |
test(dateTime.Year()==0); |
|
2063 |
test.Next(_L("Setting date using :")); |
|
2064 |
err=now.Set(_L(":")); |
|
2065 |
dateTime=now.DateTime(); |
|
2066 |
test(err==KErrNone); |
|
2067 |
test(dateTime.MicroSecond()==0); |
|
2068 |
test(dateTime.Second()==0); |
|
2069 |
test(dateTime.Minute()==0); |
|
2070 |
test(dateTime.Hour()==0); |
|
2071 |
test(dateTime.Day()==0); |
|
2072 |
test(dateTime.Month()==0); |
|
2073 |
test(dateTime.Year()==0); |
|
2074 |
test.Next(_L("Setting date using YYYYMMDD.HHMMSS:MMMM should fail")); |
|
2075 |
err=now.Set(_L("19900101.105630:1234")); // Wrong way round |
|
2076 |
dateTime=now.DateTime(); |
|
2077 |
test(err==KErrGeneral); |
|
2078 |
test(dateTime.MicroSecond()==0); |
|
2079 |
test(dateTime.Second()==0); |
|
2080 |
test(dateTime.Minute()==0); |
|
2081 |
test(dateTime.Hour()==0); |
|
2082 |
test(dateTime.Day()==0); |
|
2083 |
test(dateTime.Month()==0); |
|
2084 |
test(dateTime.Year()==0); |
|
2085 |
test.Next(_L("Setting date using YYYYMMDD:HHMMSS.MMMMMMM should fail")); |
|
2086 |
err=now.Set(_L("19900101:105630.1234567")); // Microseconds too long |
|
2087 |
dateTime=now.DateTime(); |
|
2088 |
test(err==KErrGeneral); |
|
2089 |
test(dateTime.MicroSecond()==0); |
|
2090 |
test(dateTime.Second()==0); |
|
2091 |
test(dateTime.Minute()==0); |
|
2092 |
test(dateTime.Hour()==0); |
|
2093 |
test(dateTime.Day()==0); |
|
2094 |
test(dateTime.Month()==0); |
|
2095 |
test(dateTime.Year()==0); |
|
2096 |
test.End(); |
|
2097 |
} |
|
2098 |
||
2099 |
struct TestInfo |
|
2100 |
{ |
|
2101 |
TestInfo (TTime aTime,TInt aMicroSec,TInt aSec,TInt aMin,TInt aHour,TInt aDay,TInt aMonth,TInt aYear,TText* aDayString,TTime aNextMin) |
|
2102 |
{ |
|
2103 |
iTime=aTime; |
|
2104 |
iMicroSec=aMicroSec; |
|
2105 |
iSec=aSec; |
|
2106 |
iMin=aMin; |
|
2107 |
iHour=aHour; |
|
2108 |
iDay=aDay; |
|
2109 |
iMonth=aMonth; |
|
2110 |
iYear=aYear; |
|
2111 |
iDayString=aDayString; |
|
2112 |
iNextMin=aNextMin; |
|
2113 |
} |
|
2114 |
TTime iTime; |
|
2115 |
TInt iMicroSec; |
|
2116 |
TInt iSec; |
|
2117 |
TInt iMin; |
|
2118 |
TInt iHour; |
|
2119 |
TInt iDay; |
|
2120 |
TInt iMonth; |
|
2121 |
TInt iYear; |
|
2122 |
TText* iDayString; |
|
2123 |
TTime iNextMin; |
|
2124 |
}; |
|
2125 |
||
2126 |
const TestInfo KTestArray[]= |
|
2127 |
{ |
|
2128 |
TestInfo(TTime(KDaysToMicroSeconds*31+1),1,0,0,0,0,EFebruary,0,(TText*)_S("!Thu!am!00!02!"),TTime(KDaysToMicroSeconds*31+60000000)), |
|
2129 |
TestInfo(TTime(KDaysToMicroSeconds*31),0,0,0,0,0,EFebruary,0,(TText*)_S("!Thu!am!00!02!"),TTime(KDaysToMicroSeconds*31)), |
|
2130 |
TestInfo(TTime(KDaysToMicroSeconds*31-1),999999,59,59,23,30,EJanuary,0,(TText*)_S("!Wed!pm!59!01!"),TTime(KDaysToMicroSeconds*31)), |
|
2131 |
TestInfo(TTime(60000001),1,0,1,0,0,EJanuary,0,(TText*)_S("!Mon!am!01!01!"),TTime(120000000)), |
|
2132 |
TestInfo(TTime(60000000),0,0,1,0,0,EJanuary,0,(TText*)_S("!Mon!am!01!01!"),TTime(60000000)), |
|
2133 |
TestInfo(TTime(59999999),999999,59,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(60000000)), |
|
2134 |
TestInfo(TTime(1000001),1,1,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(60000000)), |
|
2135 |
TestInfo(TTime(1000000),0,1,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(60000000)), |
|
2136 |
TestInfo(TTime(999999),999999,0,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(60000000)), |
|
2137 |
TestInfo(TTime(1),1,0,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(60000000)), |
|
2138 |
TestInfo(TTime(0),0,0,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(0)), |
|
2139 |
TestInfo(TTime(-1),999999,59,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(0)), |
|
2140 |
TestInfo(TTime(-1000000),0,59,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(0)), |
|
2141 |
TestInfo(TTime(-999999),1,59,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(0)), |
|
2142 |
TestInfo(TTime(-1000001),999999,58,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(0)), |
|
2143 |
TestInfo(TTime(-60000000),0,0,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(-60000000)), |
|
2144 |
TestInfo(TTime(-59999999),1,0,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(0)), |
|
2145 |
TestInfo(TTime(-60000001),999999,59,58,23,30,EDecember,-1,(TText*)_S("!Sun!pm!58!12!"),TTime(-60000000)), |
|
2146 |
TestInfo(TTime(-180000000),0,0,57,23,30,EDecember,-1,(TText*)_S("!Sun!pm!57!12!"),TTime(-180000000)), |
|
2147 |
TestInfo(TTime(-179999999),1,0,57,23,30,EDecember,-1,(TText*)_S("!Sun!pm!57!12!"),TTime(-120000000)), |
|
2148 |
TestInfo(TTime(-180000001),999999,59,56,23,30,EDecember,-1,(TText*)_S("!Sun!pm!56!12!"),TTime(-180000000)), |
|
2149 |
TestInfo(TTime(-KDaysToMicroSeconds+1),1,0,0,0,30,EDecember,-1,(TText*)_S("!Sun!am!00!12!"),TTime(-KDaysToMicroSeconds+60000000)), |
|
2150 |
TestInfo(TTime(-KDaysToMicroSeconds),0,0,0,0,30,EDecember,-1,(TText*)_S("!Sun!am!00!12!"),TTime(-KDaysToMicroSeconds)), |
|
2151 |
TestInfo(TTime(-KDaysToMicroSeconds-1),999999,59,59,23,29,EDecember,-1,(TText*)_S("!Sat!pm!59!12!"),TTime(-KDaysToMicroSeconds)), |
|
2152 |
TestInfo(TTime(-KDaysToMicroSeconds*7),0,0,0,0,24,EDecember,-1,(TText*)_S("!Mon!am!00!12!"),TTime(-KDaysToMicroSeconds*7)), |
|
2153 |
TestInfo(TTime(-KDaysToMicroSeconds*14),0,0,0,0,17,EDecember,-1,(TText*)_S("!Mon!am!00!12!"),TTime(-KDaysToMicroSeconds*14)), |
|
2154 |
TestInfo(TTime(-KDaysToMicroSeconds*14+1),1,0,0,0,17,EDecember,-1,(TText*)_S("!Mon!am!00!12!"),TTime(-KDaysToMicroSeconds*14+60000000)), |
|
2155 |
TestInfo(TTime(-KDaysToMicroSeconds*14-1),999999,59,59,23,16,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(-KDaysToMicroSeconds*14)), |
|
2156 |
TestInfo(TTime(-KDaysToMicroSeconds*92),0,0,0,0,0,EOctober,-1,(TText*)_S("!Sun!am!00!10!"),TTime(-KDaysToMicroSeconds*92)), |
|
2157 |
TestInfo(TTime(-KDaysToMicroSeconds*92+1),1,0,0,0,0,EOctober,-1,(TText*)_S("!Sun!am!00!10!"),TTime(-KDaysToMicroSeconds*92+60000000)), |
|
2158 |
TestInfo(TTime(-KDaysToMicroSeconds*92-1),999999,59,59,23,29,ESeptember,-1,(TText*)_S("!Sat!pm!59!09!"),TTime(-KDaysToMicroSeconds*92)), |
|
2159 |
TestInfo(Time::NullTTime(),224192,5,59,19,21,EDecember,-292272,(TText*)_S("!Thu!pm!59!12!"),TTime(Time::NullTTime().Int64()-Time::NullTTime().Int64()%60000000)) |
|
2160 |
}; |
|
2161 |
||
2162 |
void TestTTime::Test13() |
|
2163 |
{ |
|
2164 |
TBuf<0x80> testString; |
|
2165 |
TInt i=0; |
|
2166 |
for (;i<(TInt)(sizeof(KTestArray)/sizeof(TestInfo))-1;i++) |
|
2167 |
{ |
|
2168 |
TTime time=KTestArray[i].iTime; |
|
2169 |
TInt r=time.DateTime().MicroSecond(); |
|
2170 |
test(r==KTestArray[i].iMicroSec); |
|
2171 |
r=time.DateTime().Second(); |
|
2172 |
test(r==KTestArray[i].iSec); |
|
2173 |
r=time.DateTime().Minute(); |
|
2174 |
test(r==KTestArray[i].iMin); |
|
2175 |
r=time.DateTime().Hour(); |
|
2176 |
test(r==KTestArray[i].iHour); |
|
2177 |
r=time.DateTime().Day(); |
|
2178 |
test(r==KTestArray[i].iDay); |
|
2179 |
r=time.DateTime().Month(); |
|
2180 |
test(r==KTestArray[i].iMonth); |
|
2181 |
r=time.DateTime().Year(); |
|
2182 |
test(r==KTestArray[i].iYear); |
|
2183 |
TRAP(r,time.FormatL(testString,_L("!%*E!%*A!%T!%F%M!"))); |
|
2184 |
test(r==KErrNone); |
|
2185 |
test(testString==TPtrC(KTestArray[i].iDayString)); |
|
2186 |
TTimeIntervalMicroSeconds usFrom; |
|
2187 |
usFrom=time.MicroSecondsFrom(TTime(0)); |
|
2188 |
test(usFrom==time.Int64()); |
|
2189 |
usFrom=TTime(0).MicroSecondsFrom(time); |
|
2190 |
test(usFrom==-time.Int64()); |
|
2191 |
usFrom=time.MicroSecondsFrom(TTime(-1)); |
|
2192 |
test(usFrom==time.Int64()+1); |
|
2193 |
usFrom=TTime(-1).MicroSecondsFrom(time); |
|
2194 |
test(usFrom==-time.Int64()-1); |
|
2195 |
usFrom=time.MicroSecondsFrom(TTime(1)); |
|
2196 |
test(usFrom==time.Int64()-1); |
|
2197 |
usFrom=TTime(1).MicroSecondsFrom(time); |
|
2198 |
test(usFrom==-time.Int64()+1); |
|
2199 |
TTime time2=time+TTimeIntervalYears(0); |
|
2200 |
test(time2==time); |
|
2201 |
time2=time+TTimeIntervalYears(1); |
|
2202 |
r=time2.DateTime().Year(); |
|
2203 |
test(r==KTestArray[i].iYear+1); |
|
2204 |
time2=time-TTimeIntervalYears(1); |
|
2205 |
r=time2.DateTime().Year(); |
|
2206 |
test(r==KTestArray[i].iYear-1); |
|
2207 |
time2=time+TTimeIntervalMonths(0); |
|
2208 |
test(time2==time); |
|
2209 |
time2=time+TTimeIntervalMonths(1); |
|
2210 |
r=time2.DateTime().Month(); |
|
2211 |
test(r==(KTestArray[i].iMonth+1)%12); |
|
2212 |
time2=time-TTimeIntervalMonths(1); |
|
2213 |
r=time2.DateTime().Month(); |
|
2214 |
test(r==(KTestArray[i].iMonth+11)%12); |
|
2215 |
time2=time+TTimeIntervalDays(0); |
|
2216 |
test(time2==time); |
|
2217 |
time2=time+TTimeIntervalHours(0); |
|
2218 |
test(time2==time); |
|
2219 |
time2=time+TTimeIntervalMinutes(0); |
|
2220 |
test(time2==time); |
|
2221 |
time2=time+TTimeIntervalSeconds(0); |
|
2222 |
test(time2==time); |
|
2223 |
time2=time+TTimeIntervalMicroSeconds(0); |
|
2224 |
test(time2==time); |
|
2225 |
time.RoundUpToNextMinute(); |
|
2226 |
test(time==TTime(KTestArray[i].iNextMin)); |
|
2227 |
} |
|
2228 |
||
2229 |
TTime time=KTestArray[i].iTime; |
|
2230 |
test(time==Time::NullTTime()); |
|
2231 |
TInt r=time.DateTime().MicroSecond(); |
|
2232 |
test(r==KTestArray[i].iMicroSec); |
|
2233 |
r=time.DateTime().Second(); |
|
2234 |
test(r==KTestArray[i].iSec); |
|
2235 |
r=time.DateTime().Minute(); |
|
2236 |
test(r==KTestArray[i].iMin); |
|
2237 |
r=time.DateTime().Hour(); |
|
2238 |
test(r==KTestArray[i].iHour); |
|
2239 |
r=time.DateTime().Day(); |
|
2240 |
test(r==KTestArray[i].iDay); |
|
2241 |
r=time.DateTime().Month(); |
|
2242 |
test(r==KTestArray[i].iMonth); |
|
2243 |
r=time.DateTime().Year(); |
|
2244 |
test(r==KTestArray[i].iYear); |
|
2245 |
TRAP(r,time.FormatL(testString,_L("!%*E!%*A!%T!%F%M!"))); |
|
2246 |
test(r==KErrNone); |
|
2247 |
test(testString==TPtrC(KTestArray[i].iDayString)); |
|
2248 |
TTimeIntervalMicroSeconds usFrom; |
|
2249 |
usFrom=time.MicroSecondsFrom(TTime(0)); |
|
2250 |
test(usFrom==time.Int64()); |
|
2251 |
usFrom=TTime(0).MicroSecondsFrom(time); |
|
2252 |
test(usFrom==-time.Int64()); |
|
2253 |
usFrom=time.MicroSecondsFrom(TTime(-1)); |
|
2254 |
test(usFrom==time.Int64()+1); |
|
2255 |
usFrom=TTime(-1).MicroSecondsFrom(time); |
|
2256 |
test(usFrom==-time.Int64()-1); |
|
2257 |
usFrom=time.MicroSecondsFrom(TTime(1)); |
|
2258 |
test(usFrom==time.Int64()-1); |
|
2259 |
usFrom=TTime(1).MicroSecondsFrom(time); |
|
2260 |
test(usFrom==-time.Int64()+1); |
|
2261 |
TTime time2=time+TTimeIntervalYears(0); |
|
2262 |
test(time2==time); |
|
2263 |
time2=time+TTimeIntervalYears(1); |
|
2264 |
r=time2.DateTime().Year(); |
|
2265 |
test(r==KTestArray[i].iYear+1); |
|
2266 |
time2=time+TTimeIntervalMonths(0); |
|
2267 |
test(time2==time); |
|
2268 |
time2=time+TTimeIntervalMonths(1); |
|
2269 |
r=time2.DateTime().Month(); |
|
2270 |
test(r==(KTestArray[i].iMonth+1)%12); |
|
2271 |
time2=time+TTimeIntervalDays(0); |
|
2272 |
test(time2==time); |
|
2273 |
time2=time+TTimeIntervalHours(0); |
|
2274 |
test(time2==time); |
|
2275 |
time2=time+TTimeIntervalMinutes(0); |
|
2276 |
test(time2==time); |
|
2277 |
time2=time+TTimeIntervalSeconds(0); |
|
2278 |
test(time2==time); |
|
2279 |
time2=time+TTimeIntervalMicroSeconds(0); |
|
2280 |
test(time2==time); |
|
2281 |
time.RoundUpToNextMinute(); |
|
2282 |
test(time==TTime(KTestArray[i].iNextMin)); |
|
2283 |
||
2284 |
} |
|
2285 |
||
2286 |
||
2287 |
void TestTTime::TestSecureClock() |
|
2288 |
{ |
|
2289 |
// See if secure clock present and early exit if its not enabled |
|
2290 |
TInt nso = 0; |
|
2291 |
TInt r = HAL::Get(HAL::ETimeNonSecureOffset,nso); |
|
2292 |
if (r != KErrNone) { |
|
2293 |
RDebug::Printf("WARNING: Secure clock test skipped because offset HAL attribute not present!"); |
|
2294 |
return; |
|
2295 |
} |
|
2296 |
||
2297 |
// Get the secure and nonsecure times |
|
2298 |
TTime securetime, now, march2001; |
|
2299 |
r = securetime.HomeTimeSecure(); |
|
2300 |
if (r==KErrNoSecureTime) { |
|
2301 |
TDateTime randomdate; |
|
2302 |
randomdate.Set(2005, ESeptember, 13, 0,0,0,0); |
|
2303 |
r = User::SetHomeTimeSecure(randomdate); |
|
2304 |
test_Equal(KErrNone, r); |
|
2305 |
r = securetime.HomeTimeSecure(); |
|
2306 |
} |
|
2307 |
test_Equal(KErrNone, r); |
|
2308 |
now.HomeTime(); |
|
2309 |
PrintTime("hometime=", now); |
|
2310 |
PrintTime("securetime=", securetime); |
|
2311 |
||
2312 |
// Set nonsecure time to March 2001 |
|
2313 |
TDateTime bday; |
|
2314 |
bday.Set(2001, EMarch, 6, 0,0,0,0); |
|
2315 |
march2001 = bday; |
|
2316 |
r = User::SetHomeTime(march2001); |
|
2317 |
test(r==KErrNone); |
|
2318 |
||
2319 |
// Check the nonsecure system time really updated to March 2001 |
|
2320 |
TTime now2, securetime2; |
|
2321 |
TTimeIntervalSeconds seconds_diff(100); |
|
2322 |
now2.HomeTime(); |
|
2323 |
r=now2.SecondsFrom(march2001, seconds_diff); |
|
2324 |
test(r==0); |
|
2325 |
test(seconds_diff == TTimeIntervalSeconds(0)); |
|
2326 |
||
2327 |
// Check the secure system time did not change as a result of changing nonsecure time |
|
2328 |
r = securetime2.HomeTimeSecure(); |
|
2329 |
test(r==KErrNone); |
|
2330 |
seconds_diff = TTimeIntervalSeconds(100); |
|
2331 |
r=securetime2.SecondsFrom(securetime, seconds_diff); |
|
2332 |
test(r==0); |
|
2333 |
test(seconds_diff == TTimeIntervalSeconds(0)); |
|
2334 |
||
2335 |
// Set secure time to March 2001 (this would fail without DRM rights) |
|
2336 |
// *** NB: Setting H4's rtc to any time before 1/1/2000 *** |
|
2337 |
// *** will not work but no error will be reported! *** |
|
2338 |
securetime2 = march2001; |
|
2339 |
r = User::SetHomeTimeSecure(securetime2); |
|
2340 |
test(r==KErrNone); |
|
2341 |
||
2342 |
// Check both secure & nonsecure system times are March 2001 |
|
2343 |
TTime now3, securetime3; |
|
2344 |
now3.HomeTime(); |
|
2345 |
r = securetime3.HomeTimeSecure(); |
|
2346 |
test(r==KErrNone); |
|
2347 |
r = securetime3.SecondsFrom(march2001, seconds_diff); |
|
2348 |
test(seconds_diff == TTimeIntervalSeconds(0)); |
|
2349 |
r = now3.SecondsFrom(march2001, seconds_diff); |
|
2350 |
test(seconds_diff == TTimeIntervalSeconds(0)); |
|
2351 |
||
2352 |
// Verify the offset changes by the right amount when the nonsecure time is changed |
|
2353 |
TTime time; |
|
2354 |
r = HAL::Get(HAL::ETimeNonSecureOffset,nso); |
|
2355 |
test_Equal(KErrNone, r); |
|
2356 |
time.UniversalTime(); |
|
2357 |
time+=TTimeIntervalMinutes(30); |
|
2358 |
TInt nso_expected = nso + 30*60; |
|
2359 |
r=User::SetUTCTime(time); |
|
2360 |
test_Equal(KErrNone, r); |
|
2361 |
r = HAL::Get(HAL::ETimeNonSecureOffset,nso); |
|
2362 |
test_Equal(KErrNone, r); |
|
2363 |
test_Equal(nso_expected, nso); |
|
2364 |
||
2365 |
// Restore secure clock and system time to what they were at the top of this function |
|
2366 |
r = User::SetHomeTimeSecure(securetime); |
|
2367 |
test_Equal(KErrNone, r); |
|
2368 |
r = User::SetHomeTime(now); |
|
2369 |
test_Equal(KErrNone, r); |
|
2370 |
||
2371 |
} |
|
2372 |
||
2373 |
GLDEF_C TInt E32Main() |
|
2374 |
{ |
|
2375 |
||
2376 |
test.Title(); |
|
2377 |
test.Start(_L("Testing TDateTime classes")); |
|
2378 |
TestTTime T; |
|
2379 |
||
2380 |
TLocale savedLocale; |
|
2381 |
||
2382 |
TLocale b; |
|
2383 |
b.SetDateSeparator('\0',0); |
|
2384 |
b.SetDateSeparator('/',1); |
|
2385 |
b.SetDateSeparator('/',2); |
|
2386 |
b.SetDateSeparator('\0',3); |
|
2387 |
b.SetDateFormat(EDateEuropean); |
|
2388 |
b.SetTimeFormat(ETime12); |
|
2389 |
b.SetTimeSeparator('\0',0); |
|
2390 |
b.SetTimeSeparator(':',1); |
|
2391 |
b.SetTimeSeparator(':',2); |
|
2392 |
b.SetTimeSeparator('\0',3); |
|
2393 |
b.SetAmPmSpaceBetween(ETrue); |
|
2394 |
b.SetAmPmSymbolPosition(ELocaleAfter); |
|
2395 |
b.SetWorkDays(0x1F); |
|
2396 |
b.SetStartOfWeek(EMonday); |
|
2397 |
b.Set(); |
|
2398 |
||
2399 |
TTimeIntervalSeconds savedOffset = User::UTCOffset(); |
|
2400 |
User::SetUTCOffset(0); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2401 |
|
0 | 2402 |
test.Next(_L("Testing TDateTime class")); |
2403 |
T.Test1(); |
|
2404 |
test.Next(_L("Testing TTimeIntervalMicroSeconds")); |
|
2405 |
T.Test2(); |
|
2406 |
test.Next(_L("Testing TTimeIntervalSeconds")); |
|
2407 |
T.Test3(); |
|
2408 |
test.Next(_L("Testing other time intervals")); |
|
2409 |
T.Test4(); |
|
2410 |
test.Next(_L("Testing TDateTime To TTime conversions")); |
|
2411 |
T.Test5(); |
|
2412 |
test.Next(_L("Testing adding TTimeIntervals and Subtracting TTimes")); |
|
2413 |
T.Test6(); |
|
2414 |
test.Next(_L("Day numbers in week and year")); |
|
2415 |
T.Test7(); |
|
2416 |
test.Next(_L("week numbers in year")); |
|
2417 |
T.Test8(); |
|
2418 |
test.Next(_L("String parsing")); |
|
2419 |
T.Test9(); |
|
2420 |
T.Test9(); |
|
2421 |
test.Next(_L("Remaining Time functions")); |
|
2422 |
//T.Test10(); |
|
2423 |
test.Next(_L("Test time change")); |
|
2424 |
T.Test11(); |
|
2425 |
test.Next(_L("Test TTime::Set(TDesC aString)")); |
|
2426 |
T.Test12(); |
|
2427 |
test.Next(_L("Test negative times")); |
|
2428 |
T.Test13(); |
|
2429 |
test.Next(_L("Test secure clock")); |
|
2430 |
T.TestSecureClock(); |
|
2431 |
test.Next(_L("The year 2000")); |
|
2432 |
TTime year2000(TDateTime(2000,EJanuary,0,0,0,0,0)); |
|
2433 |
test.Printf(_L("\tYear 2000 = %016lx\n"),year2000.Int64()); |
|
2434 |
savedLocale.Set(); //restore locale info |
|
2435 |
User::SetUTCOffset(savedOffset); |
|
2436 |
test.End(); |
|
2437 |
return(0); |
|
2438 |
} |