lowlevellibsandfws/pluginfw/Framework/RomResolverTest/t_romresolver.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1997-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 // This test assumes the following setup:
       
    15 // EComRomRslvrExampleOnC on C:
       
    16 // EComRomRslvrExampleOnZ on Z:
       
    17 // The tests work by checking that the correct implementations are chosen from two plug-ins, one on C:, one on Z:
       
    18 // Implementation:		On C:					On Z:								Expected result:
       
    19 // 10009DC6			version 2				version 1							ROM resolver selects version 2 on C:
       
    20 // 10009DC7			version 1				version 2							ROM resolver selects version 2 on Z:
       
    21 // 10009DCF			version 1				-									ROM resolver does not return this
       
    22 // 
       
    23 //
       
    24 
       
    25 #include <e32test.h>
       
    26 #include <f32file.h>
       
    27 #include <bautils.h>
       
    28 
       
    29 #include <ecom/ecom.h>
       
    30 #include "EComUidCodes.h"
       
    31 #include "Interface.h" // interface to Plugins
       
    32 #include "../EcomTestUtils/EcomTestUtils.h"
       
    33 
       
    34 TUid KUidInterface = {0x10009DC8};
       
    35 const TInt KUidImplementationAValue = 0x10009DC6;
       
    36 const TInt KUidImplementationBValue = 0x10009DC7;
       
    37 const TInt KUidImplementationCValue = 0x10009DCF;
       
    38 const TInt KOneSecond = 1000000;
       
    39 
       
    40 LOCAL_D RTest test(_L("t_romresolver.exe"));
       
    41 
       
    42 _LIT(KEComPlugin2OnZ, "z:\\RAMOnly\\EComRomRslvrExampleOnC.dll");
       
    43 
       
    44 _LIT(KEComPluginRsc2OnZ, "z:\\RAMOnly\\EComRomRslvrExampleOnC.rsc");
       
    45 _LIT(KEComPlugin2OnC, "c:\\sys\\bin\\EComRomRslvrExampleOnC.dll");
       
    46 _LIT(KEComPluginRsc2OnC, "c:\\resource\\plugins\\EComRomRslvrExampleOnC.rsc");
       
    47 
       
    48 
       
    49 class TheTest
       
    50 	{
       
    51 public:
       
    52 	void StartTestL();
       
    53 	};
       
    54 
       
    55 /**
       
    56 @SYMTestCaseID          SYSLIB-ECOM-CT-0663
       
    57 @SYMTestCaseDesc	    Tests for REComSession::ListImplementationsL() function
       
    58 @SYMTestPriority 	    High
       
    59 @SYMTestActions  	    Tests for interface implementation data
       
    60 @SYMTestExpectedResults The test must not fail.
       
    61 @SYMREQ                 REQ0000
       
    62 */
       
    63 LOCAL_C void TestDefaultResolverL()
       
    64 	{
       
    65 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0663 TestDefaultResolverL "));
       
    66 
       
    67 	//
       
    68 	// Testing a overloaded method for ListImplementationsL
       
    69 	// ------------------------------------------------------------------
       
    70 	//
       
    71 
       
    72 	// Set up for heap leak checking
       
    73 	__UHEAP_MARK;
       
    74 
       
    75 	// and leaking thread handles
       
    76 	TInt startProcessHandleCount;
       
    77 	TInt startThreadHandleCount;
       
    78 	TInt endProcessHandleCount;
       
    79 	TInt endThreadHandleCount;
       
    80 	// Test Starts...
       
    81 
       
    82 	RThread thisThread;
       
    83 	thisThread.HandleCount(startProcessHandleCount, startThreadHandleCount);
       
    84 
       
    85 	RImplInfoPtrArray ifArray;
       
    86 
       
    87 	TEComResolverParams ResolverParams;
       
    88 	_LIT8(KImplementationTest,"text/wml");
       
    89 	ResolverParams.SetDataType(KImplementationTest());
       
    90 	ResolverParams.SetWildcardMatch(ETrue);	// Allow wildcard matching
       
    91 
       
    92 	REComSession::ListImplementationsL(
       
    93 			KUidInterface,
       
    94 			ResolverParams,
       
    95 			KDefaultResolverUid,
       
    96 			ifArray);
       
    97 
       
    98 	const TInt availCount = ifArray.Count();
       
    99 	test.Printf(_L("Found %d implementations.\n"),availCount);
       
   100 	test(availCount==3);
       
   101 
       
   102 	for (TInt count=0;count<availCount;++count)
       
   103 		{
       
   104 		const CImplementationInformation* info = ifArray[count];
       
   105 
       
   106 		TDriveName driveName = info->Drive().Name();
       
   107 		test.Printf(_L("%d. uid={%x} version=%d on drive %S\n"), count+1, info->ImplementationUid(), info->Version(), &driveName);
       
   108 
       
   109 		switch(info->ImplementationUid().iUid)
       
   110 			{
       
   111 			case KUidImplementationAValue:
       
   112 				test(info->Version()==1);
       
   113 				test(info->Drive()==EDriveZ);
       
   114 				break;
       
   115 
       
   116 			case KUidImplementationBValue:
       
   117 				test(info->Version()==2);
       
   118 				test(info->Drive()==EDriveZ);
       
   119 				break;
       
   120 
       
   121 			case KUidImplementationCValue:
       
   122 				test(info->Version()==1);
       
   123 				test(info->Drive()==EDriveC);
       
   124 				break;
       
   125 
       
   126 			default:
       
   127 				test.Printf(_L("Unknown implementation UID\n"));
       
   128 				test(0);
       
   129 			}
       
   130 		}
       
   131 
       
   132 	// Empty the array of implementations
       
   133 	test.Printf(_L("Destroying List..."));
       
   134 	ifArray.ResetAndDestroy();
       
   135 
       
   136 	REComSession::FinalClose(); // Don't want leaks outside the test
       
   137 
       
   138 	// Check for open handles
       
   139 	thisThread.HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   140 
       
   141 	test(startThreadHandleCount == endThreadHandleCount);
       
   142 	test.Printf(_L("Great ! No handle mismatch."));
       
   143 
       
   144 	// Test Ends...
       
   145 
       
   146 	__UHEAP_MARKEND;								}
       
   147 
       
   148 /**
       
   149 @SYMTestCaseID          SYSLIB-ECOM-CT-0664
       
   150 @SYMTestCaseDesc	    Tests for REComSession::ListImplementationsL() function
       
   151 @SYMTestPriority 	    High
       
   152 @SYMTestActions  	    Tests for interface implementation data
       
   153 @SYMTestExpectedResults The test must not fail.
       
   154 @SYMREQ                 REQ0000
       
   155 */
       
   156 LOCAL_C void TestRomResolverL()
       
   157 	{
       
   158 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0664 TestRomResolverL "));
       
   159 
       
   160 	//
       
   161 	// Testing a overloaded method for ListImplementationsL
       
   162 	// ------------------------------------------------------------------
       
   163 	//
       
   164 
       
   165 	// Set up for heap leak checking
       
   166 	__UHEAP_MARK;
       
   167 
       
   168 	// and leaking thread handles
       
   169 	TInt startProcessHandleCount;
       
   170 	TInt startThreadHandleCount;
       
   171 	TInt endProcessHandleCount;
       
   172 	TInt endThreadHandleCount;
       
   173 	// Test Starts...
       
   174 
       
   175 	RThread thisThread;
       
   176 	thisThread.HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   177 
       
   178 	RImplInfoPtrArray ifArray;
       
   179 
       
   180 	TEComResolverParams ResolverParams;
       
   181 	_LIT8(KImplementationTest,"text/wml");
       
   182 	ResolverParams.SetDataType(KImplementationTest());
       
   183 	ResolverParams.SetWildcardMatch(ETrue);	// Allow wildcard matching
       
   184 
       
   185 	REComSession::ListImplementationsL(
       
   186 			KUidInterface,
       
   187 			ResolverParams,
       
   188 			KRomOnlyResolverUid,
       
   189 			ifArray);
       
   190 
       
   191 	const TInt availCount = ifArray.Count();
       
   192 	test.Printf(_L("Found %d implementations.\n"),availCount);
       
   193 	test(availCount == 2);
       
   194 
       
   195 	for (TInt count=0;count<availCount;++count)
       
   196 		{
       
   197 		const CImplementationInformation* info = ifArray[count];
       
   198 
       
   199 		TDriveName driveName = info->Drive().Name();
       
   200 		test.Printf(_L("%d. uid={%x} version=%d on drive %S\n"), count+1, info->ImplementationUid(), info->Version(), &driveName);
       
   201 
       
   202 		switch(info->ImplementationUid().iUid)
       
   203 			{
       
   204 			case KUidImplementationAValue:
       
   205 				test(info->Version()==1);
       
   206 				test(info->Drive()==EDriveZ);
       
   207 				break;
       
   208 
       
   209 			case KUidImplementationBValue:
       
   210 				test(info->Version()==2);
       
   211 				test(info->Drive()==EDriveZ);
       
   212 				break;
       
   213 
       
   214 			default:
       
   215 				test.Printf(_L("Unknown implementation UID\n"));
       
   216 				test(0);
       
   217 			}
       
   218 		}
       
   219 
       
   220 	// Empty the array of implementations
       
   221 	test.Printf(_L("Destroying List..."));
       
   222 	ifArray.ResetAndDestroy();
       
   223 
       
   224 	REComSession::FinalClose(); // Don't want leaks outside the test
       
   225 
       
   226 	// Check for open handles
       
   227 	thisThread.HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   228 
       
   229 	test(startThreadHandleCount == endThreadHandleCount);
       
   230 	test.Printf(_L("Great ! No handle mismatch."));
       
   231 
       
   232 	// Test Ends...
       
   233 
       
   234 	__UHEAP_MARKEND;								}
       
   235 
       
   236 LOCAL_C void TestListImplementationL()
       
   237 	{
       
   238 	TestDefaultResolverL();
       
   239 	TestRomResolverL();
       
   240 	}
       
   241 
       
   242 void TheTest::StartTestL()
       
   243 	{
       
   244 	TestListImplementationL();
       
   245 	}
       
   246 
       
   247 TInt DoTestsL()
       
   248 	{
       
   249 	// Should any tests leave past the lowest level???
       
   250 	TheTest theT;
       
   251 	theT.StartTestL();
       
   252 	return KErrNone;
       
   253 	}
       
   254 
       
   255 void CopyFiles()
       
   256 	{
       
   257 	TRAPD(err, EComTestUtils::FileManCopyFileL(KEComPlugin2OnZ, KEComPlugin2OnC));
       
   258 	test(err==KErrNone);
       
   259 
       
   260 	TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginRsc2OnZ, KEComPluginRsc2OnC));
       
   261 	test(err==KErrNone);
       
   262 	}
       
   263 
       
   264 void CleanupFiles()
       
   265 	{
       
   266 	TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComPlugin2OnC));
       
   267 	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginRsc2OnC));
       
   268 	}
       
   269 
       
   270 GLDEF_C TInt E32Main()
       
   271 	{
       
   272 	__UHEAP_MARK;
       
   273 	test.Title();
       
   274 	test.Start(_L("Rom resolver tests"));
       
   275 
       
   276 	// get clean-up stack
       
   277 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   278 
       
   279 	CopyFiles();
       
   280 	//The reason for the folowing delay is:
       
   281 	//ECOM server could be already started. It means that when we copy some
       
   282 	//ECOM plugins from Z: to C: drive - ECOM server should look for and
       
   283 	//find the new ECOM plugins. The ECOM server uses for that CDiscoverer::CIdleScanningTimer
       
   284 	//which is an active object. So the discovering service is asynchronous. We have to
       
   285 	//wait some time until it finishes. Otherwise ListImplementationsL could fail to find
       
   286 	//requested implementations.
       
   287 	User::After(KOneSecond * 3);
       
   288 
       
   289 	TRAPD(err,DoTestsL());
       
   290 
       
   291 	delete cleanup;
       
   292 
       
   293 	test(err==KErrNone);
       
   294 
       
   295 	CleanupFiles();
       
   296 
       
   297 	test.Next(_L("/n"));
       
   298 	test.End();
       
   299 	test.Close();
       
   300 	__UHEAP_MARKEND;
       
   301 	return(0);
       
   302 	}