imagingandcamerafws/cameraunittest/src/tsu_ecm_ram/rampluginload.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 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 //
       
    15 
       
    16 #include "rampluginload.h"
       
    17 #include <ecam.h>
       
    18 #include <ecam/ecamplugin.h>
       
    19 #include <ecamuids.hrh>
       
    20 
       
    21 #include <ecom/ecomresolverparams.h>
       
    22 
       
    23 #ifndef __WINSCW__
       
    24 const TInt KMaxProcessNameLength = 50; // Max process name length.
       
    25 _LIT(KProcessFileManCopyFile, "copyfile.exe");
       
    26 _LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
       
    27 
       
    28 _LIT(KOriginalDllOnZ, "Z:\\testplugins\\ecamramplugin.dll");
       
    29 _LIT(KMovedDllOnC, "C:\\Sys\\Bin\\ecamramplugin.dll");
       
    30 _LIT(KOriginalRscFileOnZ, "Z:\\testplugins\\ecamramplugin.rsc");
       
    31 _LIT(KMovedRscFileOnC, "C:\\Resource\\Plugins\\ecamramplugin.rsc");
       
    32 
       
    33 const TInt KWaitThreeSeconds = 3000000;
       
    34 #endif
       
    35 
       
    36 
       
    37 void LaunchProcessL(const TDesC& aProcessName, const TDesC& aCmdLine)
       
    38 	{
       
    39 	TRequestStatus stat;    
       
    40 	RProcess p;
       
    41 	User::LeaveIfError(p.Create(aProcessName, aCmdLine));
       
    42 
       
    43 	// Asynchronous logon: completes when process terminates with process 
       
    44 	// exit code
       
    45 	p.Logon(stat);
       
    46 	p.Resume();
       
    47 	User::WaitForRequest(stat);
       
    48 
       
    49 	TExitType exitType = p.ExitType();
       
    50 	TInt exitReason = p.ExitReason();
       
    51 
       
    52 	p.Close();
       
    53 	User::LeaveIfError(exitReason);
       
    54 	}
       
    55 
       
    56 TInt VersionLinearOrderFunction(const CImplementationInformation& pluginA, 
       
    57                                 const CImplementationInformation& pluginB)
       
    58 	{
       
    59 	if (pluginA.Version() == pluginB.Version())
       
    60 		{
       
    61 		return 0;
       
    62 		}
       
    63 
       
    64 	return (pluginA.Version() < pluginB.Version())? 1: -1;	
       
    65 	}
       
    66 
       
    67 //
       
    68 // RRamPluginLoadTest
       
    69 //
       
    70 
       
    71 RRamPluginLoadTest* RRamPluginLoadTest::NewL(TBool aAllocTest)
       
    72 	{
       
    73 	RRamPluginLoadTest* self = new (ELeave) RRamPluginLoadTest(aAllocTest);
       
    74 	return self;	
       
    75 	}
       
    76 	
       
    77 RRamPluginLoadTest::RRamPluginLoadTest(TBool /*aAllocTest*/)
       
    78 	{
       
    79 	iTestStepName = _L("MM-ECM-RAM-U-001");
       
    80 	}
       
    81 	
       
    82 TVerdict RRamPluginLoadTest::DoTestStepL()
       
    83 	{
       
    84 	TVerdict result = EPass;
       
    85 #ifndef __WINSCW__
       
    86 	TBuf<KMaxFileName*2> dllNames(KOriginalDllOnZ);
       
    87 	TBuf<KMaxFileName*2> rscNames(KOriginalRscFileOnZ);
       
    88 
       
    89 	dllNames.Append(KSeparator);
       
    90 	dllNames.Append(KMovedDllOnC);
       
    91 	rscNames.Append(KSeparator);
       
    92 	rscNames.Append(KMovedRscFileOnC);
       
    93 	TBufC<KMaxProcessNameLength> copyProcess(KProcessFileManCopyFile);
       
    94 
       
    95 	// launch copyfile.exe to copy plugin from z: to c:
       
    96 	TRAPD(ret, LaunchProcessL(copyProcess, dllNames));
       
    97 	if(ret == KErrNone)
       
    98 		{
       
    99 		INFO_PRINTF1(_L("Succesfully copied dll"));
       
   100 		}
       
   101 	else
       
   102 		{
       
   103 		INFO_PRINTF2(_L("Copying dll failed with %d"), ret);
       
   104 		result = EFail;
       
   105 		return result;
       
   106 		}
       
   107 	TRAP(ret, LaunchProcessL(copyProcess, rscNames));
       
   108 	if(ret == KErrNone)
       
   109 		{
       
   110 		INFO_PRINTF1(_L("Succesfully copied rsc file"));
       
   111 		}
       
   112 	else
       
   113 		{
       
   114 		INFO_PRINTF2(_L("Copying rsc file failed with %d"), ret);
       
   115 		result = EFail;
       
   116 		return result;
       
   117 		}
       
   118 
       
   119 	User::After(KWaitThreeSeconds); // Wait for ECom to re-scan drives so it can pick up new plugin now on c:
       
   120 #endif
       
   121 	_LIT(KRamPluginDisplayName, "Ram ECam Plugin");
       
   122 	TBufC<15> expectedName(KRamPluginDisplayName);
       
   123 
       
   124 	TBool pluginFound = EFalse;
       
   125 	TInt error = KErrNone;
       
   126 
       
   127 	INFO_PRINTF1(_L("Listing available plugins using REComSession::ListImplementationsL()..."));
       
   128 	TUid interfaceUid = {KUidOnboardCameraPlugin};
       
   129 	TEComResolverParams resolverParams;
       
   130 	resolverParams.SetDataType(KECamPluginMatchString);
       
   131 	RImplInfoPtrArray pluginArray;
       
   132 
       
   133 	TRAP(error, REComSession::ListImplementationsL(interfaceUid, resolverParams, pluginArray));	
       
   134 	if (error != KErrNone)
       
   135 		{
       
   136 		INFO_PRINTF2(_L("ListImplementationsL() failed - %d"), error);
       
   137 		result = EFail;
       
   138 		return result;
       
   139 		}
       
   140 	else
       
   141 		{
       
   142 		pluginArray.Sort(VersionLinearOrderFunction);
       
   143 		for (TInt i = 0; i < pluginArray.Count(); ++i)
       
   144 			{
       
   145 			TBuf<2> drive;
       
   146 			drive = pluginArray[i]->Drive().Name();
       
   147 			INFO_PRINTF3(_L("%S located on drive %S"), &(pluginArray[i]->DisplayName()), &(drive));
       
   148 			if((pluginArray[i]->DisplayName() == expectedName) && (pluginArray[i]->Drive() == 2))
       
   149 				{
       
   150 				pluginFound = ETrue;
       
   151 				}
       
   152 			}
       
   153 		pluginArray.Close();
       
   154 
       
   155 		if(!pluginFound)
       
   156 			{
       
   157 			INFO_PRINTF1(_L("REComSession::ListImplementationsL() could not find plugin in RAM"));
       
   158 			}
       
   159 		}
       
   160 
       
   161 	INFO_PRINTF1(_L("Checking if CCamera::New2L() can successfully load plugin residing in RAM"));
       
   162 	MCameraObserver2* observer2 = NULL;
       
   163 	TRAP(error, CCamera* camera = CCamera::New2L(*observer2, 0, 0));
       
   164 #ifdef _DEBUG
       
   165 	if(error == KErrNone)
       
   166 		{
       
   167 		INFO_PRINTF1(_L("UDEB mode: Expected behaviour - successfully loaded plugin"));
       
   168 		}
       
   169 	else
       
   170 		{
       
   171 		INFO_PRINTF2(_L("UDEB mode: Unexpected behaviour - could not load plugin, error = %d"), error);
       
   172 		result = EFail;
       
   173 		}
       
   174 #else
       
   175 	if (error == KErrNone)
       
   176 		{
       
   177 		INFO_PRINTF1(_L("UREL mode: Unexpected behaviour - successfully loaded plugin"));
       
   178 		result = EFail;
       
   179 		}
       
   180 	else
       
   181 		{
       
   182 		INFO_PRINTF2(_L("UREL mode: Expected behaviour - could not load plugin, error = %d"), error);
       
   183 		}
       
   184 #endif
       
   185 
       
   186 	return result;
       
   187 	}