Update contrib.
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
 
     2 // All rights reserved.
 
     3 // This component and the accompanying materials are made available
 
     4 // under the terms of "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".
 
     8 // Initial Contributors:
 
     9 // Nokia Corporation - initial contribution.
 
    18  @internalComponent - Internal Symbian test code 
 
    27 #include <ecom/ecom.h>
 
    33   Auxiliary Fn for Test Case ID T-Maps-testTMappingDataTypeToAppL
 
    35   This function receives two mappings, and verifies if they data members 
 
    39 TBool CT_Maps::cmpMappingDataTypeToAdd( TMappingDataTypeToApp& map1, TMappingDataTypeToApp& map2 )
 
    41 	return TBool( map1.iAppUid == map2.iAppUid &&
 
    42 		map1.iDataType == map2.iDataType && 
 
    43 		map1.iPriority == map2.iPriority &&
 
    44 		map1.iServiceUid == map2.iServiceUid);
 
    48 //const TInt KErrTestFailed = -1;
 
    52    @SYMTestCaseID		T-Maps-testTMappingDataTypeToAppL
 
    56    @SYMTestCaseDesc 	Tests TMappingDataTypeToApp class 
 
    60    @SYMTestStatus 		Implemented
 
    62    @SYMTestActions  	The test creates 3 different mappings, identified by a TUid, TDataType
 
    63    and TDataTypePriority, verifying that they are correctly created. The consitency of these 
 
    64    mappings through the process of writing and reading to and from a stream is also checked.\n
 
    65    Also, a store of mappings is created, verifying the insertion, and the insertion depending
 
    66    on the TDataTypePriority, checking that it handles the insertion in accordance.\n 
 
    68    TMappingDataTypeToApp::TMappingDataTypeToApp(const TDataType& aDataType, TDataTypePriority aPriority, TUid aUid) \n
 
    69    CTypeStoreManager::NewL(RFs& aFs) \n
 
    70    CTypeStoreManager::InsertDataMappingL(const TDataType& aDataType, TDataTypePriority aPriority, TUid aUid) \n
 
    71    CTypeStoreManager::GetAppByDataType(const TDataType& aDataType, TUid& aUid) const \n
 
    72    CTypeStoreManager::InsertIfHigherL(const TDataType& aDataType, TDataTypePriority aPriority, TUid aUid) \n
 
    74    @SYMTestExpectedResults Test should complete without any panic.
 
    77 void CT_Maps::testTMappingDataTypeToAppL()
 
    79 	const TUid uid1 = { 0x11111111 };
 
    80 	const TUid uid2 = { 0x22222222 };
 
    81 	const TUid uid3 = { 0x33333333 };
 
    82 	const TUid uid4 = { 0x44444444 };
 
    83 	const TUid uid5 = { 0x55555555 };
 
    84 	const TUid uid6 = { 0x66666666 };
 
    86 	const TUid serviceUid1 = { 0x00001111 };
 
    87 	const TUid serviceUid2 = { 0x00002222 };
 
    88 	//const TUid serviceUid3 = { 0x00003333 };
 
    89 	const TUid serviceUid4 = { 0x00004444 };
 
    91 	const TDataType data1( uid1 );
 
    92 	const TDataType data2( uid2 );
 
    93 	const TDataType data3( uid3 );
 
    94 	const TDataType data4( uid4 );
 
    98 	// Test that mappings are serialized correctly
 
    99 	TMappingDataTypeToApp mapping1( data1, TDataTypePriority( 100 ), uid3 );
 
   100 	TMappingDataTypeToApp mapping2( data1, TDataTypePriority( 100 ), uid3 );
 
   101 	TMappingDataTypeToApp mapping3( data2, TDataTypePriority( 200 ), uid4 );
 
   107 	TBuf<256> tmpfilename;
 
   109 	buf1.Temp( iFs, KTempRootDir, tmpfilename, EFileWrite|EFileStream );
 
   110 	buf2.Temp( iFs, KTempRootDir, tmpfilename, EFileWrite|EFileStream );
 
   111 	buf3.Temp( iFs, KTempRootDir, tmpfilename, EFileWrite|EFileStream );
 
   113 	RWriteStream write1( &buf1 );
 
   114 	RWriteStream write2( &buf2 );
 
   115 	RWriteStream write3( &buf3 );
 
   117 	RReadStream read1( &buf1 );
 
   118 	RReadStream read2( &buf2 );
 
   119 	RReadStream read3( &buf3 );
 
   121 	TEST(  cmpMappingDataTypeToAdd( mapping1, mapping2 ) );
 
   122 	TEST( !cmpMappingDataTypeToAdd( mapping1, mapping3 ) );
 
   123 	TEST( !cmpMappingDataTypeToAdd( mapping2, mapping3 ) );
 
   125 	INFO_PRINTF1(_L("Testing storage of objects to stream"));
 
   135 	TEST(  cmpMappingDataTypeToAdd( mapping1, mapping2 ) );
 
   136 	TEST( !cmpMappingDataTypeToAdd( mapping1, mapping3 ) );
 
   137 	TEST( !cmpMappingDataTypeToAdd( mapping2, mapping3 ) );
 
   139 	INFO_PRINTF1(_L("Testing reconstruction from stream"));
 
   145 	TEST( !cmpMappingDataTypeToAdd( mapping1, mapping2 ) );
 
   146 	TEST( !cmpMappingDataTypeToAdd( mapping1, mapping3 ) );
 
   147 	TEST(  cmpMappingDataTypeToAdd( mapping2, mapping3 ) );
 
   162 	// Test the insert and find functions
 
   163 	INFO_PRINTF1(_L("Data map insertion"));
 
   165 	CTypeStoreManager* tsm = CTypeStoreManager::NewL( iFs );
 
   166 	CleanupStack::PushL( tsm );
 
   168 	tsm->InsertDataMappingL( data1, TDataTypePriority( 100 ), uid1 ); //data1 mapped to uid1
 
   169 	tsm->InsertDataMappingL( data2, TDataTypePriority( 200 ), uid2 ); //data2 mapped to uid2
 
   170 	tsm->InsertDataMappingL( data1, TDataTypePriority( 100 ), uid1, serviceUid1 ); 
 
   171 	tsm->InsertDataMappingL( data2, TDataTypePriority( 100 ), uid6, serviceUid2 ); 
 
   172 	tsm->InsertDataMappingL( data1, TDataTypePriority( 200 ), uid3 ); //data1 mapped to uid3, not uid1 anymore
 
   173 	tsm->InsertDataMappingL( data4, TDataTypePriority( 200 ), uid4, serviceUid4 ); 
 
   174 	tsm->InsertDataMappingL( data4, TDataTypePriority( 200 ), uid5 ); 
 
   176 	tsm->GetAppByDataType( data1, result );
 
   177 	TEST( uid3 == result );
 
   178 	tsm->GetAppByDataType( data2, result );
 
   179 	TEST( uid2 == result );
 
   180 	tsm->GetAppByDataType( data1, serviceUid1, result);
 
   181 	TEST( uid1 == result );
 
   182 	tsm->GetAppByDataType( data2, serviceUid2, result);
 
   183 	TEST( uid6 == result );
 
   184 	tsm->GetAppByDataType( data4, result);
 
   185 	TEST( uid5 == result );
 
   186 	tsm->GetAppByDataType( data4, serviceUid4, result);
 
   187 	TEST( uid4 == result );
 
   189 	INFO_PRINTF1(_L("Data map insertion by priority"));
 
   191 	TEST(  tsm->InsertIfHigherL( data2, TDataTypePriority( 900 ), uid4 ) ); //Should be higher priority
 
   192 	tsm->GetAppByDataType( data2, result );
 
   193 	TEST( uid4 == result ); 
 
   195 	TEST( !tsm->InsertIfHigherL( data1, TDataTypePriority( 200 ), uid1 ) ); //Should be lower priority
 
   196 	tsm->GetAppByDataType( data1, result );
 
   197 	TEST( uid3 == result ); 
 
   199 	TEST( !tsm->InsertIfHigherL( data1, TDataTypePriority( 100 ), uid2 ) ); //Should be lower priority
 
   200 	tsm->GetAppByDataType( data1, result );
 
   201 	TEST( uid3 == result ); 
 
   203 	TEST(  tsm->InsertIfHigherL( data1, TDataTypePriority( 400 ), uid4 ) ); //Should be higher priority
 
   204 	tsm->GetAppByDataType( data1, result );
 
   205 	TEST( uid4 == result ); 
 
   207 	TEST( !tsm->InsertIfHigherL( data1, TDataTypePriority( 300 ), uid3 ) ); //Should be lower priority
 
   208 	tsm->GetAppByDataType( data1, result );
 
   209 	TEST( uid4 == result );
 
   211 	TEST( tsm->InsertIfHigherL( data1, TDataTypePriority( 300 ), uid3, serviceUid1 ) ); 
 
   212 	tsm->GetAppByDataType( data1, serviceUid1, result);
 
   213 	TEST( uid3 == result ); 
 
   215 	TEST( !tsm->InsertIfHigherL( data1, TDataTypePriority( 100 ), uid5, serviceUid1 ) ); 
 
   216 	tsm->GetAppByDataType( data1, serviceUid1, result);
 
   217 	TEST( uid3 == result ); 
 
   219 	tsm->InsertDataMappingL( data1, TDataTypePriority( 100 ), uid5, serviceUid1 ); 
 
   220 	tsm->GetAppByDataType( data1, serviceUid1, result);
 
   221 	TEST( uid5 == result );
 
   223 	tsm->GetAppByDataType( data4, serviceUid2, result);
 
   224 	TEST( KNullUid == result );
 
   226 	CleanupStack::PopAndDestroy(tsm);
 
   242 	// Call base class method to set up the human readable name for logging
 
   243 	SetTestStepName(KT_Maps);
 
   246 /* @SYMTestCaseID    T-Maps-doTestStepL
 
   250    @SYMTestCaseDesc     Testing of TMappingDataTypeToApp perisitance.
 
   252    @SYMTestPriority 	High
 
   254    @SYMTestStatus 		Implemented
 
   256    @SYMTestActions Just execute program.  Will pause and report any failure.
 
   258    @SYMTestExpectedResults  List of sucessfull tests should appear in a console window.
 
   260 TVerdict CT_Maps::doTestStepL()
 
   263 	INFO_PRINTF1(_L("Test Started"));
 
   264 	INFO_PRINTF1(_L("Testing the TMappingDataTypeToApp"));
 
   267 	// set up the directory structure
 
   270 	// run the testcode (inside an alloc heaven harness)
 
   274 	TRAPD(r,testTMappingDataTypeToAppL());
 
   278 	INFO_PRINTF1(_L("TMappingDataTypeToApp test finished\n"));
 
   280 	REComSession::FinalClose();
 
   283 	return TestStepResult();