Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
17 #define __E32TEST_EXTENSION__
19 #include "T_Fatcharsetconv_aux.h"
26 #include "..\server\t_server.h"
28 //#include "fat_utils.h"
32 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
33 void TestIllegalCharsWithDll()
35 test.Next(_L("Test Illegal Character handling with DLL"));
38 // logging for failure
39 gTCType = ESymbianFATSpecific;
41 failedOnBuf.CreateL(gLogFailureData.iFuncName);
44 tcUniquePath.CreateL(KNone());
47 CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));
49 TInt r = TheFs.ControlIo(CurrentDrive(), KControlIoEnableFatUtilityFunctions);
50 testAndLog(r==KErrNone);
52 r = UserSvr::ChangeLocale(KTestLocale);
53 testAndLog(r==KErrNone);
55 _LIT(KTestNormalUnicodeFileName, "\x65B0\x6587\x4EF6.TXT");
56 _LIT(KTestNormalUnicodeFileNameShortDefualt, "\x65B0\x6587\x4EF6.TXT");
57 _LIT(KTestFileNameWithIllegalChars, "\x222F\x2F3A\x3C3E\x7C00.TXT");
58 _LIT(KFileNameWithIllegalCharsShort, "___\x7C00.TXT");
59 _LIT(KTestFileNameWithWildChars, "\x235B\x245C\x255D\x265E.TXT");
60 _LIT(KTestFileNameWithWildCharsShort, "____.TXT");
64 MakeFile(KTestNormalUnicodeFileName);
65 r = TheFs.GetShortName(KTestNormalUnicodeFileName, shn);
66 testAndLog(r==KErrNone);
67 r = shn.Compare(KTestNormalUnicodeFileNameShortDefualt);
71 r = TheFs.GetLongName(KTestNormalUnicodeFileNameShortDefualt, lgn);
72 testAndLog(r==KErrNone);
73 r = lgn.Compare(KTestNormalUnicodeFileName);
76 // Test illegal 8-bit ASCII chars in 16-bit Unicode chars.
77 MakeFile(KTestFileNameWithIllegalChars);
78 r = TheFs.GetShortName(KTestFileNameWithIllegalChars, shn);
79 testAndLog(r==KErrNone);
80 r = shn.Compare(KFileNameWithIllegalCharsShort);
83 // Test wildcards, 8-bit ASCII chars in 16-bit Unicode chars.
84 MakeFile(KTestFileNameWithWildChars);
85 r = TheFs.GetShortName(KTestFileNameWithWildChars, shn);
87 r = shn.Compare(KTestFileNameWithWildCharsShort);
90 r=TheFs.Delete(KTestFileNameWithIllegalChars);
92 r=TheFs.Delete(KTestNormalUnicodeFileName);
94 r=TheFs.Delete(KTestFileNameWithWildChars);
97 r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
98 testAndLog(r==KErrNone);
100 tcUniquePath.Close();
104 void TestIllegalCharsWithoutDLL()
106 test.Next(_L("Test Illegal Character handling without DLL"));
109 // logging for failure
110 gTCType = ESymbianFATSpecific;
112 failedOnBuf.CreateL(gLogFailureData.iFuncName);
115 tcUniquePath.CreateL(KNone());
118 CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));
120 TInt r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
121 testAndLog(r==KErrNone);
123 _LIT(KTestNormalUnicodeFileName, "\x65B0\x6587\x4EF6.TXT");
124 _LIT(KTestNormalUnicodeFileNameShortDefualt, "___.TXT");
125 _LIT(KTestFileNameWithIllegalChars, "\x222F\x2F3A\x3C3E\x7C00.TXT");
126 _LIT(KFileNameWithIllegalCharsShort, "____.TXT");
127 _LIT(KTestFileNameWithWildChars, "\x235B\x245C\x255D\x265E.TXT");
128 _LIT(KTestFileNameWithWildCharsShort, "____~1.TXT");
132 MakeFile(KTestNormalUnicodeFileName);
133 r = TheFs.GetShortName(KTestNormalUnicodeFileName, shn);
134 testAndLog(r==KErrNone);
135 r = shn.Compare(KTestNormalUnicodeFileNameShortDefualt);
139 r = TheFs.GetLongName(KTestNormalUnicodeFileNameShortDefualt, lgn);
140 testAndLog(r==KErrNone);
141 r = lgn.Compare(KTestNormalUnicodeFileName);
144 // Test illegal 8-bit ASCII chars in 16-bit Unicode chars.
145 MakeFile(KTestFileNameWithIllegalChars);
146 r = TheFs.GetShortName(KTestFileNameWithIllegalChars, shn);
147 testAndLog(r==KErrNone);
148 r = shn.Compare(KFileNameWithIllegalCharsShort);
151 // Test illegal 8-bit ASCII chars in 16-bit Unicode chars.
152 MakeFile(KTestFileNameWithWildChars);
153 r = TheFs.GetShortName(KTestFileNameWithWildChars, shn);
154 testAndLog(r==KErrNone);
155 r = shn.Compare(KTestFileNameWithWildCharsShort);
158 r=TheFs.Delete(KTestFileNameWithIllegalChars);
160 r=TheFs.Delete(KTestNormalUnicodeFileName);
162 r=TheFs.Delete(KTestFileNameWithWildChars);
166 tcUniquePath.Close();
170 void TestFileLengthMax()
172 test.Next(_L("Test accesing a long file with filename length <250 characters"));
175 // logging for failure
176 gTCType = ESymbianFATSpecific;
178 failedOnBuf.CreateL(gLogFailureData.iFuncName);
181 tcUniquePath.CreateL(KNone());
184 CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));
187 TBuf<KMaxFileName> longName;
189 _LIT(KTestDir1, "\\TEST\\TESTLONGFILENAMELENGTH\\TESTMORETHAN250CHARACTERS\\") ;
190 _LIT(KTestDir2, "\x65B0\x6587\x4EF6\x4EF6(ABCDEFGH)\\(\x65B0\x6587\x4EF6\x4EF6)PQRST\\");
191 _LIT(KTestDir3, "MULTILEVEL-FOLDER1\\MULTILEVEL-FOLDER2\\MULTILEVEL-FOLDER3\\");
192 _LIT(KTestDir4, "\x65B0\x65B0\x65B0\x65B0(x6587)\\(\x6587\x6587\x6587\x6587)PQRST\\");
193 _LIT(KTestDir5, "\x4EF6\x4EF6\x4EF6\x4EF6(x4EF6)\\(\x6587\x6587\x6587\x6587)XYZ\\");
194 _LIT(KTestDir6, "TESTINGINPROGRESS\\");
195 _LIT(KTestLongFileLength, "\x4EF6\x4EF6\x4EF6\x4EF6(x4EF6).TXT");
197 longName += KTestDir1;
198 longName += KTestDir2;
199 longName += KTestDir3;
200 longName += KTestDir4;
201 longName += KTestDir5;
202 longName += KTestDir6;
204 test.Printf(_L("longName count is %d "), longName.Length());
205 TInt r=TheFs.MkDirAll(longName);
207 longName += KTestLongFileLength;
208 test.Printf(_L("longName count is %d "), longName.Length());
210 testAndLog(longName.Length()<256);
212 r=TheFile.Create(TheFs,longName ,EFileWrite);
213 testAndLog(r==KErrNone);
216 r=TheFile.Open(TheFs,longName ,EFileWrite);
217 testAndLog(r==KErrNone);
220 TheFs.Delete(longName);
223 tcUniquePath.Close();
227 void TestFileLengthExceedMax()
229 test.Next(_L("Test accesing a long file with filename length >250 characters"));
232 // logging for failure
233 gTCType = ESymbianFATSpecific;
235 failedOnBuf.CreateL(gLogFailureData.iFuncName);
238 tcUniquePath.CreateL(KNone());
241 CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));
243 TInt r = TheFs.SessionPath(gSessionPath);
244 testAndLog(r==KErrNone);
248 _LIT(KTestDir1, "\\TEST\\TESTLONGFILENAMELENGTH\\TESTMORETHAN260CHARACTERS\\") ;
249 _LIT(KTestDir2, "\x65B0\x6587\x4EF6\x4EF6(ABCDEFGH)\\(\x65B0\x6587\x4EF6\x4EF6)PQRST\\");
250 _LIT(KTestDir3, "MULTILEVEL-FOLDER1\\MULTILEVEL-FOLDER2\\MULTILEVEL-FOLDER3\\");
251 _LIT(KTestDir4, "\x65B0\x65B0\x65B0\x65B0(x6587)\\(\x6587\x6587\x6587\x6587)PQRST\\");
252 _LIT(KTestDir5, "\x4EF6\x4EF6\x4EF6\x4EF6(x4EF6)\\(\x6587\x6587\x6587\x6587)XYZ\\");
253 _LIT(KTestDir6, "TESTINGINPROGRESS(TESTLENGTH)>256\\");
254 _LIT(KTestLongFileLength, "\x4EF6\x4EF6\x4EF6\x4EF6(x4EF6).TXT");
256 longName = gSessionPath;
257 longName += KTestDir1;
258 longName += KTestDir2;
259 longName += KTestDir3;
260 longName += KTestDir4;
261 longName += KTestDir5;
262 longName += KTestDir6;
264 test.Printf(_L("longName length is %d "), longName.Length());
265 r=TheFs.MkDirAll(longName);
267 longName += KTestLongFileLength;
268 test.Printf(_L("longName count is %d "), longName.Length());
270 testAndLog(longName.Length()>256);
272 r=TheFile.Create(TheFs,longName ,EFileWrite);
273 testAndLog(r==KErrBadName);
276 r=TheFile.Open(TheFs,longName ,EFileWrite);
277 testAndLog(r==KErrBadName);
280 TheFs.Delete(longName);
282 tcUniquePath.Close();
286 void TestLeadingE5Handling()
288 test.Next(_L("Test Leading \'E5\' byte handling"));
291 // logging for failure
292 gTCType = ESymbianFATSpecific;
294 failedOnBuf.CreateL(gLogFailureData.iFuncName);
297 tcUniquePath.CreateL(KNone());
300 CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));
302 // Enables codepage dll implementation of LocaleUtils functions for this test only
303 TInt r = TheFs.ControlIo(CurrentDrive(), KControlIoEnableFatUtilityFunctions);
304 testAndLog(r==KErrNone);
306 r = UserSvr::ChangeLocale(KTestLocale);
307 testAndLog(r==KErrNone);
309 r=TheFs.SessionPath(gSessionPath);
310 testAndLog(r==KErrNone);
312 _LIT(KTestFilePathAndName, "\\F32-TST\\T_FATCHARSETCONV\\\x88F9.TXT");
313 _LIT(KTestFileShortName, "\x88F9.TXT");
315 MakeFile(KTestFilePathAndName);
317 r = TheFs.GetShortName(KTestFilePathAndName, sn);
318 testAndLog(r==KErrNone);
319 r = sn.Compare(KTestFileShortName);
320 testAndLog(r==KErrNone);
322 r=TheFs.Delete(KTestFilePathAndName);
323 testAndLog(r==KErrNone);
325 // Disables codepage dll implementation of LocaleUtils functions for other base tests
326 r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
327 testAndLog(r==KErrNone);
329 tcUniquePath.Close();
335 test.Next(_L("Test With VFAT entry, and DOS entry using Non-CP932 Japanese file's access"));
338 // logging for failure
339 gTCType = ESymbianFATSpecific;
341 failedOnBuf.CreateL(gLogFailureData.iFuncName);
344 tcUniquePath.CreateL(KNone());
347 CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));
349 _LIT(KTestNormalFileName, "\x65B0\x6587\x4EF6.TXT");
350 _LIT(KTestNormalFileNameWithUnicode, "___.TXT");
353 test.Printf(_L("Create a file without the DLL installed, and get the shortname"));
354 TInt r=TheFile.Create(TheFs,KTestNormalFileName,EFileRead|EFileWrite);
355 testAndLog(r==KErrNone);
357 r = TheFs.GetShortName(KTestNormalFileName, sn);
358 testAndLog(r==KErrNone);
359 r = sn.Compare(KTestNormalFileNameWithUnicode);
363 test.Printf(_L("Access the file without the DLL installed"));
364 r=TheFile.Open(TheFs,KTestNormalFileName,EFileWrite);
365 testAndLog(r==KErrNone);
368 r=TheFile.FullName(name);
369 testAndLog(r==KErrNone);
372 r=TheFile.Open(TheFs,KTestNormalFileNameWithUnicode,EFileWrite);
373 testAndLog(r==KErrNone);
378 r = TheFs.ControlIo(CurrentDrive(), KControlIoEnableFatUtilityFunctions);
379 testAndLog(r==KErrNone);
381 r = UserSvr::ChangeLocale(KTestLocale);
382 testAndLog(r==KErrNone);
384 test.Printf(_L("Access the file with the DLL installed"));
385 r=TheFile.Open(TheFs,KTestNormalFileName,EFileWrite);
386 testAndLog(r==KErrNone);
388 r=TheFile.FullName(name);
389 testAndLog(r==KErrNone);
392 r=TheFile.Open(TheFs,KTestNormalFileNameWithUnicode,EFileWrite);
393 testAndLog(r==KErrNone);
396 r=TheFs.Delete(KTestNormalFileName);
398 r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
399 testAndLog(r==KErrNone);
401 tcUniquePath.Close();
407 test.Next(_L("Test With VFAT entry, and DOS entry using CP932 Japanese file's access"));
410 // logging for failure
411 gTCType = ESymbianFATSpecific;
413 failedOnBuf.CreateL(gLogFailureData.iFuncName);
416 tcUniquePath.CreateL(KNone());
419 CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));
421 TInt r = TheFs.ControlIo(CurrentDrive(), KControlIoEnableFatUtilityFunctions);
424 r = UserSvr::ChangeLocale(KTestLocale);
426 r=TheFs.SetSessionPath(gSessionPath);
427 testAndLog(r==KErrNone);
429 _LIT(KTestNormalFileName, "\x65B0\x6587\x4EF6.TXT");
430 _LIT(KTestNormalFileShortName, "\x65B0\x6587\x4EF6.TXT");
432 test.Printf(_L("Create a file with the DLL installed, and get the shortname"));
433 r=TheFile.Create(TheFs,KTestNormalFileName,EFileRead|EFileWrite);
434 testAndLog(r==KErrNone);
436 r = TheFs.GetShortName(KTestNormalFileName, sn);
437 testAndLog(r==KErrNone);
438 r = sn.Compare(KTestNormalFileShortName);
442 test.Printf(_L("Access the file with the DLL installed"));
443 r=TheFile.Open(TheFs,KTestNormalFileName,EFileWrite);
444 testAndLog(r==KErrNone);
447 r=TheFile.FullName(name);
448 testAndLog(r==KErrNone);
451 r=TheFile.Open(TheFs,KTestNormalFileShortName,EFileWrite);
452 testAndLog(r==KErrNone);
455 r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
456 testAndLog(r==KErrNone);
458 test.Printf(_L("Access the file without the DLL installed"));
460 r=TheFile.Open(TheFs,KTestNormalFileName,EFileWrite);
461 testAndLog(r==KErrNone);
463 r=TheFile.FullName(name);
464 testAndLog(r==KErrNone);
467 r=TheFile.Open(TheFs,KTestNormalFileShortName,EFileWrite);
468 testAndLog(r==KErrNone);
471 r=TheFs.Delete(KTestNormalFileName);
473 tcUniquePath.Close();
479 test.Next(_L("Test Without VFAT entry, but DOS entry uses CP932 Japanese file's access"));
482 // logging for failure
483 gTCType = ESymbianFATSpecific;
485 failedOnBuf.CreateL(gLogFailureData.iFuncName);
488 tcUniquePath.CreateL(KNone());
491 CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));
496 TFileName fn = _L("\\ABCD");
498 TInt r=file.Create(TheFs,fn,EFileRead);
499 testAndLog(r==KErrNone);
502 // Assume this file is the first entry in the root directory
503 r=TheDisk.Open(TheFs,CurrentDrive());
504 testAndLog(r==KErrNone);
506 //-- read the 1st dir entry, it should be a DOS entry
507 const TInt posEntry1=gBootSector.RootDirStartSector() << KDefaultSectorLog2; //-- dir entry1 position
509 TFatDirEntry fatEntry1;
510 TPtr8 ptrEntry1((TUint8*)&fatEntry1,sizeof(TFatDirEntry));
511 testAndLog(TheDisk.Read(posEntry1, ptrEntry1)==KErrNone);
512 testAndLog(!fatEntry1.IsVFatEntry());
514 // Manually modify the short name into unicode characters
515 // Unicode: 0x(798F 5C71 96C5 6CBB)
516 // Shift-JIS: 0x(959F 8E52 89EB 8EA1)
518 TBuf8<8> unicodeSN = _L8("ABCD1234");
528 fatEntry1.SetName(unicodeSN);
529 testAndLog(TheDisk.Write(posEntry1, ptrEntry1)==KErrNone);
532 // The Unicode file name of the file that is created
539 // Access the file using its unicode file name without the DLL loaded.
540 r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
544 TInt err = TheFs.Entry(fn, entry);
545 testAndLog(err==KErrNotFound);
547 // Access the file using its unicode file name with the DLL loaded.
548 r = TheFs.ControlIo(CurrentDrive(), KControlIoEnableFatUtilityFunctions);
550 r = UserSvr::ChangeLocale(KTestLocale);
553 err = TheFs.Entry(fn, entry);
554 testAndLog(err==KErrNone);
556 //file is no more required,delete it.
557 err = TheFs.Delete(fn);
558 testAndLog(err==KErrNone);
560 r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
563 r=TheFs.SessionPath(gSessionPath);
566 tcUniquePath.Close();
570 void DoSymbianSpecificCases()
572 gLogFailureData.iTCTypeName = KSymbianFATSpecific;
573 gLogFailureData.iAPIName= KNone;
575 // Store current file name
578 while(__FILE__[i]!='\0')
580 fileName.SetLength(i+1);
581 fileName[i] = __FILE__[i++];
583 gFileName = fileName;
585 gLogFailureData.iFuncName = KTestLeadingE5Handling;
586 TestLeadingE5Handling();
588 gLogFailureData.iFuncName = KTestIllegalCharsWithDll;
589 TestIllegalCharsWithDll();
591 gLogFailureData.iFuncName = KTestIllegalCharsWithoutDLL;
592 TestIllegalCharsWithoutDLL();
594 gLogFailureData.iFuncName = KTestFileLengthMax;
597 gLogFailureData.iFuncName = KTestFileLengthExceedMax;
598 TestFileLengthExceedMax();
600 gLogFailureData.iFuncName = KTestVFATCase2;
603 gLogFailureData.iFuncName = KTestVFATCase3;
606 gLogFailureData.iFuncName = KTestVFATCase1;
611 #endif //defined(_DEBUG) || defined(_DEBUG_RELEASE)