Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "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.
23 This contains CT_FsData
28 #include "FileserverUtil.h"
36 _LIT(KAttMask, "attmask" );
38 _LIT(KDrive, "drive");
42 _LIT(KNewName, "newname");
43 _LIT(KOldName, "oldname");
44 _LIT(KLongName, "longname");
45 _LIT(KShortName, "shortname");
46 _LIT(KLengthBuffer, "length_buffer");
47 _LIT(KLengthRead, "length_read");
48 _LIT(KEntrySortKey, "sortkey");
49 _LIT(KEntrySetAttMask, "setattmask");
50 _LIT(KEntryClearAttMask, "clearattmask");
52 _LIT(KOffset, "offset");
53 _LIT(KTUidType, "uidtype");
54 _LIT(KIsDirList, "isdirlist");
55 _LIT(KRelated, "related");
56 _LIT(KBadChar, "badchar");
57 _LIT(KIsBadChar, "isbadchar");
58 _LIT(KCompareName, "comparename");
59 _LIT(KComparePath, "comparepath");
60 _LIT(KParseName, "parsename");
61 _LIT(KParseDrive, "parsedrive");
62 _LIT(KParsePath, "parsepath");
63 _LIT(KParseExt, "parseext");
64 _LIT(KIsExist, "isexist");
65 _LIT(KIsSetAtt, "issetatt");
67 _LIT(KIsOpen, "isopen");
68 _LIT(KIsValid, "isvalid");
69 _LIT(KIsInRom, "isinrom");
70 _LIT(KDirEntryArray, "dirEntryObject");
71 _LIT(KDirDirectoryArray, "dirDirectoryObject");
72 _LIT(KObjectEntry, "entry" );
74 // Attributes for compare
75 _LIT(KIsAttReadOnly, "isattreadonly");
76 _LIT(KIsAttHidden, "isatthidden");
77 _LIT(KIsAttSystem, "isattsystem");
78 _LIT(KIsAttDir, "isattdir");
79 _LIT(KIsAttArchive, "isattarchive");
80 _LIT(KIsAttAllowUid, "isattuid");
83 _LIT(KCmdRealName, "RealName");
84 _LIT(KCmdSessionPath, "SessionPath");
85 _LIT(KCmdSetSessionPath, "SetSessionPath");
86 _LIT(KCmdParse, "Parse");
87 _LIT(KCmdMkDir, "MkDir");
88 _LIT(KCmdMkDirAll, "MkDirAll");
89 _LIT(KCmdRmDir, "RmDir");
90 _LIT(KCmdGetDir, "GetDir");
91 _LIT(KCmdDelete, "Delete");
92 _LIT(KCmdRename, "Rename");
93 _LIT(KCmdReplace, "Replace");
95 _LIT(KCmdSetAtt, "SetAtt");
96 _LIT(KCmdModified, "Modified");
97 _LIT(KCmdSetModified, "SetModified");
98 _LIT(KCmdEntry, "Entry");
99 _LIT(KCmdSetEntry, "SetEntry");
100 _LIT(KCmdReadFileSection, "ReadFileSection");
101 _LIT(KCmdIsFileOpen, "IsFileOpen");
102 _LIT(KCmdGetShortName, "GetShortName");
103 _LIT(KCmdGetLongName, "GetLongName");
104 _LIT(KCmdIsFileInRom, "IsFileInRom");
105 _LIT(KCmdIsValidName, "IsValidName");
106 _LIT(KCmdSetSessionToPrivate, "SetSessionToPrivate");
107 _LIT(KCmdPrivatePath, "PrivatePath");
108 _LIT(KCmdCreatePrivatePath, "CreatePrivatePath");
111 _LIT(KESortNone, "ESortNone");
112 _LIT(KESortByName, "ESortByName");
113 _LIT(KESortByExt, "ESortByExt");
114 _LIT(KESortBySize, "ESortBySize");
115 _LIT(KESortByDate, "ESortByDate");
116 _LIT(KESortByUid, "ESortByUid");
117 _LIT(KEDirsAnyOrder, "EDirsAnyOrder");
118 _LIT(KEDirsFirst, "EDirsFirst");
119 _LIT(KEDirsLast, "EDirsLast");
120 _LIT(KEAscending, "EAscending");
121 _LIT(KEDescending, "EDescending");
122 _LIT(KEDirDescending, "EDirDescending");
125 _LIT(KEntryAttUnknown, "KEntryAttUnknown");
126 _LIT(KEntryAttReadOnlyStr, "KEntryAttReadOnly");
127 _LIT(KEntryAttHiddenStr, "KEntryAttHidden");
128 _LIT(KEntryAttSystemStr, "KEntryAttSystem");
129 _LIT(KEntryAttVolumeStr, "KEntryAttVolume");
130 _LIT(KEntryAttDirStr, "KEntryAttDir");
131 _LIT(KEntryAttArchiveStr, "KEntryAttArchive");
132 _LIT(KEntryAttAllowUidStr, "KEntryAttAllowUid");
133 _LIT(KEntryAttXIPStr, "KEntryAttXIP");
136 _LIT(KTimeFormat, "%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B"); //SIZE 30
137 #define KTimeFormatSize 30
138 #define KShortNameSize 13
139 #define KLongNameSize 256
144 * Process a files related command read from the ini file
146 * @param aCommand the command to process
147 * @param aSection the entry in the ini file requiring the command to be processed
149 * @return ETrue if the command is processed
151 TBool CT_FsData::DoCommandFilesL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aSynchronous*/)
153 TBool retVal = ETrue;
155 if (aCommand == KCmdAtt)
159 else if (aCommand == KCmdCreatePrivatePath)
161 DoCmdCreatePrivatePath(aSection);
163 else if (aCommand == KCmdDelete)
165 DoCmdDelete(aSection);
167 else if (aCommand == KCmdEntry)
169 DoCmdEntryL(aSection);
171 else if (aCommand == KCmdGetDir)
173 DoCmdGetDir(aSection);
175 else if (aCommand == KCmdGetShortName)
177 DoCmdGetShortName(aSection);
179 else if (aCommand == KCmdGetLongName)
181 DoCmdGetLongName(aSection);
183 else if (aCommand == KCmdIsFileInRom)
185 DoCmdIsFileInRom(aSection);
187 else if (aCommand == KCmdIsFileOpen)
189 DoCmdIsFileOpen(aSection);
191 else if (aCommand == KCmdIsValidName)
193 DoCmdIsValidName(aSection);
195 else if (aCommand == KCmdMkDir)
197 DoCmdMkDir(aSection);
199 else if (aCommand == KCmdMkDirAll)
201 DoCmdMkDirAll(aSection);
203 else if (aCommand == KCmdModified)
205 DoCmdModified(aSection);
207 else if (aCommand == KCmdParse)
209 DoCmdParse(aSection);
211 else if (aCommand == KCmdPrivatePath)
213 DoCmdPrivatePath(aSection);
215 else if (aCommand == KCmdReadFileSection)
217 DoCmdReadFileSectionL(aSection);
219 else if (aCommand == KCmdRealName)
221 DoCmdRealName(aSection);
223 else if (aCommand == KCmdRename)
225 DoCmdRename(aSection);
227 else if (aCommand == KCmdReplace)
229 DoCmdReplace(aSection);
231 else if (aCommand == KCmdRmDir)
233 DoCmdRmDir(aSection);
235 else if (aCommand == KCmdSessionPath)
237 DoCmdSessionPath(aSection);
239 else if (aCommand == KCmdSetAtt)
241 DoCmdSetAtt(aSection);
243 else if (aCommand == KCmdSetEntry)
245 DoCmdSetEntry(aSection);
247 else if (aCommand == KCmdSetModified)
249 DoCmdSetModified(aSection);
251 else if (aCommand == KCmdSetSessionPath)
253 DoCmdSetSessionPath(aSection);
255 else if (aCommand == KCmdSetSessionToPrivate)
257 DoCmdSetSessionToPrivate(aSection);
267 void CT_FsData::DoCmdRealName(const TDesC& aSection)
269 // Gets name of file from ini file.
271 if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
273 // Gets the real name of a file.
275 TInt err = iFs->RealName(name, realName);
278 ERR_PRINTF2(_L("RealName error %d"), err);
284 INFO_PRINTF2(_L("Real name: %S"), &realName);
286 // Compares realname from ini file and realname from function.
288 if (GET_OPTIONAL_STRING_PARAMETER(KCompareName(), aSection, compareName))
290 if (compareName.CompareC(realName, 0, NULL) != 0)
292 ERR_PRINTF3(_L("Error compare %S != %S"), &realName, &compareName);
293 SetBlockResult(EFail);
297 INFO_PRINTF3(_L("%S == %S"), &realName, &compareName);
304 void CT_FsData::DoCmdSessionPath(const TDesC& aSection)
306 // Gets the session path.
307 TBuf<KMaxTestExecuteCommandLength> path;
308 TInt err = iFs->SessionPath(path);
311 ERR_PRINTF2(_L("SessionPath error %d"), err);
316 // Prints session path.
317 INFO_PRINTF2(_L("Session path is %S"), &path);
319 // Compares path from ini file and path from function.
321 if (GET_OPTIONAL_STRING_PARAMETER(KComparePath(), aSection, comparePath))
323 if (comparePath.CompareC(path, 0, NULL) != 0)
325 ERR_PRINTF3(_L("Error compare %S != %S"), &path, &comparePath);
326 SetBlockResult(EFail);
330 INFO_PRINTF3(_L("%S == %S"), &path, &comparePath);
336 void CT_FsData::DoCmdSetSessionPath(const TDesC& aSection)
338 // Gets path from ini file.
340 if (GET_MANDATORY_STRING_PARAMETER(KPath(), aSection, path))
342 // Sets the session path for the current file server client.
343 TInt err = iFs->SetSessionPath(path);
346 ERR_PRINTF2(_L("SetSessionPath error %d"), err);
351 // Prints session path.
352 INFO_PRINTF2(_L("Path is set into %S"), &path);
357 void CT_FsData::DoCmdParse(const TDesC& aSection)
359 // Gets name of file from ini file.
361 if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
367 // Reads the related file specification.
368 if (GET_OPTIONAL_STRING_PARAMETER(KRelated(), aSection, related))
370 INFO_PRINTF2(_L("Related parameter: %S"), &related);
372 // Parses a filename specification, specifying related file path components.
373 err = iFs->Parse(name, related, parse);
377 // Parses a filename specification.
378 err = iFs->Parse(name, parse);
383 ERR_PRINTF2(_L("Parse error %d"), err);
388 // Writes parsed components to log file.
389 TPtrC parsedResult[] =
391 parse.Drive(), //parsedDrive,
392 parse.Path(), //parsedPath,
393 parse.Name(), //parsedName,
394 parse.Ext() //parsedExt,
397 TBuf<KMaxTestExecuteCommandLength> tempStore;
398 tempStore.Format(_L("Parsed %S, Drive: %S, Path: %S, Name: %S, Ext: %S"), &name,
399 &parsedResult[0], //Drive
400 &parsedResult[1], //Path
401 &parsedResult[2], //Name
402 &parsedResult[3]);//Ext
403 INFO_PRINTF1(tempStore);
406 // Compares parsed components from ini file.
415 TInt size = sizeof(iniParsed) / sizeof(TPtrC);
416 for (TInt i = 0; i < size; i++)
418 // Reads components from ini
420 if (GET_OPTIONAL_STRING_PARAMETER(iniParsed[i], aSection, compareName))
422 if (parsedResult[i].CompareC(compareName, 0, NULL) != 0)
424 ERR_PRINTF3(_L("Error compare %S != %S"), &parsedResult[i], &compareName);
425 SetBlockResult(EFail);
429 INFO_PRINTF3(_L("%S == %S"), &parsedResult[i], &compareName);
437 void CT_FsData::DoCmdMkDir(const TDesC& aSection)
439 // Gets name of directiry from ini file.
441 if (GET_MANDATORY_STRING_PARAMETER(KDir(), aSection, dir))
443 // Makes a directory.
444 TInt err = iFs->MkDir(dir);
447 ERR_PRINTF2(_L("MkDir error %d"), err);
453 void CT_FsData::DoCmdMkDirAll(const TDesC& aSection)
455 // Gets name of directiry from ini file.
457 if (GET_MANDATORY_STRING_PARAMETER(KDir(), aSection, dir))
459 // Makes one or more directories.
460 TInt err = iFs->MkDirAll(dir);
463 ERR_PRINTF2(_L("MkDirAll error %d"), err);
469 void CT_FsData::DoCmdRmDir(const TDesC& aSection)
471 // Gets name of directiry from ini file.
473 if (GET_MANDATORY_STRING_PARAMETER(KDir(), aSection, dir))
475 // Removes a directory.
476 TInt err = iFs->RmDir(dir);
479 ERR_PRINTF2(_L("RmDir error %d"), err);
485 void CT_FsData::DoCmdGetDir(const TDesC& aSection)
487 TBool dataOk = ETrue;
489 // Reads name of directory from ini file.
491 if (!GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
496 // Reads sort key from ini file.
498 TUint sortKey = ESortByName;
499 if (GET_MANDATORY_STRING_PARAMETER(KEntrySortKey(), aSection, entrySortKey))
501 if ( !ConvertToSortKey(entrySortKey, sortKey) )
504 if ( GET_MANDATORY_INT_PARAMETER(KEntrySortKey(), aSection, intTemp) )
519 // Reads attribute mask from ini file
521 // Reads uidtype from ini file
524 TUidType uidType = KNullUid;
525 TBool isUidType = EFalse;
527 TUint attMask = KEntryAttNormal;
529 TBool isDirList = FALSE;
531 if (FileserverUtil::GetAttMask(*this, aSection, KAttMask(), attMask))
533 // Reads boolean of dirlist from ini file.
534 GET_OPTIONAL_BOOL_PARAMETER(KIsDirList(), aSection, isDirList);
536 else if (GET_MANDATORY_INT_PARAMETER(KTUidType(), aSection, intUIDType))
538 TUid id = TUid::Uid(intUIDType);
539 uidType = TUidType(id);
540 INFO_PRINTF2(_L("UID type set to %d"), uidType[0].iUid);
545 ERR_PRINTF2(_L("attmask or %S must be declared !!!"), &KTUidType);
548 // If all data was read
551 // Gets a filtered list of a directory's contents.
553 CT_DirData* dirWrapperEntry = NULL;
554 CT_DirData* dirWrapperDirectory = NULL;
555 CDir* entryArray = NULL;
556 CDir* dirArray = NULL;
558 TPtrC dirDirectoryArray;
560 if (GET_OPTIONAL_STRING_PARAMETER(KDirEntryArray(), aSection, dirEntryArray))
562 TRAP(err, dirWrapperEntry = static_cast<CT_DirData*>(GetDataWrapperL(dirEntryArray)));
565 if (GET_OPTIONAL_STRING_PARAMETER(KDirDirectoryArray(), aSection, dirDirectoryArray))
567 TRAP(err, dirWrapperDirectory = static_cast<CT_DirData*>(GetDataWrapperL(dirDirectoryArray)));
572 // Gets a filtered list of a directory's contents by UID type.
573 err = iFs->GetDir(name, uidType, sortKey, entryArray);
579 // Gets a filtered list of the directory and file entries contained in a directory,
580 // and a list of the directory entries only.
581 err = iFs->GetDir(name, attMask, sortKey, entryArray, dirArray);
585 // Gets a filtered list of a directory's contents.
586 err = iFs->GetDir(name, attMask, sortKey, entryArray);
592 ERR_PRINTF2(_L("GetDir error %d"), err);
597 // Writes sorted entries to log file.
598 INFO_PRINTF2(_L("PATH %S"), &name);
599 for (TInt i = 0; i < entryArray->Count(); i++)
601 TBuf<KMaxTestExecuteCommandLength> tempStore;
602 tempStore.Format(_L("%d) %S"), i+1, &(*entryArray)[i].iName);
603 INFO_PRINTF1(tempStore);
606 // If "_comparename" of parameter is set in INI file, then
607 // try to find this name in the list of entries.
609 if (GET_OPTIONAL_STRING_PARAMETER(KCompareName(), aSection, compareName))
611 // Find compare name in list of entries.
612 TBool isFind = FALSE;
613 for (TInt i = 0; i < entryArray->Count(); i++)
615 if (compareName.CompareC((*entryArray)[i].iName, 0, NULL) == 0)
621 // Reads a flag which specifies a name should be existing or not be existing
622 // specified in parameter "KCompareName".
623 TBool isExist = TRUE;
624 GET_OPTIONAL_BOOL_PARAMETER(KIsExist(), aSection, isExist);
626 TPtrC strIsExist = isExist ? _L("EXIST") : _L("NOT EXIST");
627 INFO_PRINTF3(_L("%S must be %S"), &compareName, &strIsExist);
629 TPtrC strIsFind = isFind ? _L("FOUND") : _L("NOT FOUND");
630 INFO_PRINTF3(_L("%S is %S"), &compareName, &strIsFind);
632 // If name has been found when this name must not be existing
633 // or when name has been not found when name must be existing
634 // then test case fail.
635 if (isExist != isFind)
637 ERR_PRINTF1(_L("Expected exist does not match actual"));
638 SetBlockResult(EFail);
643 // Delete list of data
648 dirWrapperEntry->SetObjectL(entryArray);
658 if(dirWrapperDirectory)
660 dirWrapperDirectory->SetObjectL(dirArray);
671 void CT_FsData::DoCmdDelete(const TDesC& aSection)
673 // Reads name of file from ini file.
675 if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
677 // Deletes a single file.
678 TInt err = iFs->Delete(name);
681 ERR_PRINTF2(_L("Delete error %d"), err);
687 void CT_FsData::DoCmdRename(const TDesC& aSection)
691 // Reads the old name of file or directory from ini file.
693 if ( !GET_MANDATORY_STRING_PARAMETER(KOldName(), aSection, oldName) )
698 // Reads the new name of file or directory from ini file.
700 if ( !GET_MANDATORY_STRING_PARAMETER(KNewName(), aSection, newName) )
707 // Renames a single file or directory.
708 TInt err = iFs->Rename(oldName, newName);
711 ERR_PRINTF2(_L("Rename error %d"), err);
716 INFO_PRINTF3(_L("File %S was renamed to %S successfully"), &oldName, &newName);
721 void CT_FsData::DoCmdReplace(const TDesC& aSection)
725 // Reads the old name of file from ini file.
727 if ( !GET_MANDATORY_STRING_PARAMETER(KOldName(), aSection, oldName) )
732 // Reads the new name of file from ini file.
734 if ( !GET_MANDATORY_STRING_PARAMETER(KNewName(), aSection, newName) )
741 // Replaces a single file with another.
742 TInt err = iFs->Replace(oldName, newName);
745 ERR_PRINTF2(_L("Replace error %d"), err);
750 INFO_PRINTF3(_L("File %S was replaced to %S successfully"), &oldName, &newName);
755 void CT_FsData::DoCmdAtt(const TDesC& aSection)
757 // Reads the name of file from ini file.
759 if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
761 // Gets a file's attributes.
763 TInt err = iFs->Att(name, attValue);
764 INFO_PRINTF2(_L("RFs::Att = 0x%X"), attValue);
767 ERR_PRINTF2(_L("Att error %d"), err);
783 // Writes what attributes has a file.
784 INFO_PRINTF1(_L("--- START --- print all attributes"));
786 TInt size = sizeof(arrAttMask) / sizeof(TUint);
787 for (TInt i = 0; i < size; i++)
789 if (attValue & arrAttMask[i])
791 INFO_PRINTF2(_L("Attribute %S is set"), &ConvertToStrAttMask(arrAttMask[i]));
795 INFO_PRINTF2(_L("Attribute %S is not set"), &ConvertToStrAttMask(arrAttMask[i]));
798 INFO_PRINTF1(_L("--- END --- print all attributes"));
800 // Reads atribute wich is testing.
801 TPtrC testAttMaskStr;
802 if(GET_OPTIONAL_STRING_PARAMETER(KEntrySetAttMask(), aSection, testAttMaskStr))
804 TUint testAttMask = 0;
805 if (FileserverUtil::GetAttMask(*this, aSection, KEntrySetAttMask(), testAttMask))
807 // Reads a flag which specifies a attribute should be set or not set
808 // specified in parameter "KEntrySetAttMask".
809 TBool testIsSet = TRUE;
810 if (GET_OPTIONAL_BOOL_PARAMETER(KIsSetAtt(), aSection, testIsSet))
812 INFO_PRINTF2(_L("TEST attributes %S must be set"), &ConvertToStrAttMask(testAttMask));
816 INFO_PRINTF2(_L("TEST attributes %S must not be set"), &ConvertToStrAttMask(testAttMask));
818 if ( (attValue&testAttMask)==testAttMask )
822 ERR_PRINTF2(_L("All bits not set %S"), &ConvertToStrAttMask(testAttMask));
823 SetBlockResult(EFail);
826 else if ( (attValue&testAttMask)==0 )
830 ERR_PRINTF2(_L("Some bits set %S"), &ConvertToStrAttMask(testAttMask));
831 SetBlockResult(EFail);
836 ERR_PRINTF2(_L("Some bits set %S"), &ConvertToStrAttMask(testAttMask));
837 SetBlockResult(EFail);
842 ERR_PRINTF1(_L("Unknown attribute!"));
843 SetBlockResult(EFail);
850 void CT_FsData::DoCmdSetAtt(const TDesC& aSection)
852 // Reads attributes to be set from ini file.
853 TUint setAttMask = 0;
855 if (!FileserverUtil::GetAttMask(*this, aSection, KEntrySetAttMask(), setAttMask))
857 ERR_PRINTF1(_L("Unknown attribute!"));
858 SetBlockResult(EFail);
861 // Reads attributes to be clear from ini file.
862 TUint clearAttMask = 0;
863 if (!FileserverUtil::GetAttMask(*this, aSection, KEntryClearAttMask(), clearAttMask))
865 ERR_PRINTF1(_L("Unknown attribute!"));
866 SetBlockResult(EFail);
869 // Reads the name of file or directory from ini file.
871 if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
873 // Sets or clears the attributes of a single file or directory.
874 TInt err = iFs->SetAtt(name, setAttMask, clearAttMask);
877 ERR_PRINTF2(_L("SetAtt error %d"), err);
882 INFO_PRINTF1(_L("SetAtt() is successful"));
887 void CT_FsData::DoCmdModified(const TDesC& aSection)
889 // Reads the name of file or directory from ini file.
891 if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
893 // Gets the last modification date and time of a file or a directory, in UTC.
895 TInt err = iFs->Modified(name, time);
898 ERR_PRINTF2(_L("Modified error %d"), err);
903 // Write to log modified date and time.
904 TBuf<KTimeFormatSize> dateString;
905 TRAP (err, time.FormatL(dateString, KTimeFormat));
908 ERR_PRINTF2(_L("time.FormatL() error %d"), err);
909 SetBlockResult(EFail);
913 INFO_PRINTF3(_L("File %S modified: %S"), &name, &dateString);
915 // Reads time in ini file which must be returned from function "Modified()".
917 if (GET_OPTIONAL_STRING_PARAMETER(KTime(), aSection, inputTime))
919 // Convert input string in "KTime" from ini to TTime object.
920 // Assigns a date and time contained in a descriptor.
922 TInt err = iniTime.Set(inputTime);
925 // Compares time from ini file and time returned from function.
928 INFO_PRINTF1(_L("Time equal"));
932 ERR_PRINTF3(_L("Time not equal, %S != %S"), &inputTime, &dateString);
933 SetBlockResult(EFail);
938 ERR_PRINTF2(_L("Fail set time, error %d"), err);
939 SetBlockResult(EFail);
947 void CT_FsData::DoCmdSetModified(const TDesC& aSection)
949 // Reads the time from ini file.
952 if (GET_OPTIONAL_STRING_PARAMETER(KTime(), aSection, inputTime))
954 // Assigns a date and time contained in a descriptor.
955 TInt err = time.Set(inputTime);
958 ERR_PRINTF2(_L("Time set failed, error %d"), err);
959 SetBlockResult(EFail);
963 // Reads the name of file or directory from ini file.
965 if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
967 // Sets the date and time that the contents of a file or directory were modified, in UTC.
968 TInt err = iFs->SetModified(name, time);
971 ERR_PRINTF2(_L("SetModified error %d"), err);
976 INFO_PRINTF1(_L("SetModified() OK"));
981 void CT_FsData::DoCmdEntryL(const TDesC& aSection)
983 TBool isEntryNew = EFalse;
985 // Reads the name of file or directory from ini file.
987 if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
989 TEntry *entry = NULL;
991 // Gets the entry details for a file or directory.
992 TPtrC entryObjectName;
993 if( GET_OPTIONAL_STRING_PARAMETER( KObjectEntry, aSection, entryObjectName ) )
995 INFO_PRINTF1( _L( "Get TEntry class instance." ) );
996 TRAPD( err, entry = (TEntry*)GetDataObjectL(entryObjectName));
997 if ( err != KErrNone )
999 ERR_PRINTF3( _L( "Unrecognized object name parameter value: %S. Error %d"), &entryObjectName, err );
1000 SetBlockResult(EFail);
1004 INFO_PRINTF1( _L( "TEntry class instance accepted OK." ) );
1009 INFO_PRINTF1( _L( "Create new temporary TEntry() class instance." ) );
1010 TRAPD( err, entry = new (ELeave) TEntry() );
1011 if ( err!=KErrNone )
1013 ERR_PRINTF2( _L( "new TEntry() error %d" ), err );
1014 SetBlockResult(EFail);
1022 if ( entry != NULL )
1024 TInt err = iFs->Entry(name, *entry);
1025 if (err != KErrNone)
1027 ERR_PRINTF2(_L("Entry error %d"), err);
1032 // Prints all entry details for the file or directory.
1033 // and compares these entry fith entry in ini file
1037 KEntryAttArchiveStr(),
1038 KEntryAttHiddenStr(),
1039 KEntryAttReadOnlyStr(),
1040 KEntryAttSystemStr(),
1041 KEntryAttAllowUidStr()
1044 TInt64 arrFunctions[] =
1047 entry->IsArchive() > 0,
1048 entry->IsHidden() > 0,
1049 entry->IsReadOnly() > 0,
1050 entry->IsSystem() > 0,
1051 entry->IsTypeValid() > 0
1064 TInt size = sizeof(arrNames) / sizeof(TPtrC);
1065 for (TInt i = 0; i < size; i++)
1067 TBuf<KMaxTestExecuteCommandLength> tempStore;
1068 if (arrFunctions[i])
1070 tempStore.Format(_L("%S - attribute %S is SET"), &name, &arrNames[i]);
1074 tempStore.Format(_L("%S - attribute %S is NOT SET"), &name, &arrNames[i]);
1076 INFO_PRINTF1(tempStore);
1078 // If iniParam[] is set in ini then compare with attribute returned from function.
1079 TBool iniCompare = FALSE;
1080 if (GET_OPTIONAL_BOOL_PARAMETER(iniParam[i], aSection, iniCompare))
1082 // Compares entry in ini file and entry returned from function.
1083 if (arrFunctions[i] != iniCompare)
1085 ERR_PRINTF2(_L("Error compare attribute %S"), &iniParam[i]);
1086 SetBlockResult(EFail);
1091 // Prints size of file.
1092 INFO_PRINTF3(_L("%S - size %d"), &name, entry->iSize);
1094 // Compare size of file returned from function with size from ini.
1096 if (GET_OPTIONAL_INT_PARAMETER(KSize(), aSection, iniSize))
1098 if (entry->iSize != iniSize)
1100 ERR_PRINTF3(_L("Size from ini file not equal with size returned from function (%d != %d)"), iniSize, entry->iSize);
1101 SetBlockResult(EFail);
1105 // Prints the system time of last modification.
1106 TBuf<KTimeFormatSize> dateString;
1107 entry->iModified.FormatL(dateString, KTimeFormat);
1108 INFO_PRINTF3(_L("%S - modified %S"), &name, &dateString);
1110 // Compare time from ini with time returned from function.
1112 if (GET_OPTIONAL_STRING_PARAMETER(KTime(), aSection, iniTimeStr))
1114 // Assigns a date and time contained in a descriptor.
1117 TInt error = iniTime.Set(iniTimeStr);
1118 if(error == KErrNone)
1120 // Compares size in ini file and size returned from function.
1121 if (entry->iModified != iniTime)
1123 ERR_PRINTF1(_L("Time from ini file not equal with time returned from function."));
1124 SetBlockResult(EFail);
1129 ERR_PRINTF3(_L("Cannot convert %S to TTime type. Error: %d"), &iniTimeStr, error);
1130 SetBlockResult(EFail);
1134 // Prints the file's UIDtype.
1135 INFO_PRINTF3(_L("%S - UIDtype %d"), &name, entry->MostDerivedUid().iUid);
1139 INFO_PRINTF1(_L("Delete temporary TEntry() class instance."));
1148 void CT_FsData::DoCmdSetEntry(const TDesC& aSection)
1152 TUint setAttMask = 0;
1153 if (!FileserverUtil::GetAttMask(*this, aSection, KEntrySetAttMask(), setAttMask))
1156 ERR_PRINTF1(_L("Unknown attribute!"));
1157 SetBlockResult(EFail);
1160 // Reads attributes to be clear from ini file.
1161 TUint clearAttMask = 0;
1162 if (!FileserverUtil::GetAttMask(*this, aSection, KEntryClearAttMask(), clearAttMask))
1165 ERR_PRINTF1(_L("Unknown attribute!"));
1166 SetBlockResult(EFail);
1168 // Reads the time from ini file.
1171 if (GET_OPTIONAL_STRING_PARAMETER(KTime(), aSection, inputTime))
1173 // Assigns a date and time contained in a descriptor.
1174 TInt err = time.Set(inputTime);
1175 if (err != KErrNone)
1177 ERR_PRINTF2(_L("Time set failed, error %d"), err);
1178 SetBlockResult(EFail);
1182 // Reads the name of file or directory from ini file.
1184 if (!GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
1191 // Sets both the attributes and the last modified date and time for a file or directory.
1192 TInt err = iFs->SetEntry(name, time, setAttMask, clearAttMask);
1193 if (err != KErrNone)
1195 ERR_PRINTF2(_L("SetEntry error %d"), err);
1200 INFO_PRINTF1(_L("SetEntry() is successful."));
1205 void CT_FsData::DoCmdReadFileSectionL(const TDesC& aSection)
1207 TBuf<KMaxTestExecuteCommandLength> tempStore;
1208 TBool dataOk = ETrue;
1211 // Reads the offset, in bytes, from the start of the file where reading is to start.
1213 if (!GET_MANDATORY_INT_PARAMETER(KOffset(), aSection, offset))
1218 // Reads the number of bytes to be read from the file.
1219 TInt lengthRead = 0;
1220 if (!GET_MANDATORY_INT_PARAMETER(KLengthRead(), aSection, lengthRead))
1225 // Reads the number of bytes to be alocated.
1226 TInt lengthBuffer = 0;
1227 if (!GET_MANDATORY_INT_PARAMETER(KLengthBuffer(), aSection, lengthBuffer))
1232 // Reads the name of file from ini file.
1234 if (!GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
1241 // Creates 8-bit heap descriptor.
1242 HBufC8* buffer = NULL;
1243 TRAPD (err, buffer = HBufC8::NewL(lengthBuffer));
1244 if (err == KErrNone)
1246 // Pushes descriptor onto the cleanup stack.
1247 CleanupStack::PushL(buffer);
1249 // Create memory for 16-bit bufer.
1250 HBufC* buffer16 = NULL;
1251 TRAP (err, buffer16 = HBufC::NewL(lengthBuffer));
1252 if (err != KErrNone)
1254 ERR_PRINTF2(_L("The 16-bit heap descriptor cannot be created, err %d"), err);
1255 SetBlockResult(EFail);
1256 CleanupStack::PopAndDestroy(buffer);
1260 // Pushes descriptor onto the cleanup stack.
1261 CleanupStack::PushL(buffer16);
1263 // Reads data from a file without opening it.
1264 TPtr8 bufferPtr = buffer->Des();
1265 err = iFs->ReadFileSection(name, offset, bufferPtr, lengthRead);
1266 if (err != KErrNone)
1268 ERR_PRINTF2(_L("ReadFileSection error %d"), err);
1273 // Writes data from a file.
1274 tempStore.Format(_L("The data from a file %S, offset =%d, length_buffer =%d, length_read =%d"), &name, offset, lengthBuffer, lengthRead);
1275 INFO_PRINTF1(tempStore);
1276 // Converts 8-bit to 16-bit.
1277 buffer16->Des().Copy(bufferPtr);
1278 TPtr16 bufferPtr16 = buffer16->Des();
1279 INFO_PRINTF2(_L("%S"), &bufferPtr16);
1282 // Clean memory buffer and buffer16
1283 CleanupStack::PopAndDestroy(2, buffer); // buffer, buffer16.
1288 ERR_PRINTF2(_L("The 8-bit heap descriptor cannot be created, err %d"), err);
1289 SetBlockResult(EFail);
1294 void CT_FsData::DoCmdIsFileOpen(const TDesC& aSection)
1296 // Reads the name of file from ini file.
1298 if (GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, file))
1300 // Tests whether a file is open.
1302 TInt err = iFs->IsFileOpen(file, isOpen);
1303 if (err != KErrNone)
1305 ERR_PRINTF2(_L("IsFileOpen error %d"), err);
1312 INFO_PRINTF2(_L("The File %S is OPEN"), &file);
1316 INFO_PRINTF2(_L("The FILE %S is CLOSED"), &file);
1319 // Compare parameter from ini
1321 if (GET_OPTIONAL_BOOL_PARAMETER(KIsOpen(), aSection, iniIsOpen))
1323 if (isOpen != iniIsOpen)
1325 ERR_PRINTF2(_L("Error compare parameter %S"), &KIsOpen);
1326 SetBlockResult(EFail);
1333 void CT_FsData::DoCmdGetShortName(const TDesC& aSection)
1335 // Reads the long name of file from ini file.
1337 if (GET_MANDATORY_STRING_PARAMETER(KLongName(), aSection, longName))
1339 // Gets the short filename associated with a VFAT long filename.
1340 TBuf<KShortNameSize> shortName;
1341 TInt err = iFs->GetShortName(longName, shortName);
1342 if (err != KErrNone)
1344 ERR_PRINTF2(_L("GetShortName error %d"), err);
1349 INFO_PRINTF2(_L("Short name: %S"), &shortName);
1351 // Compares name from ini file and name from function.
1353 if (GET_OPTIONAL_STRING_PARAMETER(KShortName(), aSection, compareName))
1355 if (shortName.CompareC(compareName, 0, NULL) != 0)
1357 ERR_PRINTF3(_L("%S != %S"), &shortName, &compareName);
1358 SetBlockResult(EFail);
1362 INFO_PRINTF3(_L("%S == %S"), &shortName, &compareName);
1369 void CT_FsData::DoCmdGetLongName(const TDesC& aSection)
1371 // Reads the short name of file from ini file.
1373 if (GET_MANDATORY_STRING_PARAMETER(KShortName(), aSection, shortName))
1375 // Gets the long filename associated with a short (8.3) filename.
1376 TBuf<KLongNameSize> longName;
1377 TInt err = iFs->GetLongName(shortName, longName);
1378 if (err != KErrNone)
1380 ERR_PRINTF2(_L("GetLongName error %d"), err);
1385 INFO_PRINTF2(_L("Long name: %S"), &longName);
1387 // Compares name from ini file and name from function.
1389 if (GET_OPTIONAL_STRING_PARAMETER(KLongName(), aSection, compareName))
1391 if (longName.CompareC(compareName, 0, NULL) != 0)
1393 ERR_PRINTF3(_L("%S != %S"), &longName, &compareName);
1394 SetBlockResult(EFail);
1398 INFO_PRINTF3(_L("%S == %S"), &longName, &compareName);
1405 void CT_FsData::DoCmdIsFileInRom(const TDesC& aSection)
1407 // Reads the name of file from ini file.
1409 if (GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, file))
1411 // Gets a pointer to the specified file, if it is in ROM.
1412 iIsFileInRom=iFs->IsFileInRom(file);
1413 INFO_PRINTF2(_L("Fs->IsFileInRom = 0x%X"), iIsFileInRom);
1415 TBool isInROM = (iIsFileInRom!=NULL);
1418 INFO_PRINTF2(_L("File %S in ROM"), &file);
1422 INFO_PRINTF2(_L("File %S not in ROM"), &file);
1425 // Compare parameter from ini
1426 TBool iniIsInROM = FALSE;
1427 if (GET_OPTIONAL_BOOL_PARAMETER(KIsInRom(), aSection, iniIsInROM))
1429 if (isInROM != iniIsInROM)
1431 ERR_PRINTF1(_L("Expected result does not match actual"));
1432 SetBlockResult(EFail);
1438 void CT_FsData::DoCmdIsValidName(const TDesC& aSection)
1440 // Reads the name of file from ini file.
1442 if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name))
1444 TBool isValid = FALSE;
1446 if (GET_OPTIONAL_BOOL_PARAMETER(KIsBadChar(), aSection, isBadChar))
1448 // Tests whether a filename and path are syntactically correct.
1449 // badChar = on return, contains any illegal character within name,
1450 // if the path is valid, badChar is blank.
1453 isValid = iFs->IsValidName(name, badChar);
1454 INFO_PRINTF2(_L("BadChar: %c"), badChar);
1457 if (GET_OPTIONAL_STRING_PARAMETER(KBadChar(), aSection, iniBadChar))
1459 TText expectedBadChar=iniBadChar[0];
1460 if (badChar != expectedBadChar)
1462 ERR_PRINTF3(_L("Error compare badchar %c != %c"), badChar, expectedBadChar);
1463 SetBlockResult(EFail);
1467 INFO_PRINTF3(_L("Badchar's has equal value %c == %c"), badChar, expectedBadChar);
1473 // Tests whether a filename and path are syntactically correct.
1474 isValid = iFs->IsValidName(name);
1479 INFO_PRINTF2(_L("Name %S is valid"), &name);
1483 INFO_PRINTF2(_L("Name %S is not valid"), &name);
1486 // Compare parameter from ini
1488 if (GET_OPTIONAL_BOOL_PARAMETER(KIsValid(), aSection, iniIsValid))
1490 if (isValid != iniIsValid)
1492 ERR_PRINTF1(_L("Error compare with ini parameter"));
1493 SetBlockResult(EFail);
1499 void CT_FsData::DoCmdSetSessionToPrivate(const TDesC& aSection)
1501 // Reads the name of drive from ini file.
1502 TDriveNumber driveNumber;
1503 if (!GetDriveNumberFromConfig(aSection, KDrive(), driveNumber))
1505 ERR_PRINTF2(_L("Error read parameter %S"), &KDrive());
1506 SetBlockResult(EFail);
1510 // Sets the session path to point to the private path on the specified drive.
1511 TInt err = iFs->SetSessionToPrivate(driveNumber);
1512 if (err != KErrNone)
1514 ERR_PRINTF2(_L("SetSessionToPrivate error %d"), err);
1519 INFO_PRINTF1(_L("Function DoCmdSetSessionToPrivate() OK"));
1524 void CT_FsData::DoCmdPrivatePath(const TDesC& aSection)
1526 // Creates the text defining the private path for a process.
1527 TBuf<KMaxTestExecuteCommandLength> privatePath;
1528 TInt err = iFs->PrivatePath(privatePath);
1529 if (err != KErrNone)
1531 ERR_PRINTF2(_L("PrivatePath error %d"), err);
1536 INFO_PRINTF2(_L("PrivatePath: %S"), &privatePath);
1538 // Compares path from ini file and path from function.
1540 if (GET_OPTIONAL_STRING_PARAMETER(KComparePath(), aSection, comparePath))
1542 if (comparePath.CompareC(privatePath, 0, NULL) != 0)
1544 ERR_PRINTF3(_L("%S != %S"), &privatePath, &comparePath);
1545 SetBlockResult(EFail);
1549 INFO_PRINTF3(_L("%S == %S"), &privatePath, &comparePath);
1555 void CT_FsData::DoCmdCreatePrivatePath(const TDesC& aSection)
1557 // Reads the name of drive from ini file.
1558 TDriveNumber driveNumber;
1559 if (!GetDriveNumberFromConfig(aSection, KDrive(), driveNumber))
1561 ERR_PRINTF2(_L("Error read parameter %S"), &KDrive());
1562 SetBlockResult(EFail);
1566 // Creates the private path for a process on the specified drive.
1567 TInt err = iFs->CreatePrivatePath(driveNumber);
1568 if (err != KErrNone)
1570 ERR_PRINTF2(_L("PrivatePath error %d"), err);
1575 INFO_PRINTF1(_L("Function DoCmdCreatePrivatePath() OK"));
1580 TBool CT_FsData::ConvertToSortKey(const TDesC& aSortKeyStr, TUint& aSortKey)
1584 if (aSortKeyStr == KESortNone)
1586 aSortKey = ESortNone;
1588 else if (aSortKeyStr == KESortByName)
1590 aSortKey = ESortByName;
1592 else if (aSortKeyStr == KESortByExt)
1594 aSortKey = ESortByExt;
1596 else if (aSortKeyStr == KESortBySize)
1598 aSortKey = ESortBySize;
1600 else if (aSortKeyStr == KESortByDate)
1602 aSortKey = ESortByDate;
1604 else if (aSortKeyStr == KESortByUid)
1606 aSortKey = ESortByUid;
1608 else if (aSortKeyStr == KEDirsAnyOrder)
1610 aSortKey = EDirsAnyOrder;
1612 else if (aSortKeyStr == KEDirsFirst)
1614 aSortKey = EDirsFirst;
1616 else if (aSortKeyStr == KEDirsLast)
1618 aSortKey = EDirsLast;
1620 else if (aSortKeyStr == KEAscending)
1622 aSortKey = EAscending;
1624 else if (aSortKeyStr == KEDescending)
1626 aSortKey = EDescending;
1628 else if (aSortKeyStr == KEDirDescending)
1630 aSortKey = EDirDescending;
1632 else if (aSortKeyStr.Match((_L("*|*"))) != KErrNotFound)
1636 TInt location = aSortKeyStr.Match(_L("*|*"));
1637 //Converting Left part of the data
1638 TPtrC left = aSortKeyStr.Left(location);
1639 if (ConvertToSortKey(left, tmpSortKey))
1641 aSortKey = tmpSortKey;
1648 //Converting right data can be with another "|"
1649 TPtrC right = aSortKeyStr.Mid(location + 1);
1651 if (ConvertToSortKey(right, tmpSortKey))
1653 aSortKey = aSortKey | tmpSortKey;
1668 const TDesC& CT_FsData::ConvertToStrAttMask(TUint aAttMask)
1672 case KEntryAttReadOnly:
1673 return KEntryAttReadOnlyStr;
1674 case KEntryAttHidden:
1675 return KEntryAttHiddenStr;
1676 case KEntryAttSystem:
1677 return KEntryAttSystemStr;
1678 case KEntryAttVolume:
1679 return KEntryAttVolumeStr;
1681 return KEntryAttDirStr;
1682 case KEntryAttArchive:
1683 return KEntryAttArchiveStr;
1685 return KEntryAttXIPStr;
1689 return KEntryAttUnknown;