kerneltest/f32test/server/t_pwstr.cpp
changeset 9 96e5fb8b040d
child 6 0173bcd7697c
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     1 // Copyright (c) 1998-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 // f32test\server\t_pwstr.cpp
       
    15 // Tests peripheral bus controller password store.
       
    16 // 
       
    17 //
       
    18 
       
    19 //#include <p32mmc.h>
       
    20 
       
    21 #include <e32test.h>
       
    22 #include <f32fsys.h>
       
    23 #include <e32def.h>
       
    24 #include <e32def_private.h>
       
    25 
       
    26 // define this macro to autodetect card re-insertion
       
    27 #define __AUTO_DETECT_MEDIA_CHANGE__
       
    28 
       
    29 const TUint KMMCCIDLength=16;
       
    30 
       
    31 class TCID
       
    32 	{
       
    33 public:
       
    34 	inline TCID() {}					// Default constructor
       
    35 	inline TCID(const TUint8*);
       
    36 	inline TCID& operator=(const TCID&);
       
    37 	inline TCID& operator=(const TUint8*);
       
    38 	inline TBool operator==(const TCID&) const;
       
    39 	inline TBool operator==(const TUint8*) const;
       
    40 	inline void Copy(TUint8*) const;		// Copies big endian 16 bytes CID
       
    41 	inline TUint8 At(TUint anIndex) const;	// Byte from CID at anIndex
       
    42 //private:
       
    43 public:
       
    44 	TUint8 iData[KMMCCIDLength];		// Big endian 128 bit bitfield representing CID
       
    45 	};
       
    46 
       
    47 class TMMC
       
    48 	{
       
    49 public:
       
    50 	static inline TUint32 BigEndian32(const TUint8*);
       
    51 	static inline void BigEndian4Bytes(TUint8* aPtr, TUint32 aVal);
       
    52 	};
       
    53 
       
    54 
       
    55 //	--------  class TCID  --------
       
    56 
       
    57 inline TCID::TCID(const TUint8* aPtr)
       
    58 	{memcpy(&iData[0], aPtr, KMMCCIDLength);}
       
    59 
       
    60 inline TCID& TCID::operator=(const TCID& aCID)
       
    61 	{memcpy(&iData[0], &aCID.iData[0], KMMCCIDLength); return(*this);}
       
    62 
       
    63 inline TCID& TCID::operator=(const TUint8* aPtr)
       
    64 	{memcpy(&iData[0], aPtr, KMMCCIDLength); return(*this);}
       
    65 
       
    66 inline TBool TCID::operator==(const TCID& aCID) const
       
    67 	{return(memcompare(&iData[0],KMMCCIDLength,&aCID.iData[0],KMMCCIDLength)==0);}
       
    68 
       
    69 inline TBool TCID::operator==(const TUint8* aPtr) const
       
    70 	{return(memcompare(&iData[0],KMMCCIDLength,aPtr,KMMCCIDLength)==0);}
       
    71 
       
    72 inline void TCID::Copy(TUint8* aPtr) const
       
    73 	{memcpy(aPtr, &iData[0], KMMCCIDLength);}
       
    74 
       
    75 inline TUint8 TCID::At(TUint anIndex) const
       
    76 	{return(iData[KMMCCIDLength-1-anIndex]);}
       
    77 
       
    78 
       
    79 inline TUint32 TMMC::BigEndian32(const TUint8* aPtr)
       
    80 	{return( (aPtr[0]<<24) | (aPtr[1]<<16) | (aPtr[2]<<8) | (aPtr[3]) );}
       
    81 
       
    82 inline void TMMC::BigEndian4Bytes(TUint8* aPtr, TUint32 aVal)
       
    83 	{
       
    84 	aPtr[0] = (TUint8)((aVal >> 24) & 0xFF);
       
    85 	aPtr[1] = (TUint8)((aVal >> 16) & 0xFF);
       
    86 	aPtr[2] = (TUint8)((aVal >> 8) & 0xFF);
       
    87 	aPtr[3] = (TUint8)(aVal & 0xFF);
       
    88 	}
       
    89 
       
    90 // Static data.
       
    91 
       
    92 LOCAL_D RTest test(_L("T_PWSTR"));
       
    93 
       
    94 LOCAL_D TBusLocalDrive TBLD;
       
    95 LOCAL_D TBool TBLDChangedFlag;
       
    96 
       
    97 LOCAL_D TInt TBLDNum = -1; 	// Change this to specify the drive under test
       
    98 							// e.g. for the lm_pana board when fitted to the
       
    99 							// integrator, TBLDNum should be set to 3.
       
   100 
       
   101 LOCAL_D TInt RFsDNum = -1;	// File Server Drive number
       
   102 
       
   103 struct TTestMapping
       
   104 	{
       
   105 	TInt iCIDIdx;							// index in CID
       
   106 	TInt iPWDIdx;							// index in PWD
       
   107 	};
       
   108 
       
   109 const TInt KMaxLengthOfStoreMapping = KMMCCIDLength + sizeof(TInt32) + KMaxMediaPassword;
       
   110 // EMaxPasswordLength is max size of the password store descriptor
       
   111 // (which actually contains multiple mappings of CID and passwords)
       
   112 const TInt KMaxNumOfStoreEntries= TPasswordStore::EMaxPasswordLength/KMaxLengthOfStoreMapping;
       
   113 
       
   114 const TInt KPWDCnt(4);
       
   115 LOCAL_C TMediaPassword *PWDs[KPWDCnt];
       
   116 
       
   117 //Allocate enough unique CIDs to be able to overflow the store 
       
   118 const TInt KCIDCnt(KMaxNumOfStoreEntries+1);
       
   119 LOCAL_C TCID *CIDs[KCIDCnt];
       
   120 
       
   121 //Let the descriptor be one mapping longer than allowed by the password
       
   122 //store to test overflowing it.
       
   123 const TInt KMaxPersistentStore(TPasswordStore::EMaxPasswordLength+KMaxLengthOfStoreMapping);
       
   124 typedef TBuf8<KMaxPersistentStore> TPersistentStore;
       
   125 LOCAL_C TInt mapSizes[KCIDCnt][KPWDCnt];
       
   126 
       
   127 // Static function prototypes.
       
   128 
       
   129 LOCAL_C void AllocateTestData();
       
   130 LOCAL_C void DeleteTestData();
       
   131 
       
   132 LOCAL_C void AllocateCIDs();
       
   133 LOCAL_C void DeleteCIDs();
       
   134 
       
   135 LOCAL_C void AllocatePasswords();
       
   136 LOCAL_C void DeletePasswords();
       
   137 
       
   138 LOCAL_C void SetUpMapSizes();
       
   139 
       
   140 LOCAL_C void AddMapping(TDes8 &aSt, const TCID *aCID, const TMediaPassword *aPWD);
       
   141 LOCAL_C void DumpStore(const TDesC &aName, const TDesC8 &aSt);
       
   142 LOCAL_C TBool StoresEqual(const TDesC8 &aSt0, const TDesC8 &aSt1);
       
   143 LOCAL_C TBool IsStoreValid(const TDesC8 &aSt);
       
   144 LOCAL_C void PrintCID(const TCID &aCID);
       
   145 LOCAL_C void ParseStore(const TDesC8 &aStore, CArrayFixSeg<TTestMapping> *aMP);
       
   146 LOCAL_C void TestStaticStore();
       
   147 
       
   148 LOCAL_C void RemountMedia();
       
   149 LOCAL_C void AttemptToUnlock(TMediaPassword &aPWD, TBool aStore = EFalse);
       
   150 LOCAL_C void TestLockUnlock();
       
   151 LOCAL_C void TestElidePasswords();
       
   152 LOCAL_C void TestNullPasswords();
       
   153 LOCAL_C void TestControllerStore();
       
   154 
       
   155 LOCAL_C TInt AccessDisk();
       
   156 LOCAL_C void TestAutoUnlock();
       
   157 
       
   158 LOCAL_C void RunTests();
       
   159 
       
   160 // Test data
       
   161 
       
   162 
       
   163 LOCAL_C void AllocateCIDs()
       
   164 //
       
   165 // Allocates a set of static global media identifiers on the heap.
       
   166 // The identifiers are all exactly 128 bits.
       
   167 // Because the test uses only one card, CIDs 1 through 3 can be arbitrary
       
   168 // (they are just used to construct store data.)
       
   169 // 
       
   170 // Format is "CIDXccccccccccc#", where X is the ASCII digit for the index.
       
   171 // The CID is stored internally in big endian format.
       
   172 // TCID::At(TInt i) returns the i'th byte, i.e. cid >> (i * 8) & 0xff, which
       
   173 // is the opposite order to the way they are stored in the array.
       
   174 // CIDs are formed in the same way in pp_mmc.cpp, the WINS ASSP layer.
       
   175 //
       
   176 // For actual card tests, CIDs[0] must correspond to the card's actual CID.
       
   177 //
       
   178 	{
       
   179 
       
   180 #if 1
       
   181 	static TUint8 ht0[KMMCCIDLength] =			// CID0
       
   182 		{
       
   183 		0x06,	0x00,	0x00,	0x31,
       
   184 		0x36,	0x4d,	0x20,	0x20,
       
   185 		0x20,	0x00,	0xb4,	0xff,
       
   186 		0xff,	0xff,	0x63,	0xd9
       
   187 		};
       
   188 #else
       
   189 	static TUint8 ht0[KMMCCIDLength] =			// BPC2
       
   190 		{
       
   191 		0x06,	0x00,	0x00,	0x31,
       
   192 		0x36,	0x4d,	0x20,	0x20,
       
   193 		0x20,	0x00,	0x89,	0xff,
       
   194 		0xff,	0xff,	0x63,	0xa7
       
   195 		};
       
   196 #endif
       
   197 
       
   198 	test.Start(_L("AllocateCIDs"));
       
   199 
       
   200 	TInt i;
       
   201 	for (i = 0; i < KCIDCnt; i++)
       
   202 		{
       
   203 		TUint8 bf[KMMCCIDLength];
       
   204 		TUint j;
       
   205 		bf[0] = 'C';
       
   206 		bf[1] = 'I';
       
   207 		bf[2] = 'D';
       
   208 		bf[3] = TUint8('0' + i);
       
   209 		for (j = 4; j < KMMCCIDLength - 1; j++)
       
   210 			bf[j] = 'c';
       
   211 		bf[KMMCCIDLength - 1] = '#';
       
   212 
       
   213 		if (i == 0)
       
   214 			{
       
   215 			TUint cidIdx = 0;
       
   216 			TLocalDriveCapsV5 driveCaps;
       
   217 			TPckg<TLocalDriveCapsV5> driveCapsPkg(driveCaps);	
       
   218 			if(TBLD.Caps(driveCapsPkg) == KErrNone)
       
   219 				{
       
   220 				// V5 of TLocalDriveCapsV5 now contains a serial number
       
   221 				// which for MMC cards is defined to be the unique CID
       
   222 				if(driveCaps.iSerialNumLength == KMMCCIDLength)
       
   223 					{
       
   224 					for(cidIdx=0; cidIdx<KMMCCIDLength; cidIdx++)
       
   225 						{
       
   226 						bf[cidIdx] = driveCaps.iSerialNum[KMMCCIDLength-cidIdx-1];
       
   227 						}
       
   228 					}
       
   229 				}
       
   230 			if(cidIdx == KMMCCIDLength)
       
   231 				{
       
   232 				test((CIDs[i] = new TCID(bf)) != NULL);
       
   233 				}
       
   234 			else
       
   235 				{
       
   236 #ifdef __WINS__
       
   237 				test((CIDs[i] = new TCID(bf)) != NULL);
       
   238 #else
       
   239 				test((CIDs[i] = new TCID(ht0)) != NULL);
       
   240 #endif
       
   241 				}
       
   242 			}
       
   243 		else
       
   244 			{
       
   245 			test((CIDs[i] = new TCID(bf)) != NULL);
       
   246 			}
       
   247 		}
       
   248 
       
   249 	test.End();
       
   250 	}
       
   251 
       
   252 
       
   253 LOCAL_C void DeleteCIDs()
       
   254 //
       
   255 // Deletes static global media identifiers from the heap.
       
   256 //
       
   257 	{
       
   258 	test.Start(_L("DeleteCIDs"));
       
   259 
       
   260 	TInt i;
       
   261 	for (i = 0; i < KCIDCnt; i++)
       
   262 		delete CIDs[i];
       
   263 
       
   264 	test.End();
       
   265 	}
       
   266 
       
   267 
       
   268 LOCAL_C void AllocatePasswords()
       
   269 //
       
   270 // Allocates a set of static global TMediaPassword objects on the heap.
       
   271 // The passwords range from zero to 16 bytes in length.
       
   272 //
       
   273 	{
       
   274 	test.Start(_L("AllocatePasswords"));
       
   275 
       
   276 	TInt i;
       
   277 	for (i = 0; i < KPWDCnt; i++)
       
   278 		{
       
   279 		test((PWDs[i] = new TMediaPassword) != NULL);
       
   280 		TInt j;
       
   281 		for (j = 0; j < i * 2; j++)
       
   282 			PWDs[i]->Append(TChar('a' + i + j));
       
   283 		}
       
   284 
       
   285 	test.End();
       
   286 	}
       
   287 
       
   288 
       
   289 LOCAL_C void DeletePasswords()
       
   290 //
       
   291 // Deletes static global TMediaPassword objects from the heap.
       
   292 //
       
   293 	{
       
   294 	test.Start(_L("DeletePasswords"));
       
   295 
       
   296 	TInt i;
       
   297 	for (i = 0; i < KPWDCnt; i++)
       
   298 		delete PWDs[i];
       
   299 
       
   300 	test.End();
       
   301 	}
       
   302 
       
   303 
       
   304 LOCAL_C void SetUpMapSizes()
       
   305 //
       
   306 // Initializes static global mapSizes[,] with the persistent store mapping
       
   307 // sizes of each CID and password.
       
   308 //
       
   309 	{
       
   310 	test.Start(_L("SetUpMapSizes"));
       
   311 
       
   312 	TInt i;
       
   313 	for (i = 0; i < KCIDCnt; i++)
       
   314 		{
       
   315 		TInt j;
       
   316 
       
   317 		for (j = 0; j < KPWDCnt; j++)
       
   318 			mapSizes[i][j] = KMMCCIDLength + sizeof(TInt32) + PWDs[j]->Length();
       
   319 		}
       
   320 
       
   321 	test.End();
       
   322 	}
       
   323 
       
   324 
       
   325 LOCAL_C void AllocateTestData()
       
   326 //
       
   327 // Allocates all test data objects on the heap.
       
   328 //
       
   329 	{
       
   330 	AllocateCIDs();
       
   331 	AllocatePasswords();
       
   332 
       
   333 	SetUpMapSizes();
       
   334 	}
       
   335 
       
   336 
       
   337 LOCAL_C void DeleteTestData()
       
   338 //
       
   339 // Frees all test data objects on the heap.
       
   340 //
       
   341 	{
       
   342 	DeletePasswords();
       
   343 	DeleteCIDs();
       
   344 	}
       
   345 
       
   346 
       
   347 // Test functions.
       
   348 
       
   349 
       
   350 LOCAL_C void TestStaticStore()
       
   351 //
       
   352 // Tests the non card specific virtual functions in DPeriphBusController.
       
   353 //	TInt ReadPasswordData(TDes8 &aBuf);
       
   354 //	TInt WritePasswordData(const TDesC8 &aBuf);
       
   355 //	TInt PasswordStoreLengthInBytes();
       
   356 //
       
   357 // store is reset at start of DMMCController::WritePasswordData().
       
   358 //
       
   359 	{
       
   360 	test.Start(_L("TestStore"));
       
   361 
       
   362 	// TBuf8<KMaxPersistentStore> is 4 + 4 + 256 bytes, so allocate on heap.
       
   363 	TPersistentStore *pwStore;
       
   364 	test((pwStore = new TPersistentStore) != NULL);
       
   365 	TPersistentStore &wStore = *pwStore;
       
   366 	TPersistentStore *prStore;
       
   367 	test((prStore = new TPersistentStore) != NULL);
       
   368 	TPersistentStore &rStore = *prStore;
       
   369 
       
   370 	// WritePasswordData()
       
   371 
       
   372 	test.Next(_L("WritePasswordData()"));
       
   373 
       
   374 	test(TBLD.WritePasswordData(wStore) == KErrNone);// empty
       
   375 	test(TBLD.PasswordStoreLengthInBytes() == 0);
       
   376 
       
   377 	AddMapping(wStore, CIDs[1], PWDs[1]);						// exactly one entry
       
   378 	test(TBLD.WritePasswordData(wStore) == KErrNone);
       
   379 	test(TBLD.PasswordStoreLengthInBytes() == mapSizes[1][1]);
       
   380 
       
   381 	AddMapping(wStore, CIDs[2], PWDs[2]);						// exactly two entries
       
   382 	test(TBLD.WritePasswordData(wStore) == KErrNone);
       
   383 	test(TBLD.PasswordStoreLengthInBytes() == mapSizes[1][1] + mapSizes[2][2]);
       
   384 
       
   385 	TInt i;
       
   386 	for (i = 0; i < wStore.Length(); i++)						// corrupt (partial)
       
   387 		{
       
   388 		wStore.SetLength(i);
       
   389 		TInt r(TBLD.WritePasswordData(wStore));
       
   390 		if (i == 0 || i == mapSizes[0][0] || i == mapSizes[0][0] + mapSizes[1][1])
       
   391 			test(r == KErrNone);
       
   392 		else
       
   393 			test(r == KErrCorrupt && TBLD.PasswordStoreLengthInBytes() == 0);
       
   394 		}
       
   395 
       
   396 	test.Next(_L("Exceeding password store size"));	
       
   397 
       
   398 	wStore.Zero();	// empty password store
       
   399 	test(TBLD.WritePasswordData(wStore) == KErrNone);
       
   400 
       
   401 	test.Printf(_L("Adding mappings...\n"));
       
   402 
       
   403 	const TMediaPassword password(_L8("abcdefghijklmnop")); //Need a max length password (KMaxMediaPassword)
       
   404 	for(TInt n=0; n<KCIDCnt; ++n)
       
   405 		{
       
   406 		AddMapping(wStore, CIDs[n], &password);
       
   407 		test.Printf(_L("Mapping:%d store size: %d bytes\n"),n , wStore.Length() );
       
   408 		const TInt r = TBLD.WritePasswordData(wStore);
       
   409 		test.Printf(_L("WritePasswordData() --> ret=%d\n"), r);
       
   410 	 	if(n==KMaxNumOfStoreEntries)
       
   411 	 		test(r == KErrOverflow);
       
   412 	 	else
       
   413 	 		test(r == KErrNone);	
       
   414 		}
       
   415 
       
   416 
       
   417 	// ReadPasswordData().
       
   418 
       
   419 	test.Next(_L("ReadPasswordData()"));
       
   420 
       
   421 	wStore.Zero();												// empty
       
   422 	test(TBLD.WritePasswordData(wStore) == KErrNone);
       
   423 	test(TBLD.ReadPasswordData(rStore) == KErrNone);
       
   424 	test(rStore.Length() == 0);
       
   425 
       
   426 	AddMapping(wStore, CIDs[1], PWDs[1]);						// exactly one entry
       
   427 	test(TBLD.WritePasswordData(wStore) == KErrNone);
       
   428 	rStore.SetLength(0);										// lt store len
       
   429 	test(TBLD.ReadPasswordData(rStore) == KErrNone);
       
   430 	test(rStore.Length() == TBLD.PasswordStoreLengthInBytes());
       
   431 																// gt store len
       
   432 	rStore.SetLength(TBLD.PasswordStoreLengthInBytes() + 4);
       
   433 	test(TBLD.ReadPasswordData(rStore) == 0);
       
   434 	test(rStore.Length() == TBLD.PasswordStoreLengthInBytes());
       
   435 	
       
   436 	TBuf8<2> srStore;											// max lt store len
       
   437 	test(TBLD.ReadPasswordData(srStore) == KErrOverflow);
       
   438 
       
   439 	// Stress test high turnover with memory failure.
       
   440 
       
   441 	test.Next(_L("Memory test"));
       
   442 
       
   443 	TInt r;										// error code
       
   444 
       
   445 	TInt m;
       
   446 	for (m = 1; m < 100; m++)
       
   447 		{
       
   448 		__KHEAP_SETFAIL(RHeap::EDeterministic, m);
       
   449 
       
   450 		TInt j;
       
   451 		for (j = 1; j < KCIDCnt - 1; j++)
       
   452 			{
       
   453 			TInt k;
       
   454 			for (k = 1; k < KPWDCnt - 1; k++)
       
   455 				{
       
   456 				wStore.Zero();
       
   457 
       
   458 				AddMapping(wStore, CIDs[j], PWDs[k]);
       
   459 				AddMapping(wStore, CIDs[j + 1], PWDs[k + 1]);
       
   460 
       
   461 				if ((r = TBLD.WritePasswordData(wStore)) != KErrNone)
       
   462 					{
       
   463 					test(r == KErrNoMemory);
       
   464 					test(TBLD.PasswordStoreLengthInBytes() == 0);
       
   465 					}
       
   466 				else
       
   467 					{
       
   468 					test(TBLD.ReadPasswordData(rStore) == KErrNone);
       
   469 					test(IsStoreValid(rStore) && StoresEqual(rStore, wStore));
       
   470 					}
       
   471 				}
       
   472 			}
       
   473 		__KHEAP_RESET;
       
   474 		}	// for (m = 1; m < 16; m++)
       
   475 
       
   476 	// Clear the store for subsequent tests.
       
   477 
       
   478 	wStore.Zero();
       
   479 	test(TBLD.WritePasswordData(wStore) == KErrNone);
       
   480 	test(TBLD.PasswordStoreLengthInBytes() == 0);
       
   481 
       
   482 	delete prStore;
       
   483 	delete pwStore;
       
   484 
       
   485 	test.End();
       
   486 	}
       
   487 
       
   488 
       
   489 LOCAL_C void AddMapping(TDes8 &aSt, const TCID *aCID, const TMediaPassword *aPWD)
       
   490 //
       
   491 // Adds aCID |-> aPWD mapping to persistent file's store contents.
       
   492 //
       
   493 	{
       
   494 	aSt.SetLength(aSt.Length() + KMMCCIDLength);
       
   495 	aCID->Copy(&aSt[aSt.Length() - KMMCCIDLength]);
       
   496 
       
   497 	TUint8 lenBuf[sizeof(TInt32)];		// TInt32, big endian
       
   498 	TMMC::BigEndian4Bytes(lenBuf, TInt32(aPWD->Length()));
       
   499 	aSt.Append(&lenBuf[0], sizeof(TInt32));
       
   500 
       
   501 	aSt.Append(*aPWD);
       
   502 	}
       
   503 
       
   504 
       
   505 LOCAL_C TBool IsStoreValid(const TDesC8 &aSt)
       
   506 // 
       
   507 // Checks the integrity of the supplied buffer.
       
   508 // 
       
   509 	{
       
   510 	TInt iBIdx;									// buffer index
       
   511 	TBool corrupt(EFalse);						// abort flag
       
   512 	for (iBIdx = 0; iBIdx < aSt.Length(); /* nop */)
       
   513 		{
       
   514 		// Enough raw data for CID, PWD_LEN and 1 byte of PWD.
       
   515 		corrupt = TUint(aSt.Length() - iBIdx) < KMMCCIDLength + sizeof(TInt32) + 1;
       
   516 		if (corrupt)
       
   517 			break;
       
   518 		
       
   519 		// PWD_LEN is valid and enough raw data left for PWD.
       
   520 		iBIdx += KMMCCIDLength;
       
   521 		const TInt32 pwd_len(TMMC::BigEndian32(aSt.Mid(iBIdx).TDesC8::Ptr()));
       
   522 		corrupt = !(
       
   523 				(pwd_len <= KMaxMediaPassword)
       
   524 			&&	aSt.Length() - iBIdx >= TInt(sizeof(TInt32)) + pwd_len );
       
   525 		if (corrupt)
       
   526 			break;
       
   527 		
       
   528 		// skip over PWD_LEN and PWD to next entry.
       
   529 		iBIdx += sizeof(TInt32) + pwd_len;
       
   530 		}
       
   531 
       
   532 	if (corrupt)
       
   533 		DumpStore(_L("invalid"), aSt);
       
   534 
       
   535 	return ! corrupt;
       
   536 	}
       
   537 
       
   538 
       
   539 LOCAL_C void PrintCID(const TCID &aCID)
       
   540 //
       
   541 // Prints the 128 bit CID in big endian format.
       
   542 //
       
   543 	{
       
   544 	test.Printf(_L("CID: "));
       
   545 	TInt i;
       
   546 	for (i = 0; i < TInt(KMMCCIDLength); i += 4)
       
   547 		{
       
   548 		TInt j;
       
   549 		for (j = i; j < i + 4; ++j)
       
   550 			{
       
   551 			test.Printf(_L("%02x: %02x "), j, aCID.At(KMMCCIDLength - j - 1));
       
   552 			}
       
   553 		test.Printf(_L("\n"));
       
   554 		}
       
   555 	}
       
   556 
       
   557 
       
   558 LOCAL_C void ParseStore(const TDesC8 &aSt, CArrayFixSeg<TTestMapping> *aMP)
       
   559 //
       
   560 // Fills aMP with the mappings in aSt.
       
   561 //
       
   562 	{
       
   563 	TInt iBIdx;									// buffer index
       
   564 	TInt r(KErrNone);							// exit code
       
   565 	for (iBIdx = 0; r == KErrNone && iBIdx < aSt.Length(); /* nop */)
       
   566 		{
       
   567 		// Calculate index for CID.
       
   568 		TPtrC8 pCID(aSt.Mid(iBIdx, KMMCCIDLength));	// CID
       
   569 		const TCID cid(pCID.Ptr());
       
   570 		TInt cidIdx;
       
   571 		for (cidIdx = 0; cidIdx < KCIDCnt && !(*(CIDs[cidIdx]) == cid); cidIdx++)
       
   572 			{ /* empty. */ }
       
   573 		// If invalid CID then print CID with valid CIDs.
       
   574 		if (!(cidIdx < KCIDCnt))
       
   575 			{
       
   576 			test.Printf(_L("ParseStore: invalid CID\n"));
       
   577 			PrintCID(cid);
       
   578 			TInt i;
       
   579 			for (i = 0; i < KCIDCnt; i++)
       
   580 				{
       
   581 				test.Printf(_L("ParseStore: valid CID %d\n"), i);
       
   582 				PrintCID(*CIDs[i]);
       
   583 				}
       
   584 			test(EFalse);
       
   585 			}
       
   586 
       
   587 		const TInt32 pwd_len(TMMC::BigEndian32(&aSt[iBIdx + KMMCCIDLength]));
       
   588 
       
   589 		// Calculate index for PWD.
       
   590 		TMediaPassword pwd;
       
   591 		pwd.Copy(&aSt[iBIdx + KMMCCIDLength + sizeof(TInt32)], pwd_len);
       
   592 
       
   593 		TInt pwdIdx;
       
   594 		for (pwdIdx = 0; pwdIdx < KPWDCnt && *PWDs[pwdIdx] != pwd; pwdIdx++)
       
   595 			{ /* empty. */ }
       
   596 		test(pwdIdx < KPWDCnt);
       
   597 
       
   598 		TTestMapping mp;
       
   599 		mp.iCIDIdx = cidIdx;
       
   600 		mp.iPWDIdx = pwdIdx;
       
   601 		TRAP(r, aMP->InsertL(0, mp));
       
   602 		test(r == KErrNone);
       
   603 
       
   604 		iBIdx += KMMCCIDLength + sizeof(TInt32) + pwd_len;
       
   605 		}
       
   606 	}
       
   607 
       
   608 
       
   609 LOCAL_C void DumpStore(const TDesC &aName, const TDesC8 &aSt)
       
   610 //
       
   611 // Prints the contents of the supplied store.
       
   612 //
       
   613 	{
       
   614 	test.Printf(_L("\nstore %S: len = %d\n"), &aName, aSt.Length());
       
   615 
       
   616 	TInt i;
       
   617 	for (i = 0; i < aSt.Length(); i += 8)
       
   618 		{
       
   619 		TInt j;
       
   620 		for (j = i; j < Min(aSt.Length(), i + 8); j++)
       
   621 			test.Printf(_L("%02d: %03d : %02x : %c \n "), j, aSt[j], aSt[j], aSt[j]);
       
   622 		test.Printf(_L("\n"));
       
   623 		}
       
   624 	}
       
   625 
       
   626 
       
   627 LOCAL_C TBool StoresEqual(const TDesC8 &aSt0, const TDesC8 &aSt1)
       
   628 //
       
   629 // Compares aSt1 with aSt2.  Return value indicates whether or not the
       
   630 // stores contain exactly the same mappings, but not necessarily in the
       
   631 // same order.
       
   632 //
       
   633 	{
       
   634 	TBool same(EFalse);
       
   635 
       
   636 	CArrayFixSeg<TTestMapping> *ramp0, *ramp1;
       
   637 
       
   638 	test((ramp0 = new(ELeave) CArrayFixSeg<TTestMapping>(2)) != NULL);
       
   639 	test((ramp1 = new(ELeave) CArrayFixSeg<TTestMapping>(2)) != NULL);
       
   640 	
       
   641 	test(IsStoreValid(aSt0));
       
   642 	test(IsStoreValid(aSt1));
       
   643 
       
   644 	ParseStore(aSt0, ramp0);
       
   645 	ParseStore(aSt1, ramp1);
       
   646 
       
   647 	TArray<TTestMapping> a0(ramp0->Array());
       
   648 	TArray<TTestMapping> a1(ramp1->Array());
       
   649 
       
   650 	if (a0.Count() == a1.Count())
       
   651 	// if #a0 == #a1 and a0 <= a1 then a0 == a1.
       
   652 		{
       
   653 		TBool allInA1(ETrue);
       
   654 		TInt i;
       
   655 		for (i = 0; allInA1 && i < a0.Count(); i++)
       
   656 			{
       
   657 			TBool found(EFalse);
       
   658 			TInt j;
       
   659 			for (j = 0; ! found && j < a0.Count(); j++)
       
   660 				{
       
   661 				found = (
       
   662 						a0[i].iCIDIdx == a1[j].iCIDIdx
       
   663 					&&	a0[i].iPWDIdx == a1[j].iPWDIdx );
       
   664 				}
       
   665 			allInA1 = found;
       
   666 			}
       
   667 
       
   668 		same = allInA1;
       
   669 		}
       
   670 
       
   671 	delete ramp1;
       
   672 	delete ramp0;
       
   673 
       
   674 	if (! same)
       
   675 		{
       
   676 		DumpStore(_L("0"), aSt0);
       
   677 		DumpStore(_L("1"), aSt1);
       
   678 		}
       
   679 
       
   680 	return same;
       
   681 	}
       
   682 
       
   683 
       
   684 LOCAL_C void RemountMedia()
       
   685 //
       
   686 // Forces a media remount and waits for it to take effect.  If the card has a
       
   687 // password, it will become locked the next time that it is powered up.
       
   688 //
       
   689 	{
       
   690 //#ifdef __WINS__
       
   691 //	TBLD.ForceMediaChange();
       
   692 //	UserSvr::ForceRemountMedia(ERemovableMedia0);
       
   693 //	User::After(1 * 1000 * 1000);
       
   694 //#else
       
   695 
       
   696 #ifdef __AUTO_DETECT_MEDIA_CHANGE__
       
   697 	RFs fs;
       
   698 	test(fs.Connect() == KErrNone);
       
   699 
       
   700 	test.Printf(_L("Remove and re-insert card.."));
       
   701 
       
   702 	TInt r;
       
   703 	do
       
   704 		{
       
   705 		TRequestStatus status;
       
   706 		TDriveUnit driveUnit(RFsDNum);
       
   707 		TDriveName driveName = driveUnit.Name();
       
   708 		fs.NotifyChange(ENotifyAll, status, driveName);
       
   709 		test(status == KRequestPending);
       
   710 		User::WaitForRequest(status);
       
   711 		test.Printf(_L("\rAccessing card...          \r"));
       
   712 
       
   713 		r = AccessDisk();
       
   714 		if (r == KErrNotReady)
       
   715 			test.Printf(_L("\rRemove and re-insert card.."));
       
   716 
       
   717 		if (r != KErrNone && r != KErrNotReady && r != KErrLocked)
       
   718 			test.Printf(_L("AccessDisk() returned %d"), r);
       
   719 		}
       
   720 	while (r == KErrNotReady);
       
   721 
       
   722 	test.Printf(_L("\n"));
       
   723 
       
   724 	fs.Close();
       
   725 
       
   726 #else
       
   727 	// Power down the card so that it is locked the next time it is powered up.
       
   728 	test.Printf(_L("Remove and re-insert card.  Press \'z\' when finished.\n"));
       
   729 	while (test.Getch() != 'z')
       
   730 		{ /* empty. */ }
       
   731 #endif
       
   732 
       
   733 //#endif
       
   734 	}
       
   735 
       
   736 
       
   737 LOCAL_C void AttemptToUnlock(TMediaPassword &aPWD, TBool aStore)
       
   738 //
       
   739 // Tests that the card is locked and then tries to unlock it.
       
   740 //
       
   741 	{
       
   742 	TInt r = AccessDisk();
       
   743 	if (r != KErrLocked)
       
   744 		test.Printf(_L("AccessDisk() returned %d\n"), r);
       
   745 	test(r == KErrLocked);
       
   746 	test(TBLD.Unlock(aPWD, aStore) == KErrNone);
       
   747 	}
       
   748 
       
   749 
       
   750 LOCAL_C void TestLockUnlock()
       
   751 //
       
   752 // Tests TBusLocalDrive functions for locking / unlocking individual cards.
       
   753 // Lock() currently means set password only.  The media must be remounted before it
       
   754 // can really be locked.
       
   755 //
       
   756 //			EPbPswdUnlock		EPbPswdLock			EPbPswdClear
       
   757 //			right	wrong		right	wrong		right	wrong	
       
   758 // locked	None	AccDen		AccDec	AccDen		AccDen	AccDen	
       
   759 // unlocked	AldExst	AldExst		None	AccDec		None	AccDen	
       
   760 //
       
   761 // Locked means inaccessible, not just has password.
       
   762 // 
       
   763 	{
       
   764 	test.Start(_L("TestLockUnlock"));
       
   765 
       
   766 	TMediaPassword nul(*PWDs[0]);
       
   767 	TMediaPassword arb1(*PWDs[1]);
       
   768 	TMediaPassword arb2(*PWDs[2]);
       
   769 
       
   770 	// Clear the password store for when function run on its own.
       
   771 	TBuf8<1> nulSt;
       
   772 	test(TBLD.WritePasswordData(nulSt) == KErrNone);// empty
       
   773 	test(TBLD.PasswordStoreLengthInBytes() == 0);
       
   774 
       
   775 	// Give the card an arbitrary password
       
   776 	test.Next(_L("assign test password"));
       
   777 	test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone);
       
   778 	RemountMedia();												// card is now locked
       
   779 
       
   780 	test.Next(_L("lock locked card"));
       
   781 	test(TBLD.SetPassword(arb2, arb1, EFalse) == KErrAccessDenied);	// lock locked wrong
       
   782 	test(TBLD.SetPassword(arb1, arb1, EFalse) == KErrAccessDenied);	// lock locked right
       
   783 
       
   784 	test.Next(_L("unlock locked card"));
       
   785 	test(TBLD.Unlock(arb2, EFalse) == KErrAccessDenied);		// unlock locked wrong
       
   786 	AttemptToUnlock(arb1);
       
   787 
       
   788 	test.Next(_L("unlock unlocked card"));
       
   789 	test(TBLD.Unlock(arb1, EFalse) == KErrAlreadyExists);		// unlock unlocked right
       
   790 	test(TBLD.Unlock(arb2, EFalse) == KErrAlreadyExists);		// unlock unlocked wrong
       
   791 
       
   792 	test.Next(_L("lock unlocked card"));
       
   793 	test(TBLD.SetPassword(arb2, arb1, EFalse) == KErrAccessDenied);	// lock unlocked wrong
       
   794 	test(TBLD.SetPassword(arb1, arb1, EFalse) == KErrNone);			// lock unlocked right
       
   795 
       
   796 	test.Next(_L("clear unlocked card"));
       
   797 	test(TBLD.Clear(arb2) == KErrAccessDenied);					// clear unlocked wrong
       
   798 
       
   799 	//!!! If clear with wrong password, cannot clear with right password in same
       
   800 	// power session (H).
       
   801 	RemountMedia();
       
   802 	AttemptToUnlock(arb1);
       
   803 	test(TBLD.Clear(arb1) == KErrNone);
       
   804 
       
   805 	test.Next(_L("assign test password"));
       
   806 	test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone);				// give test password
       
   807 	RemountMedia();												// make inaccessible
       
   808 
       
   809 	test.Next(_L("clear locked card"));
       
   810 	test(TBLD.Clear(arb2) == KErrAccessDenied);					// clear locked wrong
       
   811 	test(TBLD.Clear(arb1) == KErrAccessDenied);					// clear locked right
       
   812 
       
   813 	// Clear password for subsequent tests.
       
   814 	test.Next(_L("clear password"));
       
   815 	AttemptToUnlock(arb1);
       
   816 	test(TBLD.Clear(arb1) == KErrNone);
       
   817 	test(TBLD.WritePasswordData(nulSt) == KErrNone);
       
   818 	test(TBLD.PasswordStoreLengthInBytes() == 0);
       
   819 
       
   820 	test.End();
       
   821 	}
       
   822 
       
   823 
       
   824 /**
       
   825  * Because MultiMediaCards cannot distinguish where the current password ends
       
   826  * and the new password begins, test the media driver can abort those operations
       
   827  * that would end up giving the user unexpected passwords.
       
   828  * 
       
   829  * The stores are directly compared with buffers because they only use one password
       
   830  * and the passwords are not part of the standard test data.
       
   831  */
       
   832 
       
   833 LOCAL_C void TestElidePasswords()
       
   834 	{
       
   835 	test.Start(_L("TestElidePasswords"));
       
   836 
       
   837 	TMediaPassword a((const TUint8*) "a");		TMediaPassword bcxyz((const TUint8*) "bcxyz");
       
   838 	TMediaPassword ab((const TUint8*) "ab");	TMediaPassword cxyz((const TUint8*) "cxyz");
       
   839 	TMediaPassword abc((const TUint8*) "abc");	TMediaPassword xyz((const TUint8*) "xyz");
       
   840 
       
   841 	TPersistentStore* pstoreAB;
       
   842 	test((pstoreAB = new TPersistentStore) != 0);
       
   843 	TPersistentStore& storeAB = *pstoreAB;
       
   844 	AddMapping(storeAB, CIDs[0], &ab);
       
   845 
       
   846 	TPersistentStore* pstoreCXYZ;
       
   847 	test((pstoreCXYZ = new TPersistentStore) != 0);
       
   848 	TPersistentStore& storeCXYZ = *pstoreCXYZ;
       
   849 	AddMapping(storeCXYZ, CIDs[0], &cxyz);
       
   850 
       
   851 	TPersistentStore *pstoreRd;									// scratch for reading
       
   852 	test((pstoreRd = new TPersistentStore) != NULL);
       
   853 	TPersistentStore& storeRd = *pstoreRd;
       
   854 
       
   855 	TBuf8<1> nulSt;
       
   856 	test(TBLD.SetPassword(nulSt, ab, ETrue) == KErrNone);
       
   857 	RemountMedia();												// card is now locked
       
   858 	test(AccessDisk() == KErrNone);
       
   859 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
   860 	test(storeRd == storeAB);
       
   861 
       
   862 	test.Next(_L("current password too short"));
       
   863 	test(TBLD.SetPassword(a, bcxyz, ETrue) == KErrAccessDenied);
       
   864 	test(AccessDisk() == KErrNone);
       
   865 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
   866 	test(storeRd == storeAB);
       
   867 
       
   868 	test.Next(_L("current password too long"));
       
   869 	test(TBLD.SetPassword(abc, xyz, ETrue) == KErrAccessDenied);
       
   870 	test(AccessDisk() == KErrNone);
       
   871 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
   872 	test(storeRd == storeAB);
       
   873 
       
   874 	test.Next(_L("current password exactly right"));
       
   875 	test(TBLD.SetPassword(ab, cxyz, ETrue) == KErrNone);
       
   876 	test(AccessDisk() == KErrNone);
       
   877 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
   878 	test(storeRd == storeCXYZ);
       
   879 
       
   880 	test.Next(_L("clean up for following tests"));
       
   881 	test(TBLD.Clear(cxyz) == KErrNone);
       
   882 	test(TBLD.WritePasswordData(nulSt) == KErrNone);
       
   883 	test(TBLD.PasswordStoreLengthInBytes() == 0);
       
   884 
       
   885 	delete pstoreRd;
       
   886 	delete pstoreCXYZ;
       
   887 	delete pstoreAB;
       
   888 
       
   889 	test.End();
       
   890 	}
       
   891 
       
   892 
       
   893 /**
       
   894  * test the special cases where null passwords are used.  These are all failed with
       
   895  * KErrAccessDenied by the controller.
       
   896  */
       
   897 
       
   898 LOCAL_C void TestNullPasswords()
       
   899 	{
       
   900 	test.Start(_L("TestNullPasswords"));
       
   901 
       
   902 	TMediaPassword nul(*PWDs[0]);
       
   903 	TMediaPassword arb1(*PWDs[1]);
       
   904 
       
   905 	test.Next(_L("card has no password"));
       
   906 	test(TBLD.SetPassword(nul, nul, ETrue) == KErrAccessDenied);
       
   907 	test(TBLD.Unlock(nul, ETrue) == KErrAlreadyExists);
       
   908 	test(TBLD.Clear(nul) == KErrAccessDenied);
       
   909 
       
   910 	test.Next(_L("card has password and is unlocked"));
       
   911 	test(TBLD.SetPassword(nul, arb1, ETrue) == KErrNone);
       
   912 	RemountMedia();
       
   913 	test(AccessDisk() == KErrNone);
       
   914 	test(TBLD.SetPassword(nul, nul, ETrue) == KErrAccessDenied);
       
   915 	test(TBLD.Unlock(nul, ETrue) == KErrAlreadyExists);
       
   916 	test(TBLD.Clear(nul) == KErrAccessDenied);
       
   917 
       
   918 	test.Next(_L("clean up for following tests"));
       
   919 	test(TBLD.Clear(arb1) == KErrNone);
       
   920 	TBuf8<1> nulSt;
       
   921 	test(TBLD.WritePasswordData(nulSt) == KErrNone);
       
   922 	test(TBLD.PasswordStoreLengthInBytes() == 0);
       
   923 
       
   924 	test.End();
       
   925 	}
       
   926 
       
   927 
       
   928 LOCAL_C void TestControllerStore()
       
   929 // 
       
   930 // Performs standard password functions but stores the mappings in the controller store.
       
   931 //
       
   932 // + mapping added to store (if not exists)
       
   933 // - mapping removed from store (if exists)
       
   934 // 
       
   935 //			EPbPswdUnlock		EPbPswdLock			EPbPswdClear
       
   936 //			right	wrong		right	wrong		right	wrong	
       
   937 // locked	None1	AccDen-		AccDec	AccDen		AccDen	AccDen
       
   938 // unlocked	AccDen	AccDen		None+	AccDec-		None-	AccDen-
       
   939 //
       
   940 // Locked means inaccessible, not just has password.
       
   941 // When the user supplies a password, the mapping in the password store is not used.
       
   942 //
       
   943 // 1.	A locked card with the right mapping in the store cannot happen because of the
       
   944 //		automatic unlocking mechanism.
       
   945 //
       
   946 // Tests start with an unlocked card that has no password.
       
   947 //
       
   948 	{
       
   949 	test.Start(_L("TestControllerStore"));
       
   950 
       
   951 	test.Next(_L("allocate test data"));
       
   952 
       
   953 	TMediaPassword nul(*PWDs[0]);
       
   954 	TMediaPassword arb1(*PWDs[1]);
       
   955 	TMediaPassword arb2(*PWDs[2]);
       
   956 
       
   957 	TPersistentStore *pstoreDef;								// { 3 |-> 3 }
       
   958 	test((pstoreDef = new TPersistentStore) != NULL);
       
   959 	TPersistentStore &storeDef = *pstoreDef;
       
   960 	AddMapping(storeDef, CIDs[3], PWDs[3]);
       
   961 
       
   962 	TPersistentStore *pstore0_1;								// { 3 |-> 3, 0 |-> 1 }
       
   963 	test((pstore0_1 = new TPersistentStore) != NULL);
       
   964 	TPersistentStore &store0_1 = *pstore0_1;
       
   965 	AddMapping(store0_1, CIDs[3], PWDs[3]);
       
   966 	AddMapping(store0_1, CIDs[0], PWDs[1]);
       
   967 
       
   968 	TPersistentStore *pstore0_2;								// { 3 |-> 3, 0 |-> 2 }
       
   969 	test((pstore0_2 = new TPersistentStore) != NULL);
       
   970 	TPersistentStore &store0_2 = *pstore0_2;
       
   971 	AddMapping(store0_2, CIDs[3], PWDs[3]);
       
   972 	AddMapping(store0_2, CIDs[0], PWDs[2]);
       
   973 
       
   974 	TPersistentStore *pstoreRd;									// temp for reading
       
   975 	test((pstoreRd = new TPersistentStore) != NULL);
       
   976 	TPersistentStore &storeRd = *pstoreRd;
       
   977 
       
   978 	// Give card arbitrary password but do not lock or store.
       
   979 	test.Next(_L("assign test password"));
       
   980 	test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone);
       
   981 
       
   982 	// Lock
       
   983 
       
   984 	// Lock unlocked right out.
       
   985 	test.Next(_L("lock unlocked right out"));
       
   986 	test(TBLD.WritePasswordData(storeDef) == KErrNone);
       
   987 	test(TBLD.SetPassword(arb1, arb1, ETrue) == KErrNone);				// + (0 |-> 1)
       
   988 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
   989 	test(StoresEqual(storeRd, store0_1));
       
   990 
       
   991 	// Lock unlocked right in (different to make sure store modified.)
       
   992 	test.Next(_L("lock unlocked right in"));
       
   993 	test(TBLD.WritePasswordData(store0_1) == KErrNone);
       
   994 	test(TBLD.SetPassword(arb1, arb2, ETrue) == KErrNone);				// - (0 |-> 1) + (0 |-> 2)
       
   995 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
   996 	test(StoresEqual(storeRd, store0_2));
       
   997 
       
   998 	// Lock unlocked wrong out.
       
   999 	test.Next(_L("lock unlocked wrong out"));
       
  1000 	test(TBLD.SetPassword(arb2, arb1, ETrue) == KErrNone);				// restore to arb1
       
  1001 	test(TBLD.WritePasswordData(storeDef) == KErrNone);
       
  1002 	test(TBLD.SetPassword(arb2, arb1, ETrue) == KErrAccessDenied);		// not add (0 |-> 1)
       
  1003 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1004 	test(StoresEqual(storeRd, storeDef));
       
  1005 
       
  1006 	// Lock unlocked wrong in.
       
  1007 	test.Next(_L("lock unlocked wrong in"));
       
  1008 	test(TBLD.WritePasswordData(store0_1) == KErrNone);
       
  1009 	test(TBLD.SetPassword(arb2, arb1, ETrue) == KErrAccessDenied);		// - (0 |-> 1)
       
  1010 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1011 	test(StoresEqual(storeRd, store0_1));
       
  1012 
       
  1013 
       
  1014 	// Unlock
       
  1015 
       
  1016 	// Unlock locked right out.
       
  1017 	test.Next(_L("unlock locked right out"));
       
  1018 	test(TBLD.WritePasswordData(storeDef) == KErrNone);
       
  1019 	RemountMedia();												// make inaccessible
       
  1020 	AttemptToUnlock(arb1, ETrue);								// + (0 |-> 1)
       
  1021 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1022 	test(StoresEqual(storeRd, store0_1));
       
  1023 	
       
  1024 	// Unlock locked right in - see note 1.
       
  1025 
       
  1026 	// Unlock locked wrong in.
       
  1027 	test.Next(_L("unlock locked wrong in"));
       
  1028 	test(TBLD.WritePasswordData(store0_2) == KErrNone);
       
  1029 	RemountMedia();												// make inaccessible
       
  1030 	test(TBLD.Unlock(arb2, ETrue) == KErrAccessDenied);			// - (0 |-> 2)
       
  1031 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1032 	test(StoresEqual(storeRd, storeDef));
       
  1033 
       
  1034 	// Unlock locked wrong out.
       
  1035 	test.Next(_L("unlock locked wrong out"));
       
  1036 	test(TBLD.WritePasswordData(storeDef) == KErrNone);
       
  1037 	RemountMedia();												// make inaccessible
       
  1038 	test(TBLD.Unlock(arb2, ETrue) == KErrAccessDenied);			// not add (0 |-> 2)
       
  1039 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1040 	test(StoresEqual(storeRd, storeDef));
       
  1041 
       
  1042 
       
  1043 	// Clear
       
  1044 
       
  1045 	// Clear unlocked right out.
       
  1046 	test.Next(_L("clear unlocked right out"));
       
  1047 	test(TBLD.WritePasswordData(storeDef) == KErrNone);
       
  1048 	AttemptToUnlock(arb1);										// make accessible
       
  1049 	test(TBLD.Clear(arb1) == KErrNone);							// not add (0 |-> 1)
       
  1050 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1051 	test(StoresEqual(storeRd, storeDef));
       
  1052 
       
  1053 	// Clear unlocked right in.
       
  1054 	test.Next(_L("clear unlocked right in"));
       
  1055 	test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone);				// give password
       
  1056 	test(TBLD.WritePasswordData(store0_1) == KErrNone);
       
  1057 	test(TBLD.Clear(arb1) == KErrNone);							// - (0 |-> 2)
       
  1058 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1059 	test(StoresEqual(storeRd, storeDef));
       
  1060 
       
  1061 	// Clear unlocked wrong out.
       
  1062 	test.Next(_L("clear unlocked wrong out"));
       
  1063 	test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone);				// give password
       
  1064 	test(TBLD.WritePasswordData(storeDef) == KErrNone);
       
  1065 	test(TBLD.Clear(arb2) == KErrAccessDenied);					// not add (0 |-> 2)
       
  1066 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1067 	test(StoresEqual(storeRd, storeDef));
       
  1068 
       
  1069 	// Clear unlocked wrong in.
       
  1070 	test.Next(_L("clear unlocked wrong in"));
       
  1071 	test(TBLD.WritePasswordData(store0_1) == KErrNone);
       
  1072 	test(TBLD.Clear(arb2) == KErrAccessDenied);					// - (0 |-> 2)
       
  1073 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1074 	test(StoresEqual(storeRd, store0_1));
       
  1075 
       
  1076 	// Clear password for subsequent tests.
       
  1077 
       
  1078 	test.Next(_L("clean up for following tests"));
       
  1079 	test(TBLD.WritePasswordData(storeDef) == KErrNone);
       
  1080 	RemountMedia();
       
  1081 	AttemptToUnlock(arb1);
       
  1082 	test(TBLD.Clear(arb1) == KErrNone);
       
  1083 	TBuf8<1> nulSt;
       
  1084 	test(TBLD.WritePasswordData(nulSt) == KErrNone);
       
  1085 	test(TBLD.PasswordStoreLengthInBytes() == 0);
       
  1086 
       
  1087 	test.Next(_L("free test data"));
       
  1088 
       
  1089 	delete pstoreRd;
       
  1090 	delete pstore0_2;
       
  1091 	delete pstore0_1;
       
  1092 	delete pstoreDef;
       
  1093 
       
  1094 	test.End();
       
  1095 	}
       
  1096 
       
  1097 
       
  1098 LOCAL_C TInt AccessDisk()
       
  1099 //
       
  1100 // Attempts to read the first sector of the removable media to determine whether
       
  1101 // it is locked.
       
  1102 //
       
  1103 	{
       
  1104 	const TInt KSectSize = 512;
       
  1105 	TBuf8<KSectSize> sect;						// 8 + 512
       
  1106 
       
  1107 	return TBLD.Read(0, KSectSize, sect);
       
  1108 	}
       
  1109 
       
  1110 
       
  1111 LOCAL_C void TestAutoUnlock()
       
  1112 //
       
  1113 // Tests controller internal store unlocking mechanism.
       
  1114 // A locked card should be transparently unlocked after the peripheral bus is
       
  1115 // powered up.
       
  1116 //
       
  1117 	{
       
  1118 	test.Start(_L("TestAutoUnlock"));
       
  1119 
       
  1120 	test.Next(_L("allocate test data"));
       
  1121 
       
  1122 	TMediaPassword nul(*PWDs[0]);
       
  1123 	TMediaPassword arb1(*PWDs[1]);
       
  1124 
       
  1125 	TPersistentStore *pstoreDef;								// { 3 |-> 3 }
       
  1126 	test((pstoreDef = new TPersistentStore) != NULL);
       
  1127 	TPersistentStore &storeDef = *pstoreDef;
       
  1128 	AddMapping(storeDef, CIDs[3], PWDs[3]);
       
  1129 
       
  1130 	TPersistentStore *pstore0_1;								// { 3 |-> 3, 0 |-> 1 }
       
  1131 	test((pstore0_1 = new TPersistentStore) != NULL);
       
  1132 	TPersistentStore &store0_1 = *pstore0_1;
       
  1133 	AddMapping(store0_1, CIDs[3], PWDs[3]);
       
  1134 	AddMapping(store0_1, CIDs[0], PWDs[1]);
       
  1135 
       
  1136 	TPersistentStore *pstore0_2;								// { 3 |-> 3, 0 |-> 2 }
       
  1137 	test((pstore0_2 = new TPersistentStore) != NULL);
       
  1138 	TPersistentStore &store0_2 = *pstore0_2;
       
  1139 	AddMapping(store0_2, CIDs[3], PWDs[3]);
       
  1140 	AddMapping(store0_2, CIDs[0], PWDs[2]);
       
  1141 
       
  1142 	TPersistentStore *pstoreRd;									// temp for reading
       
  1143 	test((pstoreRd = new TPersistentStore) != NULL);
       
  1144 	TPersistentStore &storeRd = *pstoreRd;
       
  1145 
       
  1146 	test.Next(_L("assign password"));
       
  1147 	test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone);				// give password
       
  1148 
       
  1149 	// No mapping in store.
       
  1150 	test.Next(_L("no mapping in store"));
       
  1151 	test(TBLD.WritePasswordData(storeDef) == KErrNone);
       
  1152 	RemountMedia();
       
  1153 	test(AccessDisk() == KErrLocked);
       
  1154 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1155 	test(StoresEqual(storeRd, storeDef));
       
  1156 
       
  1157 	// Right mapping in store.
       
  1158 	test.Next(_L("right mapping in store"));
       
  1159 	test(TBLD.WritePasswordData(store0_1) == KErrNone);
       
  1160 	RemountMedia();
       
  1161 	test(AccessDisk() == KErrNone);
       
  1162 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1163 	test(StoresEqual(storeRd, store0_1));
       
  1164 
       
  1165 	// Wrong mapping in store - mapping should be removed.
       
  1166 	test.Next(_L("wrong mapping in store"));
       
  1167 	test(TBLD.WritePasswordData(store0_2) == KErrNone);
       
  1168 	RemountMedia();
       
  1169 	test(AccessDisk() == KErrLocked);
       
  1170 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1171 	test(StoresEqual(storeRd, storeDef));
       
  1172 
       
  1173 	// Redundant mapping in store.
       
  1174 	test.Next(_L("redundant mapping in store"));
       
  1175 	AttemptToUnlock(arb1);
       
  1176 	test(TBLD.Clear(arb1) == KErrNone);
       
  1177 	test(TBLD.WritePasswordData(store0_2) == KErrNone);
       
  1178 	RemountMedia();
       
  1179 	test(AccessDisk() == KErrNone);
       
  1180 	test(TBLD.ReadPasswordData(storeRd) == KErrNone);
       
  1181 	test(StoresEqual(storeRd, storeDef));
       
  1182 
       
  1183 	test.Next(_L("clean up for following tests"));
       
  1184 	TBuf8<1> nulSt;
       
  1185 	test(TBLD.WritePasswordData(nulSt) == KErrNone);
       
  1186 	test(TBLD.PasswordStoreLengthInBytes() == 0);
       
  1187 
       
  1188 	test.Next(_L("free test data"));
       
  1189 	delete pstoreRd;
       
  1190 	delete pstore0_2;
       
  1191 	delete pstore0_1;
       
  1192 	delete pstoreDef;
       
  1193 
       
  1194 	test.End();
       
  1195 	}
       
  1196 
       
  1197 
       
  1198 LOCAL_C void TestPasswordFile()
       
  1199 //
       
  1200 // Additional test added for INC066636
       
  1201 //
       
  1202 // Tests that the MMC password file is created in the correct place on the disk
       
  1203 // as defined by KMediaPWrdFile in f32fsys.h
       
  1204 //
       
  1205 // The following test cases are checked:
       
  1206 //  o  Card can be locked
       
  1207 //  o  Cannot lock the card or change its password if the wrong password is 
       
  1208 //     specified
       
  1209 //  o  Password can be changed
       
  1210 //  o  Password can be removed
       
  1211 //
       
  1212 	{
       
  1213 	const TInt KDriveNum = RFsDNum;
       
  1214 
       
  1215 	TInt error = KErrNone;
       
  1216 
       
  1217 
       
  1218 	test.Start(_L("Testing password file"));
       
  1219 
       
  1220 	
       
  1221 	test.Next(_L("open connection"));
       
  1222 	RFs theFs;
       
  1223 	test(theFs.Connect() == KErrNone);
       
  1224 
       
  1225 	
       
  1226 	
       
  1227 	// Now set the first password that we will use
       
  1228 	test.Next(_L("lock the media card"));	
       
  1229 	TMediaPassword& nulPWrd = *PWDs[0];
       
  1230 	TMediaPassword& oldPWrd = *PWDs[1];
       
  1231 	error = theFs.LockDrive(KDriveNum, nulPWrd, oldPWrd, ETrue);
       
  1232 	test(KErrNone == error);
       
  1233 
       
  1234 
       
  1235 	// Verify that the password file does exist and is in the correct place
       
  1236 	test.Next(_L("check password file exists"));
       
  1237 	TEntry theEntry;
       
  1238 	TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile);
       
  1239 	mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar();
       
  1240 	error = theFs.Entry(mediaPWrdFile, theEntry);
       
  1241 	test (KErrNone == error);
       
  1242 
       
  1243 	
       
  1244 	// Attempt to set a new password without specifying the current one
       
  1245 	test.Next(_L("change password failure"));	
       
  1246 	TMediaPassword& newPWrd = *PWDs[2];
       
  1247 	error = theFs.LockDrive(KDriveNum, nulPWrd, newPWrd, ETrue);
       
  1248 	test(KErrAccessDenied == error);
       
  1249 
       
  1250 
       
  1251 	// Change the password for a new one...
       
  1252 	test.Next(_L("change password success"));	
       
  1253 	error = theFs.LockDrive(KDriveNum, oldPWrd, newPWrd, ETrue);
       
  1254 	test(KErrNone == error);
       
  1255 
       
  1256 	
       
  1257 	// Clear the password
       
  1258 	test.Next(_L("clear the password"));	
       
  1259 	error = theFs.ClearPassword(KDriveNum, newPWrd);
       
  1260 	test(KErrNone == error);
       
  1261 
       
  1262 
       
  1263 	// Check that the password has been removed from the file
       
  1264 	// (KMediaPWrdFile should now be zero bytes in size)
       
  1265 	test.Next(_L("check password removal"));
       
  1266 	error = theFs.Entry(mediaPWrdFile, theEntry);
       
  1267 	test (KErrNone == error);
       
  1268 	test (0 == theEntry.iSize);
       
  1269 
       
  1270 	
       
  1271 	// Remove the password file
       
  1272 	test.Next(_L("tidy up"));
       
  1273 	error = theFs.Delete(mediaPWrdFile);
       
  1274 	test (KErrNone == error);
       
  1275 
       
  1276 
       
  1277 	theFs.Close();
       
  1278 
       
  1279 	test.End();
       
  1280 	}
       
  1281 
       
  1282 
       
  1283 LOCAL_C void TestFormatErase()
       
  1284 //
       
  1285 // Additional test added for DEF067976 - MR1: Force Erase of MMC lock UI until complete 
       
  1286 //
       
  1287 // Tests that a card can be locked & then force-erased using the new format switch
       
  1288 //
       
  1289 // Test modified for INC073653 - RFormat::Open returns KErrNone, even if card is locked
       
  1290 //
       
  1291 // RFormat:Open now returns KErrLocked if media is locked (previously this wasn't returned
       
  1292 // until calling RFormat::Next
       
  1293 //
       
  1294 //
       
  1295 	{
       
  1296 	TInt r = KErrNone;
       
  1297 
       
  1298 	test.Start(_L("Testing force erase"));
       
  1299 
       
  1300 	
       
  1301 	test.Next(_L("open connection"));
       
  1302 	RFs fs;
       
  1303 	test(fs.Connect() == KErrNone);
       
  1304 
       
  1305 	// Clear the password store for when function run on its own.
       
  1306 	TBuf8<1> nulSt;
       
  1307 	test(TBLD.WritePasswordData(nulSt) == KErrNone);// empty
       
  1308 	test(TBLD.PasswordStoreLengthInBytes() == 0);
       
  1309 
       
  1310 	
       
  1311 	test.Next(_L("lock card"));
       
  1312 	// Now set the first password that we will use
       
  1313 	TMediaPassword& nulPWrd = *PWDs[0];
       
  1314 	TMediaPassword& oldPWrd = *PWDs[1];
       
  1315 	r = fs.LockDrive(RFsDNum, nulPWrd, oldPWrd, EFalse);
       
  1316 	if (r != KErrNone)
       
  1317 		test.Printf(_L("RFs::LockDrive() returned %d\n"), r);
       
  1318 	test(r == KErrNone);
       
  1319 
       
  1320 	RemountMedia();		// card is now locked
       
  1321 
       
  1322 	RFormat fmt;
       
  1323 	TPckgBuf<TInt> stepPkg;
       
  1324 	TDriveUnit driveUnit(RFsDNum);
       
  1325 	TDriveName driveName = driveUnit.Name();
       
  1326 
       
  1327 	test.Next(_L("format locked card"));
       
  1328 	r = fmt.Open(fs, driveName, EHighDensity, stepPkg());
       
  1329 	if (r != KErrLocked)
       
  1330 		test.Printf(_L("RFormat::Next() returned %d\n"), r);
       
  1331 	test(r == KErrLocked);
       
  1332 
       
  1333 	test.Printf(_L("\n"));
       
  1334 	fmt.Close();
       
  1335 
       
  1336 	_LIT(KLitStars,"********************");
       
  1337 	test.Next(_L("force erase locked card"));
       
  1338 	r = fmt.Open(fs, driveName, EHighDensity | EForceErase, stepPkg());
       
  1339 	if (r != KErrNone)
       
  1340 		test.Printf(_L("RFormat::Open() returned %d\n"), r);
       
  1341 	test (r == KErrNone);
       
  1342 	
       
  1343 	while (stepPkg() > 0)
       
  1344 		{
       
  1345 		TRequestStatus status;
       
  1346 		fmt.Next(stepPkg, status);
       
  1347 		test (status == KRequestPending || status == KErrNone);
       
  1348 		User::WaitForRequest(status);
       
  1349 
       
  1350 		TInt length=(100-stepPkg())/5;
       
  1351 		length=Min(length,20);
       
  1352 		TPtrC stars=KLitStars().Left(length);
       
  1353 		test.Printf(_L("\r%S"),&stars);
       
  1354 		}
       
  1355 	test.Printf(_L("\n"));
       
  1356 	fmt.Close();
       
  1357 
       
  1358 	fs.Close();
       
  1359 
       
  1360 	test.End();
       
  1361 	}
       
  1362 
       
  1363 LOCAL_C void TestWriteToPasswordStoreUnlocksCard()
       
  1364 //
       
  1365 // Additional test added for INC096612 - Writing to password store should unlock the card
       
  1366 //
       
  1367 // Tests that a card can be auto-unlocked just by writing to the password store (as this is what 
       
  1368 // estart does)
       
  1369 //
       
  1370 //
       
  1371 	{
       
  1372 	TInt r = KErrNone;
       
  1373 
       
  1374 	test.Start(_L("Testing writing to password store unlocks the card"));
       
  1375 	
       
  1376 	test.Next(_L("open connection"));
       
  1377 	RFs fs;
       
  1378 	test(fs.Connect() == KErrNone);
       
  1379 
       
  1380 	// Clear the password store for when function run on its own.
       
  1381 	TMediaPassword& nulPWrd = *PWDs[0];
       
  1382 	TMediaPassword testPassword((const TUint8*) "xyz");
       
  1383 
       
  1384 	test(TBLD.WritePasswordData(nulPWrd) == KErrNone);// empty
       
  1385 	test(TBLD.PasswordStoreLengthInBytes() == 0);
       
  1386 	
       
  1387 	test.Next(_L("lock card"));
       
  1388 	test.Next(_L("assign test password"));
       
  1389 	r = TBLD.SetPassword(nulPWrd, testPassword, EFalse);
       
  1390 	test(r == KErrNone);
       
  1391 
       
  1392 	RemountMedia();		// card is now locked
       
  1393 
       
  1394 	// test Caps() reports that card is locked
       
  1395 	test.Next(_L("test card is locked"));
       
  1396 	TLocalDriveCapsV5 driveCaps;
       
  1397 	TPckg<TLocalDriveCapsV5> driveCapsPkg(driveCaps);	
       
  1398 	r = TBLD.Caps(driveCapsPkg);
       
  1399 	test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
       
  1400 
       
  1401 	test (r == KErrNone);
       
  1402 	test ((driveCaps.iMediaAtt & KMediaAttLocked) != 0);
       
  1403 
       
  1404 	// Write correct password to store
       
  1405 	test.Next(_L("write correct password to store"));
       
  1406 
       
  1407 	TPersistentStore *pstoreDef;
       
  1408 	test((pstoreDef = new TPersistentStore) != NULL);
       
  1409 	TPersistentStore &storeDef = *pstoreDef;
       
  1410 	AddMapping(storeDef, CIDs[0], &testPassword);
       
  1411 	r = TBLD.WritePasswordData(storeDef);
       
  1412 
       
  1413 	test.Printf(_L("WritePasswordData() returned %d\n"), r);
       
  1414 	
       
  1415 	test(r == KErrNone);
       
  1416 
       
  1417 	// test Caps() reports that card is unlocked
       
  1418 	test.Next(_L("test card is unlocked"));
       
  1419 	r = TBLD.Caps(driveCapsPkg);
       
  1420 	test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
       
  1421 
       
  1422 	test (r == KErrNone);
       
  1423 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
       
  1424 
       
  1425 	// Clear the password, remount and test card is unlocked
       
  1426 	test.Next(_L("clear password, remount & test card is unlocked"));
       
  1427 	test.Next(_L("clear the password"));	
       
  1428 	test(TBLD.Clear(testPassword) == KErrNone);
       
  1429 	RemountMedia();		
       
  1430 	test.Next(_L("test card is unlocked"));
       
  1431 
       
  1432 	r = TBLD.Caps(driveCapsPkg);
       
  1433 	test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
       
  1434 
       
  1435 	test (r == KErrNone);
       
  1436 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
       
  1437 
       
  1438 
       
  1439 	delete pstoreDef;
       
  1440 	pstoreDef = NULL;
       
  1441 	
       
  1442 	test.End();
       
  1443 	}
       
  1444 
       
  1445 
       
  1446 LOCAL_C TBool SetupDrivesForPlatform(TInt& aDrive, TInt &aRFsDriveNum)
       
  1447 /**
       
  1448  * Finds a suitable drive for the password store test
       
  1449  *
       
  1450  * @param aDrive  The number of the local drive to test
       
  1451  * @return TBool ETrue if a suitable drive is found, EFalse otherwise.
       
  1452  */
       
  1453 	{
       
  1454 	
       
  1455 	TDriveInfoV1Buf diBuf;
       
  1456 	UserHal::DriveInfo(diBuf);
       
  1457 	TDriveInfoV1 &di=diBuf();
       
  1458 
       
  1459 	test.Printf(_L(" iRegisteredDriveBitmask 0x%08X"), di.iRegisteredDriveBitmask);
       
  1460 
       
  1461 	aDrive  = -1;
       
  1462 	
       
  1463 	TLocalDriveCapsV5Buf capsBuf;
       
  1464 	TBusLocalDrive TBLD;
       
  1465 	TLocalDriveCapsV5& caps = capsBuf();
       
  1466 	TPtrC8 localSerialNum;
       
  1467 	TInt registeredDriveNum = 0;
       
  1468 	for(aDrive=0; aDrive < KMaxLocalDrives; aDrive++)
       
  1469 		{
       
  1470 		TInt driveNumberMask = 1 << aDrive;
       
  1471 		if ((di.iRegisteredDriveBitmask & driveNumberMask) == 0)
       
  1472 			continue;
       
  1473 
       
  1474 		test.Printf(_L(" Drive %d -  %S\r\n"), aDrive, &di.iDriveName[registeredDriveNum]);
       
  1475 
       
  1476 		// check that the card is readable (so we can ignore for empty card slots)
       
  1477 		if ((di.iDriveName[registeredDriveNum].MatchF(_L("MultiMediaCard0")) == KErrNone) ||
       
  1478 		    (di.iDriveName[registeredDriveNum].MatchF(_L("SDIOCard0")) == KErrNone))
       
  1479 			{
       
  1480 			
       
  1481 			TBool TBLDChangedFlag;
       
  1482 			TInt r = TBLD.Connect(aDrive, TBLDChangedFlag);
       
  1483 //test.Printf(_L(" Connect returned %d\n"), r);
       
  1484 			if (r == KErrNone)
       
  1485 				{
       
  1486 				r = TBLD.Caps(capsBuf);
       
  1487 				localSerialNum.Set(caps.iSerialNum, caps.iSerialNumLength);
       
  1488 				const TInt KSectSize = 512;
       
  1489 				TBuf8<KSectSize> sect;
       
  1490 				r = TBLD.Read(0, KSectSize, sect);
       
  1491 //test.Printf(_L(" Read returned %d\n"), r);
       
  1492 				
       
  1493 				TBLD.Disconnect();
       
  1494 				if (r == KErrNone)
       
  1495 					break;
       
  1496 				}
       
  1497 			}
       
  1498 		registeredDriveNum++;
       
  1499 		}
       
  1500 
       
  1501 	if(aDrive == KMaxLocalDrives)
       
  1502 		{
       
  1503 		test.Printf(_L(" MMC Drive Not Found\r\n"));
       
  1504 		return EFalse;
       
  1505 		}
       
  1506 
       
  1507 	// Work out the file server drive number (which isn't necessarily the same 
       
  1508 	// as the TBusLocalDrive drive number)
       
  1509 	RFs theFs;
       
  1510 	test(theFs.Connect() == KErrNone);
       
  1511 
       
  1512 	TInt i;
       
  1513 	for (i = EDriveA; i < EDriveZ; i++)
       
  1514 		{
       
  1515 		TMediaSerialNumber serialNum;
       
  1516 	    TInt r = theFs.GetMediaSerialNumber(serialNum, i);
       
  1517 		TInt len = serialNum.Length();
       
  1518 		TInt n;
       
  1519 		for (n=0; n<len; n+=16)
       
  1520 		{
       
  1521 		TBuf16<16*3 +1> buf;
       
  1522 			for (TInt m=n; m<n+16; m++)
       
  1523 				{
       
  1524 				TBuf16<3> hexBuf;
       
  1525 				hexBuf.Format(_L("%02X "),serialNum[m]);
       
  1526 				buf.Append(hexBuf);
       
  1527 				}
       
  1528 		buf.Append(_L("\n"));
       
  1529 		test.Printf(buf);
       
  1530 		}
       
  1531 		if (serialNum.Compare(localSerialNum) == 0)
       
  1532 			{
       
  1533 			TVolumeInfo vi;
       
  1534 	        r = theFs.Volume(vi, i);
       
  1535 			TBool sizeMatch = (vi.iSize < caps.iSize);
       
  1536 			if (sizeMatch)
       
  1537 				{
       
  1538 				aRFsDriveNum = i;
       
  1539 				break;
       
  1540 				}
       
  1541 			}
       
  1542 		
       
  1543 		}
       
  1544 	if (i == EDriveZ)
       
  1545 		{
       
  1546 		test.Printf(_L(" RFs MMC Drive Not Found\r\n"));
       
  1547 		return EFalse;
       
  1548 		}
       
  1549 
       
  1550 	theFs.Close();
       
  1551 
       
  1552 	return ETrue;
       
  1553 	}
       
  1554 
       
  1555 
       
  1556 TInt TestLockCard(RFs& aFs, TInt aTheMemoryCardDrive, TMediaPassword &aOldPassword, TMediaPassword& aNewPassword, TBool aStore)
       
  1557 	{
       
  1558 	TMediaPassword newPassWord;
       
  1559     TMediaPassword oldPassWord;
       
  1560     TInt err=0;
       
  1561     TDriveInfo dInfo;
       
  1562     
       
  1563     aFs.Drive(dInfo, RFsDNum);
       
  1564     
       
  1565     newPassWord.Append(aNewPassword);
       
  1566     oldPassWord.Append(aOldPassword);
       
  1567 
       
  1568     test (dInfo.iMediaAtt & KMediaAttLockable);
       
  1569       
       
  1570     err=aFs.LockDrive(RFsDNum, oldPassWord, newPassWord, aStore );
       
  1571 
       
  1572     aFs.Drive(dInfo, aTheMemoryCardDrive);
       
  1573     return err;   	
       
  1574 	}
       
  1575 
       
  1576 TInt TestUnlockCard(RFs& aFs, TInt aTheMemoryCardDrive, TMediaPassword& aPassword, TBool aStore)
       
  1577 	{
       
  1578 	TMediaPassword oldPw;
       
  1579    
       
  1580 	oldPw.Append(aPassword);
       
  1581    	TInt err = aFs.UnlockDrive( aTheMemoryCardDrive, oldPw, aStore);
       
  1582 	return err;
       
  1583 	}
       
  1584 
       
  1585 TInt TestClearPassword(RFs& aFs, TInt aTheMemoryCardDrive, TMediaPassword& aPassword)
       
  1586 	{
       
  1587 	TMediaPassword oldPwd = aPassword;
       
  1588 
       
  1589 	TInt err = aFs.ClearPassword( aTheMemoryCardDrive, oldPwd );
       
  1590 	return err;
       
  1591 	}
       
  1592 
       
  1593 
       
  1594 TInt ExecuteForcedEraseTestL(RFs& aFs, TInt aTheMemoryCardDrive)
       
  1595     {
       
  1596 	TInt err = aFs.ErasePassword( aTheMemoryCardDrive );
       
  1597 	return err;
       
  1598     }
       
  1599 
       
  1600 
       
  1601 TBool TestLocked(RFs& aFs, TInt aTheMemoryCardDrive)
       
  1602 	{
       
  1603     TDriveInfo info;
       
  1604 
       
  1605 	TInt r = aFs.Drive(info, aTheMemoryCardDrive);
       
  1606 	test (r == KErrNone);
       
  1607 
       
  1608 	return (info.iMediaAtt & KMediaAttLocked)?(TBool)ETrue:(TBool)EFalse;
       
  1609 	}
       
  1610 
       
  1611 void WaitForPowerDownLock(RFs& aFs, TInt aTheMemoryCardDrive)
       
  1612 	{
       
  1613 	test.Printf(_L("Waiting for stack to power down...\n"));
       
  1614 	TInt n;
       
  1615 	for (n=0; n<30 && !TestLocked(aFs, aTheMemoryCardDrive); n++)
       
  1616 		{
       
  1617 		User::After(1000000);
       
  1618 		}
       
  1619 	test(n < 30);
       
  1620 	test(TestLocked(aFs, aTheMemoryCardDrive));	// should now be locked
       
  1621 	}
       
  1622 	
       
  1623 void WaitForPowerDownUnlock(RFs& /*aFs*/, TInt /*aTheMemoryCardDrive*/)
       
  1624 	{
       
  1625 	test.Printf(_L("Allow some time for stack to power down"));
       
  1626 	for (TUint i=0; i < 80; ++i)
       
  1627     	{
       
  1628     	User::After(100000);
       
  1629     	test.Printf(_L("."));
       
  1630     	}
       
  1631     test.Printf(_L("\n"));
       
  1632 	}
       
  1633 	
       
  1634 /*
       
  1635 INC103721:
       
  1636 The MMC Media drivers do not power up the MMC Stack to retrieve card status,
       
  1637 the following tests ensure that the 'lock status' is correctly returned after a
       
  1638 stack power down.
       
  1639 */	
       
  1640 LOCAL_C void TestPowerDownStatus()
       
  1641 	{
       
  1642 	TInt r = KErrNone;
       
  1643 	TLocalDriveCapsV5 driveCaps;
       
  1644 	TPckg<TLocalDriveCapsV5> driveCapsPkg(driveCaps);	
       
  1645 	TMediaPassword password = (TUint8*) "salasana";
       
  1646 	TMediaPassword oldpassword;
       
  1647 		
       
  1648 	test.Start(_L("Testing Power Down Status Reporting"));
       
  1649 
       
  1650 	test.Next(_L("Open Connection"));
       
  1651 	RFs fs;
       
  1652 	test(fs.Connect() == KErrNone);
       
  1653 
       
  1654 // Lock card (with password stored) 
       
  1655 	test.Next(_L("Locking Card - Password Stored"));
       
  1656 
       
  1657 	test.Next(_L("Locking card (Successful)"))	;
       
  1658 	r = TestLockCard(fs, RFsDNum, oldpassword, password, ETrue);
       
  1659 	test(r == KErrNone); 
       
  1660 		
       
  1661 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
       
  1662 
       
  1663 	test.Next(_L("Card reports unlocked - before PowerDown"));
       
  1664 	r = TBLD.Caps(driveCapsPkg);
       
  1665 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
       
  1666 
       
  1667 	test (r == KErrNone);
       
  1668 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
       
  1669 
       
  1670 	WaitForPowerDownUnlock(fs, RFsDNum);
       
  1671 	
       
  1672 	test.Next(_L("Check card reports unlocked - after PowerDown"));
       
  1673 	r = TBLD.Caps(driveCapsPkg);
       
  1674 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
       
  1675 
       
  1676 	test (r == KErrNone);
       
  1677 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
       
  1678 	
       
  1679 	test.Next(_L("Clear password (Successful)"));
       
  1680 	r = TestClearPassword(fs, RFsDNum, password);
       
  1681 	test(r == KErrNone);
       
  1682 	
       
  1683 // Lock card (without password in store)
       
  1684 	test.Next(_L("Locking card - Password NOT Stored"));
       
  1685 
       
  1686 	test.Next(_L("Locking card (Successful)"));
       
  1687 	r = TestLockCard(fs, RFsDNum, oldpassword, password, EFalse);
       
  1688 	test(r == KErrNone); 
       
  1689 		
       
  1690 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
       
  1691 	
       
  1692 	test.Next(_L("Card is reports Unlocked - before PowerDown"));
       
  1693 	r = TBLD.Caps(driveCapsPkg);
       
  1694 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
       
  1695 
       
  1696 	test (r == KErrNone);
       
  1697 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
       
  1698 
       
  1699 	WaitForPowerDownLock(fs, RFsDNum);
       
  1700 	
       
  1701 	test.Next(_L("Card reports Locked - after PowerDown"));
       
  1702 	r = TBLD.Caps(driveCapsPkg);
       
  1703 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
       
  1704 
       
  1705 	test (r == KErrNone);
       
  1706 	test ((driveCaps.iMediaAtt & KMediaAttLocked) != 0);
       
  1707 	
       
  1708 // Unlock card
       
  1709 	test.Next(_L("Unlock 'locked' Card - Password Stored"));
       
  1710 	
       
  1711 	test.Next(_L("Unlocking card (Successful)"))	;
       
  1712 	r = TestUnlockCard(fs, RFsDNum, password, ETrue);
       
  1713 	test(r == KErrNone);
       
  1714 	test (!TestLocked(fs, RFsDNum)); // not locked as stack hasn't powered down
       
  1715 	
       
  1716 	test.Next(_L("Card reports unlocked - before PowerDown"));
       
  1717 	r = TBLD.Caps(driveCapsPkg);
       
  1718 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
       
  1719 
       
  1720 	test (r == KErrNone);
       
  1721 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
       
  1722 
       
  1723 	WaitForPowerDownUnlock(fs, RFsDNum);
       
  1724 	
       
  1725 	test.Next(_L("Card reports unlocked - after PowerDown"));
       
  1726 	r = TBLD.Caps(driveCapsPkg);
       
  1727 	test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt);
       
  1728 
       
  1729 	test (r == KErrNone);
       
  1730 	test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0);
       
  1731 	
       
  1732 	test.Next(_L("Clearing Password (Successful)"));
       
  1733 	r = TestClearPassword(fs, RFsDNum, password);
       
  1734 	test(r == KErrNone);
       
  1735 	
       
  1736 	fs.Close();
       
  1737 	
       
  1738 	test.End();
       
  1739 	}
       
  1740 
       
  1741 LOCAL_C void TestFsLockUnlock()
       
  1742 	{
       
  1743 	TInt r = KErrNone;
       
  1744 
       
  1745 	test.Start(_L("Testing RFs APIs"));
       
  1746 
       
  1747 	test.Next(_L("open connection"));
       
  1748 	RFs fs;
       
  1749 	test(fs.Connect() == KErrNone);
       
  1750 
       
  1751 
       
  1752 	test.Next(_L("test locking card"));
       
  1753 
       
  1754 	TMediaPassword oldpassword;
       
  1755 	TMediaPassword newpassword = (TUint8*) "salasana";
       
  1756 	TMediaPassword wrongpwd = (TUint8*) "failtest";
       
  1757 
       
  1758 	r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse);
       
  1759 	test(r == KErrNone);
       
  1760 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
       
  1761 
       
  1762 	test.Next(_L("test unlocking fails if still powered up"));
       
  1763 	r = TestUnlockCard(fs, RFsDNum, newpassword, EFalse);
       
  1764 	test(r == KErrAlreadyExists);		// already unlocked (as stack won't have powered down yet)
       
  1765 	test (!TestLocked(fs, RFsDNum));
       
  1766 
       
  1767 	test.Next(_L("test clearing succeeds if still powered up"));
       
  1768 	r = TestClearPassword(fs, RFsDNum, newpassword);
       
  1769 	test(r == KErrNone);
       
  1770 	test(!TestLocked(fs, RFsDNum));
       
  1771 	
       
  1772 	test.Next(_L("test locking card again"));
       
  1773 	r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse);
       
  1774 	test(r == KErrNone);
       
  1775 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
       
  1776 
       
  1777 	WaitForPowerDownLock(fs, RFsDNum);
       
  1778 
       
  1779 	// DEF111681: CheckDisk is returning bad error code when run on locked SD card
       
  1780 	// RFs::CheckDisk() should return KErrNone or KErrLocked (not KErrCorrupt) if the card is locked and the 
       
  1781 	// stack powers down
       
  1782 	// NB For FAT16 cards, the FAT will be entirely cached so CheckDisk will not actually access the media
       
  1783 	// so KErrNone will be returned. For FAT32 cards, KErrLocked will be returned.
       
  1784 	test.Next(_L("test CheckDisk() returns KErrLocked if the card is locked and the stack powered down"));
       
  1785 	WaitForPowerDownLock(fs, RFsDNum);
       
  1786 	TFileName sessionPath;
       
  1787 	sessionPath=_L("?:\\");
       
  1788 	TChar driveLetter;
       
  1789 	r = fs.DriveToChar(RFsDNum,driveLetter);
       
  1790 	test(r==KErrNone);
       
  1791 	sessionPath[0]=(TText)driveLetter;
       
  1792 	r = fs.CheckDisk(sessionPath);
       
  1793 	test(r == KErrNone || r == KErrLocked);
       
  1794 	WaitForPowerDownLock(fs, RFsDNum);
       
  1795 
       
  1796 
       
  1797 	// DEF111700: Formatting a locked SD/MMC leaves it in a bad state (causes panics later)
       
  1798 	// This was caused by format calling TDrive::MountMedia(ETrue) and then not dismounting
       
  1799 	r = fs.RemountDrive(RFsDNum);
       
  1800 	test (r == KErrNone);
       
  1801 	RFormat fmt;
       
  1802 	TPckgBuf<TInt> stepPkg;
       
  1803 	TDriveUnit driveUnit(RFsDNum);
       
  1804 	TDriveName driveName = driveUnit.Name();
       
  1805 	test.Next(_L("format locked card"));
       
  1806 	r = fmt.Open(fs, driveName, EHighDensity, stepPkg());
       
  1807 	if (r != KErrLocked)
       
  1808 		test.Printf(_L("RFormat::Next() returned %d\n"), r);
       
  1809 	test(r == KErrLocked);
       
  1810 	test.Printf(_L("\n"));
       
  1811 	fmt.Close();
       
  1812 	r = fs.CheckDisk(sessionPath);
       
  1813 	test(r == KErrLocked);
       
  1814 
       
  1815 
       
  1816 	test.Next(_L("test unlocking fails after powered down & unlocked with wrong password"));
       
  1817 	r = TestUnlockCard(fs, RFsDNum, wrongpwd, EFalse);
       
  1818 	test(r == KErrAccessDenied);		// unlocked should now fail
       
  1819 
       
  1820 	test.Next(_L("test unlocking succeeds for correct password after powered down & locked"));
       
  1821 	r = TestUnlockCard(fs, RFsDNum, newpassword, EFalse);
       
  1822 	test(r == KErrNone);		// unlocked should now succeed
       
  1823 
       
  1824 	test.Next(_L("test unlocking fails after successful unlock"));
       
  1825 	r = TestUnlockCard(fs, RFsDNum, wrongpwd, EFalse);
       
  1826 	test(r == KErrAlreadyExists);		// unlocked should now succeed
       
  1827 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
       
  1828 
       
  1829 	test.Next(_L("test locking card with new password (with wrong password as old password)"));
       
  1830 	r = TestLockCard(fs, RFsDNum, wrongpwd, newpassword, EFalse);
       
  1831 	test(r == KErrAccessDenied);
       
  1832 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
       
  1833 
       
  1834 	test.Next(_L("test locking card with new password (with right password as old password)"));
       
  1835 	r = TestLockCard(fs, RFsDNum, newpassword, wrongpwd, EFalse);
       
  1836 	test(r == KErrNone);
       
  1837 	test(!TestLocked(fs, RFsDNum));	// not locked yet as stack hasn't powered down
       
  1838 
       
  1839 	WaitForPowerDownLock(fs, RFsDNum);
       
  1840 	
       
  1841 	test.Next(_L("test clearing fails with wrong password if powered down & locked"));
       
  1842 	r = TestClearPassword(fs, RFsDNum, newpassword); // Note: we have set the wrong password as the new password
       
  1843 	test(r == KErrAccessDenied);
       
  1844 	test(TestLocked(fs, RFsDNum));
       
  1845 
       
  1846 	test.Next(_L("test clearing succeeds with right password if powered down & locked"));
       
  1847 	r = TestClearPassword(fs, RFsDNum, wrongpwd);
       
  1848 	test(r == KErrNone);
       
  1849 	test(!TestLocked(fs, RFsDNum));
       
  1850 
       
  1851 	test.Next(_L("test locking card again"));
       
  1852 	r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse);
       
  1853 	test(r == KErrNone);
       
  1854 	test(!TestLocked(fs, RFsDNum));		// not locked yet as stack hasn't powered down
       
  1855 
       
  1856 	test.Next(_L("test forced erase fails if still powered up"));
       
  1857 	r = ExecuteForcedEraseTestL(fs, RFsDNum);
       
  1858 	test(r == KErrAccessDenied);		// fails because card is not yet locked
       
  1859 
       
  1860 	WaitForPowerDownLock(fs, RFsDNum);
       
  1861 
       
  1862 
       
  1863 	test.Next(_L("test forced erase succeeds if powered down & locked"));
       
  1864 	r = ExecuteForcedEraseTestL(fs, RFsDNum);
       
  1865 	test(r == KErrNone);
       
  1866 
       
  1867 	fs.Close();
       
  1868 	test.End();
       
  1869 	}
       
  1870 
       
  1871 
       
  1872 
       
  1873 /**
       
  1874 PDEF104639: Phone automatically reboots when inserting memory card with password. 
       
  1875 Testing that TheFs.UnlockDrive() results in a notification - and doesn't crash the file server (!)
       
  1876 */
       
  1877 void TestUnlockDriveNotifyChange()
       
  1878 	{
       
  1879 	RFs fs;
       
  1880 	test(fs.Connect() == KErrNone);
       
  1881 
       
  1882 	TFileName sessionPath;
       
  1883 	sessionPath=_L("?:\\");
       
  1884 	TChar driveLetter;
       
  1885 	TInt r=fs.DriveToChar(RFsDNum,driveLetter);
       
  1886 	test(r==KErrNone);
       
  1887 	sessionPath[0]=(TText)driveLetter;
       
  1888 	r=fs.SetSessionPath(sessionPath);
       
  1889 	test(r==KErrNone);
       
  1890     
       
  1891 	TInt nRes;
       
  1892     TDriveInfo dInfo;
       
  1893 
       
  1894     nRes = fs.Drive(dInfo, RFsDNum);
       
  1895 	test(nRes == KErrNone);
       
  1896 	if (!(dInfo.iMediaAtt & KMediaAttLockable))
       
  1897 		{
       
  1898 		test.Printf(_L("Drive %d is not lockable %d\n"), RFsDNum);
       
  1899 		fs.Close();
       
  1900 		return;
       
  1901 		}
       
  1902 
       
  1903 	// attempt to lock the drive
       
  1904 	TMediaPassword oldPassword;
       
  1905 	TMediaPassword newPassword = (TUint8*) "salasana";
       
  1906     nRes = fs.LockDrive(RFsDNum, oldPassword, newPassword, EFalse );
       
  1907 	test(nRes == KErrNone);
       
  1908 
       
  1909 	WaitForPowerDownLock(fs, RFsDNum);
       
  1910 
       
  1911     TRequestStatus reqStatNotify1(KRequestPending);
       
  1912     
       
  1913     //-- set up notifier
       
  1914     fs.NotifyChange(ENotifyAll, reqStatNotify1, sessionPath);
       
  1915     test(reqStatNotify1.Int() == KRequestPending);
       
  1916 
       
  1917     //-- unlock the drive
       
  1918    	nRes = fs.UnlockDrive(RFsDNum, newPassword, EFalse);
       
  1919 	test.Printf(_L("UnlockDrive() %d reqStatNotify1 %d\n"), nRes, reqStatNotify1.Int());
       
  1920     
       
  1921     //-- check that the notifier worked
       
  1922     User::WaitForRequest(reqStatNotify1);
       
  1923     test(reqStatNotify1.Int() == KErrNone);
       
  1924 
       
  1925 	r = TestClearPassword(fs, RFsDNum, newPassword);
       
  1926 	test(r == KErrNone);
       
  1927 	test(!TestLocked(fs, RFsDNum));
       
  1928 	
       
  1929 	
       
  1930 	
       
  1931 	fs.Close();
       
  1932 	}
       
  1933 
       
  1934 
       
  1935 LOCAL_C void RunTests()
       
  1936 //
       
  1937 // Main test routine.  Calls other test functions.
       
  1938 //
       
  1939 	{
       
  1940 	__UHEAP_MARK;
       
  1941 
       
  1942 	if(TBLDNum == -1)
       
  1943 		{
       
  1944 		if(!SetupDrivesForPlatform(TBLDNum, RFsDNum))
       
  1945 			{
       
  1946 			test.Printf(_L("MMC Drive Not Found - Skipping test\r\n"));
       
  1947 			return;
       
  1948 			}
       
  1949 		}
       
  1950 
       
  1951 	test.Next(_L("Connecting TBLD"));
       
  1952 	test(TBLD.Connect(TBLDNum, TBLDChangedFlag) == KErrNone);
       
  1953 
       
  1954 	test.Next(_L("Allocating test data"));
       
  1955 	AllocateTestData();
       
  1956 
       
  1957 	test.Next(_L("Testing locking / unlocking using file server APIs"));
       
  1958 	TestFsLockUnlock();
       
  1959 	
       
  1960 	test.Next(_L("Testing Power Down Status Reporting using file server APIs"));
       
  1961 	TestPowerDownStatus();
       
  1962 
       
  1963     test.Next(_L("Testing RFs::NotifyChange() with RFs::UnlockDrive()"));
       
  1964 	TestUnlockDriveNotifyChange();
       
  1965 
       
  1966 	test.Next(_L("Forced Erase"));
       
  1967 	TestFormatErase();
       
  1968 	test.Next(_L("Testing store management"));
       
  1969 	TestStaticStore();
       
  1970 	test.Next(_L("Testing locking functions"));
       
  1971 	TestLockUnlock();
       
  1972 	test.Next(_L("Testing Elide Passwords"));
       
  1973 	TestElidePasswords();
       
  1974 	test.Next(_L("Testing Null Passwords"));
       
  1975 	TestNullPasswords();
       
  1976 	test.Next(_L("Testing controller store"));
       
  1977 	TestControllerStore();
       
  1978 	test.Next(_L("Testing auto unlock"));
       
  1979 	TestAutoUnlock();
       
  1980 	test.Next(_L("Testing password file"));
       
  1981 	TestPasswordFile();
       
  1982 	test.Next(_L("Testing writing a valid password to store unlocks card"));
       
  1983 	TestWriteToPasswordStoreUnlocksCard();
       
  1984 
       
  1985 	test.Next(_L("Disconnecting TBLD"));
       
  1986 	TBLD.Disconnect();
       
  1987 
       
  1988 	test.Next(_L("Deleting test data"));
       
  1989 	DeleteTestData();
       
  1990 
       
  1991 	__UHEAP_MARKEND;
       
  1992 	}
       
  1993 
       
  1994 
       
  1995 TInt E32Main()
       
  1996 	{
       
  1997 	
       
  1998 	test.Title();
       
  1999 	test.Start(_L("E32Main"));
       
  2000 	
       
  2001 	RunTests();
       
  2002 
       
  2003 	test.End();
       
  2004 	test.Close();
       
  2005 
       
  2006 	return KErrNone;
       
  2007 	}
       
  2008