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