diff -r 000000000000 -r a41df078684a kerneltest/f32test/server/t_fsy2k.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/f32test/server/t_fsy2k.cpp Mon Oct 19 15:55:17 2009 +0100 @@ -0,0 +1,649 @@ +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// f32test\server\t_fsy2k.cpp +// +// + +#include +#include +#include "t_server.h" +#include +#include +#include + +GLDEF_D RTest test(_L("T_FSY2K")); +GLDEF_D TBuf<128> gDateBuf; + +const TInt KMaxValidDateTimes=25; +const TInt KMaxInvalidDateTimes=7; + +static void testRFsSetEntry(TDateTime* aDateTime, TTime* aTime, TBool validDate) +// +// Test RFs::SetEntry() and RFs::Entry() functions on both a file and a directory +// + { + MakeFile(_L("Y2KTEST.tst")); + + TInt r=TheFs.SetEntry(_L("Y2KTEST.tst"),*aTime,KEntryAttHidden,KEntryAttArchive); + test(r==KErrNone); + + TEntry entry; + r=TheFs.Entry(_L("Y2KTEST.tst"),entry); + test(r==KErrNone); + + TDateTime checkDateTime=(entry.iModified).DateTime(); + test(checkDateTime.Year()==aDateTime->Year()); + if (validDate) + { + test(checkDateTime.Month()==aDateTime->Month()); + test(checkDateTime.Day()==aDateTime->Day()); + } + else + { + test(checkDateTime.Month()==aDateTime->Month()+1); + test(checkDateTime.Day()==0); + } + + (entry.iModified).FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3")); + test.Printf(_L("Valid date: %S\n"),&gDateBuf); + + r=TheFs.Delete(_L("Y2KTEST.tst")); + test(r==KErrNone); + + MakeDir(_L("\\Y2KTEST\\")); + r=TheFs.SetEntry(_L("\\Y2KTEST\\"),*aTime,KEntryAttHidden,KEntryAttArchive); + test(r==KErrNone); + + r=TheFs.Entry(_L("\\Y2KTEST\\"),entry); + test(r==KErrNone); + + checkDateTime=(entry.iModified).DateTime(); + test(checkDateTime.Year()==aDateTime->Year()); + if (validDate) + { + test(checkDateTime.Month()==aDateTime->Month()); + test(checkDateTime.Day()==aDateTime->Day()); + } + else + { + test(checkDateTime.Month()==aDateTime->Month()+1); + test(checkDateTime.Day()==0); + } + + (entry.iModified).FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3")); + test.Printf(_L("Valid date: %S\n"),&gDateBuf); + + r=TheFs.RmDir(_L("\\Y2KTEST\\")); + test(r==KErrNone); + + } + + +static void testRFsSetModified(TDateTime* aDateTime, TTime* aTime, TBool validDate) +// +// Test RFs::SetModified() and RFs::Modified() functions on both a file and a directory +// + { + MakeFile(_L("Y2KTEST.tst")); + + TInt r=TheFs.SetModified(_L("Y2KTEST.tst"),*aTime); + test(r==KErrNone); + + TTime check; + r=TheFs.Modified(_L("Y2KTEST.tst"),check); + test(r==KErrNone); + + TDateTime checkDateTime=check.DateTime(); + + test(checkDateTime.Year()==aDateTime->Year()); + if (validDate) + { + test(checkDateTime.Month()==aDateTime->Month()); + test(checkDateTime.Day()==aDateTime->Day()); + } + else + { + test(checkDateTime.Month()==aDateTime->Month()+1); + test(checkDateTime.Day()==0); + } + + + check.FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3")); + test.Printf(_L("Valid date: %S\n"),&gDateBuf); + + r=TheFs.Delete(_L("Y2KTEST.tst")); + test(r==KErrNone); + + MakeDir(_L("\\Y2KTEST\\")); + r=TheFs.SetModified(_L("\\Y2KTEST\\"),*aTime); + test(r==KErrNone); + + r=TheFs.Modified(_L("\\Y2KTEST\\"),check); + test(r==KErrNone); + + checkDateTime=check.DateTime(); + test(checkDateTime.Year()==aDateTime->Year()); + if (validDate) + { + test(checkDateTime.Month()==aDateTime->Month()); + test(checkDateTime.Day()==aDateTime->Day()); + } + else + { + test(checkDateTime.Month()==aDateTime->Month()+1); + test(checkDateTime.Day()==0); + } + + check.FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3")); + test.Printf(_L("Valid date: %S\n"),&gDateBuf); + + r=TheFs.RmDir(_L("\\Y2KTEST\\")); + test(r==KErrNone); + } + + +static void testRFileSet(TDateTime* aDateTime, TTime* aTime, TBool validDate) +// +// Test RFile::Set() and RFile::Modified() +// + { + RFile file; + TInt r=file.Replace(TheFs,_L("Y2KTEST.tst"),0); + test(r==KErrNone || r==KErrPathNotFound); + + r=file.Set(*aTime,KEntryAttHidden,KEntryAttNormal); + test(r==KErrNone); + file.Close(); + + TTime check; + file.Open(TheFs,_L("Y2KTEST.tst"),EFileWrite); + r=file.Modified(check); + test(r==KErrNone); + file.Close(); + + test.Printf(_L("Date set to ")); + test.Printf(_L("Day %d "),aDateTime->Day()); + test.Printf(_L("Month %d "),aDateTime->Month()); + test.Printf(_L("Year %d \n"),aDateTime->Year()); + + TDateTime checkDateTime=check.DateTime(); + if (checkDateTime.Year()!=aDateTime->Year()) + { + // Failure occurs for F32 releases before 111 - due to a problem + // in SFILE/SF_FILE DoFsFileSet() in which the TTime parameter + // was being incorrectly obtained. Not a year 2000 issue. + + test.Printf(_L("ERROR!\n")); + test.Printf(_L("Actually set to ")); + test.Printf(_L("Day %d "),checkDateTime.Day()); + test.Printf(_L("Month %d "),checkDateTime.Month()); + test.Printf(_L("Year %d \n"),checkDateTime.Year()); + // test.Printf(_L("Press any key to continue \n")); + // test.Getch(); + r=TheFs.Delete(_L("Y2KTEST.tst")); + return; + } + else + test(checkDateTime.Year()==aDateTime->Year()); + if (validDate) + { + test(checkDateTime.Month()==aDateTime->Month()); + test(checkDateTime.Day()==aDateTime->Day()); + } + else + { + test(checkDateTime.Month()==aDateTime->Month()+1); + test(checkDateTime.Day()==0); + } + + + check.FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3")); + test.Printf(_L("Valid date: %S\n"),&gDateBuf); + + r=TheFs.Delete(_L("Y2KTEST.tst")); + + } + + +static void testRFileSetModified(TDateTime* aDateTime, TTime* aTime, TBool validDate) +// +// Test RFile::SetModified() and RFile::Modified() +// + { + RFile file; + TInt r=file.Replace(TheFs,_L("Y2KTEST.tst"),0); + test(r==KErrNone || r==KErrPathNotFound); + + r=file.SetModified(*aTime); + test(r==KErrNone); + file.Close(); + + TTime check; + file.Open(TheFs,_L("Y2KTEST.tst"),EFileWrite); + r=file.Modified(check); + test(r==KErrNone); + file.Close(); + + TDateTime checkDateTime=check.DateTime(); + + test(checkDateTime.Year()==aDateTime->Year()); + if (validDate) + { + test(checkDateTime.Month()==aDateTime->Month()); + test(checkDateTime.Day()==aDateTime->Day()); + } + else + { + test(checkDateTime.Month()==aDateTime->Month()+1); + test(checkDateTime.Day()==0); + } + + check.FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3")); + test.Printf(_L("Valid date: %S\n"),&gDateBuf); + + r=TheFs.Delete(_L("Y2KTEST.tst")); + + } + +static void testCFileManAttribsL(TDateTime* aDateTime, TTime* aTime, TBool validDate) +// +// Test CFileMan::Attribs() +// + { + MakeFile(_L("Y2KTEST.tst")); + + CFileMan* fileMan=CFileMan::NewL(TheFs); + + TInt r=fileMan->Attribs(_L("Y2KTEST.tst"),KEntryAttHidden,KEntryAttNormal,*aTime); + test(r==KErrNone); + + TEntry entry; + r=TheFs.Entry(_L("Y2KTEST.tst"),entry); + test(r==KErrNone); + + TTime check=entry.iModified; + TDateTime checkDateTime=check.DateTime(); + + test(checkDateTime.Year()==aDateTime->Year()); + if (validDate) + { + test(checkDateTime.Month()==aDateTime->Month()); + test(checkDateTime.Day()==aDateTime->Day()); + } + else + { + test(checkDateTime.Month()==aDateTime->Month()+1); + test(checkDateTime.Day()==0); + } + + + check.FormatL(gDateBuf,_L("%*D%X%N%Y %1 %2 %3")); + test.Printf(_L("Valid date: %S\n"),&gDateBuf); + + r=TheFs.Delete(_L("Y2KTEST.tst")); + test(r==KErrNone); + + delete fileMan; + } + +// Valid dates to be tested for year 2000 compliance +// Times are always set at 11.11.00 + +LOCAL_D TInt testYearValid[KMaxValidDateTimes] = + { + 1998, // December 31 1998 + 1999, // January 01 1999 + 1999, // February 27 1999 + 1999, // February 28 1999 + 1999, // March 01 1999 + 1999, // August 31 1999 + 1999, // September 01 1999 + 1999, // September 08 1999 + 1999, // September 09 1999 + 1999, // September 09 1999 + 1999, // December 31 1999 + 2000, // January 01 2000 + 2000, // February 27 2000 + 2000, // February 28 2000 + 2000, // February 29 2000 + 2000, // March 01 2000 + 2000, // December 31 2000 + 2001, // January 01 2001 + 2001, // February 28 2001 + 2001, // March 01 2001 + 2004, // February 28 2004 + 2004, // February 29 2004 + 2004, // March 01 2004 + 2098, // January 01 2098 + 2099 // January 01 2099 + }; + +LOCAL_D TMonth testMonthValid[KMaxValidDateTimes] = + { + EDecember, // December 31 1998 + EJanuary, // January 01 1999 + EFebruary, // February 27 1999 + EFebruary, // February 28 1999 + EMarch, // March 01 1999 + EAugust, // August 31 1999 + ESeptember, // September 01 1999 + ESeptember, // September 08 1999 + ESeptember, // September 09 1999 + ESeptember, // September 10 1999 + EDecember, // December 31 1999 + EJanuary, // January 01 2000 + EFebruary, // February 27 2000 + EFebruary, // February 28 2000 + EFebruary, // February 29 2000 + EMarch, // March 01 2000 + EDecember, // December 31 2000 + EJanuary, // January 01 2001 + EFebruary, // February 28 2001 + EMarch, // March 01 2001 + EFebruary, // February 28 2004 + EFebruary, // February 29 2004 + EMarch, // March 01 2004 + EJanuary, // January 01 2098 + EJanuary // January 01 2099 + }; + +LOCAL_D TInt testDayValid[KMaxValidDateTimes] = + { + 30, // December 31 1998 + 0, // January 01 1999 + 26, // February 27 1999 + 27, // February 28 1999 + 0, // March 01 1999 + 30, // August 31 1999 + 0, // September 01 1999 + 7, // September 08 1999 + 8, // September 09 1999 + 8, // September 09 1999 + 30, // December 31 1999 + 0, // January 01 2000 + 26, // February 27 2000 + 27, // February 28 2000 + 28, // February 29 2000 + 0, // March 01 2000 + 30, // December 31 2000 + 0, // January 01 2001 + 27, // February 28 2001 + 0, // March 01 2001 + 27, // February 28 2004 + 28, // February 29 2004 + 0, // March 01 2004 + 0, // January 01 2098 + 0 // January 01 2099 + }; + + +// Invalid dates to be tested for year 2000 compliance +// Times are always set at 11.11.00 + +LOCAL_D TInt testYearInvalid[KMaxInvalidDateTimes] = + { + 1998, // April 31 1998 + 1999, // February 29 1999 + 2000, // February 30 2000 + 2001, // February 29 2001 + 2002, // February 29 2002 + 2003, // February 29 2003 + 2004, // February 30 2004 + }; + +LOCAL_D TMonth testMonthInvalid[KMaxValidDateTimes] = + { + EApril, // April 31 1998 + EFebruary, // February 29 1999 + EFebruary, // February 30 2000 + EFebruary, // February 29 2001 + EFebruary, // February 29 2002 + EFebruary, // February 29 2003 + EFebruary, // February 30 2004 + }; + +LOCAL_D TInt testDayInvalid[KMaxValidDateTimes] = + { + 30, // April 31 1998 + 28, // February 29 1999 + 29, // February 30 2000 + 28, // February 29 2001 + 28, // February 29 2002 + 28, // February 29 2003 + 29, // February 30 2004 + }; + +LOCAL_D TPtrC invalidDates[KMaxValidDateTimes] = + { + _L("31st April 1998"), + _L("29th February 1999"), + _L("30th February 2000"), + _L("29th February 2001"), + _L("29th February 2002"), + _L("29th February 2003"), + _L("30th February 2004"), + }; + + +static void TestValidDates(TDateTime* aDateTime, TTime* aTime) +// +// Test an array of valid dates for year 2000 compliance +// + { + test.Next(_L("Test RFs::SetEntry() and RFs::Entry()")); + + TDateTime* tempDateTime=aDateTime; + TTime* tempTime=aTime; + TInt i=0; + + for (;i