os/mm/imagingandcamerafws/cameraunittest/src/TSU_ECM_ADV/ecamdirectviewfindertest.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2007-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 <ecamuids.hrh>
    17 #include <ecom/ecomresolverparams.h>
    18 #include "ecamdirectviewfindertest.h"
    19 #include "ECamUnitTestPluginUids.hrh"
    20 #include "ECamUnitTestPlugin.h"
    21 #include <ecam/ecamcommonuids.hrh>
    22 
    23 /*--------------------------------------------------------
    24  	DirectViewFinder : RECamDirectViewFinderTest
    25  *--------------------------------------------------------*/
    26 RECamDirectViewFinderTest* RECamDirectViewFinderTest::NewL(const TDesC& aTestStep)
    27 	{
    28 	RECamDirectViewFinderTest* self = new (ELeave) RECamDirectViewFinderTest(aTestStep);
    29 	return self;	
    30 	}
    31 	
    32 RECamDirectViewFinderTest::RECamDirectViewFinderTest(const TDesC& aTestStep)
    33 	{
    34 	iTestStepName.Copy(aTestStep);
    35 	}
    36 	
    37 TVerdict RECamDirectViewFinderTest::DoTestStepL()
    38 	{
    39 	if(!iTestStepName.Compare(_L("MM-ECM-ADV-U-044-HP")))
    40 		{
    41 		return DoTestStep_44L();
    42 		}
    43 	else if(!iTestStepName.Compare(_L("MM-ECM-ADV-U-045-HP")))
    44 		{
    45 		return DoTestStep_45L();
    46 		}
    47 	return EInconclusive;	
    48 	}
    49 	
    50 TVerdict RECamDirectViewFinderTest::DoTestStep_44L()
    51 	{
    52 	
    53 	TVerdict verdict = EFail;
    54 	INFO_PRINTF1(_L("Alloc test"));
    55 	TInt i;
    56 	TInt err;
    57 	for (i = 1 ; ; i++)
    58 		{
    59 		__MM_HEAP_MARK;
    60 		
    61 		if (i % 5 == 0)
    62 			{
    63 			INFO_PRINTF2(_L("Fail count = %d"), i);
    64 			}
    65 
    66 		__UHEAP_SETFAIL(RHeap::EFailNext, i);
    67 
    68 		TRAP(err, verdict = DoTestStep_Alloc_44L());
    69 
    70 		TAny* testAlloc = NULL;
    71 		testAlloc = User::Alloc(1);
    72 		TBool heapTestingComplete = (testAlloc == NULL) && (err==KErrNone);
    73 		User::Free(testAlloc);
    74 
    75 		__UHEAP_RESET;
    76 		__MM_HEAP_MARKEND;
    77 
    78 		if ((err != KErrNoMemory && verdict == EPass ) || heapTestingComplete)
    79 			{
    80 			INFO_PRINTF4(_L("err = %d, verdict = %d, Fail count = %d"), err, verdict, i);
    81 			INFO_PRINTF1(_L("Alloc testing completed successfully"));
    82 			verdict = EPass;
    83 			break;
    84 			}
    85 		}
    86 	return verdict;
    87 
    88 	}
    89 	
    90 TVerdict RECamDirectViewFinderTest::DoTestStep_Alloc_44L()
    91 	{
    92 	TVerdict result = EPass;
    93 	CCamera* camera = NULL;
    94 	
    95 	MCameraObserver* observer = NULL; 
    96 	TInt error = KErrNone;
    97 	CCamera::CCameraDirectViewFinder* directviewfinder = NULL;
    98 	
    99 	// using observer 	
   100 	__MM_HEAP_MARK;
   101 	INFO_PRINTF1(_L("Create camera using Camera::NewL() and MCameraObserver"));
   102 
   103 	TRAP(error, camera = CCamera::NewL(*observer, 0));
   104 	
   105 	if (error==KErrNone)
   106 		{
   107 		CleanupStack::PushL(camera);
   108 		INFO_PRINTF1(_L("KErrNone return from CCamera::NewL()"));
   109 		directviewfinder = static_cast<CCamera::CCameraDirectViewFinder*> (camera->CustomInterface(KECamDirectViewFinderUid));
   110 	    if (directviewfinder!= NULL)
   111 	    	{
   112 	    	CleanupStack::PushL(directviewfinder);
   113 	    	INFO_PRINTF1(_L("CCameraDirectViewFinder object was created")); 
   114 	    	CleanupStack::PopAndDestroy(directviewfinder);
   115 	    	}
   116 	    else
   117     		{
   118     		INFO_PRINTF1(_L("CCameraDirectViewFinder object wasn't created"));
   119     		result = EFail;    		
   120     		CleanupStack::PopAndDestroy(camera);
   121     		User::Leave (KErrNoMemory);
   122     		}
   123     	CleanupStack::PopAndDestroy(camera);
   124 		}
   125 	else 
   126 		{
   127 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::NewL()"), error);
   128 		result = EFail;
   129 		User::Leave (KErrNoMemory);
   130 		}
   131 	__MM_HEAP_MARKEND;
   132 	
   133 	// using observer 2 
   134 	MCameraObserver2* observer2 = NULL; 
   135 	
   136 	__MM_HEAP_MARK;
   137 	INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
   138 	
   139 	TRAP(error, camera = CCamera::New2L(*observer2, 0,0));
   140 
   141 	if (error==KErrNone)
   142 		{
   143 		CleanupStack::PushL(camera);
   144 		INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
   145 		directviewfinder = 	static_cast<CCamera::CCameraDirectViewFinder*> (camera->CustomInterface(KECamDirectViewFinderUid));
   146 	    if (directviewfinder!= NULL)
   147 	    	{
   148 	    	CleanupStack::PushL(directviewfinder);
   149 	  		INFO_PRINTF1(_L("CCameraDirectViewFinder object was created")); 
   150 	    	CleanupStack::PopAndDestroy(directviewfinder);
   151 	    	}
   152 	    else
   153     		{
   154     		INFO_PRINTF1(_L("CCameraDirectViewFinder object wasn't created"));
   155     		result = EFail;
   156     		CleanupStack::PopAndDestroy(camera);
   157     		User::Leave (KErrNoMemory);    		
   158     		}	
   159 		CleanupStack::PopAndDestroy(camera);
   160 		}
   161 	else 
   162 		{
   163 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
   164 		result = EFail;
   165 		User::Leave (KErrNoMemory);
   166 		}
   167 	__MM_HEAP_MARKEND;
   168 	
   169 	// create a directviewfinder object using New2L
   170 	__MM_HEAP_MARK;
   171 	INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
   172 	
   173 	TRAP(error, camera = CCamera::New2L(*observer2, 0,0));
   174 
   175 	if (error==KErrNone)
   176 		{
   177 		CleanupStack::PushL(camera);
   178 		INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
   179 		TRAP(error, directviewfinder  = CCamera::CCameraDirectViewFinder::NewL(*camera));	
   180 		
   181 		if (error==KErrNone)
   182 	    	{
   183 	    	CleanupStack::PushL(directviewfinder);
   184 	  		INFO_PRINTF1(_L("CCameraDirectViewFinder object was created using NewL")); 
   185 	    	CleanupStack::PopAndDestroy(directviewfinder);
   186 	    	}
   187 	    else
   188     		{
   189     		INFO_PRINTF1(_L("CCameraDirectViewFinder object was not created using NewL")); 
   190     		result = EFail;
   191     		CleanupStack::PopAndDestroy(camera);
   192     		User::Leave (KErrNoMemory);
   193     		}	
   194 		CleanupStack::PopAndDestroy(camera);
   195 		}
   196 	else 
   197 		{
   198 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
   199 		result = EFail;
   200 		User::Leave (KErrNoMemory);
   201 		}
   202 	__MM_HEAP_MARKEND;
   203    
   204 	return result;	
   205 	}
   206 TVerdict RECamDirectViewFinderTest::DoTestStep_45L()
   207 	{
   208 	TVerdict result = EPass;
   209 	CCamera* camera = NULL;
   210 	
   211 	TInt error = KErrNone;
   212 	CCamera::CCameraDirectViewFinder* directviewfinder = NULL;
   213 		
   214 	// create a directviewfinder object using New2L
   215 	__MM_HEAP_MARK;
   216 	MCameraObserver2* observer2 = NULL; 
   217 	INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
   218 	
   219 	TRAP(error, camera = CCamera::New2L(*observer2, 0,0));
   220 
   221 	if (error==KErrNone)
   222 		{
   223 		CleanupStack::PushL(camera);
   224 		INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
   225 		TRAP(error, directviewfinder  = CCamera::CCameraDirectViewFinder::NewL(*camera));	
   226 		
   227 		if (error==KErrNone)
   228 	    	{
   229 	  		INFO_PRINTF1(_L("CCameraDirectViewFinder object was created using NewL")); 
   230 	    	}
   231 	    else
   232     		{
   233     		INFO_PRINTF1(_L("CCameraDirectViewFinder object was not created using NewL")); 
   234     		return EFail;
   235     		}	
   236 		}
   237 	else 
   238 		{
   239 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
   240 		result = EFail;		
   241 		}
   242 	
   243 	if (directviewfinder!= NULL)
   244     	{
   245     	CleanupStack::PushL(directviewfinder);
   246     	
   247     	// get the default viewfinder state
   248     	CCamera::CCameraDirectViewFinder::TViewFinderState vfstate;
   249     	vfstate = directviewfinder->ViewFinderState();
   250     	
   251     	// the vfstate should be EViewFinderInActive 
   252         if (vfstate != CCamera::CCameraDirectViewFinder::EViewFinderInActive)
   253         	{
   254         	INFO_PRINTF1(_L("Direct Viewfinder state incorrectly set")); 
   255         	return EFail;
   256         	}
   257         	
   258         // Assumption is that meanwhile direct viewfinder has been started. This would be done by calling CCamera::StartViewFinderDirectL(). 
   259         // This function starts the direct viewfinder and hence changes the state to active. 
   260         // Also performs initial boundary checking that 'viewfinder remains inactive before its called'. So, the vfstate changes to active.
   261         // The next step is to pause the direct viewfinder
   262                 
   263     	TRAP(error, directviewfinder->PauseViewFinderDirectL());
   264     	
   265     	if(error==KErrNone)
   266     		{
   267     		INFO_PRINTF1(_L("View finder paused successfully"));
   268     		}
   269     	else
   270     		{
   271     		INFO_PRINTF2(_L("direct viewfinder pause - %d"), error);
   272     		return EFail;
   273     		}
   274     	
   275     	vfstate = directviewfinder->ViewFinderState();
   276     	
   277     	// the vfstate should be changed to EViewFinderPause 
   278     	if (vfstate != CCamera::CCameraDirectViewFinder::EViewFinderPause)
   279         	{
   280         	INFO_PRINTF1(_L("Direct Viewfinder state incorrectly set after pausing")); 
   281         	return EFail;
   282         	}
   283     		
   284     	// The next step is to resume the direct viewfinder
   285     		
   286     	TRAP(error, directviewfinder->ResumeViewFinderDirectL());
   287     	
   288     	if(error==KErrNone)
   289     		{
   290     		INFO_PRINTF1(_L("View finder resumed successfully"));
   291     		}
   292     	else
   293     		{
   294     		INFO_PRINTF2(_L("direct viewfinder resume - %d"), error);
   295     		return EFail;
   296     		}
   297     		
   298     	vfstate = directviewfinder->ViewFinderState();
   299     	
   300     	// the vfstate should be changed to EViewFinderActive 
   301     	if (vfstate != CCamera::CCameraDirectViewFinder::EViewFinderActive)
   302         	{
   303         	INFO_PRINTF1(_L("Direct Viewfinder state incorrectly set after resuming")); 
   304         	return EFail;
   305         	}
   306     		
   307     	CleanupStack::PopAndDestroy(directviewfinder);
   308     	}
   309 	CleanupStack::PopAndDestroy(camera);
   310 	
   311 	__MM_HEAP_MARKEND;
   312    
   313 	return result;
   314 	}