1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/datetime/t_time.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,2438 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\datetime\t_time.cpp
1.18 +// Overview:
1.19 +// Date & time tests
1.20 +// API Information:
1.21 +// TDateTime, TTimeInterval...
1.22 +// Details:
1.23 +// - Set various locale settings to known values.
1.24 +// - Test the TDateTime class by checking year, month, day, hour, minute,
1.25 +// second and microsecond ranges then verify setting individual ranges.
1.26 +// - Test TTimeIntervalMicroSeconds class: verify construction and initialization.
1.27 +// Verify the "=", "<", ">", "!=", ">=" and "<=" operators.
1.28 +// - Test TTimeIntervalSeconds class: verify construction and initialization.
1.29 +// Verify the "=", "<", ">", "!=", ">=" and "<=" operators.
1.30 +// - Test TTimeIntervalMinutes, TTimeIntervalHours, TTimeIntervalDays,
1.31 +// TTimeIntervalMonths and TTimeIntervalYears classes: verify construction,
1.32 +// initialization and "=" operator.
1.33 +// - Test conversions between TDateTime and TTime objects.
1.34 +// - Test adding and differencing between TDateTime and TTime objects. Including
1.35 +// the methods: YearsFrom, MonthsFrom, DaysFrom, HoursFrom, MinutesFrom,
1.36 +// SecondsFrom and MicroSecondsFrom. Also specific tests for adding months,
1.37 +// adding days, adding hours, adding minutes, adding seconds, adding microseconds
1.38 +// and invalid differences.
1.39 +// - Test adding and subtracting different TTimeIntervals and verify the results.
1.40 +// - Test TTime's date property functions. Verify results are as expected.
1.41 +// - Test different date formats and string parsing. Verify results are as expected.
1.42 +// - Test a variety of time change scenarios and verify results are as expected.
1.43 +// - Test the TTime::Set() method with different combinations of data, verify the
1.44 +// results are as expected.
1.45 +// - Test a variety of operations involving negative times. Verify results are
1.46 +// as expected.
1.47 +// - Test year 2000 and print the results.
1.48 +// - Test secure clock is not affected by changes
1.49 +// Platforms/Drives/Compatibility:
1.50 +// All.
1.51 +// Assumptions/Requirement/Pre-requisites:
1.52 +// Failures and causes:
1.53 +// Base Port information:
1.54 +//
1.55 +//
1.56 +
1.57 +#define __E32TEST_EXTENSION__
1.58 +#include <e32test.h>
1.59 +#include <e32debug.h>
1.60 +#include <hal.h>
1.61 +
1.62 +LOCAL_D RTest test(_L("T_TIME"));
1.63 +
1.64 +//
1.65 +// duplication of local variable in UC_TIME
1.66 +LOCAL_D const TInt8 mTab[2][12]=
1.67 + {
1.68 + {31,28,31,30,31,30,31,31,30,31,30,31}, // 28 days in Feb
1.69 + {31,29,31,30,31,30,31,31,30,31,30,31} // 29 days in Feb
1.70 + };
1.71 +const TInt64 KDaysToMicroSeconds(MAKE_TINT64(20,500654080));
1.72 +const TInt64 KHoursToMicroSeconds(3600000000u);
1.73 +const TInt KSecondsToMicroSeconds=1000000;
1.74 +
1.75 +class TestTTime
1.76 + {
1.77 +public:
1.78 + void Test1(void);
1.79 + void Test2(void);
1.80 + void Test3(void);
1.81 + void Test4(void);
1.82 + void Test5(void);
1.83 + void Test6(void);
1.84 + void Test7(void);
1.85 + void Test8(void);
1.86 + void Test9(void);
1.87 + void Test10(void);
1.88 + void Test11(void);
1.89 + void Test12(void);
1.90 + void Test13(void);
1.91 + void TestSecureClock(void);
1.92 + };
1.93 +
1.94 +
1.95 +void PrintTime(char* sz, TTime& t)
1.96 +{
1.97 + TDateTime dateTime(t.DateTime());
1.98 + 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());
1.99 +}
1.100 +
1.101 +void TestTTime::Test1(void)
1.102 +//
1.103 +// Tests for TDateTime
1.104 +//
1.105 + {
1.106 + TInt year=1980; //leap year
1.107 + TMonth month=EJanuary;
1.108 + TInt day=0;
1.109 + TInt hour=0;
1.110 + TInt minute=0;
1.111 + TInt second=0;
1.112 + TInt microSecond=10;
1.113 +
1.114 + TDateTime dateTime(year,month,day,hour,minute,second,microSecond);
1.115 +
1.116 + test.Next(_L("Testing year ranges"));
1.117 + TInt ii;
1.118 + for (ii=1970; ii<2100; ii++)
1.119 + {
1.120 + test(dateTime.Set(ii,ENovember,day,hour,minute,second,microSecond)==KErrNone);
1.121 + TTime time(dateTime);
1.122 + TDateTime dateTime2(time.DateTime());
1.123 + test(dateTime2.Year()==ii);
1.124 + test(dateTime2.Month()==ENovember);
1.125 + test(dateTime2.Day()==day);
1.126 + test(dateTime2.Hour()==hour);
1.127 + test(dateTime2.Minute()==minute);
1.128 + test(dateTime2.Second()==second);
1.129 + test(dateTime2.MicroSecond()==microSecond);
1.130 + }
1.131 +
1.132 + test.Next(_L("Testing month ranges"));
1.133 + for (ii=0; ii<12; ii++)
1.134 + test(dateTime.Set(year,TMonth(ii),day,hour,minute,second,microSecond)==0);
1.135 + test(dateTime.Set(year,TMonth(12),day,hour,minute,second,microSecond)!=0);
1.136 +
1.137 + test.Next(_L("Testing day ranges"));
1.138 + for (ii=0; ii<12; ii++)
1.139 + {
1.140 + test(dateTime.Set(year,TMonth(ii),(mTab[1][ii]-1),hour,minute,second,microSecond)==0);
1.141 + test(dateTime.Set(year+1,TMonth(ii),(mTab[0][ii]-1),hour,minute,second,microSecond)==0);
1.142 + test(dateTime.Set(year+1,TMonth(ii),(mTab[0][ii]),hour,minute,second,microSecond)!=0);
1.143 + }
1.144 + test(dateTime.Set(year,month,-1,hour,minute,second,microSecond)!=0);
1.145 +
1.146 + test.Next(_L("Testing hour ranges"));
1.147 + for (ii=0; ii<24; ii++)
1.148 + test(dateTime.Set(year,EMarch,10,ii,minute,second,microSecond)==0);
1.149 + test(dateTime.Set(year,EMarch,10,-1,minute,second,microSecond)!=0);
1.150 + test(dateTime.Set(year,EMarch,10,24,minute,second,microSecond)!=0);
1.151 +
1.152 + test.Next(_L("Testing minute ranges"));
1.153 + for (ii=0; ii<60; ii++)
1.154 + test(dateTime.Set(year,EMarch,0,0,ii,second,microSecond)==0);
1.155 + test(dateTime.Set(year,EMarch,0,0,-1,second,microSecond)!=0);
1.156 + test(dateTime.Set(year,EMarch,0,0,60,second,microSecond)!=0);
1.157 +
1.158 + test.Next(_L("Testing second ranges"));
1.159 + for (ii=0; ii<60; ii++)
1.160 + test(dateTime.Set(year,EMarch,0,0,0,ii,microSecond)==0);
1.161 + test(dateTime.Set(year,EMarch,0,0,0,-1,microSecond)!=0);
1.162 + test(dateTime.Set(year,EMarch,0,0,0,60,microSecond)!=0);
1.163 +
1.164 + test.Next(_L("Testing microsecond ranges"));
1.165 + for (ii=0; ii<100; ii++)
1.166 + test(dateTime.Set(year,EMarch,0,0,0,0,ii)==0);
1.167 + test(dateTime.Set(year,EMarch,0,0,0,0,-1)!=0);
1.168 + test(dateTime.Set(year,EMarch,0,0,0,0,1000000)!=0);
1.169 +
1.170 + test.Next(_L("Testing setting individual ranges"));
1.171 +
1.172 + dateTime.Set(year,month,day,hour,minute,second,microSecond);
1.173 + year=1984;
1.174 + test(dateTime.SetYear(year)==0);
1.175 + test(dateTime.Year()==year);
1.176 + test(dateTime.Month()==month);
1.177 + test(dateTime.Day()==day);
1.178 + test(dateTime.Hour()==hour);
1.179 + test(dateTime.Minute()==minute);
1.180 + test(dateTime.Second()==second);
1.181 + test(dateTime.MicroSecond()==microSecond);
1.182 + month=EFebruary;
1.183 + test(dateTime.SetMonth(month)==0);
1.184 + test(dateTime.SetYear(year)==0);
1.185 + test(dateTime.Year()==year);
1.186 + test(dateTime.Month()==month);
1.187 + test(dateTime.Day()==day);
1.188 + test(dateTime.Hour()==hour);
1.189 + test(dateTime.Minute()==minute);
1.190 + test(dateTime.Second()==second);
1.191 + test(dateTime.MicroSecond()==microSecond);
1.192 + day=28;
1.193 + test(dateTime.SetDay(day)==0);
1.194 + test(dateTime.SetYear(year)==0);
1.195 + test(dateTime.Year()==year);
1.196 + test(dateTime.Month()==month);
1.197 + test(dateTime.Day()==day);
1.198 + test(dateTime.Hour()==hour);
1.199 + test(dateTime.Minute()==minute);
1.200 + test(dateTime.Second()==second);
1.201 + test(dateTime.MicroSecond()==microSecond);
1.202 + hour=12;
1.203 + test(dateTime.SetHour(hour)==0);
1.204 + test(dateTime.SetYear(year)==0);
1.205 + test(dateTime.Year()==year);
1.206 + test(dateTime.Month()==month);
1.207 + test(dateTime.Day()==day);
1.208 + test(dateTime.Hour()==hour);
1.209 + test(dateTime.Minute()==minute);
1.210 + test(dateTime.Second()==second);
1.211 + test(dateTime.MicroSecond()==microSecond);
1.212 + minute=57;
1.213 + test(dateTime.SetMinute(minute)==0);
1.214 + test(dateTime.SetYear(year)==0);
1.215 + test(dateTime.Year()==year);
1.216 + test(dateTime.Month()==month);
1.217 + test(dateTime.Day()==day);
1.218 + test(dateTime.Hour()==hour);
1.219 + test(dateTime.Minute()==minute);
1.220 + test(dateTime.Second()==second);
1.221 + test(dateTime.MicroSecond()==microSecond);
1.222 + second=2;
1.223 + test(dateTime.SetSecond(second)==0);
1.224 + test(dateTime.SetYear(year)==0);
1.225 + test(dateTime.Year()==year);
1.226 + test(dateTime.Month()==month);
1.227 + test(dateTime.Day()==day);
1.228 + test(dateTime.Hour()==hour);
1.229 + test(dateTime.Minute()==minute);
1.230 + test(dateTime.Second()==second);
1.231 + test(dateTime.MicroSecond()==microSecond);
1.232 + microSecond=99999;
1.233 + test(dateTime.SetMicroSecond(microSecond)==0);
1.234 + test(dateTime.SetYear(year)==0);
1.235 + test(dateTime.Year()==year);
1.236 + test(dateTime.Month()==month);
1.237 + test(dateTime.Day()==day);
1.238 + test(dateTime.Hour()==hour);
1.239 + test(dateTime.Minute()==minute);
1.240 + test(dateTime.Second()==second);
1.241 + test(dateTime.MicroSecond()==microSecond);
1.242 +
1.243 + test(dateTime.SetYear(1981)!=0);
1.244 + test(dateTime.SetMonth((TMonth)15)!=0);
1.245 + test(dateTime.SetDay(-1)!=0);
1.246 + test(dateTime.SetHour(100)!=0);
1.247 + test(dateTime.SetMinute(-15)!=0);
1.248 + test(dateTime.SetSecond(60)!=0);
1.249 + test(dateTime.SetMicroSecond(-2)!=0);
1.250 + test(dateTime.Year()==year);
1.251 + test(dateTime.Month()==month);
1.252 + test(dateTime.Day()==day);
1.253 + test(dateTime.Hour()==hour);
1.254 + test(dateTime.Minute()==minute);
1.255 + test(dateTime.Second()==second);
1.256 + test(dateTime.MicroSecond()==microSecond);
1.257 + }
1.258 +
1.259 + void TestTTime::Test2(void)
1.260 + //
1.261 + // Tests for TTimeIntervalMicroSeconds
1.262 + //
1.263 + {
1.264 + test.Next(_L("Construction"));
1.265 + TTimeIntervalMicroSeconds t1; // uninitialised
1.266 + TTimeIntervalMicroSeconds t2(0);
1.267 + test(t2.Int64()==0 );
1.268 + TTimeIntervalMicroSeconds t3(1000000);
1.269 + test(t3.Int64()==1000000 );
1.270 + TTimeIntervalMicroSeconds t4(-452);
1.271 + test(t4.Int64()==-452 );
1.272 +
1.273 + TTimeIntervalMicroSeconds t5(MAKE_TINT64(0x7fffffff,0xffffffff));
1.274 + t5.Int64();
1.275 +
1.276 + test.Next(_L("operator ="));
1.277 + TInt num(1234);
1.278 + t1=num;
1.279 + t2=t1;
1.280 + test(t1.Int64()==t2.Int64());
1.281 +
1.282 + test.Next(_L("operator <"));
1.283 + test((t4<t1)!=0);
1.284 + test((t3<t2)==0);
1.285 + test((t2<t3)!=0);
1.286 +
1.287 + test.Next(_L("operator >"));
1.288 + test((t1>t4)!=0);
1.289 + test((t2>t3)==0);
1.290 + test((t2>t1)==0);
1.291 +
1.292 + test.Next(_L("operator !="));
1.293 + test((t1!=t3)!=0);
1.294 + test((t1!=t2)==0);
1.295 +
1.296 + test.Next(_L("operator >="));
1.297 + test((t3>=t4)!=0);
1.298 + test((t1>=t2)!=0);
1.299 + test((t1>=t3)==0);
1.300 +
1.301 + test.Next(_L("operator <="));
1.302 + test((t4<=t3)!=0);
1.303 + test((t1<=t2)!=0);
1.304 + test((t3<=t2)==0);
1.305 + }
1.306 +
1.307 +void TestTTime::Test3(void)
1.308 +//
1.309 +// Tests for TTimeIntervaSeconds (and therefore TTimeIntervalBase)
1.310 +//
1.311 + {
1.312 + test.Next(_L("Construction"));
1.313 + TTimeIntervalSeconds s1; // uninitialised
1.314 + TTimeIntervalSeconds s2(0);
1.315 + test(s2.Int()==0 );
1.316 +
1.317 + TTimeIntervalSeconds s3(1);
1.318 + test(s3.Int()==1 );
1.319 + test(s3.Int()!=0 );
1.320 +
1.321 + TTimeIntervalSeconds s4(-1);
1.322 + test(s4.Int()==-1 );
1.323 +
1.324 + TTimeIntervalSeconds s8(2147483647);
1.325 + test(s8.Int()== 2147483647);
1.326 +
1.327 + test.Next(_L("operator ="));
1.328 + s1=0;
1.329 + test(s1.Int()==0 );
1.330 + TTimeIntervalSeconds s5(5),s6;
1.331 + s6=s5;
1.332 + test(s5.Int()==s6.Int());
1.333 + s6=3;
1.334 + test(s5.Int()!=s6.Int());
1.335 +
1.336 + test.Next(_L("operator <"));
1.337 + test((s6<s3)==0);
1.338 + test((s3<s5)!=0);
1.339 + test((s4<s1)!=0);
1.340 +
1.341 + test.Next(_L("operator >"));
1.342 + test((s3>s6)==0);
1.343 + test((s5>s3)!=0);
1.344 + test((s1>s4)!=0);
1.345 +
1.346 + test.Next(_L("operator !="));
1.347 + s6=s5;
1.348 + test((s6!=s5)==0);
1.349 + test((s3!=s4)!=0);
1.350 + test((s1!=s2)==0);
1.351 +
1.352 + test.Next(_L("operator >="));
1.353 + test((s1>=s6)==0);
1.354 + test((s3>=s5)==0);
1.355 + test((s5>=s3)!=0);
1.356 + test((s6>=s5)!=0);
1.357 + test((s1>=s2)!=0);
1.358 +
1.359 + test.Next(_L("operator <="));
1.360 + test((s6<=s1)==0);
1.361 + test((s5<=s3)==0);
1.362 + test((s3<=s5)!=0);
1.363 + test((s6<=s5)!=0);
1.364 + test((s1<=s2)!=0);
1.365 + }
1.366 +
1.367 +void TestTTime::Test4()
1.368 +//
1.369 +// Tests for all other time intervals
1.370 +//
1.371 + {
1.372 + test.Next(_L("TTimeIntervalMinutes"));
1.373 + test.Next(_L("Construction"));
1.374 + TTimeIntervalMinutes m1; // uninitialised
1.375 + TTimeIntervalMinutes m2(0);
1.376 + test(m2.Int()==0 );
1.377 + TTimeIntervalMinutes m3(1);
1.378 + test(m3.Int()==1 );
1.379 + test(m3.Int()!=0 );
1.380 + TTimeIntervalMinutes m4a(-1);
1.381 + test(m4a.Int()==-1 );
1.382 + TTimeIntervalMinutes m4(0xffffffff);
1.383 + test((TUint)m4.Int()==0xffffffff);
1.384 + test.Next(_L("operator ="));
1.385 + m1=0;
1.386 + test(m1.Int()==0 );
1.387 + TTimeIntervalMinutes m5(5),m6;
1.388 + m6=m5;
1.389 + test(m5.Int()==m6.Int());
1.390 + m6=3;
1.391 + m5=m6;
1.392 + test(m5.Int()==m6.Int());
1.393 +
1.394 + test.Next(_L("TTimeIntervalHours"));
1.395 + test.Next(_L("Construction"));
1.396 + TTimeIntervalHours h1; // uninitialised
1.397 + TTimeIntervalHours h2(0);
1.398 + test(h2.Int()==0 );
1.399 + TTimeIntervalHours h3(1);
1.400 + test(h3.Int()==1 );
1.401 + test(h3.Int()!=0 );
1.402 + TTimeIntervalHours h4a(-1);
1.403 + test(h4a.Int()==-1 );
1.404 + TTimeIntervalHours h4(0xffffffff);
1.405 + test((TUint)h4.Int()==0xffffffff);
1.406 + test.Next(_L("operator ="));
1.407 + h1=0;
1.408 + test(h1.Int()==0 );
1.409 + TTimeIntervalHours h5(5),h6;
1.410 + h6=h5;
1.411 + test(h5.Int()==h6.Int());
1.412 +
1.413 + test.Next(_L("TTImeIntervalDays"));
1.414 + test.Next(_L("Construction"));
1.415 + TTimeIntervalDays d1; // uninitialised
1.416 + TTimeIntervalDays d2(0);
1.417 + test(d2.Int()==0 );
1.418 + TTimeIntervalDays d3(1);
1.419 + test(d3.Int()==1 );
1.420 + test(d3.Int()!=0 );
1.421 + TTimeIntervalDays d4a(-1);
1.422 + test(d4a.Int()==-1 );
1.423 + TTimeIntervalDays d4(0xffffffff);
1.424 + test((TUint)d4.Int()==0xffffffff);
1.425 + test.Next(_L("operator ="));
1.426 + d1=0;
1.427 + test(d1.Int()==0 );
1.428 + TTimeIntervalDays d5(5),d6;
1.429 + d6=d5;
1.430 + test(d5.Int()==d6.Int());
1.431 +
1.432 + test.Next(_L("TTimeIntervalMonths"));
1.433 + test.Next(_L("Construction"));
1.434 + TTimeIntervalMonths mo1; // uninitialised
1.435 + TTimeIntervalMonths mo2(0);
1.436 + test(mo2.Int()==0 );
1.437 + TTimeIntervalMonths mo3(1);
1.438 + test(mo3.Int()==1 );
1.439 + test(mo3.Int()!=0 );
1.440 + TTimeIntervalMonths mo4a(-1);
1.441 + test(mo4a.Int()==-1 );
1.442 + TTimeIntervalMonths mo4(0xffffffff);
1.443 + test((TUint)mo4.Int()==0xffffffff);
1.444 + test.Next(_L("operator ="));
1.445 + mo1=0;
1.446 + test(mo1.Int()==0 );
1.447 + TTimeIntervalMonths mo5(5),mo6;
1.448 + mo6=mo5;
1.449 + test(mo5.Int()==mo6.Int());
1.450 +
1.451 + test.Next(_L("TTimeIntervalYears"));
1.452 + test.Next(_L("Construction"));
1.453 + TTimeIntervalYears y1; // uninitialised
1.454 + TTimeIntervalYears y2(0);
1.455 + test(y2.Int()==0 );
1.456 + TTimeIntervalYears y3(1);
1.457 + test(y3.Int()==1 );
1.458 + test(y3.Int()!=0 );
1.459 + TTimeIntervalYears y4a(-1);
1.460 + test(y4a.Int()==-1 );
1.461 + TTimeIntervalYears y4(0xffffffff);
1.462 + test((TUint)y4.Int()==0xffffffff);
1.463 + test.Next(_L("operator ="));
1.464 + y1=0;
1.465 + test(y1.Int()==0 );
1.466 + TTimeIntervalYears y5(17),y6;
1.467 + y6=y5;
1.468 + test(y5.Int()==y6.Int());
1.469 + y6=16;
1.470 + test(y5.Int()!=y6.Int());
1.471 + y5=16;
1.472 + test(y5.Int()==y6.Int());
1.473 + }
1.474 +
1.475 +
1.476 +void TestTTime::Test5()
1.477 +//
1.478 +// TDateTime to TTime convertions and vice versa, very large loop, so in own function for easy removal
1.479 +//
1.480 + {
1.481 + TInt microSecond=500000;
1.482 + TDateTime dateTime(0,EJanuary,0,0,0,0,microSecond);
1.483 + TInt year;
1.484 + for(year=1590;year<1710;year+=2)
1.485 + {
1.486 + dateTime.SetYear(year);
1.487 + for(TInt m=0;m<6;m++)
1.488 + {
1.489 + static TInt months[]={0,1,2,8,9,11};
1.490 + TInt month=months[m];
1.491 + dateTime.SetDay(0); // to make sure next line always suceeds
1.492 + dateTime.SetMonth((TMonth)month);
1.493 + for(TInt d=0;d<6;d++)
1.494 + {
1.495 + static TInt days[]={0,1,27,28,29,30};
1.496 + TInt day=days[d];
1.497 + if (day>=mTab[Time::IsLeapYear(year)][month])
1.498 + break;
1.499 + dateTime.SetDay(day);
1.500 + for(TInt h=0;h<4;h++)
1.501 + {
1.502 + static TInt hours[]={0,11,12,23};
1.503 + TInt hour=hours[h];
1.504 + dateTime.SetHour(hour);
1.505 + for(TInt minute=0;minute<60;minute+=59)
1.506 + {
1.507 + dateTime.SetMinute(minute);
1.508 + for(TInt second=0;second<60;second+=59)
1.509 + {
1.510 + dateTime.SetSecond(second);
1.511 + TTime tim(dateTime);
1.512 + dateTime = tim.DateTime();
1.513 + test(dateTime.Year()==year);
1.514 + test(dateTime.Month()==(TMonth)month);
1.515 + test(dateTime.Day()==day);
1.516 + test(dateTime.Hour()==hour);
1.517 + test(dateTime.Minute()==minute);
1.518 + test(dateTime.Second()==second);
1.519 + test(dateTime.MicroSecond()==microSecond);
1.520 + }
1.521 + }
1.522 + }
1.523 + }
1.524 + }
1.525 + }
1.526 +
1.527 +// smaller loop for -ve dates
1.528 + for (year=-150; year<5; year+=15)
1.529 + {
1.530 + dateTime.SetYear(year);
1.531 + for(TInt month=0; month<12; month+=5)
1.532 + {
1.533 + dateTime.SetDay(0); // to make sure next line always suceeds
1.534 + dateTime.SetMonth((TMonth)month);
1.535 + for(TInt day=0; day<30; day+=7)
1.536 + {
1.537 + if (day>=mTab[Time::IsLeapYear(year)][month])
1.538 + break;
1.539 + dateTime.SetDay(day);
1.540 + for(TInt hour=0; hour<24; hour+=6)
1.541 + {
1.542 + dateTime.SetHour(hour);
1.543 + for(TInt minute=0; minute<60; minute+=15)
1.544 + {
1.545 + dateTime.SetMinute(minute);
1.546 + for(TInt second=0; second<60; second+=20)
1.547 + {
1.548 + dateTime.SetSecond(second);
1.549 + TTime tim(dateTime);
1.550 + dateTime = tim.DateTime();
1.551 + test(dateTime.Year()==year);
1.552 + test(dateTime.Month()==(TMonth)month);
1.553 + test(dateTime.Day()==day);
1.554 + test(dateTime.Hour()==hour);
1.555 + test(dateTime.Minute()==minute);
1.556 + test(dateTime.Second()==second);
1.557 + test(dateTime.MicroSecond()==microSecond);
1.558 + }
1.559 + }
1.560 + }
1.561 + }
1.562 + }
1.563 + }
1.564 +
1.565 + TTime tim(MAKE_TINT64(0x7fffffff,0xffffffff));
1.566 + dateTime = tim.DateTime();
1.567 + tim = dateTime;
1.568 + test(tim.Int64()==MAKE_TINT64(0x7fffffff,0xffffffff));
1.569 + }
1.570 +
1.571 +void TestTTime::Test6()
1.572 +//
1.573 +// Adding and differencing
1.574 +//
1.575 + {
1.576 + TDateTime dateTime(4,EJanuary,30,0,0,0,0);
1.577 +
1.578 + test.Next(_L("TTimeIntervalYears"));
1.579 + TTime base=dateTime;
1.580 + TTimeIntervalYears year(1);
1.581 + TTime result=base+year;
1.582 + dateTime=result.DateTime();
1.583 + test(dateTime.Year()==5);
1.584 + test(dateTime.Month()==EJanuary);
1.585 + test(dateTime.Day()==30);
1.586 + test(result.YearsFrom(base)==year);
1.587 + year=2000;
1.588 + result+=year;
1.589 + dateTime=result.DateTime();
1.590 + test(dateTime.Year()==2005);
1.591 + test(dateTime.Month()==EJanuary);
1.592 + test(dateTime.Day()==30);
1.593 + test(result.YearsFrom(base)==TTimeIntervalYears(2001));
1.594 + test(base.YearsFrom(result)==TTimeIntervalYears(-2001));
1.595 +
1.596 + test.Next(_L("YearsFrom"));
1.597 + TTime timeNow;
1.598 + timeNow.HomeTime();
1.599 + TTime timeFuture=timeNow+TTimeIntervalYears(10);
1.600 + test(timeFuture.YearsFrom(timeNow).Int()==10);
1.601 + test(timeNow.YearsFrom(timeFuture).Int()==-10);
1.602 + TTime mintime = Time::MinTTime();
1.603 + test(timeNow.YearsFrom(mintime).Int()>0);//must be positive value
1.604 + test(mintime.YearsFrom(timeNow).Int()<0);//must be negative value
1.605 + TTime maxtime = Time::MaxTTime();
1.606 + test(timeNow.YearsFrom(maxtime).Int()<0);//must be negative value
1.607 + test(maxtime.YearsFrom(timeNow).Int()>0);//must be positive value
1.608 +
1.609 + test.Next(_L("Adding months"));
1.610 + TTimeIntervalMonths month(1);
1.611 + result=base+month;
1.612 + dateTime=result.DateTime();
1.613 + test(dateTime.Year()==4);
1.614 + test(dateTime.Month()==EFebruary);
1.615 + test(dateTime.Day()==28); // leap year
1.616 + test(result.YearsFrom(base)==TTimeIntervalYears(0));
1.617 + test(base.YearsFrom(result)==TTimeIntervalYears(0));
1.618 + test(result.MonthsFrom(base)==month);
1.619 + test(base.MonthsFrom(result)==TTimeIntervalMonths(-month.Int()));
1.620 + month=12;
1.621 + result+=month;
1.622 + dateTime=result.DateTime();
1.623 + test(dateTime.Year()==5);
1.624 + test(dateTime.Month()==EFebruary);
1.625 + test(dateTime.Day()==27); // not aleap year
1.626 + test(result.YearsFrom(base)==TTimeIntervalYears(1));
1.627 + test(base.YearsFrom(result)==TTimeIntervalYears(-1));
1.628 + test(result.MonthsFrom(base)==TTimeIntervalMonths(13));
1.629 + test(base.MonthsFrom(result)==TTimeIntervalYears(-13));
1.630 +
1.631 + test.Next(_L("MonthsFrom"));
1.632 + timeNow.HomeTime();
1.633 + timeFuture=timeNow+TTimeIntervalMonths(10);
1.634 + test(timeFuture.MonthsFrom(timeNow).Int()==10);
1.635 + test(timeNow.MonthsFrom(timeFuture).Int()==-10);
1.636 + test(timeNow.MonthsFrom(mintime).Int()>0);//must be positive value
1.637 + test(mintime.MonthsFrom(timeNow).Int()<0);//must be negative value
1.638 + test(timeNow.MonthsFrom(maxtime).Int()<0);//must be negative value
1.639 + test(maxtime.MonthsFrom(timeNow).Int()>0);//must be positive value
1.640 +
1.641 + test.Next(_L("Adding days"));
1.642 + TTimeIntervalDays day(1);
1.643 + result=base+day;
1.644 + dateTime=result.DateTime();
1.645 + test(dateTime.Year()==4);
1.646 + test(dateTime.Month()==EFebruary);
1.647 + test(dateTime.Day()==0);
1.648 + test(result.YearsFrom(base)==TTimeIntervalYears(0));
1.649 + test(base.YearsFrom(result)==TTimeIntervalYears(0));
1.650 + test(result.MonthsFrom(base)==TTimeIntervalMonths(0));
1.651 + test(base.MonthsFrom(result)==TTimeIntervalMonths(0));
1.652 + test(result.DaysFrom(base)==day);
1.653 + test(base.DaysFrom(result)==TTimeIntervalDays(-day.Int()));
1.654 + day=60;
1.655 + result+=day;
1.656 + dateTime=result.DateTime();
1.657 + test(dateTime.Year()==4);
1.658 + test(dateTime.Month()==EApril);
1.659 + test(dateTime.Day()==0);
1.660 + test(result.YearsFrom(base)==TTimeIntervalYears(0));
1.661 + test(base.YearsFrom(result)==TTimeIntervalYears(0));
1.662 + test(result.MonthsFrom(base)==TTimeIntervalMonths(2));
1.663 + test(base.MonthsFrom(result)==TTimeIntervalMonths(-2));
1.664 + test(result.DaysFrom(base)==TTimeIntervalDays(61));
1.665 + test(base.DaysFrom(result)==TTimeIntervalDays(-61));
1.666 +
1.667 + test.Next(_L("DaysFrom"));
1.668 + timeNow.HomeTime();
1.669 + timeFuture=timeNow+TTimeIntervalDays(10);
1.670 + test(timeFuture.DaysFrom(timeNow).Int()==10);
1.671 + test(timeNow.DaysFrom(timeFuture).Int()==-10);
1.672 + test(timeNow.DaysFrom(mintime).Int()>0);//must be positive value
1.673 + test(mintime.DaysFrom(timeNow).Int()<0);//must be negative value
1.674 + test(timeNow.DaysFrom(maxtime).Int()<0);//must be negative value
1.675 + test(maxtime.DaysFrom(timeNow).Int()>0);//must be positive value
1.676 +
1.677 + test.Next(_L("Adding hours"));
1.678 + TTimeIntervalHours hour(6);
1.679 + result=base+hour;
1.680 + dateTime=result.DateTime();
1.681 + test(dateTime.Year()==4);
1.682 + test(dateTime.Month()==EJanuary);
1.683 + test(dateTime.Day()==30);
1.684 + test(dateTime.Hour()==6);
1.685 + test(result.YearsFrom(base)==TTimeIntervalYears(0));
1.686 + test(base.YearsFrom(result)==TTimeIntervalYears(0));
1.687 + test(result.MonthsFrom(base)==TTimeIntervalMonths(0));
1.688 + test(base.MonthsFrom(result)==TTimeIntervalMonths(0));
1.689 + test(result.DaysFrom(base)==TTimeIntervalDays(0));
1.690 + test(base.DaysFrom(result)==TTimeIntervalDays(0));
1.691 + TInt ret=result.HoursFrom(base,hour);
1.692 + test(ret==0);
1.693 + test(hour==TTimeIntervalHours(6));
1.694 + ret=base.HoursFrom(result,hour);
1.695 + test(ret==0);
1.696 + test(hour==TTimeIntervalHours(-6));
1.697 + hour=20;
1.698 + result+=hour;
1.699 + dateTime=result.DateTime();
1.700 + test(dateTime.Year()==4);
1.701 + test(dateTime.Month()==EFebruary);
1.702 + test(dateTime.Day()==0);
1.703 + test(dateTime.Hour()==2);
1.704 + test(result.YearsFrom(base)==TTimeIntervalYears(0));
1.705 + test(base.YearsFrom(result)==TTimeIntervalYears(0));
1.706 + test(result.MonthsFrom(base)==TTimeIntervalMonths(0));
1.707 + test(base.MonthsFrom(result)==TTimeIntervalMonths(0));
1.708 + test(result.DaysFrom(base)==TTimeIntervalDays(1));
1.709 + test(base.DaysFrom(result)==TTimeIntervalDays(-1));
1.710 + ret=result.HoursFrom(base,hour);
1.711 + test(ret==0);
1.712 + test(hour==TTimeIntervalHours(26));
1.713 + ret=base.HoursFrom(result,hour);
1.714 + test(ret==0);
1.715 + test(hour==TTimeIntervalHours(-26));
1.716 +
1.717 + test.Next(_L("HoursFrom"));
1.718 + timeNow.HomeTime();
1.719 + timeFuture=timeNow+TTimeIntervalHours(10);
1.720 + test(timeFuture.HoursFrom(timeNow,hour)==KErrNone);
1.721 + test(hour.Int()==10);
1.722 + test(timeNow.HoursFrom(timeFuture,hour)==KErrNone);
1.723 + test(hour.Int()==-10); // fails this in 059
1.724 + timeFuture=timeNow+TTimeIntervalHours(KMaxTInt);
1.725 + test(timeFuture.HoursFrom(timeNow,hour)==KErrNone);
1.726 + test(hour.Int()==KMaxTInt);
1.727 + test(timeNow.HoursFrom(timeFuture,hour)==KErrNone);
1.728 + test(hour.Int()==-KMaxTInt);
1.729 + timeFuture=timeFuture+TTimeIntervalHours(1);
1.730 + test(timeFuture.HoursFrom(timeNow,hour)==KErrOverflow);
1.731 + test(timeNow.HoursFrom(timeFuture,hour)==KErrNone);
1.732 + test(hour.Int()==KMinTInt);
1.733 + timeFuture=timeFuture+TTimeIntervalHours(1);
1.734 + test(timeFuture.HoursFrom(timeNow,hour)==KErrOverflow);
1.735 + test(timeNow.HoursFrom(timeFuture,hour)==KErrOverflow);
1.736 +
1.737 + test.Next(_L("Adding minutes"));
1.738 + TTimeIntervalMinutes minute(73);
1.739 + result=base+minute;
1.740 + dateTime=result.DateTime();
1.741 + test(dateTime.Year()==4);
1.742 + test(dateTime.Month()==EJanuary);
1.743 + test(dateTime.Day()==30);
1.744 + test(dateTime.Hour()==1);
1.745 + test(dateTime.Minute()==13);
1.746 + test(result.YearsFrom(base)==TTimeIntervalYears(0));
1.747 + test(base.YearsFrom(result)==TTimeIntervalYears(0));
1.748 + test(result.MonthsFrom(base)==TTimeIntervalMonths(0));
1.749 + test(base.MonthsFrom(result)==TTimeIntervalMonths(0));
1.750 + test(result.DaysFrom(base)==TTimeIntervalDays(0));
1.751 + test(base.DaysFrom(result)==TTimeIntervalDays(0));
1.752 + ret=result.HoursFrom(base,hour);
1.753 + test(ret==0);
1.754 + test(hour==TTimeIntervalHours(1));
1.755 + ret=base.HoursFrom(result,hour);
1.756 + test(ret==0);
1.757 + test(hour==TTimeIntervalHours(-1));
1.758 + ret=result.MinutesFrom(base,minute);
1.759 + test(ret==0);
1.760 + test(minute==TTimeIntervalMinutes(73));
1.761 + ret=base.MinutesFrom(result,minute);
1.762 + test(ret==0);
1.763 + test(minute==TTimeIntervalMinutes(-73));
1.764 + minute=1367;
1.765 + result+=minute;
1.766 + dateTime=result.DateTime();
1.767 + test(dateTime.Year()==4);
1.768 + test(dateTime.Month()==EFebruary);
1.769 + test(dateTime.Day()==0);
1.770 + test(dateTime.Hour()==0);
1.771 + test(dateTime.Minute()==0);
1.772 + test(result.YearsFrom(base)==TTimeIntervalYears(0));
1.773 + test(base.YearsFrom(result)==TTimeIntervalYears(0));
1.774 + test(result.MonthsFrom(base)==TTimeIntervalMonths(0));
1.775 + test(base.MonthsFrom(result)==TTimeIntervalMonths(0));
1.776 + test(result.DaysFrom(base)==TTimeIntervalDays(1));
1.777 + test(base.DaysFrom(result)==TTimeIntervalDays(-1));
1.778 + ret=result.HoursFrom(base,hour);
1.779 + test(ret==0);
1.780 + test(hour==TTimeIntervalHours(24));
1.781 + ret=base.HoursFrom(result,hour);
1.782 + test(ret==0);
1.783 + test(hour==TTimeIntervalHours(-24));
1.784 + ret=result.MinutesFrom(base,minute);
1.785 + test(ret==0);
1.786 + test(minute==TTimeIntervalMinutes(1440));
1.787 + ret=base.MinutesFrom(result,minute);
1.788 + test(ret==0);
1.789 + test(minute==TTimeIntervalMinutes(-1440));
1.790 +
1.791 + test.Next(_L("MinutesFrom"));
1.792 + timeNow.HomeTime();
1.793 + timeFuture=timeNow+TTimeIntervalMinutes(10);
1.794 + test(timeFuture.MinutesFrom(timeNow,minute)==KErrNone);
1.795 + test(minute.Int()==10);
1.796 + test(timeNow.MinutesFrom(timeFuture,minute)==KErrNone);
1.797 + test(minute.Int()==-10); // fails this in 059
1.798 + timeFuture=timeNow+TTimeIntervalMinutes(KMaxTInt);
1.799 + test(timeFuture.MinutesFrom(timeNow,minute)==KErrNone);
1.800 + test(minute.Int()==KMaxTInt);
1.801 + test(timeNow.MinutesFrom(timeFuture,minute)==KErrNone);
1.802 + test(minute.Int()==-KMaxTInt);
1.803 + timeFuture=timeFuture+TTimeIntervalMinutes(1);
1.804 + test(timeFuture.MinutesFrom(timeNow,minute)==KErrOverflow);
1.805 + test(timeNow.MinutesFrom(timeFuture,minute)==KErrNone);
1.806 + test(minute.Int()==KMinTInt);
1.807 + timeFuture=timeFuture+TTimeIntervalMinutes(1);
1.808 + test(timeFuture.MinutesFrom(timeNow,minute)==KErrOverflow);
1.809 + test(timeNow.MinutesFrom(timeFuture,minute)==KErrOverflow);
1.810 +
1.811 + test.Next(_L("Adding seconds"));
1.812 + TTimeIntervalSeconds second(305222);
1.813 + result=base+second;
1.814 + dateTime=result.DateTime();
1.815 + test(dateTime.Year()==4);
1.816 + test(dateTime.Month()==EFebruary);
1.817 + test(dateTime.Day()==2);
1.818 + test(dateTime.Hour()==12);
1.819 + test(dateTime.Minute()==47);
1.820 + test(dateTime.Second()==2);
1.821 + test(result.YearsFrom(base)==TTimeIntervalYears(0));
1.822 + test(base.YearsFrom(result)==TTimeIntervalYears(0));
1.823 + test(result.MonthsFrom(base)==TTimeIntervalMonths(0));
1.824 + test(base.MonthsFrom(result)==TTimeIntervalMonths(0));
1.825 + test(result.DaysFrom(base)==TTimeIntervalDays(3));
1.826 + test(base.DaysFrom(result)==TTimeIntervalDays(-3));
1.827 + ret=result.HoursFrom(base,hour);
1.828 + test(ret==0);
1.829 + test(hour==TTimeIntervalHours(84));
1.830 + ret=base.HoursFrom(result,hour);
1.831 + test(ret==0);
1.832 + test(hour==TTimeIntervalHours(-84));
1.833 + ret=result.MinutesFrom(base,minute);
1.834 + test(ret==0);
1.835 + test(minute==TTimeIntervalMinutes(5087));
1.836 + ret=base.MinutesFrom(result,minute);
1.837 + test(ret==0);
1.838 + test(minute==TTimeIntervalMinutes(-5087));
1.839 + ret=result.SecondsFrom(base,second);
1.840 + test(ret==0);
1.841 + test(second==TTimeIntervalSeconds(305222));
1.842 + ret=base.SecondsFrom(result,second);
1.843 + test(ret==0);
1.844 + test(second==TTimeIntervalSeconds(-305222));
1.845 + second=58;
1.846 + result+=second;
1.847 + dateTime=result.DateTime();
1.848 + test(dateTime.Year()==4);
1.849 + test(dateTime.Month()==EFebruary);
1.850 + test(dateTime.Day()==2);
1.851 + test(dateTime.Hour()==12);
1.852 + test(dateTime.Minute()==48);
1.853 + test(dateTime.Second()==0);
1.854 + test(result.YearsFrom(base)==TTimeIntervalYears(0));
1.855 + test(base.YearsFrom(result)==TTimeIntervalYears(0));
1.856 + test(result.MonthsFrom(base)==TTimeIntervalMonths(0));
1.857 + test(base.MonthsFrom(result)==TTimeIntervalMonths(0));
1.858 + test(result.DaysFrom(base)==TTimeIntervalDays(3));
1.859 + test(base.DaysFrom(result)==TTimeIntervalDays(-3));
1.860 + ret=result.HoursFrom(base,hour);
1.861 + test(ret==0);
1.862 + test(hour==TTimeIntervalHours(84));
1.863 + ret=base.HoursFrom(result,hour);
1.864 + test(ret==0);
1.865 + test(hour==TTimeIntervalHours(-84));
1.866 + ret=result.MinutesFrom(base,minute);
1.867 + test(ret==0);
1.868 + test(minute==TTimeIntervalMinutes(5088));
1.869 + ret=base.MinutesFrom(result,minute);
1.870 + test(ret==0);
1.871 + test(minute==TTimeIntervalMinutes(-5088));
1.872 + ret=result.SecondsFrom(base,second);
1.873 + test(ret==0);
1.874 + test(second==TTimeIntervalSeconds(305280));
1.875 + ret=base.SecondsFrom(result,second);
1.876 + test(ret==0);
1.877 + test(second==TTimeIntervalSeconds(-305280));
1.878 +
1.879 + test.Next(_L("SecondsFrom"));
1.880 + timeNow.HomeTime();
1.881 + timeFuture=timeNow+TTimeIntervalSeconds(10);
1.882 + test(timeFuture.SecondsFrom(timeNow,second)==KErrNone);
1.883 + test(second.Int()==10);
1.884 + test(timeNow.SecondsFrom(timeFuture,second)==KErrNone);
1.885 + test(second.Int()==-10);
1.886 + timeFuture=timeNow+TTimeIntervalSeconds(KMaxTInt);
1.887 + test(timeFuture.SecondsFrom(timeNow,second)==KErrNone);
1.888 + test(second.Int()==KMaxTInt);
1.889 + test(timeNow.SecondsFrom(timeFuture,second)==KErrNone);
1.890 + test(second.Int()==-KMaxTInt);
1.891 + timeFuture=timeFuture+TTimeIntervalSeconds(1);
1.892 + test(timeFuture.SecondsFrom(timeNow,second)==KErrOverflow);
1.893 + test(timeNow.SecondsFrom(timeFuture,second)==KErrNone);
1.894 + test(second.Int()==KMinTInt);
1.895 + timeFuture=timeFuture+TTimeIntervalSeconds(1);
1.896 + test(timeFuture.SecondsFrom(timeNow,second)==KErrOverflow);
1.897 + test(timeNow.SecondsFrom(timeFuture,second)==KErrOverflow);
1.898 +
1.899 + test.Next(_L("Adding microseconds"));
1.900 + TTimeIntervalMicroSeconds microsecond=KDaysToMicroSeconds+KHoursToMicroSeconds+MAKE_TINT64(0,5000);
1.901 + result=base+microsecond;
1.902 + dateTime=result.DateTime();
1.903 + test(dateTime.Year()==4);
1.904 + test(dateTime.Month()==EFebruary);
1.905 + test(dateTime.Day()==0);
1.906 + test(dateTime.Hour()==1);
1.907 + test(dateTime.Minute()==0);
1.908 + test(dateTime.Second()==0);
1.909 + test(dateTime.MicroSecond()==5000);
1.910 + test(result.YearsFrom(base)==TTimeIntervalYears(0));
1.911 + test(base.YearsFrom(result)==TTimeIntervalYears(0));
1.912 + test(result.MonthsFrom(base)==TTimeIntervalMonths(0));
1.913 + test(base.MonthsFrom(result)==TTimeIntervalMonths(0));
1.914 + test(result.DaysFrom(base)==TTimeIntervalDays(1));
1.915 + test(base.DaysFrom(result)==TTimeIntervalDays(-1));
1.916 + ret=result.HoursFrom(base,hour);
1.917 + test(ret==0);
1.918 + test(hour==TTimeIntervalHours(25));
1.919 + ret=base.HoursFrom(result,hour);
1.920 + test(ret==0);
1.921 + test(hour==TTimeIntervalHours(-25));
1.922 + ret=result.MinutesFrom(base,minute);
1.923 + test(ret==0);
1.924 + test(minute==TTimeIntervalMinutes(1500));
1.925 + ret=base.MinutesFrom(result,minute);
1.926 + test(ret==0);
1.927 + test(minute==TTimeIntervalMinutes(-1500));
1.928 + ret=result.SecondsFrom(base,second);
1.929 + test(ret==0);
1.930 + test(second==TTimeIntervalSeconds(90000));
1.931 + ret=base.SecondsFrom(result,second);
1.932 + test(ret==0);
1.933 + test(second==TTimeIntervalSeconds(-90000));
1.934 + test(result.MicroSecondsFrom(base)==microsecond);
1.935 + microsecond=5008;
1.936 + result+=microsecond;
1.937 + dateTime=result.DateTime();
1.938 + test(dateTime.Year()==4);
1.939 + test(dateTime.Month()==EFebruary);
1.940 + test(dateTime.Day()==0);
1.941 + test(dateTime.Hour()==1);
1.942 + test(dateTime.Minute()==0);
1.943 + test(dateTime.Second()==0);
1.944 + test(dateTime.MicroSecond()==10008);
1.945 +
1.946 + test.Next(_L("MicroSecondsFrom"));
1.947 + timeNow.HomeTime();
1.948 + timeFuture=timeNow+TTimeIntervalMicroSeconds(10);
1.949 + test(timeFuture.MicroSecondsFrom(timeNow).Int64()==10);
1.950 + test(timeNow.MicroSecondsFrom(timeFuture).Int64()==-10);
1.951 +
1.952 + test.Next(_L("Testing invalid differences"));
1.953 + TInt64 overflow(KMaxTInt);
1.954 + overflow++;
1.955 + overflow*=KSecondsToMicroSeconds;
1.956 + result=base+TTimeIntervalMicroSeconds(overflow);
1.957 + ret=result.SecondsFrom(base,second);
1.958 + test(ret==KErrOverflow);
1.959 + overflow*=60;
1.960 + result=base+TTimeIntervalMicroSeconds(overflow);
1.961 + ret=result.MinutesFrom(base,minute);
1.962 + test(ret==KErrOverflow);
1.963 + overflow*=60;
1.964 + result=base+TTimeIntervalMicroSeconds(overflow);
1.965 + ret=result.HoursFrom(base,hour);
1.966 + test(ret==KErrOverflow);
1.967 +
1.968 + test.Next(_L("Specific MonthsFrom() tests"));
1.969 +
1.970 + base=TDateTime(1995,EJanuary,30,0,0,0,0);
1.971 + result=TDateTime(1995,EFebruary,27,0,0,0,0);
1.972 + test(result.MonthsFrom(base)==TTimeIntervalMonths(1));
1.973 +
1.974 + base=TDateTime(1995,EJanuary,27,0,0,0,0);
1.975 + result=TDateTime(1995,EFebruary,27,0,0,0,0);
1.976 + test(result.MonthsFrom(base)==TTimeIntervalMonths(1));
1.977 +
1.978 + base=TDateTime(1995,EJanuary,29,0,0,0,0);
1.979 + result=TDateTime(1995,EFebruary,27,0,0,0,0);
1.980 + test(result.MonthsFrom(base)==TTimeIntervalMonths(1));
1.981 +
1.982 + base=TDateTime(1995,EJanuary,30,0,0,0,0);
1.983 + result=TDateTime(1995,EFebruary,27,0,0,0,0);
1.984 + test(base.MonthsFrom(result)==TTimeIntervalMonths(-1));
1.985 + test(result.MonthsFrom(base)==TTimeIntervalMonths(1));
1.986 +
1.987 + base=TDateTime(1995,EJanuary,27,0,0,0,0);
1.988 + result=TDateTime(1995,EFebruary,27,0,0,0,0);
1.989 + test(base.MonthsFrom(result)==TTimeIntervalMonths(-1));
1.990 + test(result.MonthsFrom(base)==TTimeIntervalMonths(1));
1.991 +
1.992 + base=TDateTime(1995,EJanuary,29,0,0,0,0);
1.993 + result=TDateTime(1995,EFebruary,27,0,0,0,0);
1.994 + test(base.MonthsFrom(result)==TTimeIntervalMonths(-1));
1.995 + test(result.MonthsFrom(base)==TTimeIntervalMonths(1));
1.996 +
1.997 + base=TDateTime(1995,EJanuary,26,0,0,0,0);
1.998 + result=TDateTime(1995,EFebruary,27,0,0,0,0);
1.999 + test(base.MonthsFrom(result)==TTimeIntervalMonths(-1));
1.1000 + test(result.MonthsFrom(base)==TTimeIntervalMonths(1));
1.1001 +
1.1002 + base=TDateTime(1995,EFebruary,27,0,0,0,0);
1.1003 + result=TDateTime(1995,EMarch,29,0,0,0,0);
1.1004 + test(base.MonthsFrom(result)==TTimeIntervalMonths(-1));
1.1005 + test(result.MonthsFrom(base)==TTimeIntervalMonths(1));
1.1006 +
1.1007 + base=TDateTime(1995,EFebruary,27,0,0,0,0);
1.1008 + result=TDateTime(1995,EMarch,30,0,0,0,0);
1.1009 + test(base.MonthsFrom(result)==TTimeIntervalMonths(-1));
1.1010 + test(result.MonthsFrom(base)==TTimeIntervalMonths(1));
1.1011 +
1.1012 + base=TDateTime(1995,EFebruary,27,13,0,0,0);
1.1013 + result=TDateTime(1995,EJanuary,29,12,0,0,0);
1.1014 + test(base.MonthsFrom(result)==TTimeIntervalMonths(1));
1.1015 + test(result.MonthsFrom(base)==TTimeIntervalMonths(-1));
1.1016 +
1.1017 + base=TDateTime(1995,EFebruary,27,12,0,0,0);
1.1018 + result=TDateTime(1995,EJanuary,29,13,0,0,0);
1.1019 + test(base.MonthsFrom(result)==TTimeIntervalMonths(0));
1.1020 + test(result.MonthsFrom(base)==TTimeIntervalMonths(0));
1.1021 +
1.1022 + base=TDateTime(1995,EJanuary,27,12,0,0,0);
1.1023 + result=TDateTime(1995,EJanuary,29,13,0,0,0);
1.1024 + test(base.MonthsFrom(result)==TTimeIntervalMonths(0));
1.1025 + test(result.MonthsFrom(base)==TTimeIntervalMonths(0));
1.1026 +
1.1027 + test.Next(_L("Looped MonthsFrom() test"));
1.1028 + const TTime endBase=MAKE_TINT64(74334524,25422354);
1.1029 + const TTime endResult=MAKE_TINT64(154334524,25422354);
1.1030 + const TTimeIntervalMicroSeconds plus=MAKE_TINT64(1234567,23453452);
1.1031 + for (base=MAKE_TINT64(3563656,3456235623u);base<endBase;base+=plus)
1.1032 + for (result=MAKE_TINT64(3563656,3456235623u);result<endResult;result+=plus)
1.1033 + test(base.MonthsFrom(result).Int()==-result.MonthsFrom(base).Int());
1.1034 + }
1.1035 +
1.1036 +void TestTTime::Test7()
1.1037 +//
1.1038 +// subtracting
1.1039 +//
1.1040 + {
1.1041 + TDateTime dateTime(1996,EApril,3,0,0,0,0);
1.1042 + TTime base(dateTime);
1.1043 + TTime tim(base);
1.1044 +
1.1045 + tim+=TTimeIntervalYears(7);
1.1046 + tim+=TTimeIntervalMonths(3);
1.1047 + tim+=TTimeIntervalDays(40);
1.1048 + tim+=TTimeIntervalHours(-3);
1.1049 + tim+=TTimeIntervalMinutes(1234);
1.1050 + tim+=TTimeIntervalSeconds(666);
1.1051 + tim+=TTimeIntervalMicroSeconds(-876540);
1.1052 + tim-=TTimeIntervalMicroSeconds(-876540);
1.1053 + tim-=TTimeIntervalSeconds(666);
1.1054 + tim-=TTimeIntervalMinutes(1234);
1.1055 + tim-=TTimeIntervalHours(-3);
1.1056 + tim-=TTimeIntervalDays(40);
1.1057 + tim-=TTimeIntervalMonths(3);
1.1058 + tim-=TTimeIntervalYears(7);
1.1059 + test (base==tim);
1.1060 +
1.1061 + tim-=TTimeIntervalMicroSeconds(9999999);
1.1062 + tim-=TTimeIntervalSeconds(52);
1.1063 + tim-=TTimeIntervalMinutes(-13);
1.1064 + tim-=TTimeIntervalHours(-337);
1.1065 + tim-=TTimeIntervalDays(1010);
1.1066 + tim-=TTimeIntervalMonths(-150);
1.1067 + tim-=TTimeIntervalYears(337);
1.1068 + tim+=TTimeIntervalYears(337);
1.1069 + tim+=TTimeIntervalMonths(-150);
1.1070 + tim+=TTimeIntervalDays(1010);
1.1071 + tim+=TTimeIntervalHours(-337);
1.1072 + tim+=TTimeIntervalMinutes(-13);
1.1073 + tim+=TTimeIntervalSeconds(52);
1.1074 + tim+=TTimeIntervalMicroSeconds(9999999);
1.1075 + test (base==tim);
1.1076 +
1.1077 + tim=TDateTime(-50,EMarch,6,14,45,3,100);
1.1078 + dateTime=tim.DateTime();
1.1079 + test(dateTime.Year()==-50);
1.1080 + test(dateTime.Month()==EMarch);
1.1081 + test(dateTime.Day()==6);
1.1082 + test(dateTime.Hour()==14);
1.1083 + test(dateTime.Minute()==45);
1.1084 + test(dateTime.Second()==3);
1.1085 + test(dateTime.MicroSecond()==100);
1.1086 +
1.1087 + tim=TDateTime(-241,EJanuary,0,0,0,0,0);
1.1088 + tim-=TTimeIntervalMicroSeconds(1);
1.1089 + dateTime=tim.DateTime();
1.1090 + test(dateTime.Year()==-242);
1.1091 + test(dateTime.Month()==EDecember);
1.1092 + test(dateTime.Day()==30);
1.1093 + test(dateTime.Hour()==23);
1.1094 + test(dateTime.Minute()==59);
1.1095 + test(dateTime.Second()==59);
1.1096 + test(dateTime.MicroSecond()==999999);
1.1097 +
1.1098 + tim=Time::MaxTTime();
1.1099 + dateTime=tim.DateTime();
1.1100 + tim=dateTime;
1.1101 + test(tim==Time::MaxTTime());
1.1102 +
1.1103 + tim=Time::MinTTime();
1.1104 + dateTime=tim.DateTime();
1.1105 + tim=dateTime;
1.1106 + test(tim==Time::MinTTime());
1.1107 + }
1.1108 +
1.1109 +void TestTTime::Test8()
1.1110 +//
1.1111 +// Test TTime's date property functions
1.1112 +// this implicitly tests Time's date property functions.
1.1113 +//
1.1114 + {
1.1115 + test.Next(_L("Thorough Test with 4 day week rule"));
1.1116 +
1.1117 + TInt year=4;
1.1118 + TMonth month=EJanuary;
1.1119 + TInt day=30;
1.1120 + TInt hour=0;
1.1121 + TInt minute=0;
1.1122 + TInt second=0;
1.1123 + TInt microSecond=0;
1.1124 + TDateTime dateTime(year,month,day,hour,minute,second,microSecond);
1.1125 + TTime tim(dateTime);
1.1126 +
1.1127 + test(tim.DayNoInWeek()==0);
1.1128 + test(tim.DayNoInYear()==31);
1.1129 + test(tim.WeekNoInYear()==5);
1.1130 +
1.1131 + dateTime.SetDay(29);
1.1132 + tim=dateTime;
1.1133 + test(tim.DayNoInWeek()==6);
1.1134 + test(tim.DayNoInYear()==30);
1.1135 + test(tim.WeekNoInYear()==4);
1.1136 +
1.1137 + dateTime.SetMonth(EJanuary);
1.1138 + dateTime.SetDay(0);
1.1139 + TInt y;
1.1140 + for (y=1990;y<2020;y++)
1.1141 + {
1.1142 + dateTime.SetYear(y);
1.1143 + tim=dateTime;
1.1144 + test(tim.DayNoInYear()==1);
1.1145 + TInt r=tim.WeekNoInYear();
1.1146 + if (tim.DayNoInWeek()<=3)
1.1147 + test(r==1);
1.1148 + else
1.1149 + test(r==52 || r==53);
1.1150 + }
1.1151 +
1.1152 + dateTime.SetMonth(EDecember);
1.1153 + dateTime.SetDay(30);
1.1154 + TInt m(0);
1.1155 + TInt d(0);
1.1156 + TInt dn(0);
1.1157 + TInt wkn(0);
1.1158 + TInt wk(0);
1.1159 + for (y=1900;y<1921;y++) // MUST BEGIN 0N 1900 (been run to 2500)
1.1160 + {
1.1161 + dateTime.SetYear(y);
1.1162 + for (m=0;m<12;m++)
1.1163 + {
1.1164 + dateTime.SetMonth(TMonth(m));
1.1165 + for (d=0;d<Time::DaysInMonth(y,TMonth(m));d++)
1.1166 + {
1.1167 + dateTime.SetDay(d);
1.1168 + tim=dateTime;
1.1169 + wk=tim.WeekNoInYear();
1.1170 + dn++;
1.1171 + if (dn>6)
1.1172 + dn=0;
1.1173 + if (dn==1)
1.1174 + {
1.1175 + wkn++;
1.1176 + if((m==11 && d>=28) | (m==0 && d<=3))
1.1177 + wkn=1;
1.1178 + }
1.1179 + test(wkn==wk);
1.1180 + }
1.1181 + dateTime.SetDay(0);
1.1182 + }
1.1183 + }
1.1184 +
1.1185 + test.Next(_L("Testing wk53 in a year with 4 days in last week"));
1.1186 + dateTime.SetYear(2009);
1.1187 + dateTime.SetMonth(EDecember);
1.1188 + dateTime.SetDay(27); // 28th, day is 0-based
1.1189 + dateTime.SetHour(8); // Ensure the remaining days are 3.somefraction to test rounding
1.1190 + tim=dateTime;
1.1191 + test(tim.DayNoInWeek()==0);
1.1192 + test(tim.DayNoInMonth()==27);
1.1193 + test(tim.DayNoInYear()==362);
1.1194 + test(tim.WeekNoInYear()==53);
1.1195 + dateTime.SetYear(2010);
1.1196 + dateTime.SetMonth(EJanuary);
1.1197 + dateTime.SetDay(3); // 4th, day is 0-based
1.1198 + tim=dateTime;
1.1199 + test(tim.DayNoInWeek()==0);
1.1200 + test(tim.DayNoInMonth()==3);
1.1201 + test(tim.DayNoInYear()==4);
1.1202 + test(tim.WeekNoInYear()==1);
1.1203 + dateTime.SetHour(0);
1.1204 +
1.1205 + test.Next(_L("Testing other week no. rules"));
1.1206 + dateTime.SetYear(1995);
1.1207 + dateTime.SetDay(14);
1.1208 + dateTime.SetMonth(ENovember);
1.1209 + tim=dateTime;
1.1210 + test(tim.DayNoInWeek()==2);
1.1211 + test(tim.DayNoInYear()==319);
1.1212 + test(tim.WeekNoInYear()==46);
1.1213 +
1.1214 +// Different First Week rules
1.1215 + test.Next(_L("Test week no in year by different rules"));
1.1216 + test(tim.WeekNoInYear(EFirstFullWeek)==46);
1.1217 + test(tim.WeekNoInYear(EFirstWeek)==47);
1.1218 + test(tim.WeekNoInYear(EFirstFourDayWeek)==46);
1.1219 +
1.1220 + dateTime.SetYear(1997);
1.1221 + dateTime.SetMonth(EJanuary);
1.1222 + dateTime.SetDay(6);
1.1223 + tim=dateTime;
1.1224 + test(tim.WeekNoInYear()==2);
1.1225 + test(tim.WeekNoInYear(EFirstFullWeek)==1);
1.1226 + test(tim.WeekNoInYear(EFirstWeek)==2);
1.1227 + test(tim.WeekNoInYear(EFirstFourDayWeek)==2);
1.1228 +
1.1229 +
1.1230 + dateTime.SetYear(1999);
1.1231 + tim=dateTime;
1.1232 + test(tim.WeekNoInYear()==1);
1.1233 + test(tim.WeekNoInYear(EFirstFullWeek)==1);
1.1234 + test(tim.WeekNoInYear(EFirstWeek)==2);
1.1235 + test(tim.WeekNoInYear(EFirstFourDayWeek)==1);
1.1236 +
1.1237 +// Year start dates different from jan 1st
1.1238 + dateTime.SetYear(1995);
1.1239 + dateTime.SetMonth(ENovember);
1.1240 + dateTime.SetDay(14);
1.1241 + TTime tim2(dateTime); // cTime
1.1242 + dateTime.SetMonth(EJune);
1.1243 + tim=dateTime; //dTime
1.1244 +
1.1245 + test(tim2.DayNoInYear(tim)==154);
1.1246 + test(tim2.WeekNoInYear(tim)==23);
1.1247 + test(tim2.WeekNoInYear(tim,EFirstFullWeek)==22);
1.1248 + test(tim.DayNoInYear(tim2)==213);
1.1249 + test(tim.WeekNoInYear(tim2)==31);
1.1250 + test(tim.WeekNoInYear(tim2,EFirstFullWeek)==30);
1.1251 +
1.1252 + dateTime.SetYear(1999);
1.1253 + dateTime.SetMonth(EJanuary);
1.1254 + dateTime.SetDay(6);
1.1255 + tim2=dateTime;
1.1256 + test(tim2.WeekNoInYear(tim,EFirstFullWeek)==30);
1.1257 + test(tim2.WeekNoInYear(tim,EFirstWeek)==30);
1.1258 + test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==30);
1.1259 +
1.1260 + dateTime.SetYear(1904);
1.1261 + dateTime.SetMonth(EFebruary);
1.1262 + dateTime.SetDay(28);
1.1263 + tim=dateTime;
1.1264 + dateTime.SetYear(1955);
1.1265 + dateTime.SetMonth(EJanuary);
1.1266 + tim2=dateTime;
1.1267 + test(tim2.WeekNoInYear(tim,EFirstFullWeek)==48);
1.1268 + test(tim2.WeekNoInYear(tim,EFirstWeek)==49);
1.1269 + test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==48);
1.1270 + dateTime.SetMonth(EMarch);
1.1271 + tim2=dateTime;
1.1272 + test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==5);
1.1273 + test(tim2.WeekNoInYear(tim,EFirstFullWeek)==5);
1.1274 + dateTime.SetYear(1994);
1.1275 + dateTime.SetMonth(EMarch);
1.1276 + dateTime.SetDay(0);
1.1277 + dateTime.SetHour(12);
1.1278 + tim2=dateTime;
1.1279 + test(tim2.WeekNoInYear(tim,EFirstFullWeek)==1);
1.1280 + test(tim2.WeekNoInYear(tim,EFirstWeek)==1);
1.1281 + test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==1);
1.1282 + dateTime.SetYear(1991);
1.1283 + dateTime.SetMonth(EMarch);
1.1284 + dateTime.SetDay(0);
1.1285 + dateTime.SetHour(12);
1.1286 + tim2=dateTime;
1.1287 + test(tim2.WeekNoInYear(tim,EFirstFullWeek)==52);
1.1288 + test(tim2.WeekNoInYear(tim,EFirstWeek)==1);
1.1289 + test(tim2.WeekNoInYear(tim,EFirstFourDayWeek)==1);
1.1290 + }
1.1291 +
1.1292 +
1.1293 +void TestTTime::Test9()
1.1294 +//
1.1295 +// string handling
1.1296 +//
1.1297 + {
1.1298 + TInt lyear =1993;
1.1299 + TInt lmonth =6;
1.1300 + TInt lday =3;
1.1301 + TInt lhour =13;
1.1302 + TInt lminute =53;
1.1303 + TInt lsecond =20;
1.1304 + TInt lmicroSecond =12345;
1.1305 + TDateTime aDate(lyear,TMonth(lmonth),lday,lhour,lminute,lsecond,lmicroSecond);
1.1306 + test.Next(_L("Different DateFormats"));
1.1307 + TTime aTime(aDate);
1.1308 + TBuf<0x80> testString;
1.1309 + TDateTime aDateTime=aTime.DateTime();
1.1310 + aDateTime.Month();
1.1311 + aTime.FormatL(testString,(_L("%E")));
1.1312 + if (testString.Compare(_L("Sunday")))
1.1313 + test.Panic(_L("%%E"));
1.1314 + aTime.FormatL(testString,(_L("%*E")));
1.1315 + if (testString.Compare(_L("Sun")))
1.1316 + test.Panic(_L("%%*E"));
1.1317 + TLocale local;
1.1318 + local.SetDateFormat(EDateEuropean);
1.1319 + local.Set();
1.1320 + aTime.FormatL(testString,(_L("%D%M%Y%/0%1%/1%2%/2%3%/3")));
1.1321 + if (testString.Compare(_L("04/07/1993")))
1.1322 + test.Panic(_L("%%D%%M%%Y"));
1.1323 + local.SetDateFormat(EDateAmerican);
1.1324 + local.Set();
1.1325 + aTime.FormatL(testString,(_L("%*D%X%N%Y%1 %2 '%*3")));
1.1326 + if (testString.Compare(_L("July 4th '93")))
1.1327 + test.Panic(_L("%%*D%%X%%N'%%*Y, American"));
1.1328 + local.SetDateFormat(EDateJapanese);
1.1329 + local.Set();
1.1330 + aTime.FormatL(testString,(_L("%*D%*N%4 %5")));
1.1331 + if (testString.Compare(_L("Jul 4")))
1.1332 + test.Panic(_L("%%*D%%*N, Japanese"));
1.1333 + aTime.FormatL(testString,(_L("%F%Y %D%X %N")));
1.1334 + if (testString.Compare(_L("1993 04th July")))
1.1335 + test.Panic(_L("%%F%%Y %%D%%X %%N"));
1.1336 + test.Next(_L("Times"));
1.1337 + aTime.FormatL(testString,(_L("%*I%:1%T%A")));
1.1338 + if (testString.Compare(_L("1:53 pm")))
1.1339 + test.Panic(_L("%%*I%%:1%%T%%A"));
1.1340 + local.SetAmPmSymbolPosition(ELocaleBefore);
1.1341 + local.Set();
1.1342 + aTime.FormatL(testString,(_L("%*I%:1%T%A")));
1.1343 + if (testString.Compare(_L("1:53pm ")))
1.1344 + test.Panic(_L("%%*I%%:1%%T%%A Bef"));
1.1345 + local.SetAmPmSpaceBetween(EFalse);
1.1346 + local.Set();
1.1347 + aTime.FormatL(testString,(_L("%*I%:1%T%A")));
1.1348 + if (testString.Compare(_L("1:53pm")))
1.1349 + test.Panic(_L("%%*I%%:1%%T%%A Bef NoSp"));
1.1350 + local.SetAmPmSymbolPosition(ELocaleAfter);
1.1351 + local.Set();
1.1352 + aTime.FormatL(testString,(_L("%*I%:1%T%A")));
1.1353 + if (testString.Compare(_L("1:53pm")))
1.1354 + test.Panic(_L("%%*I%%:1%%T%%A NoSp"));
1.1355 +
1.1356 + aTime.FormatL(testString,(_L("%-A%*I%:1%T%+A")));
1.1357 + if (testString.Compare(_L("1:53pm")))
1.1358 + test.Panic(_L("%%-A%%*I%%:1%%T%%+A NoSp"));
1.1359 + local.SetAmPmSymbolPosition(ELocaleBefore);
1.1360 + local.Set();
1.1361 + aTime.FormatL(testString,(_L("%-A%*I%:1%T%+A")));
1.1362 + if (testString.Compare(_L("pm1:53")))
1.1363 + test.Panic(_L("%%-A%%*I%%:1%%T%%+A Bef NoSp"));
1.1364 + local.SetAmPmSpaceBetween(ETrue);
1.1365 + local.Set();
1.1366 + aTime.FormatL(testString,(_L("%-A%*I%:1%T%+A")));
1.1367 + if (testString.Compare(_L("pm 1:53")))
1.1368 + test.Panic(_L("%%-A%%*I%%:1%%T%%+A Bef"));
1.1369 + local.SetAmPmSymbolPosition(ELocaleAfter);
1.1370 + local.Set();
1.1371 + aTime.FormatL(testString,(_L("%-A%*I%:1%T%+A")));
1.1372 + if (testString.Compare(_L("1:53 pm")))
1.1373 + test.Panic(_L("%%-A%%*I%%:1%%T%%+A"));
1.1374 +
1.1375 + aTime.FormatL(testString,(_L("%:0%H%:1%T%:2%S%.%C%:3")));
1.1376 + if (testString.Compare(_L("13:53:20.012345")))
1.1377 + test.Panic(_L("%%:0%%H%%:1%%T%%:2%%S%%.%%C%%:3 1"));
1.1378 + local.SetDecimalSeparator(',');
1.1379 + local.Set();
1.1380 + aTime.FormatL(testString,(_L("%:0%H%:1%T%:2%S%.%C%:3")));
1.1381 + if (testString.Compare(_L("13:53:20,012345")))
1.1382 + test.Panic(_L("%%:0%%H%%:1%%T%%:2%%S%%.%%C%%:3 2"));
1.1383 + local.SetDecimalSeparator('.');
1.1384 + local.Set();
1.1385 +
1.1386 + aTime.FormatL(testString,(_L("%T%:2%S%.%*C0")));
1.1387 + if (testString.Compare(_L("53:20.")))
1.1388 + test.Panic(_L("%%T%%:2%%S.%%*C0"));
1.1389 + aTime.FormatL(testString,(_L("%S%.%*C1")));
1.1390 + if (testString.Compare(_L("20.0")))
1.1391 + test.Panic(_L("%%S.%%*C1"));
1.1392 + aTime.FormatL(testString,(_L(".%*C3")));
1.1393 + if (testString.Compare(_L(".012")))
1.1394 + test.Panic(_L(".%%*C3"));
1.1395 + aTime.FormatL(testString,(_L("%*C6")));
1.1396 + if (testString.Compare(_L("012345")))
1.1397 + test.Panic(_L("%%*C6"));
1.1398 + aTime.FormatL(testString,(_L(".%*CZTest")));
1.1399 + if (testString.Compare(_L(".012345Test")))
1.1400 + test.Panic(_L("%%*C6"));
1.1401 + aTime.FormatL(testString,(_L("%J%:1%T%B")));
1.1402 + if (testString.Compare(_L("1:53 pm")))
1.1403 + test.Panic(_L("%%J%%:1%%T%%B"));
1.1404 + aTime.FormatL(testString,(_L("%J%:1%T%*B")));
1.1405 + if (testString.Compare(_L("1:53pm")))
1.1406 + test.Panic(_L("%%J%%:1%%T%%*B"));
1.1407 + local.SetTimeFormat(ETime24);
1.1408 + local.Set();
1.1409 + aTime.FormatL(testString,(_L("%J%:1%T%B")));
1.1410 + if (testString.Compare(_L("13:53")))
1.1411 + test.Panic(_L("%%J%%:1%%T%%B, ETime24"));
1.1412 + aTime.FormatL(testString,(_L("%J%:1%T%*B")));
1.1413 + if (testString.Compare(_L("13:53")))
1.1414 + test.Panic(_L("%%J%%:1%%T%%*B, ETime24"));
1.1415 + test.Next(_L("Miscellaneous"));
1.1416 + aTime.FormatL(testString,(_L("%W")));
1.1417 + if (testString.Compare(_L("26")))
1.1418 + test.Panic(_L("%%W"));
1.1419 + aTime.FormatL(testString,(_L("%*Z")));
1.1420 + if (testString.Compare(_L("185")))
1.1421 + test.Panic(_L("%%*Z"));
1.1422 + test.Next(_L("Junk strings"));
1.1423 + aTime.FormatL(testString,(_L("%F %M%O%N%D%A%Y")));
1.1424 + if (testString.Compare(_L(" 07OJuly04 pm1993")))
1.1425 + test.Panic(_L(" MONDAY"));
1.1426 + aTime.FormatL(testString,(_L("%*D%X %N '%*Y")));
1.1427 + if (testString.Compare(_L(" '")))
1.1428 + test.Panic(_L(" '"));
1.1429 + aTime.FormatL(testString,(_L("%G%K%L%O%P%Q%R%U%V%%")));
1.1430 + if (testString.Compare(_L("GKLOPQRUV%")))
1.1431 + test.Panic(_L("GKLOPQRUV%%"));
1.1432 + aDate.Set(1993,TMonth(6),3,0,0,0,0);
1.1433 + aTime=aDate;
1.1434 + aTime.FormatL(testString,(_L("%*I%:1%T%A")));
1.1435 + if (testString.Compare(_L("12:00 am")))
1.1436 + test.Panic(_L("testDate->time"));
1.1437 + aTime.FormatL(testString,(_L("%*I%:1%T%*A")));
1.1438 + if (testString.Compare(_L("12:00am")))
1.1439 + test.Panic(_L("testDate->time 2"));
1.1440 + aTime.FormatL(testString,(_L("unformatted string"))); // test added 25/08/95
1.1441 + if (testString.Compare(_L("unformatted string")))
1.1442 + test.Panic(_L("unformatted string"));
1.1443 + TBuf<8> buf;
1.1444 + TRAPD(r,aTime.FormatL(buf,_L("%F %M%O%N%D%A%Y")));
1.1445 + test(r==KErrOverflow);
1.1446 + TRAP(r,aTime.FormatL(buf,_L("qwertyuiop")));
1.1447 + test(r==KErrOverflow);
1.1448 + TRAP(r,aTime.FormatL(testString,_L("%:4")));
1.1449 + test(r==KErrGeneral);
1.1450 + TRAP(r,aTime.FormatL(testString,_L("%/4")));
1.1451 + test(r==KErrGeneral);
1.1452 + TRAP(r,aTime.FormatL(testString,_L("%:/")));
1.1453 + test(r==KErrGeneral);
1.1454 + TRAP(r,aTime.FormatL(testString,_L("%//")));
1.1455 + test(r==KErrGeneral);
1.1456 + TRAP(r,aTime.FormatL(testString,_L("%:z")));
1.1457 + test(r==KErrGeneral);
1.1458 + TRAP(r,aTime.FormatL(testString,_L("%/z")));
1.1459 + test(r==KErrGeneral);
1.1460 + TRAP(r,aTime.FormatL(testString,_L("%: ")));
1.1461 + test(r==KErrGeneral);
1.1462 + TRAP(r,aTime.FormatL(testString,_L("%/ ")));
1.1463 + test(r==KErrGeneral);
1.1464 + TRAP(r,aTime.FormatL(testString,_L("%- ")));
1.1465 + test(r==KErrGeneral);
1.1466 + TRAP(r,aTime.FormatL(testString,_L("%+ ")));
1.1467 + test(r==KErrGeneral);
1.1468 +
1.1469 + // HA - 258
1.1470 + aTime.Set(_L("19991231:000000.0000"));
1.1471 + local.SetTimeFormat(ETime24);
1.1472 + local.Set();
1.1473 + aTime.FormatL(testString, _L("%*J%BX"));
1.1474 + test(testString==_L("0X"));
1.1475 + local.SetTimeFormat(ETime12);
1.1476 + local.Set();
1.1477 + aTime.FormatL(testString, _L("%*J%BX"));
1.1478 + test(testString==_L("12 amX"));
1.1479 + aTime.FormatL(testString, _L("%IX"));
1.1480 + test(testString==_L("12X"));
1.1481 + aTime.FormatL(testString, _L("%HX"));
1.1482 + test(testString==_L("00X"));
1.1483 +
1.1484 + //Reset so it can be run twice
1.1485 + local.SetDateFormat(EDateEuropean);
1.1486 + local.SetTimeFormat(ETime12);
1.1487 + local.Set();
1.1488 +
1.1489 + // Test for overload of TTime::FormatL(TDes& aDes,const TDesC& aFormat,const TLocale& aLocale);
1.1490 + // Reset Time and dates
1.1491 + aDate.Set(lyear,TMonth(lmonth),lday,lhour,lminute,lsecond,lmicroSecond);
1.1492 + test.Next(_L("Different DateFormats with specified locale"));
1.1493 + TTime aTimeLocale(aDate);
1.1494 +
1.1495 + local.SetDateFormat(EDateAmerican);
1.1496 + aTimeLocale.FormatL(testString,(_L("%*D%X%N%Y%1 %2 '%*3")),local);
1.1497 + if (testString.Compare(_L("July 4th '93")))
1.1498 + test.Panic(_L("%%*D%%X%%N'%%*Y, American"));
1.1499 + local.SetDateFormat(EDateJapanese);
1.1500 + aTimeLocale.FormatL(testString,(_L("%*D%*N%4 %5")),local);
1.1501 + if (testString.Compare(_L("Jul 4")))
1.1502 + test.Panic(_L("%%*D%%*N, Japanese"));
1.1503 + aTimeLocale.FormatL(testString,(_L("%F%Y %D%X %N")),local);
1.1504 + if (testString.Compare(_L("1993 04th July")))
1.1505 + test.Panic(_L("%%F%%Y %%D%%X %%N"));
1.1506 +
1.1507 + test.Next(_L("Times with specified locale"));
1.1508 + aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local);
1.1509 + if (testString.Compare(_L("1:53 pm")))
1.1510 + test.Panic(_L("%%*I%%:1%%T%%A"));
1.1511 + local.SetAmPmSymbolPosition(ELocaleBefore);
1.1512 + aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local);
1.1513 + if (testString.Compare(_L("1:53pm ")))
1.1514 + test.Panic(_L("%%*I%%:1%%T%%A Bef"));
1.1515 + local.SetAmPmSpaceBetween(EFalse);
1.1516 + aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local);
1.1517 + if (testString.Compare(_L("1:53pm")))
1.1518 + test.Panic(_L("%%*I%%:1%%T%%A Bef NoSp"));
1.1519 + local.SetAmPmSymbolPosition(ELocaleAfter);
1.1520 + aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local);
1.1521 + if (testString.Compare(_L("1:53pm")))
1.1522 + test.Panic(_L("%%*I%%:1%%T%%A NoSp"));
1.1523 + aTimeLocale.FormatL(testString,(_L("%-A%*I%:1%T%+A")),local);
1.1524 + if (testString.Compare(_L("1:53pm")))
1.1525 + test.Panic(_L("%%-A%%*I%%:1%%T%%+A NoSp"));
1.1526 + local.SetAmPmSymbolPosition(ELocaleBefore);
1.1527 + aTimeLocale.FormatL(testString,(_L("%-A%*I%:1%T%+A")),local);
1.1528 + if (testString.Compare(_L("pm1:53")))
1.1529 + test.Panic(_L("%%-A%%*I%%:1%%T%%+A Bef NoSp"));
1.1530 + local.SetAmPmSpaceBetween(ETrue);
1.1531 + aTimeLocale.FormatL(testString,(_L("%-A%*I%:1%T%+A")),local);
1.1532 + if (testString.Compare(_L("pm 1:53")))
1.1533 + test.Panic(_L("%%-A%%*I%%:1%%T%%+A Bef"));
1.1534 + local.SetAmPmSymbolPosition(ELocaleAfter);
1.1535 + aTimeLocale.FormatL(testString,(_L("%-A%*I%:1%T%+A")),local);
1.1536 + if (testString.Compare(_L("1:53 pm")))
1.1537 + test.Panic(_L("%%-A%%*I%%:1%%T%%+A"));
1.1538 + aTimeLocale.FormatL(testString,(_L("%:0%H%:1%T%:2%S%.%C%:3")),local);
1.1539 + if (testString.Compare(_L("13:53:20.012345")))
1.1540 + test.Panic(_L("%%:0%%H%%:1%%T%%:2%%S%%.%%C%%:3 1"));
1.1541 + local.SetDecimalSeparator(',');
1.1542 + aTimeLocale.FormatL(testString,(_L("%:0%H%:1%T%:2%S%.%C%:3")),local);
1.1543 + if (testString.Compare(_L("13:53:20,012345")))
1.1544 + test.Panic(_L("%%:0%%H%%:1%%T%%:2%%S%%.%%C%%:3 2"));
1.1545 + local.SetDecimalSeparator('.');
1.1546 + aTimeLocale.FormatL(testString,(_L("%T%:2%S%.%*C0")),local);
1.1547 + if (testString.Compare(_L("53:20.")))
1.1548 + test.Panic(_L("%%T%%:2%%S.%%*C0"));
1.1549 + aTimeLocale.FormatL(testString,(_L("%S%.%*C1")),local);
1.1550 + if (testString.Compare(_L("20.0")))
1.1551 + test.Panic(_L("%%S.%%*C1"));
1.1552 + aTimeLocale.FormatL(testString,(_L(".%*C3")),local);
1.1553 + if (testString.Compare(_L(".012")))
1.1554 + test.Panic(_L(".%%*C3"));
1.1555 + aTimeLocale.FormatL(testString,(_L("%*C6")),local);
1.1556 + if (testString.Compare(_L("012345")))
1.1557 + test.Panic(_L("%%*C6"));
1.1558 + aTimeLocale.FormatL(testString,(_L(".%*CZTest")),local);
1.1559 + if (testString.Compare(_L(".012345Test")))
1.1560 + test.Panic(_L("%%*C6"));
1.1561 + aTimeLocale.FormatL(testString,(_L("%J%:1%T%B")),local);
1.1562 + if (testString.Compare(_L("1:53 pm")))
1.1563 + test.Panic(_L("%%J%%:1%%T%%B"));
1.1564 + aTimeLocale.FormatL(testString,(_L("%J%:1%T%*B")),local);
1.1565 + if (testString.Compare(_L("1:53pm")))
1.1566 + test.Panic(_L("%%J%%:1%%T%%*B"));
1.1567 + local.SetTimeFormat(ETime24);
1.1568 + aTimeLocale.FormatL(testString,(_L("%J%:1%T%B")),local);
1.1569 + if (testString.Compare(_L("13:53")))
1.1570 + test.Panic(_L("%%J%%:1%%T%%B, ETime24"));
1.1571 + aTimeLocale.FormatL(testString,(_L("%J%:1%T%*B")),local);
1.1572 + if (testString.Compare(_L("13:53")))
1.1573 + test.Panic(_L("%%J%%:1%%T%%*B, ETime24"));
1.1574 +
1.1575 + test.Next(_L("Miscellaneous with specified locale"));
1.1576 + aTimeLocale.FormatL(testString,(_L("%W")),local);
1.1577 + if (testString.Compare(_L("26")))
1.1578 + test.Panic(_L("%%W"));
1.1579 + aTimeLocale.FormatL(testString,(_L("%*Z")),local);
1.1580 + if (testString.Compare(_L("185")))
1.1581 + test.Panic(_L("%%*Z"));
1.1582 +
1.1583 + test.Next(_L("Junk strings with specified locale"));
1.1584 + aTimeLocale.FormatL(testString,(_L("%F %M%O%N%D%A%Y")),local);
1.1585 + if (testString.Compare(_L(" 07OJuly04 pm1993")))
1.1586 + test.Panic(_L(" MONDAY"));
1.1587 + aTimeLocale.FormatL(testString,(_L("%*D%X %N '%*Y")),local);
1.1588 + if (testString.Compare(_L(" '")))
1.1589 + test.Panic(_L(" '"));
1.1590 + aTimeLocale.FormatL(testString,(_L("%G%K%L%O%P%Q%R%U%V%%")),local);
1.1591 + if (testString.Compare(_L("GKLOPQRUV%")))
1.1592 + test.Panic(_L("GKLOPQRUV%%"));
1.1593 + aDate.Set(1993,TMonth(6),3,0,0,0,0);
1.1594 + aTimeLocale=aDate;
1.1595 + aTimeLocale.FormatL(testString,(_L("%*I%:1%T%A")),local);
1.1596 + if (testString.Compare(_L("12:00 am")))
1.1597 + test.Panic(_L("testDate->time"));
1.1598 + aTimeLocale.FormatL(testString,(_L("%*I%:1%T%*A")),local);
1.1599 + if (testString.Compare(_L("12:00am")))
1.1600 + test.Panic(_L("testDate->time 2"));
1.1601 + aTimeLocale.FormatL(testString,(_L("unformatted string")),local); // test added 25/08/95
1.1602 + if (testString.Compare(_L("unformatted string")))
1.1603 + test.Panic(_L("unformatted string"));
1.1604 + TRAP(r,aTimeLocale.FormatL(buf,_L("%F %M%O%N%D%A%Y"),local));
1.1605 + test(r==KErrOverflow);
1.1606 + TRAP(r,aTimeLocale.FormatL(buf,_L("qwertyuiop"),local));
1.1607 + test(r==KErrOverflow);
1.1608 + TRAP(r,aTimeLocale.FormatL(testString,_L("%:4"),local));
1.1609 + test(r==KErrGeneral);
1.1610 + TRAP(r,aTimeLocale.FormatL(testString,_L("%/4"),local));
1.1611 + test(r==KErrGeneral);
1.1612 + TRAP(r,aTimeLocale.FormatL(testString,_L("%:/"),local));
1.1613 + test(r==KErrGeneral);
1.1614 + TRAP(r,aTimeLocale.FormatL(testString,_L("%//"),local));
1.1615 + test(r==KErrGeneral);
1.1616 + TRAP(r,aTimeLocale.FormatL(testString,_L("%:z"),local));
1.1617 + test(r==KErrGeneral);
1.1618 + TRAP(r,aTimeLocale.FormatL(testString,_L("%/z"),local));
1.1619 + test(r==KErrGeneral);
1.1620 + TRAP(r,aTimeLocale.FormatL(testString,_L("%: "),local));
1.1621 + test(r==KErrGeneral);
1.1622 + TRAP(r,aTimeLocale.FormatL(testString,_L("%/ "),local));
1.1623 + test(r==KErrGeneral);
1.1624 + TRAP(r,aTimeLocale.FormatL(testString,_L("%- "),local));
1.1625 + test(r==KErrGeneral);
1.1626 + TRAP(r,aTimeLocale.FormatL(testString,_L("%+ "),local));
1.1627 + test(r==KErrGeneral);
1.1628 + aTimeLocale.Set(_L("19991231:000000.0000"));
1.1629 + local.SetTimeFormat(ETime24);
1.1630 + aTimeLocale.FormatL(testString, _L("%*J%BX"),local);
1.1631 + test(testString==_L("0X"));
1.1632 + local.SetTimeFormat(ETime12);
1.1633 + aTimeLocale.FormatL(testString, _L("%*J%BX"),local);
1.1634 + test(testString==_L("12 amX"));
1.1635 + aTimeLocale.FormatL(testString, _L("%IX"),local);
1.1636 + test(testString==_L("12X"));
1.1637 + aTimeLocale.FormatL(testString, _L("%HX"),local);
1.1638 + test(testString==_L("00X"));
1.1639 + }
1.1640 +
1.1641 +
1.1642 +void TestTTime::Test10()
1.1643 +//
1.1644 +// The Time functions that aren't called/tested above.
1.1645 +//
1.1646 + {
1.1647 + test.Next(_L("IsLeapYear()"));
1.1648 + TDateTime date;
1.1649 + date.Set(1200,EFebruary,28,13,58,59,245322);
1.1650 + test(date.SetYear(1980)==KErrNone);
1.1651 + TBool isLeap = Time::IsLeapYear(1580);
1.1652 + TInt noUpTo = Time::LeapYearsUpTo(1580);
1.1653 + test(isLeap==1);
1.1654 + test(noUpTo==395);
1.1655 + isLeap = Time::IsLeapYear(1750);
1.1656 + noUpTo = Time::LeapYearsUpTo(1750);
1.1657 + test(isLeap==0);
1.1658 + test(noUpTo==437);
1.1659 + isLeap = Time::IsLeapYear(1980);
1.1660 + noUpTo = Time::LeapYearsUpTo(1980);
1.1661 + test(isLeap==1);
1.1662 + test(noUpTo==492);
1.1663 + isLeap = Time::IsLeapYear(2000);
1.1664 + noUpTo = Time::LeapYearsUpTo(2000);
1.1665 + test(isLeap==1);
1.1666 + test(noUpTo==497);
1.1667 + isLeap = Time::IsLeapYear(25000);
1.1668 + noUpTo = Time::LeapYearsUpTo(25000);
1.1669 + test(isLeap==0);
1.1670 + test(noUpTo==6075);
1.1671 +
1.1672 + test.Next(_L("TTime::RoundUpToNextMinute()"));
1.1673 + TTime time;
1.1674 + time.RoundUpToNextMinute();
1.1675 + TDateTime dateTime=time.DateTime();
1.1676 + test(dateTime.MicroSecond()==0);
1.1677 + test(dateTime.Second()==0);
1.1678 +
1.1679 + TDateTime dateTime2(2004,EFebruary,28,12,48,59,999999);
1.1680 + time=dateTime2;
1.1681 + time.RoundUpToNextMinute();
1.1682 + dateTime=time.DateTime();
1.1683 + test(dateTime.MicroSecond()==0);
1.1684 + test(dateTime.Second()==0);
1.1685 + test(dateTime.Minute()==dateTime2.Minute()+1);
1.1686 + test(dateTime.Hour()==dateTime2.Hour());
1.1687 + test(dateTime.Day()==dateTime2.Day());
1.1688 + test(dateTime.Month()==dateTime2.Month());
1.1689 + test(dateTime.Year()==dateTime2.Year());
1.1690 +
1.1691 + dateTime2.Set(2004,EFebruary,28,12,48,0,0);
1.1692 + time=dateTime2;
1.1693 + time.RoundUpToNextMinute();
1.1694 + dateTime=time.DateTime();
1.1695 + test(dateTime.MicroSecond()==0);
1.1696 + test(dateTime.Second()==0);
1.1697 + test(dateTime.MicroSecond()==dateTime2.MicroSecond());
1.1698 + test(dateTime.Second()==dateTime2.Second());
1.1699 + test(dateTime.Minute()==dateTime2.Minute());
1.1700 + test(dateTime.Hour()==dateTime2.Hour());
1.1701 + test(dateTime.Day()==dateTime2.Day());
1.1702 + test(dateTime.Month()==dateTime2.Month());
1.1703 + test(dateTime.Year()==dateTime2.Year());
1.1704 +
1.1705 + dateTime2.Set(2004,EFebruary,28,12,48,0,1);
1.1706 + time=dateTime2;
1.1707 + time.RoundUpToNextMinute();
1.1708 + dateTime=time.DateTime();
1.1709 + test(dateTime.MicroSecond()==0);
1.1710 + test(dateTime.Second()==0);
1.1711 + test(dateTime.Minute()==dateTime2.Minute()+1);
1.1712 + test(dateTime.Hour()==dateTime2.Hour());
1.1713 + test(dateTime.Day()==dateTime2.Day());
1.1714 + test(dateTime.Month()==dateTime2.Month());
1.1715 + test(dateTime.Year()==dateTime2.Year());
1.1716 +
1.1717 + dateTime2.Set(2037,EDecember,30,23,59,1,45341);
1.1718 + time=dateTime2;
1.1719 + time.RoundUpToNextMinute();
1.1720 + dateTime=time.DateTime();
1.1721 + test(dateTime.MicroSecond()==0);
1.1722 + test(dateTime.Second()==0);
1.1723 + test(dateTime.Minute()==0);
1.1724 + test(dateTime.Hour()==0);
1.1725 + test(dateTime.Day()==0);
1.1726 + test(dateTime.Month()==EJanuary);
1.1727 + test(dateTime.Year()==dateTime2.Year()+1);
1.1728 +
1.1729 + test.Next(_L("HomeTime and UniversalTime"));
1.1730 + time.HomeTime();
1.1731 + dateTime=time.DateTime();
1.1732 + 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());
1.1733 + time.UniversalTime();
1.1734 + dateTime=time.DateTime();
1.1735 + 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());
1.1736 +
1.1737 + test.Next(_L("SetUTCTime"));
1.1738 + time.UniversalTime();
1.1739 + time+=TTimeIntervalMinutes(30);
1.1740 + TInt r=User::SetUTCTime(time);
1.1741 + test(r==KErrNone);
1.1742 + time.HomeTime();
1.1743 + dateTime=time.DateTime();
1.1744 + 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());
1.1745 + time.UniversalTime();
1.1746 + dateTime=time.DateTime();
1.1747 + 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());
1.1748 +
1.1749 + r=User::SetUTCTime(TTime(TDateTime(2090,EJanuary,0,0,0,0,0)));
1.1750 +//#if defined (__MARM__)
1.1751 + test(r==KErrOverflow);
1.1752 +//#else
1.1753 +// test(r==KErrNone);
1.1754 +// time.HomeTime();
1.1755 +// test(time.DateTime().Second()==0);
1.1756 +// test(time.DateTime().Minute()==0);
1.1757 +// test(time.DateTime().Day()==0);
1.1758 +// test(time.DateTime().Month()==EJanuary);
1.1759 +// test(time.DateTime().Year()==2090);
1.1760 +// test(time.DateTime().Hour()==0);
1.1761 +//#endif
1.1762 +
1.1763 + time.UniversalTime();
1.1764 + time-=TTimeIntervalMinutes(30);
1.1765 + r=User::SetUTCTime(time);
1.1766 + test(r==KErrNone);
1.1767 + time.HomeTime();
1.1768 + dateTime=time.DateTime();
1.1769 + 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());
1.1770 + time.UniversalTime();
1.1771 + dateTime=time.DateTime();
1.1772 + 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());
1.1773 + test.Printf(_L("does this come out"));
1.1774 + }
1.1775 +
1.1776 +void TestTTime::Test11()
1.1777 +//
1.1778 +//
1.1779 +//
1.1780 + {
1.1781 + TTime now;
1.1782 + now.UniversalTime();
1.1783 + TTimeIntervalSeconds offset;
1.1784 + offset = User::UTCOffset();
1.1785 + RTimer timer[5];
1.1786 + TRequestStatus stat[5];
1.1787 +
1.1788 + test.Start(_L("Create timers"));
1.1789 + TInt i;
1.1790 + for (i=0; i<5; i++)
1.1791 + test(timer[i].CreateLocal()==KErrNone);
1.1792 +
1.1793 + test.Next(_L("Change the time"));
1.1794 + TInt r=User::SetUTCTime(now-TTimeIntervalMinutes(120));
1.1795 + test_Equal(r, KErrNone);
1.1796 +
1.1797 + test.Next(_L("Start an absolute timer"));
1.1798 + timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(60));
1.1799 + test.Next(_L("Change the system time"));
1.1800 + r=User::SetUTCTime(now-TTimeIntervalMinutes(120));
1.1801 + test(r==KErrNone);
1.1802 + User::WaitForRequest(stat[0]);
1.1803 + test.Next(_L("Test timer aborted"));
1.1804 + test(stat[0]==KErrAbort);
1.1805 +
1.1806 + test.Next(_L("Set UTC offset to zero"));
1.1807 + User::SetUTCOffset(0);
1.1808 + test.Next(_L("Start an absolute timer"));
1.1809 + timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(120));
1.1810 + test.Next(_L("Change the UTC offset to +1 hour"));
1.1811 + User::SetUTCOffset(3600);
1.1812 + User::WaitForRequest(stat[0]);
1.1813 + test.Next(_L("Test timer aborted"));
1.1814 + test(stat[0]==KErrAbort);
1.1815 + test.Next(_L("Start another absolute timer"));
1.1816 + timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(120));
1.1817 + test.Next(_L("Re-set the UTC offset to +1 hour"));
1.1818 + User::SetUTCOffset(3600);
1.1819 + test.Next(_L("Test timer NOT aborted (no actual time change)"));
1.1820 + test(stat[0]==KRequestPending);
1.1821 + test.Next(_L("Cancel timer"));
1.1822 + timer[0].Cancel();
1.1823 + User::WaitForRequest(stat[0]);
1.1824 + test(stat[0]==KErrCancel);
1.1825 +
1.1826 +/*
1.1827 +// This code fails intermitantly
1.1828 + FOREVER
1.1829 + {
1.1830 + timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(60));
1.1831 + test(stat[0]==KRequestPending);
1.1832 + timer[1].AtUTC(stat[1], now+TTimeIntervalMinutes(30));
1.1833 + test(stat[1]==KRequestPending);
1.1834 + test.Next(_L("ABCDEFGHIJKLMNOPQRS D FD FDDFGDF ABCDEFGHIJ ABCDEFGHIJKGL"));
1.1835 + timer[1].Cancel();
1.1836 + timer[0].Cancel();
1.1837 + User::WaitForRequest(stat[0]);
1.1838 + User::WaitForRequest(stat[1]);
1.1839 + test.Next(_L("ABCDEFGH"));
1.1840 + test(stat[0]==KErrCancel);
1.1841 + test(stat[1]==KErrCancel);
1.1842 + }
1.1843 +*/
1.1844 +
1.1845 + test.Next(_L("Start 3 absolute timers and a relative timer"));
1.1846 + timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(60));
1.1847 + test_Equal(KRequestPending, stat[0].Int());
1.1848 + timer[1].AtUTC(stat[1], now+TTimeIntervalMinutes(30));
1.1849 + test_Equal(KRequestPending, stat[1].Int());
1.1850 + timer[2].After(stat[2], 9000000);
1.1851 + test_Equal(KRequestPending, stat[2].Int());
1.1852 + timer[3].AtUTC(stat[3], now+TTimeIntervalMinutes(10));
1.1853 + test_Equal(KRequestPending, stat[3].Int());
1.1854 + TInt s=stat[2].Int();
1.1855 + test.Next(_L("Change system time"));
1.1856 + r=User::SetUTCTime(now-TTimeIntervalMinutes(100));
1.1857 + test(r==KErrNone);
1.1858 + User::WaitForRequest(stat[0]);
1.1859 + User::WaitForRequest(stat[1]);
1.1860 + User::WaitForRequest(stat[3]);
1.1861 + test.Next(_L("Test absolute timers aborted"));
1.1862 + test(stat[0]==KErrAbort);
1.1863 + test(stat[1]==KErrAbort);
1.1864 + test(stat[3]==KErrAbort);
1.1865 + test(stat[2]==s);
1.1866 + test.Next(_L("Cancel relative timer"));
1.1867 + timer[2].Cancel();
1.1868 + User::WaitForRequest(stat[2]);
1.1869 + test(stat[2]==KErrCancel);
1.1870 +
1.1871 + test.Next(_L("Start 3 relative timers and 1 absolute timer"));
1.1872 + timer[0].After(stat[0], 10000);
1.1873 + timer[1].After(stat[1], 20000);
1.1874 + timer[2].After(stat[2], 20100);
1.1875 + timer[3].AtUTC(stat[3], now+TTimeIntervalMinutes(10));
1.1876 + test.Next(_L("Wait for 1 relative timer to complete"));
1.1877 + User::WaitForRequest(stat[0]);
1.1878 + test(stat[0]==KErrNone);
1.1879 + test.Next(_L("Change the time"));
1.1880 + r=User::SetUTCTime(now-TTimeIntervalMinutes(100));
1.1881 + test(r==KErrNone);
1.1882 + User::WaitForRequest(stat[3]);
1.1883 + test(stat[3]==KErrAbort);
1.1884 + stat[3]=-999;
1.1885 + test.Next(_L("Change the time again"));
1.1886 + r=User::SetUTCTime(now-TTimeIntervalMinutes(110));
1.1887 + test(r==KErrNone);
1.1888 + test.Next(_L("Wait for other relative timers to complete"));
1.1889 + User::WaitForRequest(stat[1]);
1.1890 + User::WaitForRequest(stat[2]);
1.1891 + test(stat[1]==KErrNone);
1.1892 + test(stat[2]==KErrNone);
1.1893 + test(stat[3]==-999);
1.1894 +
1.1895 + test.Next(_L("Start 2 absolute timers"));
1.1896 + timer[0].AtUTC(stat[0], now+TTimeIntervalMinutes(60));
1.1897 + timer[1].AtUTC(stat[1], now+TTimeIntervalMinutes(30));
1.1898 + test.Next(_L("Cancel one"));
1.1899 + timer[0].Cancel();
1.1900 + User::WaitForRequest(stat[0]);
1.1901 + test(stat[0]==KErrCancel);
1.1902 + test.Next(_L("Change the time"));
1.1903 + r=User::SetUTCTime(now-TTimeIntervalMinutes(110));
1.1904 + test(r==KErrNone);
1.1905 + User::WaitForRequest(stat[1]);
1.1906 + test(stat[1]==KErrAbort);
1.1907 + test(stat[0]==KErrCancel);
1.1908 +
1.1909 + // The platform may or may not support SecureTime, and even if it does,
1.1910 + // it may not have a secure time set. So we start this test by making
1.1911 + // sure that the NonSecureOffset is set (which may fail, if it's not
1.1912 + // supported OR if it's already set); then read and write the secure
1.1913 + // time, to make sure that it's supported and we have permission.
1.1914 + User::SetUTCTime(now);
1.1915 + HAL::Set(HAL::ETimeNonSecureOffset, 0);
1.1916 + test.Next(_L("Test absolute timers with secure time change"));
1.1917 + TTime securetime;
1.1918 + if ((r = securetime.UniversalTimeSecure()) == KErrNone)
1.1919 + r = User::SetUTCTimeSecure(securetime);
1.1920 + if (r != KErrNone)
1.1921 + {
1.1922 + RDebug::Printf("WARNING: Secure clock change test skipped because secure time could not be changed!");
1.1923 + }
1.1924 + else
1.1925 + {
1.1926 + timer[0].AtUTC(stat[0], now+TTimeIntervalSeconds(5));
1.1927 + r = User::SetUTCTimeSecure(securetime+TTimeIntervalSeconds(30));
1.1928 + test_Equal(KErrNone, r);
1.1929 + r = User::SetUTCTimeSecure(securetime-TTimeIntervalSeconds(30));
1.1930 + test_Equal(KErrNone, r);
1.1931 + // The absolute timer should not have been aborted by the secure time change,
1.1932 + test_Equal(KRequestPending, stat[0].Int());
1.1933 +
1.1934 + // The outstanding absolute timer should complete before this new relative timer
1.1935 + timer[1].After(stat[1], 20000000);
1.1936 + User::WaitForRequest(stat[0], stat[1]);
1.1937 + timer[1].Cancel();
1.1938 + test_Equal(KErrNone, stat[0].Int());
1.1939 + test_Equal(KErrCancel, stat[1].Int());
1.1940 + User::SetUTCTimeSecure(securetime+TTimeIntervalSeconds(5));
1.1941 + }
1.1942 +
1.1943 + test.Next(_L("Close the timers"));
1.1944 + for (i=0; i<5; i++)
1.1945 + timer[i].Close();
1.1946 +
1.1947 + r=User::SetUTCTimeAndOffset(now,offset);
1.1948 + test(r==KErrNone);
1.1949 + test.End();
1.1950 + }
1.1951 +
1.1952 +void TestTTime::Test12()
1.1953 + {
1.1954 +
1.1955 + TInt err;
1.1956 + TDateTime dateTime;
1.1957 + test.Start(_L("Setting date using YYYYMMDD:HHMMSS.MMMMMM"));
1.1958 + TTime now(_L("19960201:122341.1234"));
1.1959 + dateTime=now.DateTime();
1.1960 + test(dateTime.MicroSecond()==1234);
1.1961 + test(dateTime.Second()==41);
1.1962 + test(dateTime.Minute()==23);
1.1963 + test(dateTime.Hour()==12);
1.1964 + test(dateTime.Day()==1);
1.1965 + test(dateTime.Month()==2);
1.1966 + test(dateTime.Year()==1996);
1.1967 + test.Next(_L("Setting date using YYYYMMDD:"));
1.1968 + err=now.Set(_L("19901129:")); // Just set the date
1.1969 + dateTime=now.DateTime();
1.1970 + test(err==KErrNone);
1.1971 + test(dateTime.MicroSecond()==0);
1.1972 + test(dateTime.Second()==0);
1.1973 + test(dateTime.Minute()==0);
1.1974 + test(dateTime.Hour()==0);
1.1975 + test(dateTime.Day()==29);
1.1976 + test(dateTime.Month()==11);
1.1977 + test(dateTime.Year()==1990);
1.1978 + test.Next(_L("Setting date using :HHMMSS."));
1.1979 + err=now.Set(_L(":105614.")); // Just the time
1.1980 + dateTime=now.DateTime();
1.1981 + test(err==KErrNone);
1.1982 + test(dateTime.MicroSecond()==0);
1.1983 + test(dateTime.Second()==14);
1.1984 + test(dateTime.Minute()==56);
1.1985 + test(dateTime.Hour()==10);
1.1986 + test(dateTime.Day()==0);
1.1987 + test(dateTime.Month()==0);
1.1988 + test(dateTime.Year()==0);
1.1989 + test.Next(_L("Setting date using .MMMMMM"));
1.1990 + err=now.Set(_L(".999999")); // Just the microseconds
1.1991 + dateTime=now.DateTime();
1.1992 + test(err==KErrNone);
1.1993 + test(dateTime.MicroSecond()==999999);
1.1994 + test(dateTime.Second()==0);
1.1995 + test(dateTime.Minute()==0);
1.1996 + test(dateTime.Hour()==0);
1.1997 + test(dateTime.Day()==0);
1.1998 + test(dateTime.Month()==0);
1.1999 + test(dateTime.Year()==0);
1.2000 + test.Next(_L("Setting date using HHMMSS should fail"));
1.2001 + err=now.Set(_L("104520")); // Invalid - no separator
1.2002 + dateTime=now.DateTime();
1.2003 + test(err==KErrGeneral);
1.2004 + test(dateTime.MicroSecond()==999999);
1.2005 + test(dateTime.Second()==0);
1.2006 + test(dateTime.Minute()==0);
1.2007 + test(dateTime.Hour()==0);
1.2008 + test(dateTime.Day()==0);
1.2009 + test(dateTime.Month()==0);
1.2010 + test(dateTime.Year()==0);
1.2011 + test.Next(_L("Setting date using :HHMMSS"));
1.2012 + err=now.Set(_L(":054531")); // Set time with no dot
1.2013 + dateTime=now.DateTime();
1.2014 + test(err==KErrNone);
1.2015 + test(dateTime.MicroSecond()==0);
1.2016 + test(dateTime.Second()==31);
1.2017 + test(dateTime.Minute()==45);
1.2018 + test(dateTime.Hour()==5);
1.2019 + test(dateTime.Day()==0);
1.2020 + test(dateTime.Month()==0);
1.2021 + test(dateTime.Year()==0);
1.2022 + test.Next(_L("Setting invalid date using YYYYMMSS:HHMMSS.MMMM"));
1.2023 + err=now.Set(_L("19910130:023210.1234")); // invalid date
1.2024 + dateTime=now.DateTime();
1.2025 + test(err==KErrGeneral);
1.2026 + test(dateTime.MicroSecond()==0);
1.2027 + test(dateTime.Second()==31);
1.2028 + test(dateTime.Minute()==45);
1.2029 + test(dateTime.Hour()==5);
1.2030 + test(dateTime.Day()==0);
1.2031 + test(dateTime.Month()==0);
1.2032 + test(dateTime.Year()==0);
1.2033 + test.Next(_L("Setting date using YYYYMMDD:.MMMM"));
1.2034 + err=now.Set(_L("19960730:.123456")); // Set date and microseconds
1.2035 + dateTime=now.DateTime();
1.2036 + test(err==KErrNone);
1.2037 + test(dateTime.MicroSecond()==123456);
1.2038 + test(dateTime.Second()==0);
1.2039 + test(dateTime.Minute()==0);
1.2040 + test(dateTime.Hour()==0);
1.2041 + test(dateTime.Day()==30);
1.2042 + test(dateTime.Month()==7);
1.2043 + test(dateTime.Year()==1996);
1.2044 + test.Next(_L("Setting date using ."));
1.2045 + err=now.Set(_L("."));
1.2046 + dateTime=now.DateTime();
1.2047 + test(err==KErrNone);
1.2048 + test(dateTime.MicroSecond()==0);
1.2049 + test(dateTime.Second()==0);
1.2050 + test(dateTime.Minute()==0);
1.2051 + test(dateTime.Hour()==0);
1.2052 + test(dateTime.Day()==0);
1.2053 + test(dateTime.Month()==0);
1.2054 + test(dateTime.Year()==0);
1.2055 + test.Next(_L("Setting date using :."));
1.2056 + err=now.Set(_L(":."));
1.2057 + dateTime=now.DateTime();
1.2058 + test(err==KErrNone);
1.2059 + test(dateTime.MicroSecond()==0);
1.2060 + test(dateTime.Second()==0);
1.2061 + test(dateTime.Minute()==0);
1.2062 + test(dateTime.Hour()==0);
1.2063 + test(dateTime.Day()==0);
1.2064 + test(dateTime.Month()==0);
1.2065 + test(dateTime.Year()==0);
1.2066 + test.Next(_L("Setting date using :"));
1.2067 + err=now.Set(_L(":"));
1.2068 + dateTime=now.DateTime();
1.2069 + test(err==KErrNone);
1.2070 + test(dateTime.MicroSecond()==0);
1.2071 + test(dateTime.Second()==0);
1.2072 + test(dateTime.Minute()==0);
1.2073 + test(dateTime.Hour()==0);
1.2074 + test(dateTime.Day()==0);
1.2075 + test(dateTime.Month()==0);
1.2076 + test(dateTime.Year()==0);
1.2077 + test.Next(_L("Setting date using YYYYMMDD.HHMMSS:MMMM should fail"));
1.2078 + err=now.Set(_L("19900101.105630:1234")); // Wrong way round
1.2079 + dateTime=now.DateTime();
1.2080 + test(err==KErrGeneral);
1.2081 + test(dateTime.MicroSecond()==0);
1.2082 + test(dateTime.Second()==0);
1.2083 + test(dateTime.Minute()==0);
1.2084 + test(dateTime.Hour()==0);
1.2085 + test(dateTime.Day()==0);
1.2086 + test(dateTime.Month()==0);
1.2087 + test(dateTime.Year()==0);
1.2088 + test.Next(_L("Setting date using YYYYMMDD:HHMMSS.MMMMMMM should fail"));
1.2089 + err=now.Set(_L("19900101:105630.1234567")); // Microseconds too long
1.2090 + dateTime=now.DateTime();
1.2091 + test(err==KErrGeneral);
1.2092 + test(dateTime.MicroSecond()==0);
1.2093 + test(dateTime.Second()==0);
1.2094 + test(dateTime.Minute()==0);
1.2095 + test(dateTime.Hour()==0);
1.2096 + test(dateTime.Day()==0);
1.2097 + test(dateTime.Month()==0);
1.2098 + test(dateTime.Year()==0);
1.2099 + test.End();
1.2100 + }
1.2101 +
1.2102 +struct TestInfo
1.2103 + {
1.2104 + TestInfo (TTime aTime,TInt aMicroSec,TInt aSec,TInt aMin,TInt aHour,TInt aDay,TInt aMonth,TInt aYear,TText* aDayString,TTime aNextMin)
1.2105 + {
1.2106 + iTime=aTime;
1.2107 + iMicroSec=aMicroSec;
1.2108 + iSec=aSec;
1.2109 + iMin=aMin;
1.2110 + iHour=aHour;
1.2111 + iDay=aDay;
1.2112 + iMonth=aMonth;
1.2113 + iYear=aYear;
1.2114 + iDayString=aDayString;
1.2115 + iNextMin=aNextMin;
1.2116 + }
1.2117 + TTime iTime;
1.2118 + TInt iMicroSec;
1.2119 + TInt iSec;
1.2120 + TInt iMin;
1.2121 + TInt iHour;
1.2122 + TInt iDay;
1.2123 + TInt iMonth;
1.2124 + TInt iYear;
1.2125 + TText* iDayString;
1.2126 + TTime iNextMin;
1.2127 + };
1.2128 +
1.2129 +const TestInfo KTestArray[]=
1.2130 + {
1.2131 + TestInfo(TTime(KDaysToMicroSeconds*31+1),1,0,0,0,0,EFebruary,0,(TText*)_S("!Thu!am!00!02!"),TTime(KDaysToMicroSeconds*31+60000000)),
1.2132 + TestInfo(TTime(KDaysToMicroSeconds*31),0,0,0,0,0,EFebruary,0,(TText*)_S("!Thu!am!00!02!"),TTime(KDaysToMicroSeconds*31)),
1.2133 + TestInfo(TTime(KDaysToMicroSeconds*31-1),999999,59,59,23,30,EJanuary,0,(TText*)_S("!Wed!pm!59!01!"),TTime(KDaysToMicroSeconds*31)),
1.2134 + TestInfo(TTime(60000001),1,0,1,0,0,EJanuary,0,(TText*)_S("!Mon!am!01!01!"),TTime(120000000)),
1.2135 + TestInfo(TTime(60000000),0,0,1,0,0,EJanuary,0,(TText*)_S("!Mon!am!01!01!"),TTime(60000000)),
1.2136 + TestInfo(TTime(59999999),999999,59,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(60000000)),
1.2137 + TestInfo(TTime(1000001),1,1,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(60000000)),
1.2138 + TestInfo(TTime(1000000),0,1,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(60000000)),
1.2139 + TestInfo(TTime(999999),999999,0,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(60000000)),
1.2140 + TestInfo(TTime(1),1,0,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(60000000)),
1.2141 + TestInfo(TTime(0),0,0,0,0,0,EJanuary,0,(TText*)_S("!Mon!am!00!01!"),TTime(0)),
1.2142 + TestInfo(TTime(-1),999999,59,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(0)),
1.2143 + TestInfo(TTime(-1000000),0,59,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(0)),
1.2144 + TestInfo(TTime(-999999),1,59,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(0)),
1.2145 + TestInfo(TTime(-1000001),999999,58,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(0)),
1.2146 + TestInfo(TTime(-60000000),0,0,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(-60000000)),
1.2147 + TestInfo(TTime(-59999999),1,0,59,23,30,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(0)),
1.2148 + TestInfo(TTime(-60000001),999999,59,58,23,30,EDecember,-1,(TText*)_S("!Sun!pm!58!12!"),TTime(-60000000)),
1.2149 + TestInfo(TTime(-180000000),0,0,57,23,30,EDecember,-1,(TText*)_S("!Sun!pm!57!12!"),TTime(-180000000)),
1.2150 + TestInfo(TTime(-179999999),1,0,57,23,30,EDecember,-1,(TText*)_S("!Sun!pm!57!12!"),TTime(-120000000)),
1.2151 + TestInfo(TTime(-180000001),999999,59,56,23,30,EDecember,-1,(TText*)_S("!Sun!pm!56!12!"),TTime(-180000000)),
1.2152 + TestInfo(TTime(-KDaysToMicroSeconds+1),1,0,0,0,30,EDecember,-1,(TText*)_S("!Sun!am!00!12!"),TTime(-KDaysToMicroSeconds+60000000)),
1.2153 + TestInfo(TTime(-KDaysToMicroSeconds),0,0,0,0,30,EDecember,-1,(TText*)_S("!Sun!am!00!12!"),TTime(-KDaysToMicroSeconds)),
1.2154 + TestInfo(TTime(-KDaysToMicroSeconds-1),999999,59,59,23,29,EDecember,-1,(TText*)_S("!Sat!pm!59!12!"),TTime(-KDaysToMicroSeconds)),
1.2155 + TestInfo(TTime(-KDaysToMicroSeconds*7),0,0,0,0,24,EDecember,-1,(TText*)_S("!Mon!am!00!12!"),TTime(-KDaysToMicroSeconds*7)),
1.2156 + TestInfo(TTime(-KDaysToMicroSeconds*14),0,0,0,0,17,EDecember,-1,(TText*)_S("!Mon!am!00!12!"),TTime(-KDaysToMicroSeconds*14)),
1.2157 + TestInfo(TTime(-KDaysToMicroSeconds*14+1),1,0,0,0,17,EDecember,-1,(TText*)_S("!Mon!am!00!12!"),TTime(-KDaysToMicroSeconds*14+60000000)),
1.2158 + TestInfo(TTime(-KDaysToMicroSeconds*14-1),999999,59,59,23,16,EDecember,-1,(TText*)_S("!Sun!pm!59!12!"),TTime(-KDaysToMicroSeconds*14)),
1.2159 + TestInfo(TTime(-KDaysToMicroSeconds*92),0,0,0,0,0,EOctober,-1,(TText*)_S("!Sun!am!00!10!"),TTime(-KDaysToMicroSeconds*92)),
1.2160 + TestInfo(TTime(-KDaysToMicroSeconds*92+1),1,0,0,0,0,EOctober,-1,(TText*)_S("!Sun!am!00!10!"),TTime(-KDaysToMicroSeconds*92+60000000)),
1.2161 + TestInfo(TTime(-KDaysToMicroSeconds*92-1),999999,59,59,23,29,ESeptember,-1,(TText*)_S("!Sat!pm!59!09!"),TTime(-KDaysToMicroSeconds*92)),
1.2162 + TestInfo(Time::NullTTime(),224192,5,59,19,21,EDecember,-292272,(TText*)_S("!Thu!pm!59!12!"),TTime(Time::NullTTime().Int64()-Time::NullTTime().Int64()%60000000))
1.2163 + };
1.2164 +
1.2165 +void TestTTime::Test13()
1.2166 + {
1.2167 + TBuf<0x80> testString;
1.2168 + TInt i=0;
1.2169 + for (;i<(TInt)(sizeof(KTestArray)/sizeof(TestInfo))-1;i++)
1.2170 + {
1.2171 + TTime time=KTestArray[i].iTime;
1.2172 + TInt r=time.DateTime().MicroSecond();
1.2173 + test(r==KTestArray[i].iMicroSec);
1.2174 + r=time.DateTime().Second();
1.2175 + test(r==KTestArray[i].iSec);
1.2176 + r=time.DateTime().Minute();
1.2177 + test(r==KTestArray[i].iMin);
1.2178 + r=time.DateTime().Hour();
1.2179 + test(r==KTestArray[i].iHour);
1.2180 + r=time.DateTime().Day();
1.2181 + test(r==KTestArray[i].iDay);
1.2182 + r=time.DateTime().Month();
1.2183 + test(r==KTestArray[i].iMonth);
1.2184 + r=time.DateTime().Year();
1.2185 + test(r==KTestArray[i].iYear);
1.2186 + TRAP(r,time.FormatL(testString,_L("!%*E!%*A!%T!%F%M!")));
1.2187 + test(r==KErrNone);
1.2188 + test(testString==TPtrC(KTestArray[i].iDayString));
1.2189 + TTimeIntervalMicroSeconds usFrom;
1.2190 + usFrom=time.MicroSecondsFrom(TTime(0));
1.2191 + test(usFrom==time.Int64());
1.2192 + usFrom=TTime(0).MicroSecondsFrom(time);
1.2193 + test(usFrom==-time.Int64());
1.2194 + usFrom=time.MicroSecondsFrom(TTime(-1));
1.2195 + test(usFrom==time.Int64()+1);
1.2196 + usFrom=TTime(-1).MicroSecondsFrom(time);
1.2197 + test(usFrom==-time.Int64()-1);
1.2198 + usFrom=time.MicroSecondsFrom(TTime(1));
1.2199 + test(usFrom==time.Int64()-1);
1.2200 + usFrom=TTime(1).MicroSecondsFrom(time);
1.2201 + test(usFrom==-time.Int64()+1);
1.2202 + TTime time2=time+TTimeIntervalYears(0);
1.2203 + test(time2==time);
1.2204 + time2=time+TTimeIntervalYears(1);
1.2205 + r=time2.DateTime().Year();
1.2206 + test(r==KTestArray[i].iYear+1);
1.2207 + time2=time-TTimeIntervalYears(1);
1.2208 + r=time2.DateTime().Year();
1.2209 + test(r==KTestArray[i].iYear-1);
1.2210 + time2=time+TTimeIntervalMonths(0);
1.2211 + test(time2==time);
1.2212 + time2=time+TTimeIntervalMonths(1);
1.2213 + r=time2.DateTime().Month();
1.2214 + test(r==(KTestArray[i].iMonth+1)%12);
1.2215 + time2=time-TTimeIntervalMonths(1);
1.2216 + r=time2.DateTime().Month();
1.2217 + test(r==(KTestArray[i].iMonth+11)%12);
1.2218 + time2=time+TTimeIntervalDays(0);
1.2219 + test(time2==time);
1.2220 + time2=time+TTimeIntervalHours(0);
1.2221 + test(time2==time);
1.2222 + time2=time+TTimeIntervalMinutes(0);
1.2223 + test(time2==time);
1.2224 + time2=time+TTimeIntervalSeconds(0);
1.2225 + test(time2==time);
1.2226 + time2=time+TTimeIntervalMicroSeconds(0);
1.2227 + test(time2==time);
1.2228 + time.RoundUpToNextMinute();
1.2229 + test(time==TTime(KTestArray[i].iNextMin));
1.2230 + }
1.2231 +
1.2232 + TTime time=KTestArray[i].iTime;
1.2233 + test(time==Time::NullTTime());
1.2234 + TInt r=time.DateTime().MicroSecond();
1.2235 + test(r==KTestArray[i].iMicroSec);
1.2236 + r=time.DateTime().Second();
1.2237 + test(r==KTestArray[i].iSec);
1.2238 + r=time.DateTime().Minute();
1.2239 + test(r==KTestArray[i].iMin);
1.2240 + r=time.DateTime().Hour();
1.2241 + test(r==KTestArray[i].iHour);
1.2242 + r=time.DateTime().Day();
1.2243 + test(r==KTestArray[i].iDay);
1.2244 + r=time.DateTime().Month();
1.2245 + test(r==KTestArray[i].iMonth);
1.2246 + r=time.DateTime().Year();
1.2247 + test(r==KTestArray[i].iYear);
1.2248 + TRAP(r,time.FormatL(testString,_L("!%*E!%*A!%T!%F%M!")));
1.2249 + test(r==KErrNone);
1.2250 + test(testString==TPtrC(KTestArray[i].iDayString));
1.2251 + TTimeIntervalMicroSeconds usFrom;
1.2252 + usFrom=time.MicroSecondsFrom(TTime(0));
1.2253 + test(usFrom==time.Int64());
1.2254 + usFrom=TTime(0).MicroSecondsFrom(time);
1.2255 + test(usFrom==-time.Int64());
1.2256 + usFrom=time.MicroSecondsFrom(TTime(-1));
1.2257 + test(usFrom==time.Int64()+1);
1.2258 + usFrom=TTime(-1).MicroSecondsFrom(time);
1.2259 + test(usFrom==-time.Int64()-1);
1.2260 + usFrom=time.MicroSecondsFrom(TTime(1));
1.2261 + test(usFrom==time.Int64()-1);
1.2262 + usFrom=TTime(1).MicroSecondsFrom(time);
1.2263 + test(usFrom==-time.Int64()+1);
1.2264 + TTime time2=time+TTimeIntervalYears(0);
1.2265 + test(time2==time);
1.2266 + time2=time+TTimeIntervalYears(1);
1.2267 + r=time2.DateTime().Year();
1.2268 + test(r==KTestArray[i].iYear+1);
1.2269 + time2=time+TTimeIntervalMonths(0);
1.2270 + test(time2==time);
1.2271 + time2=time+TTimeIntervalMonths(1);
1.2272 + r=time2.DateTime().Month();
1.2273 + test(r==(KTestArray[i].iMonth+1)%12);
1.2274 + time2=time+TTimeIntervalDays(0);
1.2275 + test(time2==time);
1.2276 + time2=time+TTimeIntervalHours(0);
1.2277 + test(time2==time);
1.2278 + time2=time+TTimeIntervalMinutes(0);
1.2279 + test(time2==time);
1.2280 + time2=time+TTimeIntervalSeconds(0);
1.2281 + test(time2==time);
1.2282 + time2=time+TTimeIntervalMicroSeconds(0);
1.2283 + test(time2==time);
1.2284 + time.RoundUpToNextMinute();
1.2285 + test(time==TTime(KTestArray[i].iNextMin));
1.2286 +
1.2287 + }
1.2288 +
1.2289 +
1.2290 +void TestTTime::TestSecureClock()
1.2291 +{
1.2292 + // See if secure clock present and early exit if its not enabled
1.2293 + TInt nso = 0;
1.2294 + TInt r = HAL::Get(HAL::ETimeNonSecureOffset,nso);
1.2295 + if (r != KErrNone) {
1.2296 + RDebug::Printf("WARNING: Secure clock test skipped because offset HAL attribute not present!");
1.2297 + return;
1.2298 + }
1.2299 +
1.2300 + // Get the secure and nonsecure times
1.2301 + TTime securetime, now, march2001;
1.2302 + r = securetime.HomeTimeSecure();
1.2303 + if (r==KErrNoSecureTime) {
1.2304 + TDateTime randomdate;
1.2305 + randomdate.Set(2005, ESeptember, 13, 0,0,0,0);
1.2306 + r = User::SetHomeTimeSecure(randomdate);
1.2307 + test_Equal(KErrNone, r);
1.2308 + r = securetime.HomeTimeSecure();
1.2309 + }
1.2310 + test_Equal(KErrNone, r);
1.2311 + now.HomeTime();
1.2312 + PrintTime("hometime=", now);
1.2313 + PrintTime("securetime=", securetime);
1.2314 +
1.2315 + // Set nonsecure time to March 2001
1.2316 + TDateTime bday;
1.2317 + bday.Set(2001, EMarch, 6, 0,0,0,0);
1.2318 + march2001 = bday;
1.2319 + r = User::SetHomeTime(march2001);
1.2320 + test(r==KErrNone);
1.2321 +
1.2322 + // Check the nonsecure system time really updated to March 2001
1.2323 + TTime now2, securetime2;
1.2324 + TTimeIntervalSeconds seconds_diff(100);
1.2325 + now2.HomeTime();
1.2326 + r=now2.SecondsFrom(march2001, seconds_diff);
1.2327 + test(r==0);
1.2328 + test(seconds_diff == TTimeIntervalSeconds(0));
1.2329 +
1.2330 + // Check the secure system time did not change as a result of changing nonsecure time
1.2331 + r = securetime2.HomeTimeSecure();
1.2332 + test(r==KErrNone);
1.2333 + seconds_diff = TTimeIntervalSeconds(100);
1.2334 + r=securetime2.SecondsFrom(securetime, seconds_diff);
1.2335 + test(r==0);
1.2336 + test(seconds_diff == TTimeIntervalSeconds(0));
1.2337 +
1.2338 + // Set secure time to March 2001 (this would fail without DRM rights)
1.2339 + // *** NB: Setting H4's rtc to any time before 1/1/2000 ***
1.2340 + // *** will not work but no error will be reported! ***
1.2341 + securetime2 = march2001;
1.2342 + r = User::SetHomeTimeSecure(securetime2);
1.2343 + test(r==KErrNone);
1.2344 +
1.2345 + // Check both secure & nonsecure system times are March 2001
1.2346 + TTime now3, securetime3;
1.2347 + now3.HomeTime();
1.2348 + r = securetime3.HomeTimeSecure();
1.2349 + test(r==KErrNone);
1.2350 + r = securetime3.SecondsFrom(march2001, seconds_diff);
1.2351 + test(seconds_diff == TTimeIntervalSeconds(0));
1.2352 + r = now3.SecondsFrom(march2001, seconds_diff);
1.2353 + test(seconds_diff == TTimeIntervalSeconds(0));
1.2354 +
1.2355 + // Verify the offset changes by the right amount when the nonsecure time is changed
1.2356 + TTime time;
1.2357 + r = HAL::Get(HAL::ETimeNonSecureOffset,nso);
1.2358 + test_Equal(KErrNone, r);
1.2359 + time.UniversalTime();
1.2360 + time+=TTimeIntervalMinutes(30);
1.2361 + TInt nso_expected = nso + 30*60;
1.2362 + r=User::SetUTCTime(time);
1.2363 + test_Equal(KErrNone, r);
1.2364 + r = HAL::Get(HAL::ETimeNonSecureOffset,nso);
1.2365 + test_Equal(KErrNone, r);
1.2366 + test_Equal(nso_expected, nso);
1.2367 +
1.2368 + // Restore secure clock and system time to what they were at the top of this function
1.2369 + r = User::SetHomeTimeSecure(securetime);
1.2370 + test_Equal(KErrNone, r);
1.2371 + r = User::SetHomeTime(now);
1.2372 + test_Equal(KErrNone, r);
1.2373 +
1.2374 +}
1.2375 +
1.2376 +GLDEF_C TInt E32Main()
1.2377 + {
1.2378 +
1.2379 + test.Title();
1.2380 + test.Start(_L("Testing TDateTime classes"));
1.2381 + TestTTime T;
1.2382 +
1.2383 + TLocale savedLocale;
1.2384 +
1.2385 + TLocale b;
1.2386 + b.SetDateSeparator('\0',0);
1.2387 + b.SetDateSeparator('/',1);
1.2388 + b.SetDateSeparator('/',2);
1.2389 + b.SetDateSeparator('\0',3);
1.2390 + b.SetDateFormat(EDateEuropean);
1.2391 + b.SetTimeFormat(ETime12);
1.2392 + b.SetTimeSeparator('\0',0);
1.2393 + b.SetTimeSeparator(':',1);
1.2394 + b.SetTimeSeparator(':',2);
1.2395 + b.SetTimeSeparator('\0',3);
1.2396 + b.SetAmPmSpaceBetween(ETrue);
1.2397 + b.SetAmPmSymbolPosition(ELocaleAfter);
1.2398 + b.SetWorkDays(0x1F);
1.2399 + b.SetStartOfWeek(EMonday);
1.2400 + b.Set();
1.2401 +
1.2402 + TTimeIntervalSeconds savedOffset = User::UTCOffset();
1.2403 + User::SetUTCOffset(0);
1.2404 +
1.2405 + test.Next(_L("Testing TDateTime class"));
1.2406 + T.Test1();
1.2407 + test.Next(_L("Testing TTimeIntervalMicroSeconds"));
1.2408 + T.Test2();
1.2409 + test.Next(_L("Testing TTimeIntervalSeconds"));
1.2410 + T.Test3();
1.2411 + test.Next(_L("Testing other time intervals"));
1.2412 + T.Test4();
1.2413 + test.Next(_L("Testing TDateTime To TTime conversions"));
1.2414 + T.Test5();
1.2415 + test.Next(_L("Testing adding TTimeIntervals and Subtracting TTimes"));
1.2416 + T.Test6();
1.2417 + test.Next(_L("Day numbers in week and year"));
1.2418 + T.Test7();
1.2419 + test.Next(_L("week numbers in year"));
1.2420 + T.Test8();
1.2421 + test.Next(_L("String parsing"));
1.2422 + T.Test9();
1.2423 + T.Test9();
1.2424 + test.Next(_L("Remaining Time functions"));
1.2425 + //T.Test10();
1.2426 + test.Next(_L("Test time change"));
1.2427 + T.Test11();
1.2428 + test.Next(_L("Test TTime::Set(TDesC aString)"));
1.2429 + T.Test12();
1.2430 + test.Next(_L("Test negative times"));
1.2431 + T.Test13();
1.2432 + test.Next(_L("Test secure clock"));
1.2433 + T.TestSecureClock();
1.2434 + test.Next(_L("The year 2000"));
1.2435 + TTime year2000(TDateTime(2000,EJanuary,0,0,0,0,0));
1.2436 + test.Printf(_L("\tYear 2000 = %016lx\n"),year2000.Int64());
1.2437 + savedLocale.Set(); //restore locale info
1.2438 + User::SetUTCOffset(savedOffset);
1.2439 + test.End();
1.2440 + return(0);
1.2441 + }