kerneltest/f32test/rofs/src/t_rofsattrib.cpp
changeset 9 96e5fb8b040d
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Test attribute settings on files
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <e32std_private.h>
       
    20 #include <e32test.h>
       
    21 #include <f32file.h>
       
    22 #include "utl.h"
       
    23 
       
    24 
       
    25 
       
    26 GLREF_D RFs TheFs;
       
    27 
       
    28 RTest	test( _L("T_ROFSATTRIB") );
       
    29 
       
    30 _LIT( KFileRsh1, "rsh" );
       
    31 _LIT( KFileRs1, "rs" );
       
    32 _LIT( KFileRh1, "rh" );
       
    33 _LIT( KFileSh1, "sh" );
       
    34 _LIT( KFileS1, "s" );
       
    35 _LIT( KFileH1, "h" );
       
    36 _LIT( KFileR1, "r" );
       
    37 _LIT( KFileR2, "r2" );
       
    38 _LIT( KFileR3, "r3" );
       
    39 _LIT( KFileS2, "s2" );
       
    40 _LIT( KFileS3, "s3" );
       
    41 _LIT( KFileH2, "h2" );
       
    42 _LIT( KFileH3, "h3" );
       
    43 _LIT( KFileRs2, "rs2" );
       
    44 _LIT( KFileRs3, "rs3" );
       
    45 _LIT( KFileRh2, "rh2" );
       
    46 _LIT( KFileRh3, "rh3" );
       
    47 _LIT( KFileRsh2, "rsh2" );
       
    48 _LIT( KFileRsh3, "rsh3" );
       
    49 
       
    50 _LIT( KDirectoryBase, "Attrib\\");
       
    51 
       
    52 LOCAL_D const TUint KFileListAllAttribs[] =
       
    53 	{
       
    54 	KEntryAttReadOnly | KEntryAttSystem | KEntryAttHidden,	// KFileRsh1
       
    55 	KEntryAttReadOnly | KEntryAttSystem,	// KFileRs1
       
    56 	KEntryAttReadOnly | KEntryAttHidden,	// KFileRh1
       
    57 	KEntryAttSystem	| KEntryAttHidden,// KFileSh1
       
    58 	KEntryAttSystem,	// KFileS1
       
    59 	KEntryAttHidden,	// KFileH1
       
    60 	KEntryAttReadOnly,	// KFileR1
       
    61 	KEntryAttReadOnly,	// KFileR2
       
    62 	KEntryAttReadOnly,	// KFileR3
       
    63 	KEntryAttSystem,	// KFileS2
       
    64 	KEntryAttSystem,	// KFileS3
       
    65 	KEntryAttHidden,	// KFileH2
       
    66 	KEntryAttHidden,	// KFileH3
       
    67 	KEntryAttReadOnly | KEntryAttSystem,	// KFileRs2
       
    68 	KEntryAttReadOnly | KEntryAttSystem,	// KFileRs3
       
    69 	KEntryAttReadOnly | KEntryAttHidden,	// KFileRh2
       
    70 	KEntryAttReadOnly | KEntryAttHidden,	// KFileRh3
       
    71 	KEntryAttReadOnly | KEntryAttSystem | KEntryAttHidden,	// KFileRsh2
       
    72 	KEntryAttReadOnly | KEntryAttSystem | KEntryAttHidden,	// KFileRsh3
       
    73 	};
       
    74 
       
    75 LOCAL_D const TDesC* KFileListAll[] =
       
    76 	{
       
    77 	&KFileRsh1,
       
    78 	&KFileRs1,
       
    79 	&KFileRh1,
       
    80 	&KFileSh1,
       
    81 	&KFileS1,
       
    82 	&KFileH1,
       
    83 	&KFileR1,
       
    84 	&KFileR2,
       
    85 	&KFileR3,
       
    86 	&KFileS2,
       
    87 	&KFileS3,
       
    88 	&KFileH2,
       
    89 	&KFileH3,
       
    90 	&KFileRs2,
       
    91 	&KFileRs3,
       
    92 	&KFileRh2,
       
    93 	&KFileRh3,
       
    94 	&KFileRsh2,
       
    95 	&KFileRsh3,
       
    96 	NULL
       
    97 	};
       
    98 
       
    99 LOCAL_D const TDesC* KFileListReadOnly[] =
       
   100 	{
       
   101 	&KFileRsh1,
       
   102 	&KFileRs1,
       
   103 	&KFileRh1,
       
   104 	&KFileR1,
       
   105 	&KFileR2,
       
   106 	&KFileR3,
       
   107 	&KFileRs2,
       
   108 	&KFileRs3,
       
   109 	&KFileRh2,
       
   110 	&KFileRh3,
       
   111 	&KFileRsh2,
       
   112 	&KFileRsh3,
       
   113 	NULL
       
   114 	};
       
   115 
       
   116 LOCAL_D const TDesC* KFileListNotHidden[] =
       
   117 	{
       
   118 	&KFileRs1,
       
   119 	&KFileS1,
       
   120 	&KFileR1,
       
   121 	&KFileR2,
       
   122 	&KFileR3,
       
   123 	&KFileS2,
       
   124 	&KFileS3,
       
   125 	&KFileRs2,
       
   126 	&KFileRs3,
       
   127 	NULL
       
   128 	};
       
   129 
       
   130 
       
   131 LOCAL_D const TDesC* KFileListNotSystem[] =
       
   132 	{
       
   133 	&KFileRh1,
       
   134 	&KFileH1,
       
   135 	&KFileR1,
       
   136 	&KFileR2,
       
   137 	&KFileR3,
       
   138 	&KFileH2,
       
   139 	&KFileH3,
       
   140 	&KFileRh2,
       
   141 	&KFileRh3,
       
   142 	NULL
       
   143 	};
       
   144 
       
   145 
       
   146 LOCAL_D const TDesC* KFileListNotSystemAndHidden[] =
       
   147 	{
       
   148 	&KFileRsh1,
       
   149 	&KFileRs1,
       
   150 	&KFileRh1,
       
   151 	&KFileS1,
       
   152 	&KFileH1,
       
   153 	&KFileR1,
       
   154 	&KFileR2,
       
   155 	&KFileR3,
       
   156 	&KFileS2,
       
   157 	&KFileS3,
       
   158 	&KFileH2,
       
   159 	&KFileH3,
       
   160 	&KFileRs2,
       
   161 	&KFileRs3,
       
   162 	&KFileRh2,
       
   163 	&KFileRh3,
       
   164 	&KFileRsh2,
       
   165 	&KFileRsh3,
       
   166 	NULL
       
   167 	};
       
   168 
       
   169 
       
   170 LOCAL_D const TDesC* KFileListNotSystemOrHidden[] =
       
   171 	{
       
   172 	&KFileR1,
       
   173 	&KFileR2,
       
   174 	&KFileR3,
       
   175 	NULL
       
   176 	};
       
   177 
       
   178 
       
   179 
       
   180 _LIT( KDriveBase, " :\\" );
       
   181 _LIT( KWildCard, "*" );
       
   182 
       
   183 
       
   184 LOCAL_C void TestFileAttribsL(TInt aDriveToTest)
       
   185 	{
       
   186 	CDir* dir;
       
   187 
       
   188 	TFileName name(KDriveBase);
       
   189 	name[0] = TText('A' + aDriveToTest);
       
   190 	name.Append( KDirectoryBase );
       
   191 	name.Append( KWildCard );
       
   192 
       
   193 	TInt r = TheFs.GetDir( name, KEntryAttMatchMask, ESortNone, dir );
       
   194 	TEST_FOR_ERROR( r );
       
   195 	test( dir->Count() > 0 );
       
   196 
       
   197 	TInt i;
       
   198 	TEntry e;
       
   199 	for( i = 0; KFileListAll[i]; i++ )
       
   200 		{
       
   201 		e = dir->operator[](i);
       
   202 		test.Printf( _L("Found entry %S"), &e.iName );
       
   203 		test( e.iName == *KFileListAll[i] );
       
   204 
       
   205 		// check attributes
       
   206 		TEST_FOR_MATCH( e.iAtt, KFileListAllAttribs[i] );
       
   207 		}
       
   208 	TEST_FOR_MATCH( i, dir->Count() );
       
   209 	delete dir;
       
   210 	}
       
   211 
       
   212 
       
   213 LOCAL_C void TestScanFilesL( const TDesC* aFileList[], TUint aAttribMask, TInt aDriveToTest )
       
   214 	//
       
   215 	// Tests scanning a directory with attribute mask
       
   216 	//
       
   217 	{
       
   218 	CDir* dir;
       
   219 
       
   220 	TFileName name(KDriveBase);
       
   221 	name[0] = TText('A' + aDriveToTest);
       
   222 	name.Append( KDirectoryBase );
       
   223 	name.Append( KWildCard );
       
   224 
       
   225 	TInt r = TheFs.GetDir( name, aAttribMask, ESortNone, dir );
       
   226 	TEST_FOR_ERROR( r );
       
   227 
       
   228 	test( dir->Count() > 0 );
       
   229 
       
   230 	TInt i;
       
   231 	TEntry e;
       
   232 	for( i = 0; aFileList[i]; i++ )
       
   233 		{
       
   234 		e = dir->operator[](i);
       
   235 		test.Printf( _L("Found entry %S"), &e.iName );
       
   236 		test( e.iName == *aFileList[i] );
       
   237 		}
       
   238 	TEST_FOR_MATCH( i, dir->Count() );
       
   239 	delete dir;
       
   240 	}
       
   241 
       
   242 
       
   243 
       
   244 
       
   245 
       
   246 //************************
       
   247 // Entry point
       
   248 
       
   249 void DoTestL(TInt aDriveToTest)
       
   250 	{
       
   251 	test.Title();
       
   252 	test.Start( _L("Testing ROFS directory structure") );
       
   253 	
       
   254 	const TUint KNotSystem = KEntryAttReadOnly | KEntryAttHidden;
       
   255 	const TUint KNotHidden = KEntryAttReadOnly | KEntryAttSystem;
       
   256 	const TUint KNotSystemOrHidden = KEntryAttNormal;
       
   257 
       
   258 	test.Next( _L("Checking attributes of files") );
       
   259 	TestFileAttribsL(aDriveToTest);
       
   260 	test.Next( _L("Testing not system") );
       
   261 	TestScanFilesL( KFileListNotSystem, KNotSystem, aDriveToTest );
       
   262 	test.Next( _L("Testing not hidden") );
       
   263 	TestScanFilesL( KFileListNotHidden, KNotHidden, aDriveToTest );
       
   264 	test.Next( _L("Testing not system or hidden") );
       
   265 	TestScanFilesL( KFileListNotSystemOrHidden, KNotSystemOrHidden, aDriveToTest );
       
   266 	test.End();
       
   267 	}