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