1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/rofs/src/t_rofsmultiple.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,328 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Test opening of hidden, replaced and newly added files belonging to multiple ROFS.
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <e32std_private.h>
1.23 +#include <e32test.h>
1.24 +#include <f32file.h>
1.25 +#include "utl.h"
1.26 +
1.27 +GLREF_D RFs TheFs;
1.28 +
1.29 +RTest test( _L("T_ROFSMULTIPLE") );
1.30 +
1.31 +// Required to test multiple ROFS
1.32 +_LIT( KTestHidden1, "Multiple\\hidden1.txt" );
1.33 +_LIT( KTestHidden2, "Multiple\\hidden2.txt" );
1.34 +_LIT( KTestHidden3, "Multiple\\hidden3.txt" );
1.35 +_LIT( KTestNew1, "Multiple\\new1.txt" );
1.36 +_LIT( KTestNew2, "Multiple\\new2.txt" );
1.37 +_LIT( KTestNew3, "Multiple\\new3.txt" );
1.38 +_LIT( KTestNew4, "Multiple\\new4.txt" );
1.39 +_LIT( KTestReplaceMe1, "Multiple\\replaceme1.txt" );
1.40 +_LIT( KTestReplaceMe2, "Multiple\\replaceme2.txt" );
1.41 +_LIT( KTestReplaceMe3, "Multiple\\replaceme3.txt" );
1.42 +_LIT( KTestReplaceMe4, "Multiple\\replaceme4.txt" );
1.43 +_LIT( KTestReplaceMe5, "Multiple\\replaceme5.txt" );
1.44 +_LIT( KTestRom, "Multiple\\rom.txt" );
1.45 +_LIT( KTestRomHide, "Multiple\\romhide.txt" );
1.46 +_LIT( KTestRomReplace, "Multiple\\romreplace.txt" );
1.47 +_LIT( KTestRomReplaceFat, "Multiple\\romreplacefat.txt" );
1.48 +_LIT8( KReplaceMe8FileContent1, "rofs1" );
1.49 +_LIT8( KReplaceMe8FileContent2, "rofs2" );
1.50 +_LIT8( KReplaceMe8FileContent3, "rofs3" );
1.51 +_LIT8( KReplaceMe8FileContent5, "cfat5" );
1.52 +
1.53 +
1.54 +_LIT( KRootFileMultiple, "Multiple\\multirofs.txt");
1.55 +
1.56 +_LIT( KDriveBase, " :\\" );
1.57 +
1.58 +const TInt KNewlyAddedFilesCount = 5;
1.59 +const TDesC* const newlyAddedFilesArray[5] =
1.60 + {
1.61 + &KTestNew1, &KTestNew2, &KTestNew3, &KTestNew4, &KTestRom
1.62 + };
1.63 +
1.64 +const TInt KReplacedFilesCount = 7;
1.65 +const TDesC* const replacedFilesArray[7] =
1.66 + {
1.67 + &KTestReplaceMe1, &KTestReplaceMe2, &KTestReplaceMe3, &KTestReplaceMe4, &KTestRomReplace, &KTestReplaceMe5, &KTestRomReplaceFat
1.68 + };
1.69 +
1.70 +const TInt KHiddenFilesCount = 4;
1.71 +const TDesC* const hiddenFilesArray[4] =
1.72 + {
1.73 + &KTestHidden1, &KTestHidden2, &KTestHidden3, &KTestRomHide
1.74 + };
1.75 +
1.76 +LOCAL_C void TestMultipleRofsL(TInt aDriveToTest)
1.77 +//
1.78 +// Test multiple Rofs
1.79 +//
1.80 + {
1.81 + TFileName name(KDriveBase);
1.82 + name[0] = TText('A' + aDriveToTest);
1.83 + TInt i;
1.84 + // hidden
1.85 + test.Next( _L("Test opening hidden files.") );
1.86 + for( i = 0; i < KHiddenFilesCount; i++ )
1.87 + {
1.88 + name.SetLength( 3 ); // trim back to drive specifier
1.89 + name.Append( *hiddenFilesArray[i] );
1.90 + test.Printf( _L("Opening file %S\n"), &name );
1.91 + RFile file;
1.92 + TInt r = file.Open( TheFs, name, EFileRead );
1.93 + TEST_FOR_MATCH( r, KErrNotFound );
1.94 + file.Close();
1.95 + }
1.96 +
1.97 + // newly added
1.98 + test.Next( _L("Test opening newly added files.") );
1.99 + for( i = 0; i < KNewlyAddedFilesCount; i++ )
1.100 + {
1.101 + name.SetLength( 3 );
1.102 + name.Append( *newlyAddedFilesArray[i] );
1.103 + test.Printf( _L("Opening file %S\n"), &name );
1.104 + RFile file;
1.105 + TInt r = file.Open( TheFs, name, EFileRead );
1.106 + TEST_FOR_ERROR( r );
1.107 + file.Close();
1.108 + }
1.109 +
1.110 + // replaced
1.111 + test.Next( _L("Test opening replaced files.") );
1.112 + for( i = 0; i < KReplacedFilesCount; i++ )
1.113 + {
1.114 + name.SetLength( 3 );
1.115 + name.Append( *replacedFilesArray[i] );
1.116 + test.Printf( _L("Opening file %S\n"), &name );
1.117 + RFile file;
1.118 + TInt r = file.Open( TheFs, name, EFileRead );
1.119 + TEST_FOR_ERROR( r );
1.120 + TBuf8<5> buf;
1.121 + r = file.Read( buf );
1.122 + TEST_FOR_ERROR( r );
1.123 + if ( i == 0 )
1.124 + test(buf == KReplaceMe8FileContent2);
1.125 + else if (i<4) // i == 1 -> 3
1.126 + test(buf == KReplaceMe8FileContent3);
1.127 + else if (i==4)
1.128 + test(buf == KReplaceMe8FileContent1);
1.129 + else
1.130 + test(buf == KReplaceMe8FileContent5);
1.131 + file.Close();
1.132 + }
1.133 + }
1.134 +
1.135 +LOCAL_C void TestFilesInRomL(TInt aDriveToTest)
1.136 +//
1.137 +// Test whether files in ROFS appear to be in ROM area of Z:
1.138 +//
1.139 + {
1.140 + test.Next( _L("Test if file is in ROM area of Z:") );
1.141 + TFileName name(KDriveBase);
1.142 + name[0] = TText('A' + aDriveToTest);
1.143 +
1.144 + TInt i;
1.145 +
1.146 + for( i = 0; i < KNewlyAddedFilesCount; i++ )
1.147 + {
1.148 + name.SetLength( 3 ); // trim back to drive specifier
1.149 + name.Append( *newlyAddedFilesArray[i] );
1.150 + test.Printf( _L("Testing newly added file %S\n"), &name );
1.151 +
1.152 +
1.153 + if (i==KNewlyAddedFilesCount)
1.154 + test( NULL != TheFs.IsFileInRom( name ) );
1.155 + else
1.156 + test( NULL == TheFs.IsFileInRom( name ) );
1.157 + }
1.158 +
1.159 + test.Next( _L("Test if replaced file is in ROM area of Z:") );
1.160 +
1.161 + for( i = 0; i < KReplacedFilesCount; i++ )
1.162 + {
1.163 + name.SetLength( 3 );
1.164 + name.Append( *replacedFilesArray[i] );
1.165 + test.Printf( _L("Testing replaced file %S\n"), &name );
1.166 + test( NULL == TheFs.IsFileInRom( name ) );
1.167 + }
1.168 +
1.169 + test.Next( _L("Test if hidden file is in ROM area of Z:") );
1.170 +
1.171 + for( i = 0; i < KHiddenFilesCount; i++ )
1.172 + {
1.173 + name.SetLength( 3 );
1.174 + name.Append( *hiddenFilesArray[i] );
1.175 + test.Printf( _L("Testing hidden file %S\n"), &name );
1.176 + test( NULL == TheFs.IsFileInRom( name ) );
1.177 + }
1.178 + }
1.179 +
1.180 +LOCAL_C void TestReadFileSectionL(TInt aDriveToTest)
1.181 +//
1.182 +// Test reading data from a file without opening it.
1.183 +//
1.184 + {
1.185 + test.Next( _L("Testing ReadFileSection()."));
1.186 +
1.187 + TBuf8<12> testDes;
1.188 + TInt r;
1.189 +
1.190 + TFileName name(KDriveBase);
1.191 + name[0] = TText('A' + aDriveToTest);
1.192 + TInt i;
1.193 + for( i = 0; i < KNewlyAddedFilesCount; i++ )
1.194 + {
1.195 + name.SetLength( 3 ); // trim back to drive specifier
1.196 + name.Append( *newlyAddedFilesArray[i] );
1.197 + r=TheFs.ReadFileSection(name,0,testDes,3);
1.198 + test(r==KErrNone);
1.199 + test(testDes.Length()==3);
1.200 + test(testDes==_L8("hel"));
1.201 +
1.202 + name.SetLength( 3 );
1.203 + name.Append( *newlyAddedFilesArray[i] );
1.204 + r=TheFs.ReadFileSection(name,0,testDes,4);
1.205 + test(r==KErrNone);
1.206 + test(testDes.Length()==4);
1.207 + test(testDes==_L8("hell"));
1.208 +
1.209 + name.SetLength( 3 );
1.210 + name.Append( *newlyAddedFilesArray[i] );
1.211 + r=TheFs.ReadFileSection(name,1,testDes,4);
1.212 + test(r==KErrNone);
1.213 + test(testDes.Length()==4);
1.214 + test(testDes==_L8("ello"));
1.215 + }
1.216 +
1.217 + test.Next( _L("Testing ReadFileSection() on replaced files."));
1.218 +
1.219 + for( i = 0; i < KReplacedFilesCount; i++ )
1.220 + {
1.221 + name.SetLength( 3 );
1.222 + name.Append( *replacedFilesArray[i] );
1.223 + r=TheFs.ReadFileSection(name,4,testDes,1);
1.224 + test(r==KErrNone);
1.225 + test(testDes.Length()==1);
1.226 + if ( i == 0 )
1.227 + test(testDes==_L8("2"));
1.228 + else if (i<4)
1.229 + test(testDes==_L8("3"));
1.230 + else if (i==4)
1.231 + test(testDes==_L8("1"));
1.232 + else
1.233 + test(testDes==_L8("5"));
1.234 + }
1.235 +
1.236 + test.Next( _L("Testing ReadFileSection() on hidden files."));
1.237 +
1.238 + for( i = 0; i < KHiddenFilesCount; i++ )
1.239 + {
1.240 + name.SetLength( 3 );
1.241 + name.Append( *hiddenFilesArray[i] );
1.242 + r=TheFs.ReadFileSection(name,0,testDes,1);
1.243 + test(r==KErrNotFound);
1.244 + }
1.245 + }
1.246 +
1.247 +LOCAL_C void TestEntryL(TInt aDriveToTest)
1.248 +//
1.249 +// Test accessing the entry details for a hidden file.
1.250 +//
1.251 + {
1.252 + test.Next( _L("Test accessing the entry details for replaced files.") );
1.253 + TFileName name(KDriveBase);
1.254 + name[0] = TText('A' + aDriveToTest);
1.255 + TEntry entry;
1.256 + TInt r;
1.257 +
1.258 + TTime dirtimes[4] = { TDateTime(2005,EDecember,9,2,0,3,0), // 10/12/2005
1.259 + TDateTime(2005,EDecember,14,4,30,33,0), // 15/12/2005
1.260 + TDateTime(2006,EJanuary,1,15,45,37,0), // 02/01/2006
1.261 + TDateTime(2006,EAugust,10,17,47,04,0) }; // 11/08/2006
1.262 +
1.263 + TInt i;
1.264 + for( i = 0; i < KReplacedFilesCount; i++ )
1.265 + {
1.266 + name.SetLength( 3 ); // trim back to drive specifier
1.267 + name.Append( *replacedFilesArray[i] );
1.268 + r = TheFs.Entry(name, entry);
1.269 + test(r==KErrNone);
1.270 + test (entry.iName==replacedFilesArray[i]->Right(entry.iName.Length()));
1.271 +
1.272 + if ( i == 0 )
1.273 + test(entry.iModified==dirtimes[1]);
1.274 + else if (i<4)
1.275 + test(entry.iModified==dirtimes[2]);
1.276 + else if (i==4)
1.277 + test(entry.iModified==dirtimes[0]);
1.278 + else
1.279 + test(entry.iModified==dirtimes[3]);
1.280 + }
1.281 +
1.282 + test.Next( _L("Test accessing the entry details for hidden files.") );
1.283 +
1.284 + for ( i = 0; i < KHiddenFilesCount; i++ )
1.285 + {
1.286 + name.SetLength( 3 );
1.287 + name.Append( *hiddenFilesArray[i] );
1.288 + r = TheFs.Entry(name, entry);
1.289 + test(r==KErrNotFound);
1.290 + }
1.291 + }
1.292 +
1.293 +//************************
1.294 +// Entry point
1.295 +
1.296 +void DoTestL(TInt aDriveToTest)
1.297 + {
1.298 + test.Title();
1.299 + test.Start( _L("Testing opening hidden, replaced and newly added files belonging to multiple ROFS.") );
1.300 +
1.301 + test.Printf( _L("Looking for multiple ROFS..\n"));
1.302 + TBool multipleRofs = EFalse;
1.303 + TFileName name(KDriveBase);
1.304 + name[0] = TText('A' + aDriveToTest);
1.305 +
1.306 + name.SetLength( 3 ); // trim back to drive specifier
1.307 + name.Append( KRootFileMultiple );
1.308 +
1.309 + RFile file;
1.310 + test.Printf( _L("Attempt to open file %S..\n"), &name );
1.311 + TInt r = file.Open( TheFs, name, EFileRead );
1.312 + if(r==KErrNone)
1.313 + {
1.314 + multipleRofs=ETrue;
1.315 + file.Close();
1.316 + test.Printf( _L("Multiple ROFS found. %S is present.\n"), &name);
1.317 + }
1.318 + else if(r==KErrNotFound)
1.319 + {
1.320 + test.Printf( _L("No multiple ROFS found. %S is not present.\n"), &name);
1.321 + }
1.322 +
1.323 + if (multipleRofs)
1.324 + {
1.325 + TestMultipleRofsL(aDriveToTest);
1.326 + TestFilesInRomL(aDriveToTest);
1.327 + TestReadFileSectionL(aDriveToTest);
1.328 + TestEntryL(aDriveToTest);
1.329 + }
1.330 + test.End();
1.331 + }