os/kernelhwsrv/kerneltest/f32test/rofs/src/t_rofsattrib.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/rofs/src/t_rofsattrib.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,267 @@
     1.4 +// Copyright (c) 2008-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 attribute settings on files
    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 +
    1.28 +
    1.29 +GLREF_D RFs TheFs;
    1.30 +
    1.31 +RTest	test( _L("T_ROFSATTRIB") );
    1.32 +
    1.33 +_LIT( KFileRsh1, "rsh" );
    1.34 +_LIT( KFileRs1, "rs" );
    1.35 +_LIT( KFileRh1, "rh" );
    1.36 +_LIT( KFileSh1, "sh" );
    1.37 +_LIT( KFileS1, "s" );
    1.38 +_LIT( KFileH1, "h" );
    1.39 +_LIT( KFileR1, "r" );
    1.40 +_LIT( KFileR2, "r2" );
    1.41 +_LIT( KFileR3, "r3" );
    1.42 +_LIT( KFileS2, "s2" );
    1.43 +_LIT( KFileS3, "s3" );
    1.44 +_LIT( KFileH2, "h2" );
    1.45 +_LIT( KFileH3, "h3" );
    1.46 +_LIT( KFileRs2, "rs2" );
    1.47 +_LIT( KFileRs3, "rs3" );
    1.48 +_LIT( KFileRh2, "rh2" );
    1.49 +_LIT( KFileRh3, "rh3" );
    1.50 +_LIT( KFileRsh2, "rsh2" );
    1.51 +_LIT( KFileRsh3, "rsh3" );
    1.52 +
    1.53 +_LIT( KDirectoryBase, "Attrib\\");
    1.54 +
    1.55 +LOCAL_D const TUint KFileListAllAttribs[] =
    1.56 +	{
    1.57 +	KEntryAttReadOnly | KEntryAttSystem | KEntryAttHidden,	// KFileRsh1
    1.58 +	KEntryAttReadOnly | KEntryAttSystem,	// KFileRs1
    1.59 +	KEntryAttReadOnly | KEntryAttHidden,	// KFileRh1
    1.60 +	KEntryAttSystem	| KEntryAttHidden,// KFileSh1
    1.61 +	KEntryAttSystem,	// KFileS1
    1.62 +	KEntryAttHidden,	// KFileH1
    1.63 +	KEntryAttReadOnly,	// KFileR1
    1.64 +	KEntryAttReadOnly,	// KFileR2
    1.65 +	KEntryAttReadOnly,	// KFileR3
    1.66 +	KEntryAttSystem,	// KFileS2
    1.67 +	KEntryAttSystem,	// KFileS3
    1.68 +	KEntryAttHidden,	// KFileH2
    1.69 +	KEntryAttHidden,	// KFileH3
    1.70 +	KEntryAttReadOnly | KEntryAttSystem,	// KFileRs2
    1.71 +	KEntryAttReadOnly | KEntryAttSystem,	// KFileRs3
    1.72 +	KEntryAttReadOnly | KEntryAttHidden,	// KFileRh2
    1.73 +	KEntryAttReadOnly | KEntryAttHidden,	// KFileRh3
    1.74 +	KEntryAttReadOnly | KEntryAttSystem | KEntryAttHidden,	// KFileRsh2
    1.75 +	KEntryAttReadOnly | KEntryAttSystem | KEntryAttHidden,	// KFileRsh3
    1.76 +	};
    1.77 +
    1.78 +LOCAL_D const TDesC* KFileListAll[] =
    1.79 +	{
    1.80 +	&KFileRsh1,
    1.81 +	&KFileRs1,
    1.82 +	&KFileRh1,
    1.83 +	&KFileSh1,
    1.84 +	&KFileS1,
    1.85 +	&KFileH1,
    1.86 +	&KFileR1,
    1.87 +	&KFileR2,
    1.88 +	&KFileR3,
    1.89 +	&KFileS2,
    1.90 +	&KFileS3,
    1.91 +	&KFileH2,
    1.92 +	&KFileH3,
    1.93 +	&KFileRs2,
    1.94 +	&KFileRs3,
    1.95 +	&KFileRh2,
    1.96 +	&KFileRh3,
    1.97 +	&KFileRsh2,
    1.98 +	&KFileRsh3,
    1.99 +	NULL
   1.100 +	};
   1.101 +
   1.102 +LOCAL_D const TDesC* KFileListReadOnly[] =
   1.103 +	{
   1.104 +	&KFileRsh1,
   1.105 +	&KFileRs1,
   1.106 +	&KFileRh1,
   1.107 +	&KFileR1,
   1.108 +	&KFileR2,
   1.109 +	&KFileR3,
   1.110 +	&KFileRs2,
   1.111 +	&KFileRs3,
   1.112 +	&KFileRh2,
   1.113 +	&KFileRh3,
   1.114 +	&KFileRsh2,
   1.115 +	&KFileRsh3,
   1.116 +	NULL
   1.117 +	};
   1.118 +
   1.119 +LOCAL_D const TDesC* KFileListNotHidden[] =
   1.120 +	{
   1.121 +	&KFileRs1,
   1.122 +	&KFileS1,
   1.123 +	&KFileR1,
   1.124 +	&KFileR2,
   1.125 +	&KFileR3,
   1.126 +	&KFileS2,
   1.127 +	&KFileS3,
   1.128 +	&KFileRs2,
   1.129 +	&KFileRs3,
   1.130 +	NULL
   1.131 +	};
   1.132 +
   1.133 +
   1.134 +LOCAL_D const TDesC* KFileListNotSystem[] =
   1.135 +	{
   1.136 +	&KFileRh1,
   1.137 +	&KFileH1,
   1.138 +	&KFileR1,
   1.139 +	&KFileR2,
   1.140 +	&KFileR3,
   1.141 +	&KFileH2,
   1.142 +	&KFileH3,
   1.143 +	&KFileRh2,
   1.144 +	&KFileRh3,
   1.145 +	NULL
   1.146 +	};
   1.147 +
   1.148 +
   1.149 +LOCAL_D const TDesC* KFileListNotSystemAndHidden[] =
   1.150 +	{
   1.151 +	&KFileRsh1,
   1.152 +	&KFileRs1,
   1.153 +	&KFileRh1,
   1.154 +	&KFileS1,
   1.155 +	&KFileH1,
   1.156 +	&KFileR1,
   1.157 +	&KFileR2,
   1.158 +	&KFileR3,
   1.159 +	&KFileS2,
   1.160 +	&KFileS3,
   1.161 +	&KFileH2,
   1.162 +	&KFileH3,
   1.163 +	&KFileRs2,
   1.164 +	&KFileRs3,
   1.165 +	&KFileRh2,
   1.166 +	&KFileRh3,
   1.167 +	&KFileRsh2,
   1.168 +	&KFileRsh3,
   1.169 +	NULL
   1.170 +	};
   1.171 +
   1.172 +
   1.173 +LOCAL_D const TDesC* KFileListNotSystemOrHidden[] =
   1.174 +	{
   1.175 +	&KFileR1,
   1.176 +	&KFileR2,
   1.177 +	&KFileR3,
   1.178 +	NULL
   1.179 +	};
   1.180 +
   1.181 +
   1.182 +
   1.183 +_LIT( KDriveBase, " :\\" );
   1.184 +_LIT( KWildCard, "*" );
   1.185 +
   1.186 +
   1.187 +LOCAL_C void TestFileAttribsL(TInt aDriveToTest)
   1.188 +	{
   1.189 +	CDir* dir;
   1.190 +
   1.191 +	TFileName name(KDriveBase);
   1.192 +	name[0] = TText('A' + aDriveToTest);
   1.193 +	name.Append( KDirectoryBase );
   1.194 +	name.Append( KWildCard );
   1.195 +
   1.196 +	TInt r = TheFs.GetDir( name, KEntryAttMatchMask, ESortNone, dir );
   1.197 +	TEST_FOR_ERROR( r );
   1.198 +	test( dir->Count() > 0 );
   1.199 +
   1.200 +	TInt i;
   1.201 +	TEntry e;
   1.202 +	for( i = 0; KFileListAll[i]; i++ )
   1.203 +		{
   1.204 +		e = dir->operator[](i);
   1.205 +		test.Printf( _L("Found entry %S"), &e.iName );
   1.206 +		test( e.iName == *KFileListAll[i] );
   1.207 +
   1.208 +		// check attributes
   1.209 +		TEST_FOR_MATCH( e.iAtt, KFileListAllAttribs[i] );
   1.210 +		}
   1.211 +	TEST_FOR_MATCH( i, dir->Count() );
   1.212 +	delete dir;
   1.213 +	}
   1.214 +
   1.215 +
   1.216 +LOCAL_C void TestScanFilesL( const TDesC* aFileList[], TUint aAttribMask, TInt aDriveToTest )
   1.217 +	//
   1.218 +	// Tests scanning a directory with attribute mask
   1.219 +	//
   1.220 +	{
   1.221 +	CDir* dir;
   1.222 +
   1.223 +	TFileName name(KDriveBase);
   1.224 +	name[0] = TText('A' + aDriveToTest);
   1.225 +	name.Append( KDirectoryBase );
   1.226 +	name.Append( KWildCard );
   1.227 +
   1.228 +	TInt r = TheFs.GetDir( name, aAttribMask, ESortNone, dir );
   1.229 +	TEST_FOR_ERROR( r );
   1.230 +
   1.231 +	test( dir->Count() > 0 );
   1.232 +
   1.233 +	TInt i;
   1.234 +	TEntry e;
   1.235 +	for( i = 0; aFileList[i]; i++ )
   1.236 +		{
   1.237 +		e = dir->operator[](i);
   1.238 +		test.Printf( _L("Found entry %S"), &e.iName );
   1.239 +		test( e.iName == *aFileList[i] );
   1.240 +		}
   1.241 +	TEST_FOR_MATCH( i, dir->Count() );
   1.242 +	delete dir;
   1.243 +	}
   1.244 +
   1.245 +
   1.246 +
   1.247 +
   1.248 +
   1.249 +//************************
   1.250 +// Entry point
   1.251 +
   1.252 +void DoTestL(TInt aDriveToTest)
   1.253 +	{
   1.254 +	test.Title();
   1.255 +	test.Start( _L("Testing ROFS directory structure") );
   1.256 +	
   1.257 +	const TUint KNotSystem = KEntryAttReadOnly | KEntryAttHidden;
   1.258 +	const TUint KNotHidden = KEntryAttReadOnly | KEntryAttSystem;
   1.259 +	const TUint KNotSystemOrHidden = KEntryAttNormal;
   1.260 +
   1.261 +	test.Next( _L("Checking attributes of files") );
   1.262 +	TestFileAttribsL(aDriveToTest);
   1.263 +	test.Next( _L("Testing not system") );
   1.264 +	TestScanFilesL( KFileListNotSystem, KNotSystem, aDriveToTest );
   1.265 +	test.Next( _L("Testing not hidden") );
   1.266 +	TestScanFilesL( KFileListNotHidden, KNotHidden, aDriveToTest );
   1.267 +	test.Next( _L("Testing not system or hidden") );
   1.268 +	TestScanFilesL( KFileListNotSystemOrHidden, KNotSystemOrHidden, aDriveToTest );
   1.269 +	test.End();
   1.270 +	}