Update contrib.
1 // Copyright (c) 2008-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 // f32test\server\T_FatCharSetConv_Main.cpp
18 #define __E32TEST_EXTENSION__
27 #include "fat_utils.h"
28 #include "T_Fatcharsetconv_Cases.h"
31 RTest test(_L("T_FatCharSetConv"));
33 using namespace Fat_Test_Utils;
35 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
38 TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c)
40 TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C));
41 TInt r = fs.ControlIo(drv, fkn, ptrC);
46 * Presetting module, presets initial source, target and comparing direcotries.
47 * @param aParam test param that contains all information about a test case
49 void DataGenerationL(const TTestParamAll& aParam)
53 path.CreateL(aParam.iSrcPrsPath);
55 path[0] = (TUint16)*aParam.iSrcDrvChar;
56 if(path[0] == (TUint8)gDriveToTest)
58 SetupDirFiles(path, aParam.iSrcPrsFiles);
61 if (aParam.iAPI == EGetShortName || aParam.iAPI == EGetShortNameWithDLL || aParam.iAPI == EGetShortNameWithoutDLL || aParam.iAPI == ERFsReplace || aParam.iAPI == ERFsRename ||aParam.iAPI == ERenameFile )
63 path[0] = (TUint16)*aParam.iTrgDrvChar;
70 * Test execution module
71 * @param aParam test param that contains all information about a test case
72 * @panic USER:84 if return codes do not match the expected values.
74 void DataExecutionL(const TTestParamAll& aParam, const TTCType aTCType)
77 srcCmdFile.CreateL(aParam.iSrcCmdPath);
79 trgCmdFile.CreateL(aParam.iTrgCmdPath);
81 srcCmd.CreateL(aParam.iSrcPrsPath);
83 if (srcCmdFile.Length() > 0)
85 srcCmdFile[0] = (TUint16)*aParam.iSrcDrvChar;
89 // srcCmdFile= gSessionPath;
90 srcCmdFile[0] = (TUint16)*aParam.iSrcDrvChar;
92 if (srcCmd.Length() > 0)
94 srcCmd[0] = (TUint16)*aParam.iSrcDrvChar;
98 // srcCmd= gSessionPath;
99 srcCmd[0] = (TUint16)*aParam.iSrcDrvChar;
102 // logging for failure
105 failedOnBuf.CreateL(KExecution());
106 gTCId = aParam.iTestCaseID;
108 tcUniquePath.CreateL(aParam.iSrcPrsPath);
115 case EGetShortNameWithDLL:
116 case EGetShortNameWithoutDLL:
119 if(aParam.iAPI == EGetShortName )
120 gLogFailureData.iAPIName = KGetShortName;
121 else if(aParam.iAPI == EGetShortNameWithDLL )
122 gLogFailureData.iAPIName = KGetShortNameWithDLL;
123 else if(aParam.iAPI == EGetShortNameWithoutDLL )
124 gLogFailureData.iAPIName = KGetShortNameWithoutDLL;
126 if (trgCmdFile.Length() > 0)
128 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
132 //trgCmdFile= gSessionPath;
133 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
136 TBuf<0x10> shortName;
137 r=TheFs.GetShortName(srcCmdFile,shortName);
138 testAndLog(r==KErrNone);
139 srcCmd.ReAllocL(srcCmd.Length() + shortName.Length());
141 testAndLog(srcCmd==trgCmdFile);
145 case ELongShortConversion:
148 gLogFailureData.iAPIName = KLongShortConversion;
149 if (trgCmdFile.Length() > 0)
151 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
155 //trgCmdFile= gSessionPath;
156 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
162 TBuf<0x10> shortName;
164 r = TheFs.GetShortName(srcCmdFile, shortName);
165 testAndLog(r==KErrNone);
167 shnFullPath.CreateL(srcCmd);
168 shnFullPath.ReAllocL(srcCmd.Length() + shortName.Length());
169 shnFullPath.Append(shortName);
170 r = shnFullPath.Compare(trgCmdFile);
171 testAndLog(r==KErrNone);
173 r = TheFs.GetLongName(shnFullPath, longName);
174 testAndLog(r==KErrNone);
176 lgnFullPath.CreateL(srcCmd);
177 lgnFullPath.ReAllocL(srcCmd.Length() + longName.Length());
178 lgnFullPath.Append(longName);
179 r = lgnFullPath.Compare(srcCmdFile);
180 testAndLog(r==KErrNone);
190 gLogFailureData.iAPIName = KCreateFile;
191 r = TheFile.Create(TheFs,srcCmdFile,EFileWrite);
192 testAndLog(r==KErrNone);
200 gLogFailureData.iAPIName = KIsValidName;
202 r=TheFs.IsValidName(srcCmdFile,badChar);
203 testAndLog(r==(TInt)ETrue);
204 r=TheFs.IsValidName(srcCmdFile);
205 testAndLog(r==(TInt)ETrue);
212 gLogFailureData.iAPIName = KMkDir;
213 r=TheFs.MkDir(srcCmdFile);
214 testAndLog(r==KErrNone);
221 gLogFailureData.iAPIName = KMkDirAll;
222 r=TheFs.MkDirAll(srcCmdFile);
223 testAndLog(r==KErrNone);
230 gLogFailureData.iAPIName = KRenameFile;
231 if (trgCmdFile.Length() > 0)
233 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
237 //trgCmdFile= gSessionPath;
238 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
241 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
242 testAndLog(r == KErrNone);
243 r=TheFile.Rename(trgCmdFile);
244 testAndLog(r==KErrNone);
249 case EReadFileSection:
252 gLogFailureData.iAPIName = KReadFileSection;
253 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
254 testAndLog(r == KErrNone);
257 TBuf8<50> writeBuf = _L8("I am going to write some junk for testing purpose");
258 TheFile.Write(writeBuf, numWrite);
260 testAndLog(r==KErrNone);
268 gLogFailureData.iAPIName = KDeleteFile;
269 r=TheFs.Delete(srcCmdFile);
270 testAndLog(r==KErrNone);
277 gLogFailureData.iAPIName = KOpenDir;
278 r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
279 testAndLog(r==KErrNone);
287 gLogFailureData.iAPIName = KReadDir;
288 r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
289 testAndLog(r==KErrNone);
297 gLogFailureData.iAPIName = KRemoveDir;
298 r=TheFs.RmDir(srcCmdFile);
299 testAndLog(r==KErrNone);
306 gLogFailureData.iAPIName = KIsFileInRom;
307 // The tested files are created on non-rom drives, which should not be found
309 TUint8* ptr=TheFs.IsFileInRom(srcCmdFile);
310 testAndLog(ptr==NULL);
317 gLogFailureData.iAPIName = KReplaceFile;
318 r=TheFile.Replace(TheFs, srcCmdFile ,EFileWrite);
319 testAndLog(r==KErrNone);
324 case EOperateOnFileNames:
327 gLogFailureData.iAPIName = KOperateOnFileNames;
328 r = TheFile.Open(TheFs, srcCmdFile, EFileRead);
329 testAndLog(r == KErrNone);
337 gLogFailureData.iAPIName = KFileModify;
339 r=TheFs.Modified(srcCmdFile,time);
340 testAndLog(r==KErrNone);
344 case EFileAttributes:
347 gLogFailureData.iAPIName = KFileAttributes;
349 r=TheFs.Att(srcCmdFile,att);
350 testAndLog(r==KErrNone);
357 gLogFailureData.iAPIName = KRFsEntry;
359 r=TheFs.Entry(srcCmdFile, entryDetail);
360 testAndLog(r==KErrNone);
367 gLogFailureData.iAPIName = KRFsReplace;
368 if (trgCmdFile.Length() > 0)
370 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
374 //trgCmdFile= gSessionPath;
375 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
377 r=TheFs.Replace(srcCmdFile,trgCmdFile);
378 testAndLog(r==KErrNone);
385 gLogFailureData.iAPIName = KRFsRename;
386 if (trgCmdFile.Length() > 0)
388 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
392 //trgCmdFile= gSessionPath;
393 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
395 r=TheFs.Rename(srcCmdFile,trgCmdFile);
396 testAndLog(r==KErrNone);
403 gLogFailureData.iAPIName = KGetDir;
405 r=TheFs.GetDir(srcCmdFile,KEntryAttNormal,ESortByName,anEntryList);
406 testAndLog(r==KErrNone);
414 gLogFailureData.iAPIName = KFileTemp;
415 TFileName tempFileName;
416 r=TheFile.Temp(TheFs,srcCmdFile,tempFileName,EFileWrite);
417 testAndLog(r == KErrNone);
425 gLogFailureData.iAPIName = KReadFromFile;
426 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
427 testAndLog(r == KErrNone);
429 TBuf8<200> writeBuf = _L8("I am going to write something to the file and then read from the specified position to test an overload of RFIle::Read");
431 TheFile.Write(writeBuf, numWrite);
432 testAndLog(r==KErrNone);
440 gLogFailureData.iAPIName = KWriteToFile;
442 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
443 testAndLog(r == KErrNone);
445 TBuf8<200> writeBuf = _L8("I am going to write something to the file and then read from the specified position to test an overload of RFIle::Read");
447 TheFile.Write(writeBuf, numWrite);
448 testAndLog(r==KErrNone);
450 testAndLog(r==KErrNone);
460 // test.Printf(_L("DataExecution::\tTest case %d passed\n"),aParam.iTestCaseID);
463 tcUniquePath.Close();
471 void DataVerificationL(const TTestParamAll& aParam, const TTCType aTCType)
474 srcCmdFile.CreateL(aParam.iSrcCmdPath);
476 trgCmdFile.CreateL(aParam.iTrgCmdPath);
478 srcCmd.CreateL(aParam.iSrcPrsPath);
480 if (srcCmdFile.Length() > 0)
482 srcCmdFile[0] = (TUint16)*aParam.iSrcDrvChar;
486 //srcCmdFile= gSessionPath;
487 srcCmdFile[0] = (TUint16)*aParam.iSrcDrvChar;
490 if (srcCmd.Length() > 0)
492 srcCmd[0] = (TUint16)*aParam.iSrcDrvChar;
496 //srcCmd= gSessionPath;
497 srcCmd[0] = (TUint16)*aParam.iSrcDrvChar;
500 // logging for failure
503 failedOnBuf.CreateL(KVerification());
504 gTCId = aParam.iTestCaseID;
506 tcUniquePath.CreateL(aParam.iSrcPrsPath);
512 case EGetShortNameWithDLL:
513 case EGetShortNameWithoutDLL:
516 if(aParam.iAPI == EGetShortName )
517 gLogFailureData.iAPIName = KGetShortName;
518 else if(aParam.iAPI == EGetShortNameWithDLL )
519 gLogFailureData.iAPIName = KGetShortNameWithDLL;
520 else if(aParam.iAPI == EGetShortNameWithoutDLL )
521 gLogFailureData.iAPIName = KGetShortNameWithoutDLL;
523 if (trgCmdFile.Length() > 0)
525 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
529 //trgCmdFile= gSessionPath;
530 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
533 TBuf<0x10> shortName;
534 r=TheFs.GetShortName(srcCmdFile,shortName);
535 testAndLog(r==KErrNone);
538 srcCmd.ReAllocL(srcCmd.Length() + shortName.Length());
540 testAndLog(srcCmd==trgCmdFile);
545 case ELongShortConversion:
548 gLogFailureData.iAPIName = KLongShortConversion;
549 if (trgCmdFile.Length() > 0)
551 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
555 //trgCmdFile= gSessionPath;
556 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
562 TBuf<0x10> shortName;
564 r = TheFs.GetShortName(srcCmdFile, shortName);
565 testAndLog(r==KErrNone);
569 shnFullPath.CreateL(srcCmd);
570 shnFullPath.ReAllocL(srcCmd.Length() + shortName.Length());
571 shnFullPath.Append(shortName);
572 r = shnFullPath.Compare(trgCmdFile);
573 testAndLog(r==KErrNone);
575 r = TheFs.GetLongName(shnFullPath, longName);
576 testAndLog(r==KErrNone);
578 lgnFullPath.CreateL(srcCmd);
579 lgnFullPath.ReAllocL(srcCmd.Length() + longName.Length());
580 lgnFullPath.Append(longName);
581 r = lgnFullPath.Compare(srcCmdFile);
582 testAndLog(r==KErrNone);
593 gLogFailureData.iAPIName = KCreateFile;
594 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
595 testAndLog(r == KErrNone);
603 gLogFailureData.iAPIName = KIsValidName;
605 r=TheFs.IsValidName(srcCmdFile,badChar);
607 r=TheFs.IsValidName(srcCmdFile);
615 gLogFailureData.iAPIName = KMkDir;
616 r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
617 testAndLog(r==KErrNone);
625 gLogFailureData.iAPIName = KMkDirAll;
626 r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
627 testAndLog(r==KErrNone);
635 gLogFailureData.iAPIName = KRenameFile;
636 if (trgCmdFile.Length() > 0)
638 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
642 //trgCmdFile= gSessionPath;
643 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
645 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
646 testAndLog(r == KErrNotFound);
647 // r = TheFile.Open(TheFs, trgCmdFile, EFileRead|EFileWrite);
648 // testAndLog(r == KErrNone);
653 case EReadFileSection:
656 gLogFailureData.iAPIName = KReadFileSection;
657 TBool isFileOpen = EFalse;
658 r=TheFs.IsFileOpen(srcCmdFile,isFileOpen);
659 testAndLog(r==KErrNone);
668 r=TheFs.ReadFileSection(srcCmdFile, 0, readBuf, numRead);
669 testAndLog(r==KErrNone);
677 gLogFailureData.iAPIName = KDeleteFile;
678 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
679 testAndLog(r == KErrNotFound);
687 gLogFailureData.iAPIName = KOpenDir;
688 r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
689 testAndLog(r==KErrNone);
697 gLogFailureData.iAPIName = KReadDir;
699 TInt dirEntryCount = 0;
700 r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
701 testAndLog(r==KErrNone);
704 r = TheDir.Read(entry);
712 testAndLog(dirEntryCount == 4);
719 gLogFailureData.iAPIName = KRemoveDir;
720 r = TheDir.Open(TheFs, srcCmdFile, KEntryAttMaskSupported);
721 testAndLog(r == KErrPathNotFound);
729 gLogFailureData.iAPIName = KIsFileInRom;
730 TUint8* ptr=TheFs.IsFileInRom(srcCmdFile);
731 // file should not be in ROM
732 testAndLog(ptr==NULL)
739 gLogFailureData.iAPIName = KReplaceFile;
740 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
741 testAndLog(r == KErrNone);
746 case EOperateOnFileNames:
749 gLogFailureData.iAPIName = KOperateOnFileNames;
751 TFileName realFileNameInFS;
752 TFileName fullFileName;
755 r = TheFile.Open(TheFs, srcCmdFile, EFileRead);
756 testAndLog(r == KErrNone);
760 r=TheFile.FullName(fullFileName);
761 testAndLog(r==KErrNone);
762 testAndLog(fullFileName==srcCmdFile);
764 TInt length = srcCmdFile.Length()-srcCmd.Length();
766 r=TheFile.Name(fileName);
767 testAndLog(r==KErrNone);
769 TBuf<50> tempFileName;
770 tempFileName = srcCmdFile.Right(length);
771 testAndLog(fileName==tempFileName);
772 testAndLog(length==fileName.Length());
774 r=TheFs.RealName(srcCmdFile,realFileNameInFS);
775 testAndLog(r==KErrNone);
776 testAndLog(realFileNameInFS==srcCmdFile);
785 gLogFailureData.iAPIName = KFileModify;
787 r=TheFs.Modified(srcCmdFile,tempTime);
788 testAndLog(r==KErrNone);
790 r=TheFs.SetModified(srcCmdFile,tempTime);
791 testAndLog(r==KErrNone);
795 case EFileAttributes:
798 gLogFailureData.iAPIName = KFileAttributes;
800 r=TheFs.Att(srcCmdFile,att);
801 testAndLog(r==KErrNone);
802 r=TheFs.SetAtt(srcCmdFile,KEntryAttHidden,0);
803 testAndLog(r==KErrNone);
804 r=TheFs.Att(srcCmdFile,att);
805 testAndLog(r==KErrNone);
812 gLogFailureData.iAPIName = KRFsEntry;
814 r=TheFs.Entry(srcCmdFile,entryDetail);
815 testAndLog(r==KErrNone);
818 r=TheFs.SetEntry(srcCmdFile, time, KEntryAttHidden, KEntryAttNormal);
819 testAndLog(r==KErrNone);
820 r=TheFs.Entry(srcCmdFile, entryDetail);
821 testAndLog(r==KErrNone);
828 gLogFailureData.iAPIName = KRFsReplace;
829 if (trgCmdFile.Length() > 0)
831 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
835 //trgCmdFile= gSessionPath;
836 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
838 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
839 testAndLog(r == KErrNotFound);
840 // r = TheFile.Open(TheFs, trgCmdFile, EFileRead|EFileWrite);
841 // testAndLog(r == KErrNone);
849 gLogFailureData.iAPIName = KRFsRename;
850 if (trgCmdFile.Length() > 0)
852 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
856 //trgCmdFile= gSessionPath;
857 trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
859 TInt len=srcCmdFile.Length();
860 if(srcCmdFile[--len]=='\\')
862 r = TheDir.Open(TheFs, srcCmdFile, KEntryAttMaskSupported);
863 testAndLog(r == KErrPathNotFound);
864 // r = TheDir.Open(TheFs, trgCmdFile, KEntryAttMaskSupported);
865 // testAndLog(r == KErrNone);
870 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
871 testAndLog(r == KErrNotFound);
872 // r = TheFile.Open(TheFs, trgCmdFile, EFileRead|EFileWrite);
873 // testAndLog(r == KErrNone);
882 gLogFailureData.iAPIName = KGetDir;
884 r=TheFs.GetDir(srcCmdFile,KEntryAttNormal,ESortByName,anEntryList);
885 testAndLog(r==KErrNone);
893 gLogFailureData.iAPIName = KFileTemp;
894 TFileName tempFileName;
895 r=TheFile.Temp(TheFs,srcCmdFile,tempFileName,EFileWrite);
896 testAndLog(r == KErrNone);
898 r = TheFile.Create(TheFs, tempFileName, EFileRead|EFileWrite);
899 testAndLog(r == KErrAlreadyExists);
906 gLogFailureData.iAPIName = KReadFromFile;
908 TInt start=0, readLen=15, readPos=10;
910 TInt numWritten = 50;
912 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
913 testAndLog(r == KErrNone);
917 r=TheFile.Seek(ESeekStart,start);
918 testAndLog(r==KErrNone);
920 readBuf.SetLength(0);
921 r=TheFile.Read(readBuf);
922 testAndLog(r == KErrNone);
923 testAndLog(numWritten == readBuf.Length());
925 //An overload of RFile::Read(), read specified no.of bytes.
926 r=TheFile.Seek(ESeekStart,start);
927 testAndLog(r==KErrNone);
929 readBuf.SetLength(0);
930 TheFile.Read(readBuf,readLen);
931 testAndLog(r == KErrNone);
932 testAndLog(readLen == readBuf.Length());
934 //An overload of RFile::Read(), read from the specified position.
935 readBuf.SetLength(0);
936 r=TheFile.Read(readPos,readBuf);
937 testAndLog(r == KErrNone);
938 testAndLog(numWritten-readPos == readBuf.Length());
947 gLogFailureData.iAPIName = KWriteToFile;
949 r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
950 testAndLog(r == KErrNone);
954 TInt writeLen=20, writePos=10, start=0, readLen=0;
955 TBuf8<200> writeBuf = _L8("I am going to write something to the file and then read from the specified position to test an overload of RFIle::Read");
956 TInt numWritten = writeBuf.Length();
959 TheFile.Write(writeBuf);
961 testAndLog(r==KErrNone);
963 r=TheFile.Seek(ESeekStart,start);
964 testAndLog(r==KErrNone);
966 readBuf.SetLength(0);
967 r=TheFile.Read(readBuf);
968 testAndLog(r==KErrNone);
969 readLen = readBuf.Length();
970 testAndLog(numWritten == readLen);
972 r=TheFile.SetSize(0);
973 testAndLog(r==KErrNone);
975 //An overload of RFile::Write(), write specified no.of bytes.
976 TheFile.Write(writeBuf,writeLen);
978 testAndLog(r==KErrNone);
980 r=TheFile.Seek(ESeekStart,start);
981 testAndLog(r==KErrNone);
983 readBuf.SetLength(0);
984 r=TheFile.Read(readBuf);
985 testAndLog(r==KErrNone);
986 readLen = readBuf.Length();
987 testAndLog(writeLen==readLen);
989 r=TheFile.SetSize(0);
990 testAndLog(r==KErrNone);
992 //An overload of RFile::Write(), write to a particular position.
993 TBuf8<50> testBuf = _L8("Testing different variants of RFile::Write APIs");
994 TheFile.Write(testBuf);
996 testAndLog(r==KErrNone);
998 TheFile.Write(writePos,writeBuf);
1000 testAndLog(r==KErrNone);
1002 r=TheFile.Seek(ESeekStart,start);
1003 testAndLog(r==KErrNone);
1005 readBuf.SetLength(0);
1006 r=TheFile.Read(readBuf);
1007 testAndLog(r==KErrNone);
1008 readLen = readBuf.Length();
1009 testAndLog(numWritten + writePos == readLen);
1011 r=TheFile.SetSize(0);
1012 testAndLog(r==KErrNone);
1014 //An overload of RFile::Write(), write to a particular position and specified no. of bytes.
1016 TheFile.Write(testBuf);
1018 testAndLog(r==KErrNone);
1020 TheFile.Write(writePos,writeBuf,writeLen);
1022 testAndLog(r==KErrNone);
1024 r=TheFile.Seek(ESeekStart,start);
1025 testAndLog(r==KErrNone);
1027 readBuf.SetLength(0);
1028 r=TheFile.Read(readBuf);
1029 testAndLog(r==KErrNone);
1031 TInt newSize = testBuf.Length()-(writePos+writeLen);
1032 if(newSize < testBuf.Length())
1034 size = testBuf.Length();
1038 readLen = readBuf.Length();
1039 testAndLog(readLen==size);
1041 r=TheFile.SetSize(0);
1042 testAndLog(r==KErrNone);
1052 // test.Printf(_L("DataVerification::\tTest case %d passed\n"),aParam.iTestCaseID);
1054 failedOnBuf.Close();
1055 tcUniquePath.Close();
1063 void DeletePathAfterTest(const TTestParamAll& aParam)
1065 TFileName path = aParam.iSrcPrsPath;
1066 if (path.Length() == 0)
1068 test.Printf(_L("ERROR<SetupDirFiles()>: Zero length src path!\n"));
1072 path[0] = (TUint16)*aParam.iSrcDrvChar;
1073 TInt idx = path.Find(_L("Src\\"));
1074 path.Delete(idx,path.Length()-idx);
1080 * Do all basic binary test cases defined in gBasicUnitaryTestCases[]
1082 void DoAllBasicUnitaryTestsL(const TTestCaseUnitaryBasic aBasicUnitaryTestCaseGroup[],
1083 TTestSwitches& aSwitches, TBool aIsWithDLL)
1085 TTestParamAll* nextTestCase = new(ELeave) TTestParamAll();
1089 // Reset the Test Log Data
1092 while(SearchTestCaseByArrayIdx(i, aBasicUnitaryTestCaseGroup,
1093 *nextTestCase, aIsWithDLL) == KErrNone)
1097 startTime.HomeTime();
1098 if(aSwitches.iExeOnSymbian || aSwitches.iExeOnWindows)
1100 DataGenerationL(*nextTestCase);
1101 DataExecutionL(*nextTestCase, EUnitaryTest);
1103 if(aSwitches.iVerOnSymbian || aSwitches.iVerOnWindows)
1105 DataVerificationL(*nextTestCase, EUnitaryTest);
1106 DeletePathAfterTest(*nextTestCase);
1111 TTimeIntervalMicroSeconds timeTaken(0);
1112 timeTaken = endTime.MicroSecondsFrom(startTime);
1114 // test.Printf(_L("Test Case Id : %d\n"),(*nextTestCase).iTestCaseID);
1116 // time=I64LOW(timeTaken.Int64()/1000);
1117 // test.Printf(_L("Time Taken by test case %d = %d mS \n"),nextTestCase.iTestCaseID,time);
1120 delete nextTestCase;
1124 * Do all basic binary test cases defined in gBasicBinaryTestCases[]
1126 void DoAllBasicBinaryTestsL(const TTestCaseBinaryBasic aBasicBinaryTestCaseGroup[],
1127 TTestSwitches& aSwitches, TBool aIsWithDLL)
1129 TTestParamAll* nextTestCase = new(ELeave) TTestParamAll();
1133 // Reset the Test Log Data
1136 while (SearchTestCaseByArrayIdx(i, aBasicBinaryTestCaseGroup,
1137 *nextTestCase, aIsWithDLL) == KErrNone)
1141 if(((aBasicBinaryTestCaseGroup[i].iBasic.iAPI==EGetShortNameWithoutDLL)))
1149 if(((aBasicBinaryTestCaseGroup[i].iBasic.iAPI== EGetShortNameWithDLL) || (aBasicBinaryTestCaseGroup[i].iBasic.iAPI==ELongShortConversion)) )
1157 startTime.HomeTime();
1159 if(aSwitches.iExeOnSymbian || aSwitches.iExeOnWindows)
1161 DataGenerationL(*nextTestCase);
1162 DataExecutionL(*nextTestCase, EBinaryTest);
1164 if(aSwitches.iVerOnSymbian || aSwitches.iVerOnWindows)
1166 DataVerificationL(*nextTestCase, EBinaryTest);
1167 DeletePathAfterTest(*nextTestCase);
1171 TTimeIntervalMicroSeconds timeTaken(0);
1172 timeTaken = endTime.MicroSecondsFrom(startTime);
1174 // test.Printf(_L("Test Case Id : %d\n"),(*nextTestCase).iTestCaseID);
1176 // time2=I64LOW(timeTaken.Int64()/1000);
1177 // test.Printf(_L("Time Taken by test id %d = %d mS \n"),nextTestCase.iTestCaseID,time2);
1181 delete nextTestCase;
1185 * Main testing control unit
1187 void TestMainWithDLLL(TTestSwitches& aSwitches)
1189 // Enables codepage dll implementation of LocaleUtils functions for this test only
1190 TInt r = TheFs.ControlIo(CurrentDrive(), KControlIoEnableFatUtilityFunctions);
1191 test(r == KErrNone);
1193 test.Printf(_L("Load the Code Page DLL"));
1194 r = UserSvr::ChangeLocale(KTestLocale);
1195 test(r == KErrNone);
1197 test.Next(_L("Test Unitary APIs with only Sync Variant with DLL"));
1198 gLogFailureData.iFuncName = KDoAllBasicUnitaryTestsL;
1199 DoAllBasicUnitaryTestsL(gBasicUnitaryTestCases, aSwitches, ETrue);
1201 test.Next(_L("Test Binary Tests with DLL"));
1202 gLogFailureData.iFuncName = KDoAllBasicBinaryTestsL;
1203 DoAllBasicBinaryTestsL(gBasicBinaryTestCases, aSwitches, ETrue);
1205 // Disables codepage dll implementation of LocaleUtils functions for other base tests
1206 r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
1207 test(r == KErrNone);
1210 void TestMainWithoutDLLL(TTestSwitches& aSwitches)
1212 test.Next(_L("Test Unitary APIs with only Sync Variant without DLL"));
1214 // Disables codepage dll implementation of LocaleUtils functions
1215 TInt r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
1216 test(r == KErrNone);
1218 gLogFailureData.iFuncName = KDoAllBasicUnitaryTestsL;
1219 DoAllBasicUnitaryTestsL(gBasicUnitaryTestCases, aSwitches, EFalse);
1221 test.Next(_L("Test Binary Tests without DLL"));
1222 gLogFailureData.iFuncName = KDoAllBasicBinaryTestsL;
1223 DoAllBasicBinaryTestsL(gBasicBinaryTestCases, aSwitches, EFalse);
1226 void TestCompatibility(const TTestSwitches& aSwitches)
1228 test.Next(_L("test compatibility"));
1230 // logging for failure
1231 gTCType = ESymbianFATSpecific;
1233 failedOnBuf.CreateL(gLogFailureData.iFuncName);
1236 tcUniquePath.CreateL(KNone());
1238 // original file name in DBCS
1239 TFileName fn1 = _L("\\\x798F\x5C71\x96C5\x6CBB");
1240 if (aSwitches.iExeOnSymbian)
1244 TFileName fn = _L("\\ABCD");
1246 TInt r=file.Create(TheFs,fn,EFileRead);
1247 testAndLog(r==KErrNone);
1250 // Assume this file is the first entry in the root directory
1251 r=TheDisk.Open(TheFs,CurrentDrive());
1252 testAndLog(r==KErrNone);
1254 //-- read the 1st dir entry, it should be a DOS entry
1255 const TInt posEntry1=gBootSector.RootDirStartSector() << KDefaultSectorLog2; //-- dir entry1 position
1257 TFatDirEntry fatEntry1;
1258 TPtr8 ptrEntry1((TUint8*)&fatEntry1,sizeof(TFatDirEntry));
1259 testAndLog(TheDisk.Read(posEntry1, ptrEntry1)==KErrNone);
1260 testAndLog(!fatEntry1.IsVFatEntry());
1262 // Manually modify the short name into unicode characters
1263 // Unicode: 0x(798F 5C71 96C5 6CBB)
1264 // Shift-JIS: 0x(959F 8E52 89EB 8EA1)
1266 TBuf8<8> unicodeSN = _L8("ABCD1234");
1267 unicodeSN[0] = 0x95;
1268 unicodeSN[1] = 0x9F;
1269 unicodeSN[2] = 0x8E;
1270 unicodeSN[3] = 0x52;
1271 unicodeSN[4] = 0x89;
1272 unicodeSN[5] = 0xEB;
1273 unicodeSN[6] = 0x8E;
1274 unicodeSN[7] = 0xA1;
1276 fatEntry1.SetName(unicodeSN);
1277 testAndLog(TheDisk.Write(posEntry1, ptrEntry1)==KErrNone);
1280 if (aSwitches.iVerOnSymbian)
1282 // Access the file without the DLL loaded.
1283 TInt r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
1284 testAndLog(r==KErrNone);
1287 r = TheFs.Entry(fn1, entry);
1288 testAndLog(r==KErrNotFound);
1290 // Access the file with the DLL loaded.
1291 r = TheFs.ControlIo(CurrentDrive(), KControlIoEnableFatUtilityFunctions);
1292 testAndLog(r==KErrNone);
1293 r = UserSvr::ChangeLocale(KTestLocale);
1294 testAndLog(r==KErrNone);
1296 r = TheFs.Entry(fn1, entry);
1297 testAndLog(r==KErrNone);
1299 r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
1300 testAndLog(r==KErrNone);
1302 failedOnBuf.Close();
1303 tcUniquePath.Close();
1306 #endif //defined(_DEBUG) || defined(_DEBUG_RELEASE)
1311 void CallTestsL(TTestSwitches& aSwitches)
1314 test.Start(_L("Starting T_FATCHARSETCONV tests"));
1316 #ifdef LOG_FAILURE_DATA
1317 test.Printf(_L("LOG_FAILURE_DATA: ON\n"));
1319 test.Printf(_L("LOG_FAILURE_DATA: OFF\n"));
1322 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1323 // Test only runs on Fat file systems
1324 TheFs.SessionPath(gSessionPath);
1325 TInt r = TheFs.FileSystemName(aSwitches.iMountedFSName, CurrentDrive());
1328 // For automated testing this test should run on FAT file systems only.
1329 // For inter-operability testing on FAT and Win32 file systems.
1330 // if ((AUTO && FAT) || (IOT && (FAT || Win32))
1331 test.Printf(_L("Current File System: \"%S\"\n"), &aSwitches.iMountedFSName);
1332 if( (gAutoTest && isFAT(aSwitches.iMountedFSName)) ||
1333 (gIOTesting && (isFAT(aSwitches.iMountedFSName) || isWin32(aSwitches.iMountedFSName))))
1335 // Log File System Name
1336 gLogFailureData.iFSName = aSwitches.iMountedFSName;
1338 // Store current file name
1341 while(__FILE__[i]!='\0')
1343 fileName.SetLength(i+1);
1344 fileName[i] = __FILE__[i++];
1346 gFileName.Append(fileName);
1349 // Special Cases - Non-Symbian
1350 // Note: this case MUST be run as the first case as it performs formatting!!
1351 TestCompatibility(aSwitches);
1352 CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));
1353 //Special Cases - Only Symbian Specific
1354 if(!gIOTesting && aSwitches.iMountedFSName.Compare(KFAT) == 0)
1356 DoSymbianSpecificCases();
1359 test.Next(_L("Test without DLL loaded"));
1364 TestMainWithoutDLLL(aSwitches);
1366 test.Next(_L("Test with DLL loaded"));
1371 TestMainWithDLLL(aSwitches);
1377 test.Printf(_L("Test only runs on \"FAT\" File Systems !!!\n"));
1379 test.Printf(_L("Test only runs on \"FAT\" and \"Win32\" File Systems !!!\n"));
1384 test.Printf(_L("Drive %C: is not ready!\n"), 'A'+CurrentDrive());
1388 test.Printf(_L("Test only runs on DEBUG builds, see test logs of debug builds for details.\n"));
1389 #endif // _DEBUG) || _DEBUG_RELEASE
1393 LOCAL_C void PushLotsL()
1395 // Expand the cleanup stack
1400 CleanupStack::PushL((CBase*)NULL);
1401 CleanupStack::Pop(1000);
1405 LOCAL_C void DoTests(TInt aDrive, TTestSwitches& aSwitches)
1407 // Do testing on aDrive
1410 gSessionPath=_L("?:\\F32-TST\\");
1412 TInt r=TheFs.DriveToChar(aDrive,driveLetter);
1414 gSessionPath[0]=(TText)driveLetter;
1415 r=TheFs.SetSessionPath(gSessionPath);
1417 test.Printf(_L("gSessionPath = \"%S\"\n"), &gSessionPath);
1419 // !!! Disable platform security tests until we get the new APIs
1420 // if(User::Capability() & KCapabilityRoot)
1421 CheckMountLFFS(TheFs,driveLetter);
1423 User::After(1000000);
1425 // Format(CurrentDrive());
1427 r=TheFs.MkDirAll(gSessionPath);
1428 if(r == KErrCorrupt)
1431 r=TheFs.MkDirAll(gSessionPath);
1434 if (r!=KErrNone && r!=KErrAlreadyExists)
1436 test.Printf(_L("MkDirAll() r %d\n"),r);
1439 TheFs.ResourceCountMarkStart();
1440 TRAP(r,CallTestsL(aSwitches));
1442 TheFs.ResourceCountMarkEnd();
1445 test.Printf(_L("Error: Leave %d\n"),r);
1450 TestingLFFS(EFalse);
1454 GLDEF_C TInt E32Main()
1456 // Test with drive nearly full
1459 CTrapCleanup* cleanup;
1460 cleanup=CTrapCleanup::New();
1461 TRAPD(r,PushLotsL());
1465 test.Start(_L("Starting tests..."));
1467 gSessionPath=_L("?:\\F32-TST\\");
1468 TTestSwitches testSwitches;
1469 ParseCommandArguments(testSwitches);
1473 TheFs.SetAllocFailure(gAllocFailOn);
1479 r=TheFs.CharToDrive(gDriveToTest,theDrive);
1482 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1483 TPckgBuf<TIOCacheValues> pkgOrgValues;
1484 TIOCacheValues& orgValues=pkgOrgValues();
1485 r = controlIo(TheFs,theDrive, KControlIoCacheCount, orgValues);
1488 test.Printf(_L("\n"));
1489 test.Printf(_L("Requests on close queue at start=%d\n"),orgValues.iCloseCount);
1490 test.Printf(_L("Requests on free queue at start=%d\n"),orgValues.iFreeCount);
1491 test.Printf(_L("Requests dynamically allocated at start=%d\n"),orgValues.iAllocated);
1492 test.Printf(_L("Requests in total at start=%d\n"),orgValues.iTotalCount);
1495 DoTests(theDrive, testSwitches);
1498 endTimeC.HomeTime();
1499 TTimeIntervalSeconds timeTakenC;
1500 r=endTimeC.SecondsFrom(timerC,timeTakenC);
1503 test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
1504 TheFs.SetAllocFailure(gAllocFailOff);
1506 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1507 TPckgBuf<TIOCacheValues> pkgValues;
1508 TIOCacheValues& values=pkgValues();
1509 r = controlIo(TheFs,theDrive, KControlIoCacheCount, values);
1512 test.Printf(_L("Requests on close queue at end=%d\n"),values.iCloseCount);
1513 test.Printf(_L("Requests on free queue at end=%d\n"),values.iFreeCount);
1514 test.Printf(_L("Requests dynamically allocated at end=%d\n"),values.iAllocated);
1515 test.Printf(_L("Requests in total at end=%d\n"),values.iTotalCount);
1517 test(orgValues.iCloseCount==values.iCloseCount);
1518 test(orgValues.iAllocated == values.iAllocated);