imagingandcamerafws/cameraunittest/src/ECamTest.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 
       
     2 // ECamTest.cpp
       
     3 
       
     4 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     5 // All rights reserved.
       
     6 // This component and the accompanying materials are made available
       
     7 // under the terms of "Eclipse Public License v1.0"
       
     8 // which accompanies this distribution, and is available
       
     9 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    10 //
       
    11 // Initial Contributors:
       
    12 // Nokia Corporation - initial contribution.
       
    13 //
       
    14 // Contributors:
       
    15 //
       
    16 // Description:
       
    17 //
       
    18 
       
    19 #include "ECamTest.h"
       
    20 #include <ecam.h>
       
    21 #include <ecam/ecamplugin.h>
       
    22 #include <ecamuids.hrh>
       
    23 
       
    24 #include <ecom/ecomresolverparams.h>
       
    25 
       
    26 #include <mm/mmpluginutils.h>
       
    27 
       
    28 //
       
    29 // RECamTest
       
    30 //
       
    31 
       
    32 RECamTest* RECamTest::NewL(TBool aAllocTest)
       
    33 	{
       
    34 	RECamTest* self = new (ELeave) RECamTest(aAllocTest);
       
    35 	return self;	
       
    36 	}
       
    37 	
       
    38 RECamTest::RECamTest(TBool /*aAllocTest*/)
       
    39 	{
       
    40 	iTestStepName = _L("MM-ECM-API-U-011");
       
    41 	}
       
    42 	
       
    43 TVerdict RECamTest::DoTestStepL()
       
    44 	{
       
    45 	TVerdict result = EPass;
       
    46 	CCamera* camera = NULL;
       
    47 	MCameraObserver* observer = NULL; // should not be used, so pass silly value. TODO make this an MCameraObserver, or arrange would not KernExec3 on real plugin
       
    48 	MCameraObserver2* observer2 = NULL; // TODO ditto
       
    49 	TInt error = KErrNone;
       
    50 
       
    51 	INFO_PRINTF1(_L("Check Opening CCam gives KErrNotSupported"));
       
    52 	
       
    53 	INFO_PRINTF1(_L("Checking basic CCamera::NewL()"));
       
    54 	__MM_HEAP_MARK;
       
    55 	TRAP(error, camera = CCamera::NewL(*observer, 0));
       
    56 	if (error==KErrNone)
       
    57 		{
       
    58 		INFO_PRINTF1(_L("Unexpected KErrNone return from CCamera::NewL()"));
       
    59 		delete camera;
       
    60 		result = EFail;
       
    61 		}
       
    62 	else if (error!=KErrNotSupported)
       
    63 		{
       
    64 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::NewL()"), error);
       
    65 		result = EFail;		
       
    66 		}
       
    67 	__MM_HEAP_MARKEND;
       
    68 	
       
    69 	INFO_PRINTF1(_L("Checking basic CCamera::NewDuplicateL()"));
       
    70 	__MM_HEAP_MARK;
       
    71 	TRAP(error, camera = CCamera::NewDuplicateL(*observer, 0));
       
    72 	if (error==KErrNone)
       
    73 		{
       
    74 		INFO_PRINTF1(_L("Unexpected KErrNone return from CCamera::NewDuplicateL()"));
       
    75 		delete camera;
       
    76 		result = EFail;
       
    77 		}
       
    78 	else if (error!=KErrNotSupported)
       
    79 		{
       
    80 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::NewDuplicateL()"), error);
       
    81 		result = EFail;		
       
    82 		}
       
    83 	__MM_HEAP_MARKEND;
       
    84 	
       
    85 	INFO_PRINTF1(_L("Checking additional \"ChunkAPI\" factory functions"));
       
    86 	INFO_PRINTF1(_L("Checking CCamera::NewL()"));
       
    87 	__MM_HEAP_MARK;
       
    88 	TRAP(error, camera = CCamera::NewL(*observer2, 0, 0));
       
    89 	if (error==KErrNone)
       
    90 		{
       
    91 		INFO_PRINTF1(_L("Unexpected KErrNone return from CCamera::NewL()"));
       
    92 		delete camera;
       
    93 		result = EFail;
       
    94 		}
       
    95 	else if (error!=KErrNotSupported)
       
    96 		{
       
    97 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::NewL()"), error);
       
    98 		result = EFail;		
       
    99 		}
       
   100 	__MM_HEAP_MARKEND;
       
   101 	
       
   102 	INFO_PRINTF1(_L("Checking CCamera::NewDuplicateL()"));
       
   103 	__MM_HEAP_MARK;
       
   104 	TRAP(error, camera = CCamera::NewDuplicateL(*observer2, 0));
       
   105 	if (error==KErrNone)
       
   106 		{
       
   107 		INFO_PRINTF1(_L("Unexpected KErrNone return from CCamera::NewDuplicateL()"));
       
   108 		delete camera;
       
   109 		result = EFail;
       
   110 		}
       
   111 	else if (error!=KErrNotSupported)
       
   112 		{
       
   113 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::NewDuplicateL()"), error);
       
   114 		result = EFail;		
       
   115 		}
       
   116 	__MM_HEAP_MARKEND;
       
   117 	
       
   118 	INFO_PRINTF1(_L("Checking CCamera::New2L()"));
       
   119 	__MM_HEAP_MARK;
       
   120 	TRAP(error, camera = CCamera::New2L(*observer2, 0, 0));
       
   121 	if (error==KErrNone)
       
   122 		{
       
   123 		INFO_PRINTF1(_L("Unexpected KErrNone return from CCamera::New2L()"));
       
   124 		delete camera;
       
   125 		result = EFail;
       
   126 		}
       
   127 	else if (error!=KErrNotSupported)
       
   128 		{
       
   129 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L()"), error);
       
   130 		result = EFail;		
       
   131 		}
       
   132 	__MM_HEAP_MARKEND;
       
   133 	
       
   134 	INFO_PRINTF1(_L("Checking CCamera::NewDuplicate2L()"));
       
   135 	__MM_HEAP_MARK;
       
   136 	TRAP(error, camera = CCamera::NewDuplicate2L(*observer2, 0));
       
   137 	if (error==KErrNone)
       
   138 		{
       
   139 		INFO_PRINTF1(_L("Unexpected KErrNone return from CCamera::NewDuplicate2L()"));
       
   140 		delete camera;
       
   141 		result = EFail;
       
   142 		}
       
   143 	else if (error!=KErrNotSupported)
       
   144 		{
       
   145 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::NewDuplicate2L()"), error);
       
   146 		result = EFail;		
       
   147 		}
       
   148 	__MM_HEAP_MARKEND;
       
   149 	
       
   150 	return result;
       
   151 	}
       
   152 	
       
   153 //
       
   154 // RECamInnerTest
       
   155 //
       
   156 
       
   157 RECamInnerTest* RECamInnerTest::NewL(TBool aAllocTest)
       
   158 	{
       
   159 	RECamInnerTest* self = new (ELeave) RECamInnerTest(aAllocTest);
       
   160 	return self;	
       
   161 	}
       
   162 	
       
   163 RECamInnerTest::RECamInnerTest(TBool /*aAllocTest*/)
       
   164 	{
       
   165 	iTestStepName = _L("MM-ECM-API-U-012");
       
   166 	}
       
   167 	
       
   168 TVerdict RECamInnerTest::DoTestStepL()
       
   169 	{
       
   170 	INFO_PRINTF1(_L("Check can actually open ECam plugin"));
       
   171 	TVerdict result = EPass;
       
   172 
       
   173 
       
   174 	INFO_PRINTF1(_L("Open stub plugin directly"));
       
   175 		{
       
   176 		__MM_HEAP_MARK;
       
   177 		// TODO - would be nice to actually call CCameraPlugin::NewL, but this is not exported, so this is extract
       
   178 		TUid implementationUid = {KUidOnboardCameraStubPlugin};
       
   179 		TUid destructorKey = {0};
       
   180 		CCamera* camera = NULL;
       
   181 		TRAPD(error,
       
   182 			camera = static_cast<CCamera*>
       
   183 				(REComSession::CreateImplementationL(implementationUid, destructorKey)));
       
   184 				
       
   185 		if (error != KErrNone)
       
   186 			{
       
   187 			INFO_PRINTF2(_L("CreateImplementationL() failed - %d"), error);
       
   188 			result = EFail;
       
   189 			}
       
   190 		else
       
   191 			{
       
   192 			delete camera;
       
   193 			REComSession::DestroyedImplementation(destructorKey);
       
   194 			REComSession::FinalClose();
       
   195 			}
       
   196 		__MM_HEAP_MARKEND;
       
   197 		}
       
   198 	
       
   199 	INFO_PRINTF1(_L("Open stub plugin via interface"));
       
   200 		{
       
   201 		__MM_HEAP_MARK;
       
   202 		// TODO - would be nice to actually call CCameraPlugin::NewL, but this is not exported, so this is extract
       
   203 		TUid interfaceUid = {KUidOnboardCameraPlugin};
       
   204 		TUid destructorKey = {0};
       
   205 		CCamera* camera = NULL;
       
   206 		TRAPD(error,
       
   207 			camera = static_cast<CCamera*>
       
   208 				(MmPluginUtils::CreateImplementationL(interfaceUid, destructorKey, KECamPluginMatchString, KRomOnlyResolverUid)));
       
   209 				
       
   210 		if (error != KErrNone)
       
   211 			{
       
   212 			INFO_PRINTF2(_L("CreateImplementationL() failed - %d"), error);
       
   213 			result = EFail;
       
   214 			}
       
   215 		else
       
   216 			{
       
   217 			delete camera;
       
   218 			REComSession::DestroyedImplementation(destructorKey);
       
   219 			REComSession::FinalClose();
       
   220 			}
       
   221 		__MM_HEAP_MARKEND;		
       
   222 		}
       
   223 	
       
   224 	return result;
       
   225 	}