|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Tests timestamp on files |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32std_private.h> |
|
20 #include <e32test.h> |
|
21 #include <f32file.h> |
|
22 #include "utl.h" |
|
23 |
|
24 GLREF_D RFs TheFs; |
|
25 |
|
26 RTest test( _L("T_ROFSTIME") ); |
|
27 |
|
28 |
|
29 |
|
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" ); |
|
48 |
|
49 _LIT( KDriveBase, " :\\" ); |
|
50 _LIT( KDirectoryScanPath, "Mixed\\*" ); |
|
51 |
|
52 //_LIT( KTimeStamp, "23/11/2001 6:44:07" ); |
|
53 |
|
54 const TInt KYear = 2001; |
|
55 const TMonth KMonth = ENovember; |
|
56 const TInt KDay = 23 - 1; |
|
57 const TInt KHour = 6; |
|
58 const TInt KMinute = 44; |
|
59 const TInt KSecond = 7; |
|
60 |
|
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; |
|
67 |
|
68 TTime gTime; |
|
69 |
|
70 |
|
71 const TDesC* const gTestFileArray[18] = |
|
72 { |
|
73 &KTestFile1, &KTestFile2, &KTestFile3, &KTestFile4, &KTestFile5, |
|
74 &KTestFile6, &KTestFile7, &KTestFile8, &KTestFile9, &KTestFile10, |
|
75 &KTestFile11, &KTestFile12, &KTestFile13, &KTestFile14, &KTestFile15, |
|
76 &KTestFile16, &KTestFile17, &KTestFile18 |
|
77 }; |
|
78 |
|
79 |
|
80 |
|
81 LOCAL_C void TestRFileL(TInt aDriveToTest, TBool aExtension) |
|
82 // |
|
83 // Tests that file modified timestamp is correct |
|
84 // |
|
85 { |
|
86 |
|
87 test.Next( _L("Test file modified time") ); |
|
88 TFileName name(KDriveBase); |
|
89 name[0] = TText('A' + aDriveToTest); |
|
90 |
|
91 TInt index =17; |
|
92 if (aExtension) index =18; |
|
93 for( TInt i = 0; i < index; i++ ) |
|
94 { |
|
95 name.SetLength( 3 ); // trim back to drive specifier |
|
96 name.Append( *gTestFileArray[i] ); |
|
97 test.Printf( _L("Opening file %S"), &name ); |
|
98 RFile file; |
|
99 TInt r = file.Open( TheFs, name, EFileRead ); |
|
100 TEST_FOR_ERROR( r ); |
|
101 TTime mod; |
|
102 r = file.Modified( mod ); |
|
103 TEST_FOR_ERROR( r ); |
|
104 |
|
105 if( mod != gTime ) |
|
106 { |
|
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"), |
|
110 expected.Day()+1, |
|
111 expected.Month()+1, |
|
112 expected.Year(), |
|
113 expected.Hour(), |
|
114 expected.Minute(), |
|
115 expected.Second(), |
|
116 got.Day()+1, |
|
117 got.Month()+1, |
|
118 got.Year(), |
|
119 got.Hour(), |
|
120 got.Minute(), |
|
121 got.Second() ); |
|
122 test.operator()( EFalse, __LINE__, (TText*)__FILE__ ); |
|
123 } |
|
124 file.Close(); |
|
125 } |
|
126 } |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 LOCAL_C void TestDirScanL(TInt aDriveToTest) |
|
132 // |
|
133 // Tests that scanning a directory gives correct timestamp for each entry |
|
134 // |
|
135 { |
|
136 test.Next( _L("Testing directory scan") ); |
|
137 CDir* dir; |
|
138 |
|
139 TFileName name(KDriveBase); |
|
140 name[0] = TText('A' + aDriveToTest); |
|
141 name.Append( KDirectoryScanPath ); |
|
142 |
|
143 TInt r = TheFs.GetDir( name, KEntryAttMaskSupported, ESortNone, dir ); |
|
144 TEST_FOR_ERROR( r ); |
|
145 |
|
146 for( TInt i = dir->Count() - 1; i > 0; i-- ) |
|
147 { |
|
148 const TEntry& e = dir->operator[](i); |
|
149 if( e.iModified != gTime ) |
|
150 { |
|
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"), |
|
154 expected.Day()+1, |
|
155 expected.Month()+1, |
|
156 expected.Year(), |
|
157 expected.Hour(), |
|
158 expected.Minute(), |
|
159 expected.Second(), |
|
160 got.Day()+1, |
|
161 got.Month()+1, |
|
162 got.Year(), |
|
163 got.Hour(), |
|
164 got.Minute(), |
|
165 got.Second() ); |
|
166 test.operator()( EFalse, __LINE__, (TText*)__FILE__ ); |
|
167 } |
|
168 } |
|
169 delete dir; |
|
170 } |
|
171 |
|
172 |
|
173 |
|
174 //************************ |
|
175 // Entry point |
|
176 |
|
177 void DoTestL(TInt aDriveToTest) |
|
178 { |
|
179 TDateTime dateTime( KYear, KMonth, KDay, KHour, KMinute, KSecond, 0 ); |
|
180 |
|
181 test.Title(); |
|
182 test.Start( _L("Testing ROFS timestamp") ); |
|
183 |
|
184 test.Printf( _L("Looking for ROFS extension\n")); |
|
185 TBool extension = EFalse; |
|
186 TFileName name(KDriveBase); |
|
187 name[0] = TText('A' + aDriveToTest); |
|
188 |
|
189 name.SetLength( 3 ); // trim back to drive specifier |
|
190 name.Append( KTestFile18 ); |
|
191 |
|
192 RFile file; |
|
193 test.Printf( _L("Opening file %S"), &name ); |
|
194 TInt r = file.Open( TheFs, name, EFileRead ); |
|
195 if(r==KErrNone) |
|
196 { |
|
197 extension=ETrue; |
|
198 file.Close(); |
|
199 dateTime.Set(KYearExt, KMonthExt, KDayExt, KHourExt, KMinuteExt, KSecondExt, 0 ); |
|
200 test.Printf( _L("ROFS extension found\n")); |
|
201 } |
|
202 else if(r==KErrNotFound) |
|
203 { |
|
204 test.Printf( _L("Not found, ROFS extension not present\n")); |
|
205 } |
|
206 |
|
207 gTime = TTime( dateTime ); |
|
208 |
|
209 TestRFileL(aDriveToTest, extension); |
|
210 TestDirScanL(aDriveToTest); |
|
211 |
|
212 test.End(); |
|
213 } |