kerneltest/f32test/rofs/src/t_rofsmultiple.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2005-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 opening of hidden, replaced and newly added files belonging to multiple ROFS.
       
    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 GLREF_D RFs TheFs;
       
    25 
       
    26 RTest test( _L("T_ROFSMULTIPLE") );
       
    27 
       
    28 // Required to test multiple ROFS
       
    29 _LIT( KTestHidden1, "Multiple\\hidden1.txt" );
       
    30 _LIT( KTestHidden2, "Multiple\\hidden2.txt" );
       
    31 _LIT( KTestHidden3, "Multiple\\hidden3.txt" );
       
    32 _LIT( KTestNew1, "Multiple\\new1.txt" );
       
    33 _LIT( KTestNew2, "Multiple\\new2.txt" );
       
    34 _LIT( KTestNew3, "Multiple\\new3.txt" );
       
    35 _LIT( KTestNew4, "Multiple\\new4.txt" );
       
    36 _LIT( KTestReplaceMe1, "Multiple\\replaceme1.txt" );
       
    37 _LIT( KTestReplaceMe2, "Multiple\\replaceme2.txt" );
       
    38 _LIT( KTestReplaceMe3, "Multiple\\replaceme3.txt" );
       
    39 _LIT( KTestReplaceMe4, "Multiple\\replaceme4.txt" );
       
    40 _LIT( KTestReplaceMe5, "Multiple\\replaceme5.txt" );
       
    41 _LIT( KTestRom,        "Multiple\\rom.txt" );
       
    42 _LIT( KTestRomHide,    "Multiple\\romhide.txt" );
       
    43 _LIT( KTestRomReplace, "Multiple\\romreplace.txt" );
       
    44 _LIT( KTestRomReplaceFat, "Multiple\\romreplacefat.txt" );
       
    45 _LIT8( KReplaceMe8FileContent1, "rofs1" );
       
    46 _LIT8( KReplaceMe8FileContent2, "rofs2" );
       
    47 _LIT8( KReplaceMe8FileContent3, "rofs3" );
       
    48 _LIT8( KReplaceMe8FileContent5, "cfat5" );
       
    49 
       
    50 
       
    51 _LIT( KRootFileMultiple, "Multiple\\multirofs.txt");
       
    52 
       
    53 _LIT( KDriveBase, " :\\" );
       
    54 
       
    55 const TInt KNewlyAddedFilesCount = 5;
       
    56 const TDesC* const newlyAddedFilesArray[5] =
       
    57 	{
       
    58 	&KTestNew1, &KTestNew2, &KTestNew3, &KTestNew4, &KTestRom
       
    59 	};
       
    60 	
       
    61 const TInt KReplacedFilesCount = 7;
       
    62 const TDesC* const replacedFilesArray[7] =
       
    63 	{
       
    64 	&KTestReplaceMe1, &KTestReplaceMe2, &KTestReplaceMe3, &KTestReplaceMe4, &KTestRomReplace, &KTestReplaceMe5,  &KTestRomReplaceFat
       
    65 	};
       
    66 
       
    67 const TInt KHiddenFilesCount = 4;
       
    68 const TDesC* const hiddenFilesArray[4] =
       
    69 	{
       
    70 	&KTestHidden1, &KTestHidden2, &KTestHidden3, &KTestRomHide 
       
    71 	};
       
    72 
       
    73 LOCAL_C void TestMultipleRofsL(TInt aDriveToTest)
       
    74 //
       
    75 // Test multiple Rofs
       
    76 //
       
    77 	{
       
    78 	TFileName name(KDriveBase);
       
    79 	name[0] = TText('A' + aDriveToTest);
       
    80 	TInt i;
       
    81 	// hidden
       
    82 	test.Next( _L("Test opening hidden files.") );
       
    83 	for( i = 0; i < KHiddenFilesCount; i++ )
       
    84 		{
       
    85 		name.SetLength( 3 );	// trim back to drive specifier
       
    86 		name.Append( *hiddenFilesArray[i] );
       
    87 		test.Printf( _L("Opening file %S\n"), &name );
       
    88 		RFile file;
       
    89 		TInt r = file.Open( TheFs, name, EFileRead );
       
    90 		TEST_FOR_MATCH( r, KErrNotFound );
       
    91 		file.Close();
       
    92 		}
       
    93 
       
    94 	// newly added
       
    95 	test.Next( _L("Test opening newly added files.") );
       
    96 	for( i = 0; i < KNewlyAddedFilesCount; i++ )
       
    97 		{
       
    98 		name.SetLength( 3 );
       
    99 		name.Append( *newlyAddedFilesArray[i] );
       
   100 		test.Printf( _L("Opening file %S\n"), &name );
       
   101 		RFile file;
       
   102 		TInt r = file.Open( TheFs, name, EFileRead );
       
   103 		TEST_FOR_ERROR( r );
       
   104 		file.Close();
       
   105 		}
       
   106 	
       
   107 	// replaced	
       
   108 	test.Next( _L("Test opening replaced files.") );
       
   109 	for( i = 0; i < KReplacedFilesCount; i++ )
       
   110 		{
       
   111 		name.SetLength( 3 );
       
   112 		name.Append( *replacedFilesArray[i] );
       
   113 		test.Printf( _L("Opening file %S\n"), &name );
       
   114 		RFile file;
       
   115 		TInt r = file.Open( TheFs, name, EFileRead );
       
   116 		TEST_FOR_ERROR( r );
       
   117 		TBuf8<5> buf;
       
   118 		r = file.Read( buf );
       
   119 		TEST_FOR_ERROR( r );
       
   120 		if ( i == 0 )
       
   121 			test(buf == KReplaceMe8FileContent2);
       
   122 		else if (i<4) // i == 1 -> 3
       
   123 			test(buf == KReplaceMe8FileContent3);
       
   124 		else if (i==4)
       
   125 			test(buf == KReplaceMe8FileContent1);
       
   126 		else 
       
   127 			test(buf == KReplaceMe8FileContent5);			
       
   128 		file.Close();
       
   129 		}
       
   130 	}
       
   131 
       
   132 LOCAL_C void TestFilesInRomL(TInt aDriveToTest)
       
   133 //
       
   134 // Test whether files in ROFS appear to be in ROM area of Z:
       
   135 //
       
   136 	{
       
   137 	test.Next( _L("Test if file is in ROM area of Z:") );	
       
   138 	TFileName name(KDriveBase);
       
   139 	name[0] = TText('A' + aDriveToTest);
       
   140 
       
   141 	TInt i;
       
   142 
       
   143 	for( i = 0; i < KNewlyAddedFilesCount; i++ )
       
   144 		{
       
   145 		name.SetLength( 3 );	// trim back to drive specifier
       
   146 		name.Append( *newlyAddedFilesArray[i] );
       
   147 		test.Printf( _L("Testing newly added file %S\n"), &name );
       
   148 		
       
   149 		
       
   150 		if (i==KNewlyAddedFilesCount)
       
   151 			test( NULL != TheFs.IsFileInRom( name ) );
       
   152 		else
       
   153 			test( NULL == TheFs.IsFileInRom( name ) );
       
   154 		}
       
   155 
       
   156 	test.Next( _L("Test if replaced file is in ROM area of Z:") );	
       
   157 
       
   158 	for( i = 0; i < KReplacedFilesCount; i++ )
       
   159 		{
       
   160 		name.SetLength( 3 );
       
   161 		name.Append( *replacedFilesArray[i] );
       
   162 		test.Printf( _L("Testing replaced file %S\n"), &name );
       
   163 		test( NULL == TheFs.IsFileInRom( name ) );
       
   164 		}
       
   165 
       
   166 	test.Next( _L("Test if hidden file is in ROM area of Z:") );
       
   167 
       
   168 	for( i = 0; i < KHiddenFilesCount; i++ )
       
   169 		{
       
   170 		name.SetLength( 3 );
       
   171 		name.Append( *hiddenFilesArray[i] );
       
   172 		test.Printf( _L("Testing hidden file %S\n"), &name );
       
   173 		test( NULL == TheFs.IsFileInRom( name ) );
       
   174 		}	
       
   175 	}
       
   176 
       
   177 LOCAL_C void TestReadFileSectionL(TInt aDriveToTest)
       
   178 //
       
   179 //	Test reading data from a file without opening it.
       
   180 //
       
   181 	{
       
   182 	test.Next( _L("Testing ReadFileSection()."));	
       
   183 	
       
   184 	TBuf8<12> testDes;
       
   185 	TInt r;
       
   186 
       
   187 	TFileName name(KDriveBase);
       
   188 	name[0] = TText('A' + aDriveToTest);
       
   189 	TInt i;
       
   190 	for( i = 0; i < KNewlyAddedFilesCount; i++ )
       
   191 		{
       
   192 		name.SetLength( 3 );	// trim back to drive specifier
       
   193 		name.Append( *newlyAddedFilesArray[i] );
       
   194 		r=TheFs.ReadFileSection(name,0,testDes,3);
       
   195 		test(r==KErrNone);
       
   196 		test(testDes.Length()==3);
       
   197 		test(testDes==_L8("hel"));
       
   198 
       
   199 		name.SetLength( 3 );
       
   200 		name.Append( *newlyAddedFilesArray[i] );
       
   201 		r=TheFs.ReadFileSection(name,0,testDes,4);
       
   202 		test(r==KErrNone);
       
   203 		test(testDes.Length()==4);
       
   204 		test(testDes==_L8("hell"));
       
   205 
       
   206 		name.SetLength( 3 );
       
   207 		name.Append( *newlyAddedFilesArray[i] );
       
   208 		r=TheFs.ReadFileSection(name,1,testDes,4);
       
   209 		test(r==KErrNone);
       
   210 		test(testDes.Length()==4);
       
   211 		test(testDes==_L8("ello"));
       
   212 		}
       
   213 
       
   214 	test.Next( _L("Testing ReadFileSection() on replaced files."));	
       
   215 
       
   216 	for( i = 0; i < KReplacedFilesCount; i++ )
       
   217 		{
       
   218 		name.SetLength( 3 );
       
   219 		name.Append( *replacedFilesArray[i] );
       
   220 		r=TheFs.ReadFileSection(name,4,testDes,1);
       
   221 		test(r==KErrNone);
       
   222 		test(testDes.Length()==1);
       
   223 		if ( i == 0 )
       
   224 			test(testDes==_L8("2"));
       
   225 		else if (i<4)
       
   226 			test(testDes==_L8("3"));
       
   227 		else if (i==4)
       
   228 			test(testDes==_L8("1"));
       
   229 		else 
       
   230 			test(testDes==_L8("5"));
       
   231 		}
       
   232 
       
   233 	test.Next( _L("Testing ReadFileSection() on hidden files."));	
       
   234 
       
   235 	for( i = 0; i < KHiddenFilesCount; i++ )
       
   236 		{	
       
   237 		name.SetLength( 3 );
       
   238 		name.Append( *hiddenFilesArray[i] );
       
   239 		r=TheFs.ReadFileSection(name,0,testDes,1);
       
   240 		test(r==KErrNotFound);
       
   241 		}
       
   242 	}
       
   243 
       
   244 LOCAL_C void TestEntryL(TInt aDriveToTest)
       
   245 //
       
   246 //	Test accessing the entry details for a hidden file.
       
   247 //
       
   248 	{
       
   249 	test.Next( _L("Test accessing the entry details for replaced files.") );
       
   250 	TFileName name(KDriveBase);
       
   251 	name[0] = TText('A' + aDriveToTest);
       
   252 	TEntry entry;
       
   253 	TInt r;
       
   254 
       
   255 	TTime dirtimes[4] = { TDateTime(2005,EDecember,9,2,0,3,0),		// 10/12/2005
       
   256 						TDateTime(2005,EDecember,14,4,30,33,0),		// 15/12/2005
       
   257 						TDateTime(2006,EJanuary,1,15,45,37,0), 		// 02/01/2006
       
   258 						TDateTime(2006,EAugust,10,17,47,04,0) }; 	// 11/08/2006
       
   259 
       
   260 	TInt i;
       
   261 	for( i = 0; i < KReplacedFilesCount; i++ )
       
   262 		{
       
   263 		name.SetLength( 3 );	// trim back to drive specifier	
       
   264 		name.Append( *replacedFilesArray[i] );
       
   265 		r = TheFs.Entry(name, entry);
       
   266 		test(r==KErrNone);
       
   267 		test (entry.iName==replacedFilesArray[i]->Right(entry.iName.Length()));
       
   268 
       
   269 		if ( i == 0 )
       
   270 			test(entry.iModified==dirtimes[1]);
       
   271 		else if (i<4)
       
   272 			test(entry.iModified==dirtimes[2]);
       
   273 		else if (i==4)
       
   274 			test(entry.iModified==dirtimes[0]);
       
   275 		else
       
   276 			test(entry.iModified==dirtimes[3]);
       
   277 		}
       
   278 	
       
   279 	test.Next( _L("Test accessing the entry details for hidden files.") );
       
   280 
       
   281 	for ( i = 0; i < KHiddenFilesCount; i++ )
       
   282 		{	
       
   283 		name.SetLength( 3 );
       
   284 		name.Append( *hiddenFilesArray[i] );
       
   285 		r = TheFs.Entry(name, entry);
       
   286 		test(r==KErrNotFound);
       
   287 		}
       
   288 	}
       
   289 
       
   290 //************************
       
   291 // Entry point
       
   292 
       
   293 void DoTestL(TInt aDriveToTest)
       
   294 	{
       
   295 	test.Title();
       
   296 	test.Start( _L("Testing opening hidden, replaced and newly added files belonging to multiple ROFS.") );
       
   297 
       
   298 	test.Printf( _L("Looking for multiple ROFS..\n"));
       
   299 	TBool multipleRofs = EFalse;
       
   300 	TFileName name(KDriveBase);
       
   301 	name[0] = TText('A' + aDriveToTest);
       
   302 
       
   303 	name.SetLength( 3 );	// trim back to drive specifier
       
   304 	name.Append( KRootFileMultiple );
       
   305 
       
   306 	RFile file;
       
   307 	test.Printf( _L("Attempt to open file %S..\n"), &name );
       
   308 	TInt r = file.Open( TheFs, name, EFileRead );
       
   309 	if(r==KErrNone)
       
   310 		{
       
   311 		multipleRofs=ETrue;
       
   312 		file.Close();
       
   313 		test.Printf( _L("Multiple ROFS found. %S is present.\n"), &name);
       
   314 		}
       
   315 	else if(r==KErrNotFound)
       
   316 		{
       
   317 		test.Printf( _L("No multiple ROFS found. %S is not present.\n"), &name);
       
   318 		}
       
   319 	
       
   320 	if (multipleRofs)
       
   321 		{	
       
   322 		TestMultipleRofsL(aDriveToTest);
       
   323 		TestFilesInRomL(aDriveToTest);
       
   324 		TestReadFileSectionL(aDriveToTest);
       
   325 		TestEntryL(aDriveToTest);
       
   326 		}
       
   327 	test.End();
       
   328 	}