sl@0
|
1 |
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// f32test\fat32\t_compat32.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#define __E32TEST_EXTENSION__
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <f32file.h>
|
sl@0
|
21 |
#include <e32svr.h>
|
sl@0
|
22 |
#include <e32test.h>
|
sl@0
|
23 |
#include <f32dbg.h>
|
sl@0
|
24 |
#include "t_server.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
#include "fat_utils.h"
|
sl@0
|
27 |
using namespace Fat_Test_Utils;
|
sl@0
|
28 |
|
sl@0
|
29 |
RTest test(_L("T_COMPAT32"));
|
sl@0
|
30 |
|
sl@0
|
31 |
static RRawDisk TheDisk;
|
sl@0
|
32 |
static TFatBootSector gBootSector;
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
static void QuickFormat()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
FormatFatDrive(TheFs, CurrentDrive(), ETrue);
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
static void ReadBootSector(TFatBootSector& aBootSector)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
|
sl@0
|
43 |
TInt nRes = ReadBootSector(TheFs, CurrentDrive(), KBootSectorNum<<KDefaultSectorLog2, aBootSector);
|
sl@0
|
44 |
test(nRes == KErrNone);
|
sl@0
|
45 |
|
sl@0
|
46 |
if(!aBootSector.IsValid())
|
sl@0
|
47 |
{
|
sl@0
|
48 |
test.Printf(_L("Wrong bootsector! Dump:\n"));
|
sl@0
|
49 |
aBootSector.PrintDebugInfo();
|
sl@0
|
50 |
test(0);
|
sl@0
|
51 |
}
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
|
sl@0
|
55 |
static void GetBootInfo()
|
sl@0
|
56 |
{
|
sl@0
|
57 |
QuickFormat();
|
sl@0
|
58 |
ReadBootSector(gBootSector);
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
enum TNameCase
|
sl@0
|
62 |
{
|
sl@0
|
63 |
EUpper, // Test directory entries with 8.3 uppercase (no VFAT entries expected)
|
sl@0
|
64 |
ELower, // Test directory entries with 8.3 lowercase ( VFAT entries expected)
|
sl@0
|
65 |
EMixed // Test directory entries with 8.3 mixed ( VFAT entries expected)
|
sl@0
|
66 |
};
|
sl@0
|
67 |
|
sl@0
|
68 |
|
sl@0
|
69 |
/**
|
sl@0
|
70 |
Fiddles with root directory entries.
|
sl@0
|
71 |
Creates a file, if it has 1 VFAT and 1 DOS dir. entries, places an illegal lower case
|
sl@0
|
72 |
symbol to the DOS entry, fixing VFAT name checksums
|
sl@0
|
73 |
*/
|
sl@0
|
74 |
static void DoFiddleWithFileNames(TNameCase aCase)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
TFileName fileName = _L("\\WORD");
|
sl@0
|
77 |
TBool expectVfatEntry = EFalse;
|
sl@0
|
78 |
|
sl@0
|
79 |
switch(aCase)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
case EUpper:
|
sl@0
|
82 |
break;
|
sl@0
|
83 |
|
sl@0
|
84 |
case ELower:
|
sl@0
|
85 |
fileName = _L("\\word");
|
sl@0
|
86 |
expectVfatEntry = ETrue;
|
sl@0
|
87 |
break;
|
sl@0
|
88 |
|
sl@0
|
89 |
case EMixed:
|
sl@0
|
90 |
fileName = _L("\\WoRd");
|
sl@0
|
91 |
expectVfatEntry = ETrue;
|
sl@0
|
92 |
break;
|
sl@0
|
93 |
|
sl@0
|
94 |
default:
|
sl@0
|
95 |
test(0);
|
sl@0
|
96 |
break;
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
RFile file;
|
sl@0
|
100 |
TInt r=file.Create(TheFs,fileName,EFileRead);
|
sl@0
|
101 |
test(r==KErrNone);
|
sl@0
|
102 |
file.Close();
|
sl@0
|
103 |
// Assume this file is the first entry in the root directory
|
sl@0
|
104 |
|
sl@0
|
105 |
|
sl@0
|
106 |
r=TheDisk.Open(TheFs,CurrentDrive());
|
sl@0
|
107 |
test(r==KErrNone);
|
sl@0
|
108 |
|
sl@0
|
109 |
//-- read 1st dir. entry it can be FAT or VFat , depending on the filename
|
sl@0
|
110 |
const TInt posEntry1=gBootSector.RootDirStartSector() << KDefaultSectorLog2; //-- dir entry1 position
|
sl@0
|
111 |
|
sl@0
|
112 |
TFatDirEntry fatEntry1;
|
sl@0
|
113 |
TPtr8 ptrEntry1((TUint8*)&fatEntry1,sizeof(TFatDirEntry));
|
sl@0
|
114 |
|
sl@0
|
115 |
test(TheDisk.Read(posEntry1, ptrEntry1)==KErrNone);
|
sl@0
|
116 |
|
sl@0
|
117 |
if(!fatEntry1.IsVFatEntry())
|
sl@0
|
118 |
{//-- we expected FAT entry, everything is OK
|
sl@0
|
119 |
test(!expectVfatEntry);
|
sl@0
|
120 |
}
|
sl@0
|
121 |
else
|
sl@0
|
122 |
{//-- we have 2 FAT entries, 1st is VFat, 2nd is DOS.
|
sl@0
|
123 |
//-- put lower case letters into DOS entry( not compliant with FAT specs), correct VFat entries checksums,
|
sl@0
|
124 |
//-- in this case the system shall correctly deal with the file, using long names.
|
sl@0
|
125 |
|
sl@0
|
126 |
test(expectVfatEntry);
|
sl@0
|
127 |
test(fatEntry1.iData[0] == 0x41); //-- must have only 2 entries
|
sl@0
|
128 |
|
sl@0
|
129 |
//-- read DOS entry now
|
sl@0
|
130 |
TFatDirEntry fatEntry2;
|
sl@0
|
131 |
TPtr8 ptrEntry2((TUint8*)&fatEntry2,sizeof(TFatDirEntry));
|
sl@0
|
132 |
const TInt posEntry2 = posEntry1 + sizeof(TFatDirEntry); //-- dir entry2 position
|
sl@0
|
133 |
|
sl@0
|
134 |
test(TheDisk.Read(posEntry2, ptrEntry2)==KErrNone);
|
sl@0
|
135 |
|
sl@0
|
136 |
//-- ensure that the name and checksum are correct
|
sl@0
|
137 |
test(fatEntry1.iData[13] == CalculateShortNameCheckSum(fatEntry2.Name()));
|
sl@0
|
138 |
test(fatEntry2.Name()==_L8("WORD "));
|
sl@0
|
139 |
|
sl@0
|
140 |
//-- put lower case symbol to the DOS entry and fix the checksum
|
sl@0
|
141 |
_LIT8(KBadDosName, "Word ");
|
sl@0
|
142 |
fatEntry2.SetName(KBadDosName);
|
sl@0
|
143 |
fatEntry1.iData[13] = CalculateShortNameCheckSum(fatEntry2.Name());
|
sl@0
|
144 |
|
sl@0
|
145 |
//-- write data to the disk
|
sl@0
|
146 |
test(TheDisk.Write(posEntry1, ptrEntry1)==KErrNone);
|
sl@0
|
147 |
test(TheDisk.Write(posEntry2, ptrEntry2)==KErrNone);
|
sl@0
|
148 |
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
TheDisk.Close();
|
sl@0
|
152 |
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
//
|
sl@0
|
156 |
// Replace a 8.3 filename with upper and lower case letters which is, actually out of FAT specs.
|
sl@0
|
157 |
// I.e. VFAT entries are valid, but DOS entry has a lower case symbol, which is wrong.
|
sl@0
|
158 |
//
|
sl@0
|
159 |
LOCAL_C void Test1(TNameCase aCase)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
test.Next(_L("Replace a file with a wrong DOS entry"));
|
sl@0
|
162 |
QuickFormat();
|
sl@0
|
163 |
|
sl@0
|
164 |
//-- N.B. This shall be the before any dir. entries creation in the root directory
|
sl@0
|
165 |
//-- because it directly accesses the directory's 1st file
|
sl@0
|
166 |
DoFiddleWithFileNames(aCase);
|
sl@0
|
167 |
|
sl@0
|
168 |
RFile file;
|
sl@0
|
169 |
TInt r;
|
sl@0
|
170 |
|
sl@0
|
171 |
r=file.Replace(TheFs,_L("\\FILE.TMP"),EFileRead);
|
sl@0
|
172 |
test(r==KErrNone);
|
sl@0
|
173 |
r=file.Write(_L8("Hello World"));
|
sl@0
|
174 |
file.Close();
|
sl@0
|
175 |
|
sl@0
|
176 |
r=TheFs.Replace(_L("\\File.tmp"),_L("\\Word"));
|
sl@0
|
177 |
test(r==KErrNone);
|
sl@0
|
178 |
|
sl@0
|
179 |
CDir* entryCount;
|
sl@0
|
180 |
r=TheFs.GetDir(_L("\\*.*"),KEntryAttMaskSupported,ESortNone,entryCount);
|
sl@0
|
181 |
test(r==KErrNone);
|
sl@0
|
182 |
TInt count=entryCount->Count();
|
sl@0
|
183 |
|
sl@0
|
184 |
test(count==1);
|
sl@0
|
185 |
delete entryCount;
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
|
sl@0
|
189 |
//
|
sl@0
|
190 |
// Renaming a 8.3 filename with upper and lower case letters which is, actually out of FAT specs.
|
sl@0
|
191 |
// I.e. VFAT entries are valid, but DOS entry has a lower case symbol, which is wrong.
|
sl@0
|
192 |
//
|
sl@0
|
193 |
LOCAL_C void Test2(TNameCase aCase)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
test.Next(_L("Rename a file with a wrong DOS entry"));
|
sl@0
|
196 |
QuickFormat();
|
sl@0
|
197 |
RFile file;
|
sl@0
|
198 |
TInt r;
|
sl@0
|
199 |
|
sl@0
|
200 |
//-- N.B. This shall be the before any dir. entries creation in the root dir
|
sl@0
|
201 |
//-- because it directly accesses the directory's 1st file
|
sl@0
|
202 |
DoFiddleWithFileNames(aCase);
|
sl@0
|
203 |
|
sl@0
|
204 |
r=file.Create(TheFs,_L("\\TEST"),EFileRead);
|
sl@0
|
205 |
test(r==KErrNone);
|
sl@0
|
206 |
file.Close();
|
sl@0
|
207 |
|
sl@0
|
208 |
r=TheFs.Rename(_L("\\TEST"),_L("\\Word"));
|
sl@0
|
209 |
test(r==KErrAlreadyExists);
|
sl@0
|
210 |
r=TheFs.Delete(_L("\\TEST"));
|
sl@0
|
211 |
test(r==KErrNone);
|
sl@0
|
212 |
|
sl@0
|
213 |
CDir* entryCount;
|
sl@0
|
214 |
r=TheFs.GetDir(_L("\\*.*"),KEntryAttMaskSupported,ESortNone,entryCount);
|
sl@0
|
215 |
test(r==KErrNone);
|
sl@0
|
216 |
TInt count=entryCount->Count();
|
sl@0
|
217 |
test(count==1);
|
sl@0
|
218 |
delete entryCount;
|
sl@0
|
219 |
}
|
sl@0
|
220 |
|
sl@0
|
221 |
|
sl@0
|
222 |
//---------------------------------------------
|
sl@0
|
223 |
//! @SYMTestCaseID PBASE-T_COMPAT32-0686
|
sl@0
|
224 |
//! @SYMTestType CT
|
sl@0
|
225 |
//! @SYMREQ DEF115314
|
sl@0
|
226 |
//! @SYMTestCaseDesc Test character '`' (0x60) is recognized as a legal char for short file names.
|
sl@0
|
227 |
//! @SYMTestActions Creates a file named "\x60\x60\x60.TXT", checks only DOS entry is created for
|
sl@0
|
228 |
//! it and its short name equals "```.TXT" instead of "___.TXT"
|
sl@0
|
229 |
//! @SYMTestExpectedResults The operation completes with error code KErrNone;
|
sl@0
|
230 |
//! @SYMTestPriority High
|
sl@0
|
231 |
//! @SYMTestStatus Implemented
|
sl@0
|
232 |
//---------------------------------------------
|
sl@0
|
233 |
void TestDEF115314()
|
sl@0
|
234 |
{
|
sl@0
|
235 |
test.Next(_L("Test DEF115314: TTG:<`(0x60) code cannot be used as valid Short File Name>"));
|
sl@0
|
236 |
QuickFormat();
|
sl@0
|
237 |
RFile file;
|
sl@0
|
238 |
TInt r;
|
sl@0
|
239 |
|
sl@0
|
240 |
TFileName fn;
|
sl@0
|
241 |
fn.Format(_L("%c:\\\x60\x60\x60.TXT"), (TUint8)gDriveToTest);
|
sl@0
|
242 |
|
sl@0
|
243 |
r = TheFs.Delete(fn);
|
sl@0
|
244 |
test(r==KErrNone || r==KErrNotFound);
|
sl@0
|
245 |
|
sl@0
|
246 |
r = file.Create(TheFs, fn, EFileRead);
|
sl@0
|
247 |
test(r==KErrNone);
|
sl@0
|
248 |
file.Close();
|
sl@0
|
249 |
|
sl@0
|
250 |
r=TheDisk.Open(TheFs,CurrentDrive());
|
sl@0
|
251 |
test(r==KErrNone);
|
sl@0
|
252 |
|
sl@0
|
253 |
//-- read 1st dir. it should be DOS Entry
|
sl@0
|
254 |
const TInt posEntry1=gBootSector.RootDirStartSector() << KDefaultSectorLog2; //-- dir entry1 position
|
sl@0
|
255 |
TFatDirEntry fatEntry1;
|
sl@0
|
256 |
TPtr8 ptrEntry1((TUint8*)&fatEntry1,sizeof(TFatDirEntry));
|
sl@0
|
257 |
test(TheDisk.Read(posEntry1, ptrEntry1)==KErrNone);
|
sl@0
|
258 |
TheDisk.Close();
|
sl@0
|
259 |
test(!fatEntry1.IsVFatEntry());
|
sl@0
|
260 |
|
sl@0
|
261 |
// tests short name
|
sl@0
|
262 |
TFileName sn;
|
sl@0
|
263 |
r = TheFs.GetShortName(fn, sn);
|
sl@0
|
264 |
test(r==KErrNone);
|
sl@0
|
265 |
test(sn.Compare(_L("```.TXT"))==0);
|
sl@0
|
266 |
|
sl@0
|
267 |
r = TheFs.Delete(fn);
|
sl@0
|
268 |
test(r==KErrNone);
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
sl@0
|
272 |
_LIT(KTestLocale, "t_tlocl_cp932.dll");
|
sl@0
|
273 |
_LIT(KTestUnicodeFileName, "\\\x65B0\x6587\x4EF6");
|
sl@0
|
274 |
#endif //_DEBUG || _DEBUG_RELEASE
|
sl@0
|
275 |
|
sl@0
|
276 |
//---------------------------------------------
|
sl@0
|
277 |
//! @SYMTestCaseID PBASE-T_COMPAT32-0685
|
sl@0
|
278 |
//! @SYMTestType CT
|
sl@0
|
279 |
//! @SYMREQ DEF113633
|
sl@0
|
280 |
//! @SYMTestCaseDesc Test FAT volume creates VFat entries for short unicode named files
|
sl@0
|
281 |
//! @SYMTestActions Enables FatUtilityFunctions. Loads cp932 codepage dll. Create a file
|
sl@0
|
282 |
//! named as "\x65B0\x6587\x4EF6", checks both a VFat entry and a DOS
|
sl@0
|
283 |
//! entry have been created for the file.
|
sl@0
|
284 |
//! @SYMTestExpectedResults The operation completes with error code KErrNone;
|
sl@0
|
285 |
//! @SYMTestPriority High
|
sl@0
|
286 |
//! @SYMTestStatus Implemented
|
sl@0
|
287 |
//---------------------------------------------
|
sl@0
|
288 |
void TestDEF113633()
|
sl@0
|
289 |
{
|
sl@0
|
290 |
test.Next(_L("Test DEF113633 - FAT should create VFat entries for unicode character contained file names"));
|
sl@0
|
291 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
sl@0
|
292 |
QuickFormat();
|
sl@0
|
293 |
RFile file;
|
sl@0
|
294 |
TInt r;
|
sl@0
|
295 |
TInt drvNum;
|
sl@0
|
296 |
|
sl@0
|
297 |
r = TheFs.CharToDrive(gDriveToTest,drvNum);
|
sl@0
|
298 |
test(r==KErrNone);
|
sl@0
|
299 |
|
sl@0
|
300 |
// turn on FatUtilityFunctions
|
sl@0
|
301 |
r = TheFs.ControlIo(drvNum, KControlIoEnableFatUtilityFunctions);
|
sl@0
|
302 |
test(r==KErrNone);
|
sl@0
|
303 |
|
sl@0
|
304 |
// load cp932 codepage dll
|
sl@0
|
305 |
r = UserSvr::ChangeLocale(KTestLocale);
|
sl@0
|
306 |
test(r==KErrNone);
|
sl@0
|
307 |
|
sl@0
|
308 |
// create file "\x65B0\x6587\x4EF6", check DOS entry & VFat entry
|
sl@0
|
309 |
r = file.Create(TheFs, KTestUnicodeFileName, EFileRead);
|
sl@0
|
310 |
test(r==KErrNone);
|
sl@0
|
311 |
file.Close();
|
sl@0
|
312 |
|
sl@0
|
313 |
r=TheDisk.Open(TheFs,CurrentDrive());
|
sl@0
|
314 |
test(r==KErrNone);
|
sl@0
|
315 |
|
sl@0
|
316 |
//-- read 1st dir. it should be VFat
|
sl@0
|
317 |
// const TInt posEntry1=gRootDirStart; //-- dir entry1 position
|
sl@0
|
318 |
const TInt posEntry1=gBootSector.RootDirStartSector() << KDefaultSectorLog2; //-- dir entry1 position
|
sl@0
|
319 |
TFatDirEntry fatEntry1;
|
sl@0
|
320 |
TPtr8 ptrEntry1((TUint8*)&fatEntry1,sizeof(TFatDirEntry));
|
sl@0
|
321 |
|
sl@0
|
322 |
test(TheDisk.Read(posEntry1, ptrEntry1)==KErrNone);
|
sl@0
|
323 |
|
sl@0
|
324 |
test(fatEntry1.IsVFatEntry());
|
sl@0
|
325 |
|
sl@0
|
326 |
test(fatEntry1.iData[0] == 0x41); //-- must have only 2 entries
|
sl@0
|
327 |
|
sl@0
|
328 |
//-- read DOS entry now
|
sl@0
|
329 |
TFatDirEntry fatEntry2;
|
sl@0
|
330 |
TPtr8 ptrEntry2((TUint8*)&fatEntry2,sizeof(TFatDirEntry));
|
sl@0
|
331 |
const TInt posEntry2 = posEntry1 + sizeof(TFatDirEntry); //-- dir entry2 position
|
sl@0
|
332 |
|
sl@0
|
333 |
test(TheDisk.Read(posEntry2, ptrEntry2)==KErrNone);
|
sl@0
|
334 |
|
sl@0
|
335 |
//-- ensure that the name and checksum are correct
|
sl@0
|
336 |
test(!fatEntry2.IsVFatEntry());
|
sl@0
|
337 |
test(fatEntry1.iData[13] == CalculateShortNameCheckSum(fatEntry2.Name()));
|
sl@0
|
338 |
|
sl@0
|
339 |
// delete file
|
sl@0
|
340 |
TheDisk.Close();
|
sl@0
|
341 |
r = TheFs.Delete(KTestUnicodeFileName);
|
sl@0
|
342 |
test(r==KErrNone);
|
sl@0
|
343 |
|
sl@0
|
344 |
// turn off FatUtilityFunctions
|
sl@0
|
345 |
r = TheFs.ControlIo(drvNum, KControlIoDisableFatUtilityFunctions);
|
sl@0
|
346 |
test(r==KErrNone);
|
sl@0
|
347 |
|
sl@0
|
348 |
#else
|
sl@0
|
349 |
test.Printf(_L("Test only runs on DEBUG builds, see test logs of debug builds for details."));
|
sl@0
|
350 |
#endif // _DEBUG) || _DEBUG_RELEASE
|
sl@0
|
351 |
}
|
sl@0
|
352 |
|
sl@0
|
353 |
|
sl@0
|
354 |
|
sl@0
|
355 |
|
sl@0
|
356 |
//---------------------------------------------
|
sl@0
|
357 |
// If the parent directory of a directory is the root directory,
|
sl@0
|
358 |
// the '..' entry should point to start cluster 0 in any case
|
sl@0
|
359 |
//---------------------------------------------
|
sl@0
|
360 |
void TestPDEF116912()
|
sl@0
|
361 |
{
|
sl@0
|
362 |
test.Next(_L("Test PDEF116912 - Check that '..' parent cluster address is 0 after renaming\n"));
|
sl@0
|
363 |
|
sl@0
|
364 |
TInt drvNum;
|
sl@0
|
365 |
test(KErrNone == TheFs.CharToDrive(gDriveToTest, drvNum));
|
sl@0
|
366 |
|
sl@0
|
367 |
if(!Is_Fat32(TheFs, drvNum))
|
sl@0
|
368 |
{
|
sl@0
|
369 |
_LIT(KMessage, "Test only applicable to FAT32 file systems. Skipping.\n");
|
sl@0
|
370 |
test.Printf(KMessage);
|
sl@0
|
371 |
return;
|
sl@0
|
372 |
}
|
sl@0
|
373 |
|
sl@0
|
374 |
QuickFormat();
|
sl@0
|
375 |
|
sl@0
|
376 |
_LIT(KDirA, "\\dirA\\");
|
sl@0
|
377 |
_LIT(KDirB, "\\dirB\\");
|
sl@0
|
378 |
|
sl@0
|
379 |
test(KErrNone == TheFs.MkDir(KDirA));
|
sl@0
|
380 |
test(KErrNone == TheFs.Rename(KDirA, KDirB));
|
sl@0
|
381 |
|
sl@0
|
382 |
test(gBootSector.IsValid());
|
sl@0
|
383 |
TInt mediaPosition = gBootSector.RootDirStartSector() * gBootSector.BytesPerSector();
|
sl@0
|
384 |
|
sl@0
|
385 |
TFatDirEntry dirEntry;
|
sl@0
|
386 |
TPtr8 ptrEntry((TUint8*) &dirEntry,sizeof(TFatDirEntry));
|
sl@0
|
387 |
|
sl@0
|
388 |
_LIT8(KDirBMatchPattern, "DIRB *");
|
sl@0
|
389 |
_LIT8(KDotDotMatchPattern, ".. *");
|
sl@0
|
390 |
|
sl@0
|
391 |
const TInt KMaxEntriesToSearch = (gBootSector.SectorsPerCluster() * gBootSector.BytesPerSector()) / KSizeOfFatDirEntry;
|
sl@0
|
392 |
test(KErrNone == TheDisk.Open(TheFs, drvNum));
|
sl@0
|
393 |
|
sl@0
|
394 |
for(TInt c = 0; c < KMaxEntriesToSearch; c++)
|
sl@0
|
395 |
{
|
sl@0
|
396 |
test(KErrNone == TheDisk.Read(mediaPosition, ptrEntry));
|
sl@0
|
397 |
|
sl@0
|
398 |
if(KErrNotFound == ptrEntry.Match(KDirBMatchPattern))
|
sl@0
|
399 |
{
|
sl@0
|
400 |
// keep scanning
|
sl@0
|
401 |
mediaPosition += sizeof(TFatDirEntry);
|
sl@0
|
402 |
}
|
sl@0
|
403 |
else
|
sl@0
|
404 |
{
|
sl@0
|
405 |
// found, locate '..' entry
|
sl@0
|
406 |
test(dirEntry.StartCluster() >= KFatFirstSearchCluser);
|
sl@0
|
407 |
mediaPosition = gBootSector.FirstDataSector();
|
sl@0
|
408 |
mediaPosition += (dirEntry.StartCluster() - KFatFirstSearchCluser) * gBootSector.SectorsPerCluster();
|
sl@0
|
409 |
mediaPosition *= gBootSector.BytesPerSector();
|
sl@0
|
410 |
mediaPosition += KSizeOfFatDirEntry; // '..' is always the 2nd entry
|
sl@0
|
411 |
|
sl@0
|
412 |
test(KErrNone == TheDisk.Read(mediaPosition, ptrEntry));
|
sl@0
|
413 |
|
sl@0
|
414 |
test(KErrNotFound != ptrEntry.Match(KDotDotMatchPattern));
|
sl@0
|
415 |
test(dirEntry.StartCluster() == 0);
|
sl@0
|
416 |
|
sl@0
|
417 |
TheDisk.Close();
|
sl@0
|
418 |
return;
|
sl@0
|
419 |
}
|
sl@0
|
420 |
}
|
sl@0
|
421 |
|
sl@0
|
422 |
// dirB entry not found - test failed
|
sl@0
|
423 |
TheDisk.Close();
|
sl@0
|
424 |
test(0);
|
sl@0
|
425 |
}
|
sl@0
|
426 |
|
sl@0
|
427 |
//---------------------------------------------
|
sl@0
|
428 |
/**
|
sl@0
|
429 |
Test replacing files by theis short names
|
sl@0
|
430 |
*/
|
sl@0
|
431 |
void TestReplaceByShortName()
|
sl@0
|
432 |
{
|
sl@0
|
433 |
test.Next(_L("Test replacing files using short names\n"));
|
sl@0
|
434 |
QuickFormat();
|
sl@0
|
435 |
|
sl@0
|
436 |
_LIT(KLongName1, "abcdefghi.txt");
|
sl@0
|
437 |
_LIT(KShortName1, "ABCDEF~1.TXT");
|
sl@0
|
438 |
const TInt KFile1Sz = 100;
|
sl@0
|
439 |
|
sl@0
|
440 |
_LIT(KLongName2, "abcdefghij.txt");
|
sl@0
|
441 |
_LIT(KShortName2, "ABCDEF~2.TXT");
|
sl@0
|
442 |
const TInt KFile2Sz = 200;
|
sl@0
|
443 |
|
sl@0
|
444 |
|
sl@0
|
445 |
TInt nRes;
|
sl@0
|
446 |
TFileName fn;
|
sl@0
|
447 |
TEntry entry;
|
sl@0
|
448 |
|
sl@0
|
449 |
TheFs.SetSessionPath(_L("\\"));
|
sl@0
|
450 |
|
sl@0
|
451 |
nRes = CreateCheckableStuffedFile(TheFs, KLongName1, KFile1Sz);
|
sl@0
|
452 |
test_KErrNone(nRes);
|
sl@0
|
453 |
|
sl@0
|
454 |
nRes = TheFs.GetShortName(KLongName1, fn);
|
sl@0
|
455 |
test(nRes == KErrNone && fn == KShortName1); //-- just check short name generation
|
sl@0
|
456 |
|
sl@0
|
457 |
nRes =CreateCheckableStuffedFile(TheFs, KLongName2, KFile2Sz);
|
sl@0
|
458 |
test_KErrNone(nRes);
|
sl@0
|
459 |
|
sl@0
|
460 |
nRes = TheFs.GetShortName(KLongName2, fn);
|
sl@0
|
461 |
test(nRes == KErrNone && fn == KShortName2); //-- just check short name generation
|
sl@0
|
462 |
|
sl@0
|
463 |
//-- try to replace the file with itself using its short name alias
|
sl@0
|
464 |
//-- nothing shall happen and the file must remain the same
|
sl@0
|
465 |
nRes = TheFs.Replace(KLongName1, KShortName1);
|
sl@0
|
466 |
test(nRes == KErrNone);
|
sl@0
|
467 |
|
sl@0
|
468 |
nRes = TheFs.Entry(KLongName1, entry);
|
sl@0
|
469 |
test(nRes == KErrNone);
|
sl@0
|
470 |
test(entry.iSize == KFile1Sz);
|
sl@0
|
471 |
|
sl@0
|
472 |
nRes = TheFs.Entry(KShortName1, entry);
|
sl@0
|
473 |
test(nRes == KErrNone);
|
sl@0
|
474 |
test(entry.iSize == KFile1Sz);
|
sl@0
|
475 |
|
sl@0
|
476 |
|
sl@0
|
477 |
nRes = TheFs.Replace(KShortName1, KLongName1);
|
sl@0
|
478 |
test(nRes == KErrNone);
|
sl@0
|
479 |
|
sl@0
|
480 |
nRes = TheFs.Entry(KLongName1, entry);
|
sl@0
|
481 |
test(nRes == KErrNone);
|
sl@0
|
482 |
test(entry.iSize == KFile1Sz);
|
sl@0
|
483 |
|
sl@0
|
484 |
nRes = TheFs.Entry(KShortName1, entry);
|
sl@0
|
485 |
test(nRes == KErrNone);
|
sl@0
|
486 |
test(entry.iSize == KFile1Sz);
|
sl@0
|
487 |
|
sl@0
|
488 |
nRes = VerifyCheckableFile(TheFs, KLongName1);
|
sl@0
|
489 |
test(nRes == KErrNone);
|
sl@0
|
490 |
|
sl@0
|
491 |
nRes = VerifyCheckableFile(TheFs, KShortName1);
|
sl@0
|
492 |
test(nRes == KErrNone);
|
sl@0
|
493 |
|
sl@0
|
494 |
|
sl@0
|
495 |
//-- replace "abcdefghi.txt" by "ABCDEF~2.TXT" which is the alias for "abcdefghij.txt"
|
sl@0
|
496 |
//-- expected: contents and all attributes of the "abcdefghij.txt" is replaced with "abcdefghi.txt"
|
sl@0
|
497 |
//-- "abcdefghi.txt" entries gets deleted.
|
sl@0
|
498 |
|
sl@0
|
499 |
nRes = TheFs.Replace(KLongName1, KShortName2);
|
sl@0
|
500 |
test(nRes == KErrNone);
|
sl@0
|
501 |
|
sl@0
|
502 |
//User::After(5*K1Sec);
|
sl@0
|
503 |
/*
|
sl@0
|
504 |
nRes = VerifyCheckableFile(TheFs, KLongName2);
|
sl@0
|
505 |
test(nRes == KErrNone);
|
sl@0
|
506 |
|
sl@0
|
507 |
nRes = VerifyCheckableFile(TheFs, KShortName2);
|
sl@0
|
508 |
test(nRes == KErrNone);
|
sl@0
|
509 |
*/
|
sl@0
|
510 |
|
sl@0
|
511 |
|
sl@0
|
512 |
nRes = TheFs.Entry(KLongName2, entry);
|
sl@0
|
513 |
test(nRes == KErrNone);
|
sl@0
|
514 |
test(entry.iSize == KFile1Sz);
|
sl@0
|
515 |
|
sl@0
|
516 |
nRes = TheFs.Entry(KShortName2, entry);
|
sl@0
|
517 |
test(nRes == KErrNone);
|
sl@0
|
518 |
test(entry.iSize == KFile1Sz && entry.iName == KLongName2);
|
sl@0
|
519 |
|
sl@0
|
520 |
|
sl@0
|
521 |
}
|
sl@0
|
522 |
|
sl@0
|
523 |
|
sl@0
|
524 |
GLDEF_C void CallTestsL()
|
sl@0
|
525 |
//
|
sl@0
|
526 |
// Call tests that may leave
|
sl@0
|
527 |
//
|
sl@0
|
528 |
{
|
sl@0
|
529 |
|
sl@0
|
530 |
TInt drvNum;
|
sl@0
|
531 |
TInt r=TheFs.CharToDrive(gDriveToTest,drvNum);
|
sl@0
|
532 |
test(r==KErrNone);
|
sl@0
|
533 |
|
sl@0
|
534 |
if (!Is_Fat(TheFs,drvNum))
|
sl@0
|
535 |
{
|
sl@0
|
536 |
test.Printf(_L("CallTestsL: Skipped: Requires FAT filesystem to run.\n"));
|
sl@0
|
537 |
return;
|
sl@0
|
538 |
}
|
sl@0
|
539 |
|
sl@0
|
540 |
|
sl@0
|
541 |
//-- set up console output
|
sl@0
|
542 |
SetConsole(test.Console());
|
sl@0
|
543 |
|
sl@0
|
544 |
//-- print drive information
|
sl@0
|
545 |
PrintDrvInfo(TheFs, drvNum);
|
sl@0
|
546 |
|
sl@0
|
547 |
GetBootInfo();
|
sl@0
|
548 |
|
sl@0
|
549 |
Test1(EUpper); // Test directory entries with 8.3 uppercase (no VFAT entries expected)
|
sl@0
|
550 |
Test1(ELower); // Test directory entries with 8.3 lowercase ( VFAT entries expected)
|
sl@0
|
551 |
Test1(EMixed); // Test directory entries with 8.3 mixed ( VFAT entries expected)
|
sl@0
|
552 |
|
sl@0
|
553 |
Test2(EUpper); // Test directory entries with 8.3 uppercase (no VFAT entries expected)
|
sl@0
|
554 |
Test2(ELower); // Test directory entries with 8.3 lowercase ( VFAT entries expected)
|
sl@0
|
555 |
Test2(EMixed); // Test directory entries with 8.3 mixed ( VFAT entries expected)
|
sl@0
|
556 |
|
sl@0
|
557 |
TestDEF115314();
|
sl@0
|
558 |
TestDEF113633();
|
sl@0
|
559 |
TestPDEF116912();
|
sl@0
|
560 |
|
sl@0
|
561 |
TestReplaceByShortName();
|
sl@0
|
562 |
|
sl@0
|
563 |
}
|
sl@0
|
564 |
|
sl@0
|
565 |
|
sl@0
|
566 |
|