changeset 4 | 56f325a607ea |
parent 0 | a41df078684a |
2:4122176ea935 | 4:56f325a607ea |
---|---|
87 void Test13(void); |
87 void Test13(void); |
88 void TestSecureClock(void); |
88 void TestSecureClock(void); |
89 }; |
89 }; |
90 |
90 |
91 |
91 |
92 |
|
93 void PrintTime(char* sz, TTime& t) |
92 void PrintTime(char* sz, TTime& t) |
94 { |
93 { |
95 TDateTime dateTime(t.DateTime()); |
94 TDateTime dateTime(t.DateTime()); |
96 RDebug::Printf("%s%+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d", sz, dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
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()); |
97 } |
96 } |
99 void TestTTime::Test1(void) |
98 void TestTTime::Test1(void) |
100 // |
99 // |
101 // Tests for TDateTime |
100 // Tests for TDateTime |
102 // |
101 // |
103 { |
102 { |
104 |
|
105 TInt year=1980; //leap year |
103 TInt year=1980; //leap year |
106 TMonth month=EJanuary; |
104 TMonth month=EJanuary; |
107 TInt day=0; |
105 TInt day=0; |
108 TInt hour=0; |
106 TInt hour=0; |
109 TInt minute=0; |
107 TInt minute=0; |
110 TInt second=0; |
108 TInt second=0; |
111 TInt microSecond=10; |
109 TInt microSecond=10; |
112 |
110 |
113 TDateTime dateTime(year,month,day,hour,minute,second,microSecond); |
111 TDateTime dateTime(year,month,day,hour,minute,second,microSecond); |
114 |
112 |
115 test.Next(_L("Testing year ranges")); |
113 test.Next(_L("Testing year ranges")); |
116 TInt ii; |
114 TInt ii; |
117 for (ii=1970; ii<2100; ii++) |
115 for (ii=1970; ii<2100; ii++) |
251 test(dateTime.Day()==day); |
249 test(dateTime.Day()==day); |
252 test(dateTime.Hour()==hour); |
250 test(dateTime.Hour()==hour); |
253 test(dateTime.Minute()==minute); |
251 test(dateTime.Minute()==minute); |
254 test(dateTime.Second()==second); |
252 test(dateTime.Second()==second); |
255 test(dateTime.MicroSecond()==microSecond); |
253 test(dateTime.MicroSecond()==microSecond); |
256 |
|
257 } |
254 } |
258 |
255 |
259 void TestTTime::Test2(void) |
256 void TestTTime::Test2(void) |
260 // |
257 // |
261 // Tests for TTimeIntervalMicroSeconds |
258 // Tests for TTimeIntervalMicroSeconds |
262 // |
259 // |
263 { |
260 { |
264 |
|
265 test.Next(_L("Construction")); |
261 test.Next(_L("Construction")); |
266 TTimeIntervalMicroSeconds t1; // uninitialised |
262 TTimeIntervalMicroSeconds t1; // uninitialised |
267 TTimeIntervalMicroSeconds t2(0); |
263 TTimeIntervalMicroSeconds t2(0); |
268 test(t2.Int64()==0 ); |
264 test(t2.Int64()==0 ); |
269 TTimeIntervalMicroSeconds t3(1000000); |
265 TTimeIntervalMicroSeconds t3(1000000); |
270 test(t3.Int64()==1000000 ); |
266 test(t3.Int64()==1000000 ); |
271 TTimeIntervalMicroSeconds t4(-452); |
267 TTimeIntervalMicroSeconds t4(-452); |
272 test(t4.Int64()==-452 ); |
268 test(t4.Int64()==-452 ); |
273 |
269 |
274 TTimeIntervalMicroSeconds t5(MAKE_TINT64(0x7fffffff,0xffffffff)); |
270 TTimeIntervalMicroSeconds t5(MAKE_TINT64(0x7fffffff,0xffffffff)); |
275 t5.Int64(); |
271 t5.Int64(); |
276 |
272 |
277 test.Next(_L("operator =")); |
273 test.Next(_L("operator =")); |
278 TInt num(1234); |
274 TInt num(1234); |
279 t1=num; |
275 t1=num; |
280 t2=t1; |
276 t2=t1; |
281 test(t1.Int64()==t2.Int64()); |
277 test(t1.Int64()==t2.Int64()); |
301 |
297 |
302 test.Next(_L("operator <=")); |
298 test.Next(_L("operator <=")); |
303 test((t4<=t3)!=0); |
299 test((t4<=t3)!=0); |
304 test((t1<=t2)!=0); |
300 test((t1<=t2)!=0); |
305 test((t3<=t2)==0); |
301 test((t3<=t2)==0); |
306 |
|
307 } |
302 } |
308 |
303 |
309 void TestTTime::Test3(void) |
304 void TestTTime::Test3(void) |
310 // |
305 // |
311 // Tests for TTimeIntervaSeconds (and therefore TTimeIntervalBase) |
306 // Tests for TTimeIntervaSeconds (and therefore TTimeIntervalBase) |
312 // |
307 // |
313 { |
308 { |
314 |
|
315 test.Next(_L("Construction")); |
309 test.Next(_L("Construction")); |
316 TTimeIntervalSeconds s1; // uninitialised |
310 TTimeIntervalSeconds s1; // uninitialised |
317 TTimeIntervalSeconds s2(0); |
311 TTimeIntervalSeconds s2(0); |
318 test(s2.Int()==0 ); |
312 test(s2.Int()==0 ); |
319 |
313 |
320 TTimeIntervalSeconds s3(1); |
314 TTimeIntervalSeconds s3(1); |
321 test(s3.Int()==1 ); |
315 test(s3.Int()==1 ); |
322 test(s3.Int()!=0 ); |
316 test(s3.Int()!=0 ); |
323 |
317 |
324 TTimeIntervalSeconds s4(-1); |
318 TTimeIntervalSeconds s4(-1); |
325 test(s4.Int()==-1 ); |
319 test(s4.Int()==-1 ); |
326 |
320 |
327 TTimeIntervalSeconds s8(2147483647); |
321 TTimeIntervalSeconds s8(2147483647); |
328 test(s8.Int()== 2147483647); |
322 test(s8.Int()== 2147483647); |
329 |
323 |
330 test.Next(_L("operator =")); |
324 test.Next(_L("operator =")); |
331 s1=0; |
325 s1=0; |
370 void TestTTime::Test4() |
364 void TestTTime::Test4() |
371 // |
365 // |
372 // Tests for all other time intervals |
366 // Tests for all other time intervals |
373 // |
367 // |
374 { |
368 { |
375 |
|
376 test.Next(_L("TTimeIntervalMinutes")); |
369 test.Next(_L("TTimeIntervalMinutes")); |
377 test.Next(_L("Construction")); |
370 test.Next(_L("Construction")); |
378 TTimeIntervalMinutes m1; // uninitialised |
371 TTimeIntervalMinutes m1; // uninitialised |
379 TTimeIntervalMinutes m2(0); |
372 TTimeIntervalMinutes m2(0); |
380 test(m2.Int()==0 ); |
373 test(m2.Int()==0 ); |
449 mo1=0; |
442 mo1=0; |
450 test(mo1.Int()==0 ); |
443 test(mo1.Int()==0 ); |
451 TTimeIntervalMonths mo5(5),mo6; |
444 TTimeIntervalMonths mo5(5),mo6; |
452 mo6=mo5; |
445 mo6=mo5; |
453 test(mo5.Int()==mo6.Int()); |
446 test(mo5.Int()==mo6.Int()); |
454 |
447 |
455 test.Next(_L("TTimeIntervalYears")); |
448 test.Next(_L("TTimeIntervalYears")); |
456 test.Next(_L("Construction")); |
449 test.Next(_L("Construction")); |
457 TTimeIntervalYears y1; // uninitialised |
450 TTimeIntervalYears y1; // uninitialised |
458 TTimeIntervalYears y2(0); |
451 TTimeIntervalYears y2(0); |
459 test(y2.Int()==0 ); |
452 test(y2.Int()==0 ); |
472 test(y5.Int()==y6.Int()); |
465 test(y5.Int()==y6.Int()); |
473 y6=16; |
466 y6=16; |
474 test(y5.Int()!=y6.Int()); |
467 test(y5.Int()!=y6.Int()); |
475 y5=16; |
468 y5=16; |
476 test(y5.Int()==y6.Int()); |
469 test(y5.Int()==y6.Int()); |
477 // |
|
478 } |
470 } |
479 |
471 |
480 |
472 |
481 void TestTTime::Test5() |
473 void TestTTime::Test5() |
482 // |
474 // |
483 // TDateTime to TTime convertions and vice versa, very large loop, so in own function for easy removal |
475 // TDateTime to TTime convertions and vice versa, very large loop, so in own function for easy removal |
484 // |
476 // |
485 { |
477 { |
486 |
|
487 TInt microSecond=500000; |
478 TInt microSecond=500000; |
488 TDateTime dateTime(0,EJanuary,0,0,0,0,microSecond); |
479 TDateTime dateTime(0,EJanuary,0,0,0,0,microSecond); |
489 TInt year; |
480 TInt year; |
490 for(year=1590;year<1710;year+=2) |
481 for(year=1590;year<1710;year+=2) |
491 { |
482 { |
577 void TestTTime::Test6() |
568 void TestTTime::Test6() |
578 // |
569 // |
579 // Adding and differencing |
570 // Adding and differencing |
580 // |
571 // |
581 { |
572 { |
582 |
|
583 TDateTime dateTime(4,EJanuary,30,0,0,0,0); |
573 TDateTime dateTime(4,EJanuary,30,0,0,0,0); |
584 |
574 |
585 test.Next(_L("TTimeIntervalYears")); |
575 test.Next(_L("TTimeIntervalYears")); |
586 TTime base=dateTime; |
576 TTime base=dateTime; |
587 TTimeIntervalYears year(1); |
577 TTimeIntervalYears year(1); |
610 test(timeNow.YearsFrom(mintime).Int()>0);//must be positive value |
600 test(timeNow.YearsFrom(mintime).Int()>0);//must be positive value |
611 test(mintime.YearsFrom(timeNow).Int()<0);//must be negative value |
601 test(mintime.YearsFrom(timeNow).Int()<0);//must be negative value |
612 TTime maxtime = Time::MaxTTime(); |
602 TTime maxtime = Time::MaxTTime(); |
613 test(timeNow.YearsFrom(maxtime).Int()<0);//must be negative value |
603 test(timeNow.YearsFrom(maxtime).Int()<0);//must be negative value |
614 test(maxtime.YearsFrom(timeNow).Int()>0);//must be positive value |
604 test(maxtime.YearsFrom(timeNow).Int()>0);//must be positive value |
615 |
605 |
616 test.Next(_L("Adding months")); |
606 test.Next(_L("Adding months")); |
617 TTimeIntervalMonths month(1); |
607 TTimeIntervalMonths month(1); |
618 result=base+month; |
608 result=base+month; |
619 dateTime=result.DateTime(); |
609 dateTime=result.DateTime(); |
620 test(dateTime.Year()==4); |
610 test(dateTime.Year()==4); |
668 test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
658 test(base.YearsFrom(result)==TTimeIntervalYears(0)); |
669 test(result.MonthsFrom(base)==TTimeIntervalMonths(2)); |
659 test(result.MonthsFrom(base)==TTimeIntervalMonths(2)); |
670 test(base.MonthsFrom(result)==TTimeIntervalMonths(-2)); |
660 test(base.MonthsFrom(result)==TTimeIntervalMonths(-2)); |
671 test(result.DaysFrom(base)==TTimeIntervalDays(61)); |
661 test(result.DaysFrom(base)==TTimeIntervalDays(61)); |
672 test(base.DaysFrom(result)==TTimeIntervalDays(-61)); |
662 test(base.DaysFrom(result)==TTimeIntervalDays(-61)); |
673 |
663 |
674 test.Next(_L("DaysFrom")); |
664 test.Next(_L("DaysFrom")); |
675 timeNow.HomeTime(); |
665 timeNow.HomeTime(); |
676 timeFuture=timeNow+TTimeIntervalDays(10); |
666 timeFuture=timeNow+TTimeIntervalDays(10); |
677 test(timeFuture.DaysFrom(timeNow).Int()==10); |
667 test(timeFuture.DaysFrom(timeNow).Int()==10); |
678 test(timeNow.DaysFrom(timeFuture).Int()==-10); |
668 test(timeNow.DaysFrom(timeFuture).Int()==-10); |
969 test(ret==KErrOverflow); |
959 test(ret==KErrOverflow); |
970 overflow*=60; |
960 overflow*=60; |
971 result=base+TTimeIntervalMicroSeconds(overflow); |
961 result=base+TTimeIntervalMicroSeconds(overflow); |
972 ret=result.HoursFrom(base,hour); |
962 ret=result.HoursFrom(base,hour); |
973 test(ret==KErrOverflow); |
963 test(ret==KErrOverflow); |
974 |
964 |
975 test.Next(_L("Specific MonthsFrom() tests")); |
965 test.Next(_L("Specific MonthsFrom() tests")); |
976 |
966 |
977 base=TDateTime(1995,EJanuary,30,0,0,0,0); |
967 base=TDateTime(1995,EJanuary,30,0,0,0,0); |
978 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
968 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
979 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
969 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
980 |
970 |
981 base=TDateTime(1995,EJanuary,27,0,0,0,0); |
971 base=TDateTime(1995,EJanuary,27,0,0,0,0); |
982 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
972 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
983 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
973 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
984 |
974 |
985 base=TDateTime(1995,EJanuary,29,0,0,0,0); |
975 base=TDateTime(1995,EJanuary,29,0,0,0,0); |
986 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
976 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
987 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
977 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
988 |
|
989 |
978 |
990 base=TDateTime(1995,EJanuary,30,0,0,0,0); |
979 base=TDateTime(1995,EJanuary,30,0,0,0,0); |
991 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
980 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
992 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
981 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
993 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
982 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
994 |
983 |
995 base=TDateTime(1995,EJanuary,27,0,0,0,0); |
984 base=TDateTime(1995,EJanuary,27,0,0,0,0); |
996 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
985 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
997 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
986 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
998 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
987 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
999 |
988 |
1000 base=TDateTime(1995,EJanuary,29,0,0,0,0); |
989 base=TDateTime(1995,EJanuary,29,0,0,0,0); |
1001 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
990 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
1002 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
991 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
1003 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
992 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
1004 |
993 |
1005 base=TDateTime(1995,EJanuary,26,0,0,0,0); |
994 base=TDateTime(1995,EJanuary,26,0,0,0,0); |
1006 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
995 result=TDateTime(1995,EFebruary,27,0,0,0,0); |
1007 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
996 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
1008 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
997 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
1009 |
998 |
1010 base=TDateTime(1995,EFebruary,27,0,0,0,0); |
999 base=TDateTime(1995,EFebruary,27,0,0,0,0); |
1011 result=TDateTime(1995,EMarch,29,0,0,0,0); |
1000 result=TDateTime(1995,EMarch,29,0,0,0,0); |
1012 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
1001 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
1013 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
1002 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
1014 |
1003 |
1015 base=TDateTime(1995,EFebruary,27,0,0,0,0); |
1004 base=TDateTime(1995,EFebruary,27,0,0,0,0); |
1016 result=TDateTime(1995,EMarch,30,0,0,0,0); |
1005 result=TDateTime(1995,EMarch,30,0,0,0,0); |
1017 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
1006 test(base.MonthsFrom(result)==TTimeIntervalMonths(-1)); |
1018 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
1007 test(result.MonthsFrom(base)==TTimeIntervalMonths(1)); |
1019 |
1008 |
1020 base=TDateTime(1995,EFebruary,27,13,0,0,0); |
1009 base=TDateTime(1995,EFebruary,27,13,0,0,0); |
1021 result=TDateTime(1995,EJanuary,29,12,0,0,0); |
1010 result=TDateTime(1995,EJanuary,29,12,0,0,0); |
1022 test(base.MonthsFrom(result)==TTimeIntervalMonths(1)); |
1011 test(base.MonthsFrom(result)==TTimeIntervalMonths(1)); |
1023 test(result.MonthsFrom(base)==TTimeIntervalMonths(-1)); |
1012 test(result.MonthsFrom(base)==TTimeIntervalMonths(-1)); |
1024 |
1013 |
1029 |
1018 |
1030 base=TDateTime(1995,EJanuary,27,12,0,0,0); |
1019 base=TDateTime(1995,EJanuary,27,12,0,0,0); |
1031 result=TDateTime(1995,EJanuary,29,13,0,0,0); |
1020 result=TDateTime(1995,EJanuary,29,13,0,0,0); |
1032 test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
1021 test(base.MonthsFrom(result)==TTimeIntervalMonths(0)); |
1033 test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
1022 test(result.MonthsFrom(base)==TTimeIntervalMonths(0)); |
1034 |
1023 |
1035 test.Next(_L("Looped MonthsFrom() test")); |
1024 test.Next(_L("Looped MonthsFrom() test")); |
1036 const TTime endBase=MAKE_TINT64(74334524,25422354); |
1025 const TTime endBase=MAKE_TINT64(74334524,25422354); |
1037 const TTime endResult=MAKE_TINT64(154334524,25422354); |
1026 const TTime endResult=MAKE_TINT64(154334524,25422354); |
1038 const TTimeIntervalMicroSeconds plus=MAKE_TINT64(1234567,23453452); |
1027 const TTimeIntervalMicroSeconds plus=MAKE_TINT64(1234567,23453452); |
1039 for (base=MAKE_TINT64(3563656,3456235623u);base<endBase;base+=plus) |
1028 for (base=MAKE_TINT64(3563656,3456235623u);base<endBase;base+=plus) |
1040 for (result=MAKE_TINT64(3563656,3456235623u);result<endResult;result+=plus) |
1029 for (result=MAKE_TINT64(3563656,3456235623u);result<endResult;result+=plus) |
1041 test(base.MonthsFrom(result).Int()==-result.MonthsFrom(base).Int()); |
1030 test(base.MonthsFrom(result).Int()==-result.MonthsFrom(base).Int()); |
1042 |
|
1043 } |
1031 } |
1044 |
1032 |
1045 void TestTTime::Test7() |
1033 void TestTTime::Test7() |
1046 // |
1034 // |
1047 // subtracting |
1035 // subtracting |
1048 // |
1036 // |
1049 { |
1037 { |
1050 |
|
1051 TDateTime dateTime(1996,EApril,3,0,0,0,0); |
1038 TDateTime dateTime(1996,EApril,3,0,0,0,0); |
1052 TTime base(dateTime); |
1039 TTime base(dateTime); |
1053 TTime tim(base); |
1040 TTime tim(base); |
1054 |
1041 |
1055 tim+=TTimeIntervalYears(7); |
1042 tim+=TTimeIntervalYears(7); |
1166 TInt dn(0); |
1153 TInt dn(0); |
1167 TInt wkn(0); |
1154 TInt wkn(0); |
1168 TInt wk(0); |
1155 TInt wk(0); |
1169 for (y=1900;y<1921;y++) // MUST BEGIN 0N 1900 (been run to 2500) |
1156 for (y=1900;y<1921;y++) // MUST BEGIN 0N 1900 (been run to 2500) |
1170 { |
1157 { |
1171 |
|
1172 |
|
1173 dateTime.SetYear(y); |
1158 dateTime.SetYear(y); |
1174 for (m=0;m<12;m++) |
1159 for (m=0;m<12;m++) |
1175 { |
1160 { |
1176 |
|
1177 dateTime.SetMonth(TMonth(m)); |
1161 dateTime.SetMonth(TMonth(m)); |
1178 for (d=0;d<Time::DaysInMonth(y,TMonth(m));d++) |
1162 for (d=0;d<Time::DaysInMonth(y,TMonth(m));d++) |
1179 { |
1163 { |
1180 dateTime.SetDay(d); |
1164 dateTime.SetDay(d); |
1181 tim=dateTime; |
1165 tim=dateTime; |
1192 test(wkn==wk); |
1176 test(wkn==wk); |
1193 } |
1177 } |
1194 dateTime.SetDay(0); |
1178 dateTime.SetDay(0); |
1195 } |
1179 } |
1196 } |
1180 } |
1197 |
1181 |
1198 test.Next(_L("Testing wk53 in a year with 4 days in last week")); |
1182 test.Next(_L("Testing wk53 in a year with 4 days in last week")); |
1199 dateTime.SetYear(2009); |
1183 dateTime.SetYear(2009); |
1200 dateTime.SetMonth(EDecember); |
1184 dateTime.SetMonth(EDecember); |
1201 dateTime.SetDay(27); // 28th, day is 0-based |
1185 dateTime.SetDay(27); // 28th, day is 0-based |
1202 dateTime.SetHour(8); // Ensure the remaining days are 3.somefraction to test rounding |
1186 dateTime.SetHour(8); // Ensure the remaining days are 3.somefraction to test rounding |
1212 test(tim.DayNoInWeek()==0); |
1196 test(tim.DayNoInWeek()==0); |
1213 test(tim.DayNoInMonth()==3); |
1197 test(tim.DayNoInMonth()==3); |
1214 test(tim.DayNoInYear()==4); |
1198 test(tim.DayNoInYear()==4); |
1215 test(tim.WeekNoInYear()==1); |
1199 test(tim.WeekNoInYear()==1); |
1216 dateTime.SetHour(0); |
1200 dateTime.SetHour(0); |
1217 |
1201 |
1218 test.Next(_L("Testing other week no. rules")); |
1202 test.Next(_L("Testing other week no. rules")); |
1219 dateTime.SetYear(1995); |
1203 dateTime.SetYear(1995); |
1220 dateTime.SetDay(14); |
1204 dateTime.SetDay(14); |
1221 dateTime.SetMonth(ENovember); |
1205 dateTime.SetMonth(ENovember); |
1222 tim=dateTime; |
1206 tim=dateTime; |
1267 dateTime.SetDay(6); |
1251 dateTime.SetDay(6); |
1268 tim2=dateTime; |
1252 tim2=dateTime; |
1269 test(tim2.WeekNoInYear(tim,EFirstFullWeek)==30); |
1253 test(tim2.WeekNoInYear(tim,EFirstFullWeek)==30); |
1270 test(tim2.WeekNoInYear(tim,EFirstWeek)==30); |
1254 test(tim2.WeekNoInYear(tim,EFirstWeek)==30); |
1271 test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==30); |
1255 test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==30); |
1272 |
1256 |
1273 dateTime.SetYear(1904); |
1257 dateTime.SetYear(1904); |
1274 dateTime.SetMonth(EFebruary); |
1258 dateTime.SetMonth(EFebruary); |
1275 dateTime.SetDay(28); |
1259 dateTime.SetDay(28); |
1276 tim=dateTime; |
1260 tim=dateTime; |
1277 dateTime.SetYear(1955); |
1261 dateTime.SetYear(1955); |
1298 dateTime.SetHour(12); |
1282 dateTime.SetHour(12); |
1299 tim2=dateTime; |
1283 tim2=dateTime; |
1300 test(tim2.WeekNoInYear(tim,EFirstFullWeek)==52); |
1284 test(tim2.WeekNoInYear(tim,EFirstFullWeek)==52); |
1301 test(tim2.WeekNoInYear(tim,EFirstWeek)==1); |
1285 test(tim2.WeekNoInYear(tim,EFirstWeek)==1); |
1302 test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==1); |
1286 test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==1); |
1303 |
|
1304 |
|
1305 |
|
1306 |
|
1307 } |
1287 } |
1308 |
1288 |
1309 |
1289 |
1310 void TestTTime::Test9() |
1290 void TestTTime::Test9() |
1311 // |
1291 // |
1500 |
1480 |
1501 //Reset so it can be run twice |
1481 //Reset so it can be run twice |
1502 local.SetDateFormat(EDateEuropean); |
1482 local.SetDateFormat(EDateEuropean); |
1503 local.SetTimeFormat(ETime12); |
1483 local.SetTimeFormat(ETime12); |
1504 local.Set(); |
1484 local.Set(); |
1505 |
1485 |
1506 // Test for overload of TTime::FormatL(TDes& aDes,const TDesC& aFormat,const TLocale& aLocale); |
1486 // Test for overload of TTime::FormatL(TDes& aDes,const TDesC& aFormat,const TLocale& aLocale); |
1507 // Reset Time and dates |
1487 // Reset Time and dates |
1508 aDate.Set(lyear,TMonth(lmonth),lday,lhour,lminute,lsecond,lmicroSecond); |
1488 aDate.Set(lyear,TMonth(lmonth),lday,lhour,lminute,lsecond,lmicroSecond); |
1509 test.Next(_L("Different DateFormats with specified locale")); |
1489 test.Next(_L("Different DateFormats with specified locale")); |
1510 TTime aTimeLocale(aDate); |
1490 TTime aTimeLocale(aDate); |
1518 if (testString.Compare(_L("Jul 4"))) |
1498 if (testString.Compare(_L("Jul 4"))) |
1519 test.Panic(_L("%%*D%%*N, Japanese")); |
1499 test.Panic(_L("%%*D%%*N, Japanese")); |
1520 aTimeLocale.FormatL(testString,(_L("%F%Y %D%X %N")),local); |
1500 aTimeLocale.FormatL(testString,(_L("%F%Y %D%X %N")),local); |
1521 if (testString.Compare(_L("1993 04th July"))) |
1501 if (testString.Compare(_L("1993 04th July"))) |
1522 test.Panic(_L("%%F%%Y %%D%%X %%N")); |
1502 test.Panic(_L("%%F%%Y %%D%%X %%N")); |
1523 |
1503 |
1524 test.Next(_L("Times with specified locale")); |
1504 test.Next(_L("Times with specified locale")); |
1525 aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local); |
1505 aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local); |
1526 if (testString.Compare(_L("1:53 pm"))) |
1506 if (testString.Compare(_L("1:53 pm"))) |
1527 test.Panic(_L("%%*I%%:1%%T%%A")); |
1507 test.Panic(_L("%%*I%%:1%%T%%A")); |
1528 local.SetAmPmSymbolPosition(ELocaleBefore); |
1508 local.SetAmPmSymbolPosition(ELocaleBefore); |
1586 if (testString.Compare(_L("13:53"))) |
1566 if (testString.Compare(_L("13:53"))) |
1587 test.Panic(_L("%%J%%:1%%T%%B, ETime24")); |
1567 test.Panic(_L("%%J%%:1%%T%%B, ETime24")); |
1588 aTimeLocale.FormatL(testString,(_L("%J%:1%T%*B")),local); |
1568 aTimeLocale.FormatL(testString,(_L("%J%:1%T%*B")),local); |
1589 if (testString.Compare(_L("13:53"))) |
1569 if (testString.Compare(_L("13:53"))) |
1590 test.Panic(_L("%%J%%:1%%T%%*B, ETime24")); |
1570 test.Panic(_L("%%J%%:1%%T%%*B, ETime24")); |
1591 |
1571 |
1592 test.Next(_L("Miscellaneous with specified locale")); |
1572 test.Next(_L("Miscellaneous with specified locale")); |
1593 aTimeLocale.FormatL(testString,(_L("%W")),local); |
1573 aTimeLocale.FormatL(testString,(_L("%W")),local); |
1594 if (testString.Compare(_L("26"))) |
1574 if (testString.Compare(_L("26"))) |
1595 test.Panic(_L("%%W")); |
1575 test.Panic(_L("%%W")); |
1596 aTimeLocale.FormatL(testString,(_L("%*Z")),local); |
1576 aTimeLocale.FormatL(testString,(_L("%*Z")),local); |
1597 if (testString.Compare(_L("185"))) |
1577 if (testString.Compare(_L("185"))) |
1598 test.Panic(_L("%%*Z")); |
1578 test.Panic(_L("%%*Z")); |
1599 |
1579 |
1600 test.Next(_L("Junk strings with specified locale")); |
1580 test.Next(_L("Junk strings with specified locale")); |
1601 aTimeLocale.FormatL(testString,(_L("%F %M%O%N%D%A%Y")),local); |
1581 aTimeLocale.FormatL(testString,(_L("%F %M%O%N%D%A%Y")),local); |
1602 if (testString.Compare(_L(" 07OJuly04 pm1993"))) |
1582 if (testString.Compare(_L(" 07OJuly04 pm1993"))) |
1603 test.Panic(_L(" MONDAY")); |
1583 test.Panic(_L(" MONDAY")); |
1604 aTimeLocale.FormatL(testString,(_L("%*D%X %N '%*Y")),local); |
1584 aTimeLocale.FormatL(testString,(_L("%*D%X %N '%*Y")),local); |
1786 test.Printf(_L(" Local Time is - %+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d\n"),dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
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()); |
1787 time.UniversalTime(); |
1767 time.UniversalTime(); |
1788 dateTime=time.DateTime(); |
1768 dateTime=time.DateTime(); |
1789 test.Printf(_L(" Universal Time is - %+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d\n"),dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
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()); |
1790 test.Printf(_L("does this come out")); |
1770 test.Printf(_L("does this come out")); |
1791 |
|
1792 } |
1771 } |
1793 |
1772 |
1794 void TestTTime::Test11() |
1773 void TestTTime::Test11() |
1795 // |
1774 // |
1796 // |
1775 // |
1797 // |
1776 // |
1798 { |
1777 { |
1799 |
|
1800 TTime now; |
1778 TTime now; |
1801 now.UniversalTime(); |
1779 now.UniversalTime(); |
1802 TTimeIntervalSeconds offset; |
1780 TTimeIntervalSeconds offset; |
1803 offset = User::UTCOffset(); |
1781 offset = User::UTCOffset(); |
1804 RTimer timer[5]; |
1782 RTimer timer[5]; |
1923 test(r==KErrNone); |
1901 test(r==KErrNone); |
1924 User::WaitForRequest(stat[1]); |
1902 User::WaitForRequest(stat[1]); |
1925 test(stat[1]==KErrAbort); |
1903 test(stat[1]==KErrAbort); |
1926 test(stat[0]==KErrCancel); |
1904 test(stat[0]==KErrCancel); |
1927 |
1905 |
1906 // The platform may or may not support SecureTime, and even if it does, |
|
1907 // it may not have a secure time set. So we start this test by making |
|
1908 // sure that the NonSecureOffset is set (which may fail, if it's not |
|
1909 // supported OR if it's already set); then read and write the secure |
|
1910 // time, to make sure that it's supported and we have permission. |
|
1911 User::SetUTCTime(now); |
|
1912 HAL::Set(HAL::ETimeNonSecureOffset, 0); |
|
1928 test.Next(_L("Test absolute timers with secure time change")); |
1913 test.Next(_L("Test absolute timers with secure time change")); |
1929 TTime securetime; |
1914 TTime securetime; |
1930 if ((r = securetime.UniversalTimeSecure()) == KErrNone) |
1915 if ((r = securetime.UniversalTimeSecure()) == KErrNone) |
1931 r = User::SetUTCTimeSecure(securetime); |
1916 r = User::SetUTCTimeSecure(securetime); |
1932 if (r != KErrNone) |
1917 if (r != KErrNone) |
1935 } |
1920 } |
1936 else |
1921 else |
1937 { |
1922 { |
1938 timer[0].AtUTC(stat[0], now+TTimeIntervalSeconds(5)); |
1923 timer[0].AtUTC(stat[0], now+TTimeIntervalSeconds(5)); |
1939 r = User::SetUTCTimeSecure(securetime+TTimeIntervalSeconds(30)); |
1924 r = User::SetUTCTimeSecure(securetime+TTimeIntervalSeconds(30)); |
1925 test_Equal(KErrNone, r); |
|
1940 r = User::SetUTCTimeSecure(securetime-TTimeIntervalSeconds(30)); |
1926 r = User::SetUTCTimeSecure(securetime-TTimeIntervalSeconds(30)); |
1941 test(r == KErrNone); |
1927 test_Equal(KErrNone, r); |
1942 // The timer should not have been aborted by the secure time change |
1928 // The absolute timer should not have been aborted by the secure time change, |
1943 User::WaitForRequest(stat[0]); |
1929 test_Equal(KRequestPending, stat[0].Int()); |
1944 test(stat[0] == KErrNone); |
1930 |
1931 // The outstanding absolute timer should complete before this new relative timer |
|
1932 timer[1].After(stat[1], 20000000); |
|
1933 User::WaitForRequest(stat[0], stat[1]); |
|
1934 timer[1].Cancel(); |
|
1935 test_Equal(KErrNone, stat[0].Int()); |
|
1936 test_Equal(KErrCancel, stat[1].Int()); |
|
1945 User::SetUTCTimeSecure(securetime+TTimeIntervalSeconds(5)); |
1937 User::SetUTCTimeSecure(securetime+TTimeIntervalSeconds(5)); |
1946 } |
1938 } |
1947 |
1939 |
1948 test.Next(_L("Close the timers")); |
1940 test.Next(_L("Close the timers")); |
1949 for (i=0; i<5; i++) |
1941 for (i=0; i<5; i++) |
2354 test(r==KErrNone); |
2346 test(r==KErrNone); |
2355 r = securetime3.SecondsFrom(march2001, seconds_diff); |
2347 r = securetime3.SecondsFrom(march2001, seconds_diff); |
2356 test(seconds_diff == TTimeIntervalSeconds(0)); |
2348 test(seconds_diff == TTimeIntervalSeconds(0)); |
2357 r = now3.SecondsFrom(march2001, seconds_diff); |
2349 r = now3.SecondsFrom(march2001, seconds_diff); |
2358 test(seconds_diff == TTimeIntervalSeconds(0)); |
2350 test(seconds_diff == TTimeIntervalSeconds(0)); |
2359 |
|
2360 |
2351 |
2361 // Verify the offset changes by the right amount when the nonsecure time is changed |
2352 // Verify the offset changes by the right amount when the nonsecure time is changed |
2362 TTime time; |
2353 TTime time; |
2363 r = HAL::Get(HAL::ETimeNonSecureOffset,nso); |
2354 r = HAL::Get(HAL::ETimeNonSecureOffset,nso); |
2364 test_Equal(KErrNone, r); |
2355 test_Equal(KErrNone, r); |
2405 b.SetStartOfWeek(EMonday); |
2396 b.SetStartOfWeek(EMonday); |
2406 b.Set(); |
2397 b.Set(); |
2407 |
2398 |
2408 TTimeIntervalSeconds savedOffset = User::UTCOffset(); |
2399 TTimeIntervalSeconds savedOffset = User::UTCOffset(); |
2409 User::SetUTCOffset(0); |
2400 User::SetUTCOffset(0); |
2410 |
2401 |
2411 test.Next(_L("Testing TDateTime class")); |
2402 test.Next(_L("Testing TDateTime class")); |
2412 T.Test1(); |
2403 T.Test1(); |
2413 test.Next(_L("Testing TTimeIntervalMicroSeconds")); |
2404 test.Next(_L("Testing TTimeIntervalMicroSeconds")); |
2414 T.Test2(); |
2405 T.Test2(); |
2415 test.Next(_L("Testing TTimeIntervalSeconds")); |
2406 test.Next(_L("Testing TTimeIntervalSeconds")); |