genericservices/mimerecognitionfw/tef/T_MstrStep.cpp
changeset 0 e4d67989cc36
child 44 97b0fb8a2cc2
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Harness for Mstr test code
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file 
       
    20  @internalComponent - Internal Symbian test code 
       
    21 */
       
    22 
       
    23 
       
    24 #include <ecom/ecom.h>
       
    25 #include "T_MstrStep.h"
       
    26 
       
    27 /**
       
    28    Constructor
       
    29  */
       
    30 CT_MstrStep::CT_MstrStep()
       
    31 	{
       
    32 	// Call base class method to set up the human readable name for logging
       
    33 	SetTestStepName(KT_MstrStep);
       
    34 	}
       
    35 	
       
    36 /**
       
    37    Destructor
       
    38  */
       
    39 CT_MstrStep::~CT_MstrStep()
       
    40 	{
       
    41 	}
       
    42 
       
    43 TVerdict CT_MstrStep::doTestStepL()
       
    44 	{	
       
    45 	INFO_PRINTF1(_L("Test Started"));
       
    46 	iFs.Connect();
       
    47 	__UHEAP_MARK;
       
    48 	TRAPD(ret,doMenuL());		
       
    49 	TEST(ret==KErrNone);
       
    50 	REComSession::FinalClose();
       
    51 	__UHEAP_MARKEND;
       
    52 	iFs.Close();
       
    53 
       
    54 	INFO_PRINTF1(_L("Test Finished"));
       
    55 	return TestStepResult();
       
    56 	}
       
    57 	
       
    58 /**
       
    59    @SYMTestCaseID		T_MstrStep_doMenuL
       
    60   
       
    61    @SYMPREQ			
       
    62   
       
    63    @SYMTestCaseDesc 	Tests data type storage
       
    64   
       
    65    @SYMTestPriority 	High
       
    66   
       
    67    @SYMTestStatus 		Implemented
       
    68    
       
    69    @SYMTestActions  	The test creates a storage manager object, which is filled with some mapings.
       
    70    The first thing to verify is the correct insertion of these mappings, checking the type, uid
       
    71    and priority. Then the mappings are stored in an INI file, and restored from there to a new 
       
    72    storage manager object. The test checks that this new object is correct and equal to the
       
    73    previous one. The test also tries to find a non-existing app mapping, which gives a 0 Uid.
       
    74    API Calls:\n	
       
    75    CTypeStoreManager::NewL(RFs& aFs) \n
       
    76    CTypeStoreManager::InsertDataMappingL(const TDataType& aDataType, TDataTypePriority aPriority, TUid aUid) \n
       
    77    CTypeStoreManager::DeleteDataMapping(const TDataType& aDataType) \n
       
    78    CTypeStoreManager::GetAppByDataType(const TDataType& aDataType, TUid& aUid) const \n
       
    79    CTypeStoreManager::StoreL() \n
       
    80    CTypeStoreManager::ReStoreL() \n
       
    81    
       
    82    @SYMTestExpectedResults Test should complete without any panic.
       
    83    
       
    84  */
       
    85 void CT_MstrStep::doMenuL()
       
    86 	{
       
    87 	INFO_PRINTF1(_L("Testing Data Type storage"));
       
    88 	INFO_PRINTF1(_L("Creating CTypeStoreManager object"));
       
    89 	CTypeStoreManager* mman = CTypeStoreManager::NewL(iFs);
       
    90 	CleanupStack::PushL(mman);
       
    91 
       
    92 	INFO_PRINTF1(_L("Adding some mappings to table"));
       
    93 	lPopulateMappingTablesL(mman);
       
    94 
       
    95 	INFO_PRINTF1(_L("Checking mappings in table"));
       
    96 	lCheckMappingsL(mman);
       
    97 		
       
    98 	INFO_PRINTF1(_L("Storing to INI file"));
       
    99 	mman->StoreL();
       
   100 
       
   101 	INFO_PRINTF1(_L("Restoring from INI file to new object"));
       
   102 	CTypeStoreManager* mman2 = CTypeStoreManager::NewL(iFs);
       
   103 	CleanupStack::PushL(mman2);
       
   104 	mman2->RestoreL();
       
   105 
       
   106 	INFO_PRINTF1(_L("Checking restored correctly"));
       
   107 
       
   108 	lCheckMappingsL(mman2);
       
   109 
       
   110 	INFO_PRINTF1(_L("Trying to find non-existent app mappings"));
       
   111 	TUid scratchUid;
       
   112 	mman->GetAppByDataType(TDataType(_L8("non/existent")),scratchUid);
       
   113 	TEST(scratchUid.iUid==0);
       
   114 
       
   115 	INFO_PRINTF1(_L("Clearing table to original state"));
       
   116 	lClearMappingTablesL(mman2);
       
   117 
       
   118 	CleanupStack::PopAndDestroy(2); // managers
       
   119 	}
       
   120 
       
   121 const TUid KTestUidValue1={10101010}; 
       
   122 const TUid KTestUidValue2={20202020}; 
       
   123 const TUid KTestUidValue3={30303030}; 
       
   124 
       
   125 void CT_MstrStep::lPopulateMappingTablesL(CTypeStoreManager* aMan)
       
   126 	{
       
   127 	aMan->InsertDataMappingL(TDataType(_L8("image/gif")),KDataTypePriorityNormal,KTestUidValue1);
       
   128 	aMan->InsertDataMappingL(TDataType(_L8("text/plain")),KDataTypePriorityNormal,KTestUidValue2);
       
   129 	aMan->InsertDataMappingL(TDataType(_L8("text/plain")),KDataTypePriorityNormal,KTestUidValue1,KTestUidValue3);
       
   130 	aMan->InsertDataMappingL(TDataType(_L8("text/word")),KDataTypePriorityNormal,KTestUidValue2);
       
   131 	aMan->InsertDataMappingL(TDataType(_L8("something/else")),KDataTypePriorityNormal,KTestUidValue3);
       
   132 	}
       
   133 
       
   134 void CT_MstrStep::lClearMappingTablesL(CTypeStoreManager* aMan)
       
   135 	{
       
   136 	aMan->DeleteDataMapping(TDataType(_L8("image/gif")));
       
   137 	aMan->DeleteDataMapping(TDataType(_L8("text/plain")));
       
   138 	aMan->DeleteDataMapping(TDataType(_L8("text/plain")), KTestUidValue3);
       
   139 	aMan->DeleteDataMapping(TDataType(_L8("text/word")));
       
   140 	aMan->DeleteDataMapping(TDataType(_L8("something/else")));
       
   141 
       
   142 	aMan->StoreL();
       
   143 	}
       
   144 
       
   145 void CT_MstrStep::lCheckMappingsL(CTypeStoreManager* aTypeMan)
       
   146 	{
       
   147 	TUid scratchUid;
       
   148 	aTypeMan->GetAppByDataType(TDataType(_L8("image/gif")),scratchUid);
       
   149 	TEST(scratchUid==KTestUidValue1);
       
   150 	aTypeMan->GetAppByDataType(TDataType(_L8("text/plain")),scratchUid);
       
   151 	TEST(scratchUid==KTestUidValue2);
       
   152 	aTypeMan->GetAppByDataType(TDataType(_L8("text/plain")),KTestUidValue3,scratchUid);
       
   153 	TEST(scratchUid==KTestUidValue1);
       
   154 	aTypeMan->GetAppByDataType(TDataType(_L8("text/word")),scratchUid);
       
   155 	TEST(scratchUid==KTestUidValue2);
       
   156 	aTypeMan->GetAppByDataType(TDataType(_L8("something/else")),scratchUid);
       
   157 	TEST(scratchUid==KTestUidValue3);
       
   158 	aTypeMan->GetAppByDataType(TDataType(_L8("image/*")),scratchUid);
       
   159 	TEST(scratchUid==KTestUidValue1);
       
   160 	
       
   161 	TDataType nativeData(KTestUidValue3);
       
   162 	TEST(nativeData.IsNative());
       
   163 
       
   164 	CArrayFixFlat<TDataType>* array=new(ELeave) CArrayFixFlat<TDataType>(1);
       
   165 	CleanupStack::PushL(array);
       
   166 	aTypeMan->GetDataTypesByAppL(KTestUidValue1,array);
       
   167 	TEST(array->Count()==1);
       
   168 	TEST((*array)[0]==TDataType(_L8("image/gif")));
       
   169 	array->Delete(0);
       
   170 	aTypeMan->GetDataTypesByAppL(KTestUidValue2,array);
       
   171 	TEST(array->Count()==2);
       
   172 	TEST((*array)[0]==TDataType(_L8("text/plain")));
       
   173 	TEST((*array)[1]==TDataType(_L8("text/word")));
       
   174 	array->Delete(0,2);
       
   175 	aTypeMan->GetDataTypesByAppL(KTestUidValue3,array);
       
   176 	TEST(array->Count()==1);
       
   177 	TEST((*array)[0]==TDataType(_L8("something/else")));
       
   178 	array->Delete(0);
       
   179 	TUid uid;
       
   180 	uid.iUid=0;
       
   181 	aTypeMan->GetDataTypesByAppL(uid,array);
       
   182 	TEST(array->Count()==4);
       
   183 	CleanupStack::PopAndDestroy(); // array
       
   184 	}