First public contribution.
1 // Copyright (c) 2002-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 // Tests timestamp on files
19 #include <e32std_private.h>
26 RTest test( _L("T_ROFSTIME") );
30 _LIT( KTestFile1, "root.txt" );
31 _LIT( KTestFile2, "Mixed\\par1.txt" );
32 _LIT( KTestFile3, "Mixed\\SubDir1\\sub1.txt" );
33 _LIT( KTestFile4, "Mixed\\SubDir2\\sub2.txt" );
34 _LIT( KTestFile5, "Mixed\\SubDir3\\sub3.txt" );
35 _LIT( KTestFile6, "Mixed\\SubDir4\\sub4.txt" );
36 _LIT( KTestFile7, "Mixed\\SubDir5\\sub5.txt" );
37 _LIT( KTestFile8, "Mixed\\SubDir6\\sub6.txt" );
38 _LIT( KTestFile9, "Mixed\\SubDir7\\sub7.txt" );
39 _LIT( KTestFile10, "Mixed\\SubDir8\\sub8.txt" );
40 _LIT( KTestFile11, "Mixed\\par2.txt" );
41 _LIT( KTestFile12, "Mixed\\par3.txt" );
42 _LIT( KTestFile13, "Mixed\\par4.txt" );
43 _LIT( KTestFile14, "Mixed\\par5.txt" );
44 _LIT( KTestFile15, "Mixed\\par6.txt" );
45 _LIT( KTestFile16, "Mixed\\par7.txt" );
46 _LIT( KTestFile17, "Mixed\\par8.txt" );
47 _LIT( KTestFile18, "ext.txt" );
49 _LIT( KDriveBase, " :\\" );
50 _LIT( KDirectoryScanPath, "Mixed\\*" );
52 //_LIT( KTimeStamp, "23/11/2001 6:44:07" );
54 const TInt KYear = 2001;
55 const TMonth KMonth = ENovember;
56 const TInt KDay = 23 - 1;
58 const TInt KMinute = 44;
59 const TInt KSecond = 7;
61 const TInt KYearExt = 2005;
62 const TMonth KMonthExt = EJune;
63 const TInt KDayExt = 14 - 1;
64 const TInt KHourExt = 20;
65 const TInt KMinuteExt = 12;
66 const TInt KSecondExt = 20;
71 const TDesC* const gTestFileArray[18] =
73 &KTestFile1, &KTestFile2, &KTestFile3, &KTestFile4, &KTestFile5,
74 &KTestFile6, &KTestFile7, &KTestFile8, &KTestFile9, &KTestFile10,
75 &KTestFile11, &KTestFile12, &KTestFile13, &KTestFile14, &KTestFile15,
76 &KTestFile16, &KTestFile17, &KTestFile18
81 LOCAL_C void TestRFileL(TInt aDriveToTest, TBool aExtension)
83 // Tests that file modified timestamp is correct
87 test.Next( _L("Test file modified time") );
88 TFileName name(KDriveBase);
89 name[0] = TText('A' + aDriveToTest);
92 if (aExtension) index =18;
93 for( TInt i = 0; i < index; i++ )
95 name.SetLength( 3 ); // trim back to drive specifier
96 name.Append( *gTestFileArray[i] );
97 test.Printf( _L("Opening file %S"), &name );
99 TInt r = file.Open( TheFs, name, EFileRead );
102 r = file.Modified( mod );
107 TDateTime expected = gTime.DateTime();
108 TDateTime got = mod.DateTime();
109 test.Printf(_L("Times don't match, expected %d-%d-%d %d:%d:%d, read %d-%d-%d %d:%d:%d\n"),
122 test.operator()( EFalse, __LINE__, (TText*)__FILE__ );
131 LOCAL_C void TestDirScanL(TInt aDriveToTest)
133 // Tests that scanning a directory gives correct timestamp for each entry
136 test.Next( _L("Testing directory scan") );
139 TFileName name(KDriveBase);
140 name[0] = TText('A' + aDriveToTest);
141 name.Append( KDirectoryScanPath );
143 TInt r = TheFs.GetDir( name, KEntryAttMaskSupported, ESortNone, dir );
146 for( TInt i = dir->Count() - 1; i > 0; i-- )
148 const TEntry& e = dir->operator[](i);
149 if( e.iModified != gTime )
151 TDateTime expected = gTime.DateTime();
152 TDateTime got = (e.iModified).DateTime();
153 test.Printf(_L("Times don't match, expected %d-%d-%d %d:%d:%d, read %d-%d-%d %d:%d:%d\n"),
166 test.operator()( EFalse, __LINE__, (TText*)__FILE__ );
174 //************************
177 void DoTestL(TInt aDriveToTest)
179 TDateTime dateTime( KYear, KMonth, KDay, KHour, KMinute, KSecond, 0 );
182 test.Start( _L("Testing ROFS timestamp") );
184 test.Printf( _L("Looking for ROFS extension\n"));
185 TBool extension = EFalse;
186 TFileName name(KDriveBase);
187 name[0] = TText('A' + aDriveToTest);
189 name.SetLength( 3 ); // trim back to drive specifier
190 name.Append( KTestFile18 );
193 test.Printf( _L("Opening file %S"), &name );
194 TInt r = file.Open( TheFs, name, EFileRead );
199 dateTime.Set(KYearExt, KMonthExt, KDayExt, KHourExt, KMinuteExt, KSecondExt, 0 );
200 test.Printf( _L("ROFS extension found\n"));
202 else if(r==KErrNotFound)
204 test.Printf( _L("Not found, ROFS extension not present\n"));
207 gTime = TTime( dateTime );
209 TestRFileL(aDriveToTest, extension);
210 TestDirScanL(aDriveToTest);