Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_fsy2k.cpp
25 GLDEF_D RTest test(_L("T_FSY2K"));
26 GLDEF_D TBuf<128> gDateBuf;
28 const TInt KMaxValidDateTimes=25;
29 const TInt KMaxInvalidDateTimes=7;
31 static void testRFsSetEntry(TDateTime* aDateTime, TTime* aTime, TBool validDate)
33 // Test RFs::SetEntry() and RFs::Entry() functions on both a file and a directory
36 MakeFile(_L("Y2KTEST.tst"));
38 TInt r=TheFs.SetEntry(_L("Y2KTEST.tst"),*aTime,KEntryAttHidden,KEntryAttArchive);
42 r=TheFs.Entry(_L("Y2KTEST.tst"),entry);
45 TDateTime checkDateTime=(entry.iModified).DateTime();
46 test(checkDateTime.Year()==aDateTime->Year());
49 test(checkDateTime.Month()==aDateTime->Month());
50 test(checkDateTime.Day()==aDateTime->Day());
54 test(checkDateTime.Month()==aDateTime->Month()+1);
55 test(checkDateTime.Day()==0);
58 (entry.iModified).FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3"));
59 test.Printf(_L("Valid date: %S\n"),&gDateBuf);
61 r=TheFs.Delete(_L("Y2KTEST.tst"));
64 MakeDir(_L("\\Y2KTEST\\"));
65 r=TheFs.SetEntry(_L("\\Y2KTEST\\"),*aTime,KEntryAttHidden,KEntryAttArchive);
68 r=TheFs.Entry(_L("\\Y2KTEST\\"),entry);
71 checkDateTime=(entry.iModified).DateTime();
72 test(checkDateTime.Year()==aDateTime->Year());
75 test(checkDateTime.Month()==aDateTime->Month());
76 test(checkDateTime.Day()==aDateTime->Day());
80 test(checkDateTime.Month()==aDateTime->Month()+1);
81 test(checkDateTime.Day()==0);
84 (entry.iModified).FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3"));
85 test.Printf(_L("Valid date: %S\n"),&gDateBuf);
87 r=TheFs.RmDir(_L("\\Y2KTEST\\"));
93 static void testRFsSetModified(TDateTime* aDateTime, TTime* aTime, TBool validDate)
95 // Test RFs::SetModified() and RFs::Modified() functions on both a file and a directory
98 MakeFile(_L("Y2KTEST.tst"));
100 TInt r=TheFs.SetModified(_L("Y2KTEST.tst"),*aTime);
104 r=TheFs.Modified(_L("Y2KTEST.tst"),check);
107 TDateTime checkDateTime=check.DateTime();
109 test(checkDateTime.Year()==aDateTime->Year());
112 test(checkDateTime.Month()==aDateTime->Month());
113 test(checkDateTime.Day()==aDateTime->Day());
117 test(checkDateTime.Month()==aDateTime->Month()+1);
118 test(checkDateTime.Day()==0);
122 check.FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3"));
123 test.Printf(_L("Valid date: %S\n"),&gDateBuf);
125 r=TheFs.Delete(_L("Y2KTEST.tst"));
128 MakeDir(_L("\\Y2KTEST\\"));
129 r=TheFs.SetModified(_L("\\Y2KTEST\\"),*aTime);
132 r=TheFs.Modified(_L("\\Y2KTEST\\"),check);
135 checkDateTime=check.DateTime();
136 test(checkDateTime.Year()==aDateTime->Year());
139 test(checkDateTime.Month()==aDateTime->Month());
140 test(checkDateTime.Day()==aDateTime->Day());
144 test(checkDateTime.Month()==aDateTime->Month()+1);
145 test(checkDateTime.Day()==0);
148 check.FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3"));
149 test.Printf(_L("Valid date: %S\n"),&gDateBuf);
151 r=TheFs.RmDir(_L("\\Y2KTEST\\"));
156 static void testRFileSet(TDateTime* aDateTime, TTime* aTime, TBool validDate)
158 // Test RFile::Set() and RFile::Modified()
162 TInt r=file.Replace(TheFs,_L("Y2KTEST.tst"),0);
163 test(r==KErrNone || r==KErrPathNotFound);
165 r=file.Set(*aTime,KEntryAttHidden,KEntryAttNormal);
170 file.Open(TheFs,_L("Y2KTEST.tst"),EFileWrite);
171 r=file.Modified(check);
175 test.Printf(_L("Date set to "));
176 test.Printf(_L("Day %d "),aDateTime->Day());
177 test.Printf(_L("Month %d "),aDateTime->Month());
178 test.Printf(_L("Year %d \n"),aDateTime->Year());
180 TDateTime checkDateTime=check.DateTime();
181 if (checkDateTime.Year()!=aDateTime->Year())
183 // Failure occurs for F32 releases before 111 - due to a problem
184 // in SFILE/SF_FILE DoFsFileSet() in which the TTime parameter
185 // was being incorrectly obtained. Not a year 2000 issue.
187 test.Printf(_L("ERROR!\n"));
188 test.Printf(_L("Actually set to "));
189 test.Printf(_L("Day %d "),checkDateTime.Day());
190 test.Printf(_L("Month %d "),checkDateTime.Month());
191 test.Printf(_L("Year %d \n"),checkDateTime.Year());
192 // test.Printf(_L("Press any key to continue \n"));
194 r=TheFs.Delete(_L("Y2KTEST.tst"));
198 test(checkDateTime.Year()==aDateTime->Year());
201 test(checkDateTime.Month()==aDateTime->Month());
202 test(checkDateTime.Day()==aDateTime->Day());
206 test(checkDateTime.Month()==aDateTime->Month()+1);
207 test(checkDateTime.Day()==0);
211 check.FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3"));
212 test.Printf(_L("Valid date: %S\n"),&gDateBuf);
214 r=TheFs.Delete(_L("Y2KTEST.tst"));
219 static void testRFileSetModified(TDateTime* aDateTime, TTime* aTime, TBool validDate)
221 // Test RFile::SetModified() and RFile::Modified()
225 TInt r=file.Replace(TheFs,_L("Y2KTEST.tst"),0);
226 test(r==KErrNone || r==KErrPathNotFound);
228 r=file.SetModified(*aTime);
233 file.Open(TheFs,_L("Y2KTEST.tst"),EFileWrite);
234 r=file.Modified(check);
238 TDateTime checkDateTime=check.DateTime();
240 test(checkDateTime.Year()==aDateTime->Year());
243 test(checkDateTime.Month()==aDateTime->Month());
244 test(checkDateTime.Day()==aDateTime->Day());
248 test(checkDateTime.Month()==aDateTime->Month()+1);
249 test(checkDateTime.Day()==0);
252 check.FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3"));
253 test.Printf(_L("Valid date: %S\n"),&gDateBuf);
255 r=TheFs.Delete(_L("Y2KTEST.tst"));
259 static void testCFileManAttribsL(TDateTime* aDateTime, TTime* aTime, TBool validDate)
261 // Test CFileMan::Attribs()
264 MakeFile(_L("Y2KTEST.tst"));
266 CFileMan* fileMan=CFileMan::NewL(TheFs);
268 TInt r=fileMan->Attribs(_L("Y2KTEST.tst"),KEntryAttHidden,KEntryAttNormal,*aTime);
272 r=TheFs.Entry(_L("Y2KTEST.tst"),entry);
275 TTime check=entry.iModified;
276 TDateTime checkDateTime=check.DateTime();
278 test(checkDateTime.Year()==aDateTime->Year());
281 test(checkDateTime.Month()==aDateTime->Month());
282 test(checkDateTime.Day()==aDateTime->Day());
286 test(checkDateTime.Month()==aDateTime->Month()+1);
287 test(checkDateTime.Day()==0);
291 check.FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3"));
292 test.Printf(_L("Valid date: %S\n"),&gDateBuf);
294 r=TheFs.Delete(_L("Y2KTEST.tst"));
300 // Valid dates to be tested for year 2000 compliance
301 // Times are always set at 11.11.00
303 LOCAL_D TInt testYearValid[KMaxValidDateTimes] =
305 1998, // December 31 1998
306 1999, // January 01 1999
307 1999, // February 27 1999
308 1999, // February 28 1999
309 1999, // March 01 1999
310 1999, // August 31 1999
311 1999, // September 01 1999
312 1999, // September 08 1999
313 1999, // September 09 1999
314 1999, // September 09 1999
315 1999, // December 31 1999
316 2000, // January 01 2000
317 2000, // February 27 2000
318 2000, // February 28 2000
319 2000, // February 29 2000
320 2000, // March 01 2000
321 2000, // December 31 2000
322 2001, // January 01 2001
323 2001, // February 28 2001
324 2001, // March 01 2001
325 2004, // February 28 2004
326 2004, // February 29 2004
327 2004, // March 01 2004
328 2098, // January 01 2098
329 2099 // January 01 2099
332 LOCAL_D TMonth testMonthValid[KMaxValidDateTimes] =
334 EDecember, // December 31 1998
335 EJanuary, // January 01 1999
336 EFebruary, // February 27 1999
337 EFebruary, // February 28 1999
338 EMarch, // March 01 1999
339 EAugust, // August 31 1999
340 ESeptember, // September 01 1999
341 ESeptember, // September 08 1999
342 ESeptember, // September 09 1999
343 ESeptember, // September 10 1999
344 EDecember, // December 31 1999
345 EJanuary, // January 01 2000
346 EFebruary, // February 27 2000
347 EFebruary, // February 28 2000
348 EFebruary, // February 29 2000
349 EMarch, // March 01 2000
350 EDecember, // December 31 2000
351 EJanuary, // January 01 2001
352 EFebruary, // February 28 2001
353 EMarch, // March 01 2001
354 EFebruary, // February 28 2004
355 EFebruary, // February 29 2004
356 EMarch, // March 01 2004
357 EJanuary, // January 01 2098
358 EJanuary // January 01 2099
361 LOCAL_D TInt testDayValid[KMaxValidDateTimes] =
363 30, // December 31 1998
364 0, // January 01 1999
365 26, // February 27 1999
366 27, // February 28 1999
368 30, // August 31 1999
369 0, // September 01 1999
370 7, // September 08 1999
371 8, // September 09 1999
372 8, // September 09 1999
373 30, // December 31 1999
374 0, // January 01 2000
375 26, // February 27 2000
376 27, // February 28 2000
377 28, // February 29 2000
379 30, // December 31 2000
380 0, // January 01 2001
381 27, // February 28 2001
383 27, // February 28 2004
384 28, // February 29 2004
386 0, // January 01 2098
391 // Invalid dates to be tested for year 2000 compliance
392 // Times are always set at 11.11.00
394 LOCAL_D TInt testYearInvalid[KMaxInvalidDateTimes] =
396 1998, // April 31 1998
397 1999, // February 29 1999
398 2000, // February 30 2000
399 2001, // February 29 2001
400 2002, // February 29 2002
401 2003, // February 29 2003
402 2004, // February 30 2004
405 LOCAL_D TMonth testMonthInvalid[KMaxValidDateTimes] =
407 EApril, // April 31 1998
408 EFebruary, // February 29 1999
409 EFebruary, // February 30 2000
410 EFebruary, // February 29 2001
411 EFebruary, // February 29 2002
412 EFebruary, // February 29 2003
413 EFebruary, // February 30 2004
416 LOCAL_D TInt testDayInvalid[KMaxValidDateTimes] =
419 28, // February 29 1999
420 29, // February 30 2000
421 28, // February 29 2001
422 28, // February 29 2002
423 28, // February 29 2003
424 29, // February 30 2004
427 LOCAL_D TPtrC invalidDates[KMaxValidDateTimes] =
429 _L("31st April 1998"),
430 _L("29th February 1999"),
431 _L("30th February 2000"),
432 _L("29th February 2001"),
433 _L("29th February 2002"),
434 _L("29th February 2003"),
435 _L("30th February 2004"),
439 static void TestValidDates(TDateTime* aDateTime, TTime* aTime)
441 // Test an array of valid dates for year 2000 compliance
444 test.Next(_L("Test RFs::SetEntry() and RFs::Entry()"));
446 TDateTime* tempDateTime=aDateTime;
447 TTime* tempTime=aTime;
450 for (;i<KMaxValidDateTimes;i++)
452 testRFsSetEntry(tempDateTime, tempTime, ETrue);
457 test.Next(_L("Test RFs::SetModified() and RFs::Modified()"));
459 tempDateTime=aDateTime;
461 for (i=0;i<KMaxValidDateTimes;i++)
463 testRFsSetModified(tempDateTime, tempTime, ETrue);
468 test.Next(_L("Test RFile::Set() and RFile::Modified()"));
470 tempDateTime=aDateTime;
472 for (i=0;i<KMaxValidDateTimes;i++)
474 testRFileSet(tempDateTime, tempTime, ETrue);
479 test.Next(_L("Test RFile::SetModified() and RFile::Modified()"));
481 tempDateTime=aDateTime;
483 for (i=0;i<KMaxValidDateTimes;i++)
485 testRFileSetModified(tempDateTime, tempTime, ETrue);
490 test.Next(_L("Test CFileMan::Attribs()"));
491 tempDateTime=aDateTime;
493 for (i=0;i<KMaxValidDateTimes;i++)
495 TRAPD(error,testCFileManAttribsL(tempDateTime, tempTime, ETrue));
496 test(error==KErrNone);
503 static void TestInvalidDates(TDateTime* aDateTime, TTime* aTime)
505 // Test an array of invalid dates for year 2000 compliance
506 // aDateTime is set as one day less than the desired invalid
507 // date, because TDateTime correctly prevents us setting invalid dates
508 // aTime is set to TDateTime + 1 day, which should be the next
509 // correct date after TDateTime, NOT the desired invalid date
512 test.Next(_L("Test RFs::SetEntry() and RFs::Entry()"));
514 TDateTime* tempDateTime=aDateTime;
515 TTime* tempTime=aTime;
518 for (;i<KMaxInvalidDateTimes;i++)
520 test.Printf(_L("Invalid date: %S\n"),&invalidDates[i]);
521 testRFsSetEntry(tempDateTime, tempTime, EFalse);
526 test.Next(_L("Test RFs::SetModified() and RFs::Modified()"));
528 tempDateTime=aDateTime;
530 for (i=0;i<KMaxInvalidDateTimes;i++)
532 test.Printf(_L("Invalid date: %S\n"),&invalidDates[i]);
533 testRFsSetModified(tempDateTime, tempTime, EFalse);
538 test.Next(_L("Test RFile::Set() and RFile::Modified()"));
540 tempDateTime=aDateTime;
542 for (i=0;i<KMaxInvalidDateTimes;i++)
544 test.Printf(_L("Invalid date: %S\n"),&invalidDates[i]);
545 testRFileSet(tempDateTime, tempTime, EFalse);
550 test.Next(_L("Test RFile::SetModified() and RFile::Modified()"));
552 tempDateTime=aDateTime;
554 for (i=0;i<KMaxInvalidDateTimes;i++)
556 test.Printf(_L("Invalid date: %S\n"),&invalidDates[i]);
557 testRFileSetModified(tempDateTime, tempTime, EFalse);
562 test.Next(_L("Test CFileMan::Attribs()"));
563 tempDateTime=aDateTime;
565 for (i=0;i<KMaxInvalidDateTimes;i++)
567 test.Printf(_L("Invalid date: %S\n"),&invalidDates[i]);
568 TRAPD(error,testCFileManAttribsL(tempDateTime, tempTime, EFalse));
569 test(error==KErrNone);
576 static void CallTests()
578 // Do tests relative to session path
582 // Set up an array of valid TDateTimes and TTimes to be tested for Y2K compliance
584 TDateTime validDateTime[KMaxValidDateTimes];
585 TTime validTime[KMaxValidDateTimes];
589 for (;i<KMaxValidDateTimes;i++)
591 // Dummy time is used to initialise validDateTime[i] before calling SetX()
592 r=validDateTime[i].Set(1998,EJune,23,11,11,11,0);
594 r=validDateTime[i].SetYear(testYearValid[i]);
596 r=validDateTime[i].SetMonth(testMonthValid[i]);
598 r=validDateTime[i].SetDay(testDayValid[i]);
600 validTime[i]=validDateTime[i];
603 // Set up an array of invalid TDateTimes and TTimes to be tested for Y2K compliance
605 TDateTime invalidDateTime[KMaxInvalidDateTimes];
606 TTime invalidTime[KMaxInvalidDateTimes];
607 TTimeIntervalDays extraDay(1);
609 for (i=0;i<KMaxInvalidDateTimes;i++)
611 // Dummy time is used to initialise validDateTime[i] before calling SetX()
612 r=invalidDateTime[i].Set(1998,EJune,22,11,11,11,0);
614 r=invalidDateTime[i].SetYear(testYearInvalid[i]);
616 r=invalidDateTime[i].SetMonth(testMonthInvalid[i]);
618 r=invalidDateTime[i].SetDay(testDayInvalid[i]);
619 test(r==KErrGeneral); // This will fail because it is an invalid date
620 r=invalidDateTime[i].SetDay(testDayInvalid[i]-1);
621 test(r==KErrNone); // Set it one day less
622 invalidTime[i]=invalidDateTime[i];
623 invalidTime[i]+=extraDay; // Add on an extra day. This should bump the
624 } // date onto the next month, NOT set the day
625 // to the invalid date in invalidDateTime[i]
627 TestValidDates(&validDateTime[0],&validTime[0]);
628 TestInvalidDates(&invalidDateTime[0],&invalidTime[0]);
631 GLDEF_C void CallTestsL(void)
633 // Do testing on aDrive
637 TInt r=TheFs.MkDirAll(_L("\\F32-TST\\YEAR 2000 TESTS\\"));
638 test(r==KErrNone || r==KErrAlreadyExists);
641 TheFs.ResourceCountMarkEnd();
644 test.Printf(_L("Error: Leave %d\n"),r);
647 r=TheFs.RmDir(_L("\\F32-TST\\YEAR 2000 TESTS\\"));