os/mm/imagingandcamerafws/cameraunittest/src/TSU_ECM_ADV/ECamPresetsTest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 
     2 // ECamPresetsTest.cpp
     3 
     4 // Copyright (c) 2005-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 <ecamuids.hrh>
    20 #include <ecom/ecomresolverparams.h>
    21 #include "ECamPresetsTest.h"
    22 #include "ECamUnitTestPluginUids.hrh"
    23 #include "ECamUnitTestPlugin.h"
    24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    25 #include <ecamadvsettingsuidsconst.hrh>
    26 #include <ecamadvsettingsconst.h>
    27 #include <ecamimageprocessingconst.h>
    28 #endif
    29 //
    30 // RECamPresetsTest
    31 //
    32 RECamPresetsTest* RECamPresetsTest::NewL(TBool aAllocTest)
    33 	{
    34 	RECamPresetsTest* self = new (ELeave) RECamPresetsTest(aAllocTest);
    35 	return self;	
    36 	}
    37 	
    38 RECamPresetsTest::RECamPresetsTest(TBool /*aAllocTest*/)
    39 	{
    40 	iTestStepName = _L("MM-ECM-ADV-U-006-HP");
    41 	}
    42 	
    43 TVerdict RECamPresetsTest::DoTestStepL()
    44 	{
    45 	TVerdict verdict = EFail;
    46 	INFO_PRINTF1(_L("Alloc test"));
    47 	TInt i;
    48 	TInt err;
    49 	for (i = 1 ; ; i++)
    50 		{
    51 		__MM_HEAP_MARK;
    52 		
    53 		if (i % 5 == 0)
    54 			{
    55 			INFO_PRINTF2(_L("Fail count = %d"), i);
    56 			}
    57 
    58 		__UHEAP_SETFAIL(RHeap::EFailNext, i);
    59 
    60 		TRAP(err, verdict = DoPresetsTestStepL());
    61 
    62 		TAny* testAlloc = User::Alloc(1);
    63 		TBool heapTestingComplete = (testAlloc == NULL) && (err==KErrNone);
    64 		User::Free(testAlloc);
    65 
    66 		__UHEAP_RESET;
    67 		__MM_HEAP_MARKEND;
    68 
    69 		if ((err != KErrNoMemory ) || heapTestingComplete)
    70 			{
    71 			INFO_PRINTF4(_L("err = %d, verdict = %d, Fail count = %d"), err, verdict, i);
    72 			INFO_PRINTF1(_L("Alloc testing completed successfully"));
    73 			verdict = EPass;
    74 			break;
    75 			}
    76 		}
    77 	return verdict;
    78 	}
    79 	
    80 TVerdict RECamPresetsTest::DoPresetsTestStepL()
    81 	{	
    82 	TVerdict result = EPass;
    83 	CCamera* camera = NULL;
    84 	
    85 	TInt error = KErrNone;
    86 	CCamera::CCameraPresets* presets = NULL;
    87 		
    88 	// using observer 2 
    89 	MCameraObserver2* observer2 = NULL; 
    90 	
    91 	__MM_HEAP_MARK;
    92 	INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
    93 	
    94 	TRAP(error, camera = CCamera::New2L(*observer2, 0,0));
    95 
    96 	if (error==KErrNone)
    97 		{
    98 		CleanupStack::PushL(camera);
    99 		INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
   100 		presets = 	static_cast<CCamera::CCameraPresets*> (camera->CustomInterface(KECamPresetsUid));
   101 	    if (presets!= NULL)
   102 	    	{
   103 	    	CleanupStack::PushL(presets);
   104 	  		INFO_PRINTF1(_L("CCameraPresets object was created")); 
   105 	    	CleanupStack::PopAndDestroy(presets);
   106 	    	}
   107 	    else
   108     		{
   109     		result = EFail;
   110     		User::Leave(KErrNoMemory);
   111     		}	
   112 		CleanupStack::PopAndDestroy(camera);
   113 		}
   114 	else 
   115 		{
   116 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
   117 		result = EFail;	
   118 		User::Leave(KErrNoMemory);	
   119 		}
   120 	__MM_HEAP_MARKEND;
   121 	
   122 	// create a presets object using NewL
   123 	__MM_HEAP_MARK;
   124 	INFO_PRINTF1(_L("Create camera using Camera::NewL() and MCameraObserver2"));
   125 	
   126 	TRAP(error, camera = CCamera::New2L(*observer2, 0,0));
   127 
   128 	if (error==KErrNone)
   129 		{
   130 		CleanupStack::PushL(camera);
   131 		INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
   132 		TRAP(error, presets  = CCamera::CCameraPresets::NewL(*camera));	
   133 		
   134 		if (error==KErrNone)
   135 	    	{
   136 	    	CleanupStack::PushL(presets);
   137 	  		INFO_PRINTF1(_L("CCameraPresets object was created using NewL")); 
   138 	    	CleanupStack::PopAndDestroy(presets);
   139 	    	}
   140 	    else
   141     		{
   142     		INFO_PRINTF1(_L("CCameraPresets object was not created using NewL")); 
   143     		result = EFail;
   144     		User::Leave(KErrNoMemory);
   145     		}	
   146 		CleanupStack::PopAndDestroy(camera);
   147 		}
   148 	else 
   149 		{
   150 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
   151 		result = EFail;
   152 		User::Leave(KErrNoMemory);		
   153 		}
   154 	__MM_HEAP_MARKEND;
   155    
   156 	return result;
   157 	}
   158 	
   159 //
   160 // RECamPresetsNotificationTest
   161 //
   162 RECamPresetsNotificationTest* RECamPresetsNotificationTest::NewL(TBool aAllocTest)
   163 	{
   164 	RECamPresetsNotificationTest* self = new (ELeave) RECamPresetsNotificationTest(aAllocTest);
   165 	CleanupStack::PushL(self);
   166 	self->ConstructL();
   167 	CleanupStack::Pop(self);
   168 	return self;	
   169 	}
   170 	
   171 void RECamPresetsNotificationTest::ConstructL()
   172 	{
   173 	iOriginalSet.Reset();
   174 	iResultSet.Reset();
   175 
   176 	}
   177 RECamPresetsNotificationTest::RECamPresetsNotificationTest(TBool /*aAllocTest*/)
   178 	{
   179 	iTestStepName = _L("MM-ECM-ADV-U-008-HP");
   180 	}
   181 	
   182 TVerdict RECamPresetsNotificationTest::DoTestStepL()
   183 	{	
   184 	TVerdict result = EPass;
   185 	CCamera* camera = NULL;
   186 	
   187 	TInt error = KErrNone;
   188 	CCamera::CCameraPresets* presets = NULL;
   189 		
   190 	__MM_HEAP_MARK;
   191 	INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
   192 	
   193 	TRAP(error, camera = CCamera::New2L(*this,0,0));
   194 
   195 	if (error==KErrNone)
   196 		{
   197 		CleanupStack::PushL(camera);
   198 		//	CCamUnitTestPlugin* camera1 = static_cast<CCamUnitTestPlugin*>(camera);
   199 		//  rely on public member, done for simplfication of an external 
   200 		//  initialization as it is the simplest way
   201 		//	camera1->iPresets = iOriginalSet;
   202 		INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
   203 		presets = static_cast<CCamera::CCameraPresets*> (camera->CustomInterface(KECamPresetsUid));
   204 	    if (presets!= NULL)
   205 	    	{
   206 	    	CleanupStack::PushL(presets);
   207 	    	
   208 	    	// get the supported set of values  
   209 	    	presets->GetSupportedPresetsL(iResultSet);
   210 
   211 	    	//verify that the input and output are the same
   212 	    	INFO_PRINTF2(_L("camera supports %d presets"),  iResultSet.Count());
   213 	       
   214 	    	// the array should not be empty 
   215 	        if (iResultSet.Count()==0)
   216 	        	{
   217 	        	result = EFail;
   218 	        	}
   219         	else
   220         		{
   221         		iResultSet.Reset();
   222         		}
   223         		
   224         	INFO_PRINTF1(_L("Current preset shall be  KUidECamPresetNone"));	
   225 	    	TUid currentPreset = presets->Preset();	    	
   226 	    
   227 	    	// Current Preset shall be KUidECamPresetNone.
   228 	    	if(currentPreset.iUid != KUidECamPresetNoneUidValue)
   229 	    		{
   230 	    		INFO_PRINTF1(_L("Current preset wrongly set"));
   231 	    		result = EFail;
   232 	    		}
   233 	    	
   234 	    	// set new value
   235 	    	iInputEventUid = KUidECamPresetBeach;
   236 	        INFO_PRINTF2(_L("Select a new preset %d"), iInputEventUid.iUid); 
   237 	        presets->SetPreset(iInputEventUid);
   238 	        
   239 	        CheckNotification(iInputEventUid, result);
   240     			
   241     		presets->GetAffectedSettingsL(iResultSet);
   242     		INFO_PRINTF2(_L("This preset affected %d settings"),  iResultSet.Count());
   243     		
   244     		// get the alternative function
   245     		RArray<TUid> associatedSettings;
   246     		CleanupClosePushL(associatedSettings);
   247     		associatedSettings.Reset();
   248     		INFO_PRINTF1(_L("Get associated settings for the selected preset"));
   249     		TRAP(error,presets->GetAssociatedSettingsL(iInputEventUid, associatedSettings));
   250 			if(error != KErrNone)
   251 				{
   252 				CleanupStack::PopAndDestroy(&associatedSettings);
   253 				}
   254 				
   255 			if (iResultSet.Count()!=associatedSettings.Count())
   256 	        	{
   257 	        	result = EFail;
   258 	        	}
   259         	else
   260         		{
   261         		iResultSet.Reset();
   262         		}	
   263         	CleanupStack::PopAndDestroy(&associatedSettings);
   264     		
   265     		// set KUidECamPresetOutdoor to get range restricted settings.
   266 	    	iInputEventUid = KUidECamPresetOutdoor;
   267 	        INFO_PRINTF2(_L("Select the Outdoor preset %d"), iInputEventUid.iUid); 
   268 	        presets->SetPreset(iInputEventUid);
   269 	        
   270 	        INFO_PRINTF1(_L("Check the RangeRestricted notification"));
   271     		CheckNotification(KUidECamEventRangeRestricted, result);
   272 	        
   273 	        if(result != EFail)
   274 	        	{
   275 	        	INFO_PRINTF1(_L("Retrieve the RangeRestricted settings"));
   276 	        	// get the range restricted settings
   277 	    		RArray<TUid> rangeRestrictedSettings;	
   278 	    		presets->GetRangeRestrictedSettingsL(rangeRestrictedSettings);
   279 	    		if (rangeRestrictedSettings.Count() == 0)
   280 		        	{
   281 		        	INFO_PRINTF1(_L("RangeRestricted settings are Zero"));
   282 		        	result = EFail;
   283 		        	}
   284 	        	rangeRestrictedSettings.Close();
   285 	        	}
   286 	        
   287 	        INFO_PRINTF1(_L("Check the FeatureRestricted settings"));
   288 	        // get the feature restricted settings
   289 	    	RArray<TUid> featureRestrictedSettings;
   290     		presets->GetFeatureRestrictedSettingsL(featureRestrictedSettings);
   291     		if (featureRestrictedSettings.Count() != 0)
   292 	        	{
   293 	        	INFO_PRINTF1(_L("FeatureRestricted settings are not Zero"));
   294 	        	result = EFail;
   295 	        	}
   296 	        featureRestrictedSettings.Close();
   297 	        
   298 	        TBool unlockSupported = EFalse;
   299 	       	presets->IsPresetUnlockSupportedL(unlockSupported);
   300 	       	if(!unlockSupported)
   301 	       		{
   302 	       		INFO_PRINTF1(_L("Preset Unlock not supported"));
   303 	       		result = EFail;
   304 	       		}
   305 	       	
   306 	       	INFO_PRINTF1(_L("Unlock Preset"));	
   307 	       	presets->UnlockPresetL();
   308 	       	CheckNotification(KUidECamEventPresetUnlocked, result);
   309 	       	
   310 	       	INFO_PRINTF1(_L("Lock Preset"));	
   311 	       	presets->LockPresetL();
   312 	       	CheckNotification(KUidECamEventPresetLocked, result);
   313 	       	
   314     		CleanupStack::PopAndDestroy(presets);
   315 	    	}
   316 	    else
   317     		{
   318     		result = EFail;
   319     		User::Leave(KErrNoMemory);
   320     		}
   321     	
   322     	CleanupStack::PopAndDestroy(camera);
   323 		}
   324 	else 
   325 		{
   326 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
   327 		result = EFail;	
   328 		User::Leave(KErrNoMemory);
   329 		}
   330 	
   331 	__MM_HEAP_MARKEND;
   332 
   333 	return result;
   334 	}
   335 
   336 //
   337 // RECamPresetsNegTest //
   338 //
   339 RECamPresetsNegTest* RECamPresetsNegTest::NewL(TBool aAllocTest)
   340 	{
   341 	RECamPresetsNegTest* self = new (ELeave) RECamPresetsNegTest(aAllocTest);
   342 	return self;	
   343 	}
   344 	
   345 RECamPresetsNegTest::RECamPresetsNegTest(TBool /*aAllocTest*/)
   346 	{
   347 	iTestStepName = _L("MM-ECM-ADV-U-0101-HP");
   348 	}
   349 	
   350 TVerdict RECamPresetsNegTest::DoTestStepL()
   351 	{	
   352 	TVerdict result = EPass;
   353 	CCamera* camera = NULL;
   354 	
   355 	TInt error = KErrNone;
   356 	CCamera::CCameraPresets* presets = NULL;		
   357 	
   358 	__MM_HEAP_MARK;
   359 	
   360 	INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
   361 	
   362 	TRAP(error, camera = CCamera::New2L(*this,0,0));
   363 
   364 	if (error==KErrNone)
   365 		{
   366 		CleanupStack::PushL(camera);
   367 		INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
   368 		presets = static_cast<CCamera::CCameraPresets*> (camera->CustomInterface(KECamPresetsUid));
   369 	    if (presets!= NULL)
   370 	    	{
   371 	    	CleanupStack::PushL(presets);	   
   372 	    	 	
   373 			TUid aCurrentPreset = presets->Preset();
   374 	    	// get the current value
   375 	    	INFO_PRINTF2(_L("Current preset %x"), aCurrentPreset.iUid);
   376 	    	
   377 	    	// get the supported set of values      	
   378 			RArray<TUid> aResultSet;
   379 			CleanupClosePushL(aResultSet);
   380 			aResultSet.Reset();
   381 	    	presets->GetSupportedPresetsL(aResultSet);
   382 
   383 	        // Setting a non supported preset should be rejected       
   384 	        // In the test plugin only KUidECamPresetOutdoor, KUidECamPresetNightPartyIndoor & KUidECamPresetBeach are supported
   385 	 	    iInputEventUid = KUidECamPresetIndoorSport;	    	
   386 	    	presets->SetPreset(iInputEventUid);	    
   387    		    	
   388 	        CheckNotificationNeg(iInputEventUid, result); 
   389 	        
   390 	        // Setting a non supported preset should be rejected       
   391 	        // In the test plugin only KUidECamPresetOutdoor, KUidECamPresetNightPartyIndoor & KUidECamPresetBeach are supported
   392 	 	    iInputEventUid = KUidECamPresetVideoTelephony;	    	
   393 	    	presets->SetPreset(iInputEventUid);	    
   394    		    	
   395 	        CheckNotificationNeg(iInputEventUid, result);
   396 	           				    		
   397 	    	TUid aGetPreset = presets->Preset();
   398 	    	
   399 	      	if ((aCurrentPreset == aGetPreset) && (aGetPreset == KUidECamPresetNone))
   400 	        	{
   401 	    		INFO_PRINTF2(_L("Current preset has not changed %x"), aGetPreset.iUid);	        	
   402 	        	}
   403 	        else
   404 	        	{
   405 				INFO_PRINTF1(_L("Expected no affected settings"));
   406 				result = EFail;
   407 	        	}	    	 	
   408 
   409 	    	// get the affected settings	        	
   410 			RArray<TUid> aAffectedSet;
   411 			CleanupClosePushL(aAffectedSet);
   412 			presets->GetAffectedSettingsL(aAffectedSet);	    	    		     
   413 	        // the list of affected settings should be empty 
   414 	        if (aAffectedSet.Count()!=0)
   415 	        	{
   416 				INFO_PRINTF1(_L("Expected no affected settings"));
   417 				result = EFail;
   418 	        	}
   419 	        else
   420 	        	{
   421 				INFO_PRINTF1(_L("No affected settings"));	        		
   422 	        	}
   423 	        	
   424 			CleanupStack::PopAndDestroy(2, &aResultSet); //aAffectedSet
   425 	    	
   426 	    	CleanupStack::PopAndDestroy(presets);
   427 	    	}
   428 	    else // preset is NULL
   429     		{
   430     		result = EFail;
   431     		}	
   432 		CleanupStack::PopAndDestroy(camera);
   433 		}
   434 	else // error != KErrNone
   435 		{
   436 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
   437 		result = EFail;		
   438 		}
   439 	__MM_HEAP_MARKEND;
   440 
   441 	return result;
   442 	}
   443 	
   444 //
   445 // RECamPresetsBaselineTest
   446 //
   447 RECamPresetsBaselineTest* RECamPresetsBaselineTest::NewL(TBool aAllocTest)
   448 	{
   449 	RECamPresetsBaselineTest* self = new (ELeave) RECamPresetsBaselineTest(aAllocTest);
   450 	CleanupStack::PushL(self);
   451 	self->ConstructL();
   452 	CleanupStack::Pop(self);
   453 	return self;	
   454 	}
   455 	
   456 void RECamPresetsBaselineTest::ConstructL()
   457 	{
   458 	iOriginalSet.Reset();
   459 	iResultSet.Reset();
   460 
   461 	}
   462 RECamPresetsBaselineTest::RECamPresetsBaselineTest(TBool /*aAllocTest*/)
   463 	{
   464 	iTestStepName = _L("MM-ECM-ADV-U-046-HP");
   465 	}
   466 
   467 TVerdict RECamPresetsBaselineTest::DoTestStepL()
   468 	{	
   469 	TVerdict result = EPass;
   470 	CCamera* camera = NULL;
   471 	
   472 	TInt error = KErrNone;
   473 	CCamera::CCameraPresets* presets = NULL;
   474 		
   475 	__MM_HEAP_MARK;
   476 	INFO_PRINTF1(_L("Create camera using Camera::NewL() and MCameraObserver2"));
   477 	
   478 	TRAP(error, camera = CCamera::NewL(*this,0,0));
   479 
   480 	if (error==KErrNone)
   481 		{
   482 		CleanupStack::PushL(camera);
   483 		//	CCamUnitTestPlugin* camera1 = static_cast<CCamUnitTestPlugin*>(camera);
   484 		//  rely on public member, done for simplfication of an external 
   485 		//  initialization as it is the simplest way
   486 		//	camera1->iPresets = iOriginalSet;
   487 		INFO_PRINTF1(_L("KErrNone return from CCamera::NewL()"));
   488 		presets = static_cast<CCamera::CCameraPresets*> (camera->CustomInterface(KECamPresetsUid));
   489 	    if (presets!= NULL)
   490 	    	{
   491 	    	CleanupStack::PushL(presets);
   492 	    	
   493 	    	// get the supported set of values  
   494 	    	presets->GetSupportedPresetsL(iResultSet);
   495 
   496 	    	//verify that the input and output are the same
   497 	    	INFO_PRINTF2(_L("camera supports %d presets"),  iResultSet.Count());
   498 	       
   499 	    	// the array should not contain any unfamiliar uid for preset(after baseline) 
   500 	        for(TInt index =0; index < iResultSet.Count(); index++)
   501 				{
   502 				/** KUidECamPresetFactoryDefaultUidValue is the baseline. Any preset with greater uid value means that it has 
   503 				been added in later versions */
   504 				if(iResultSet[index].iUid > KUidECamPresetFactoryDefaultUidValue)
   505 					{
   506 					result = EFail;
   507 					}
   508 				}
   509 	        	        
   510 	        iResultSet.Reset();
   511         	
   512 	    	presets->Preset();	    	
   513 	    	// set new unfamiliar value
   514 	    	iInputEventUid = KUidECamPresetNightPartyIndoor; 
   515 	        INFO_PRINTF2(_L("Select a new preset %d"), iInputEventUid.iUid); 
   516 	        presets->SetPreset(iInputEventUid);
   517 	        
   518 	        CheckNotification(iInputEventUid, result);
   519 	        
   520 	        if(presets->Preset().iUid != KUidECamPresetFactoryDefaultUidValue)
   521 	        	{
   522 	        	result = EFail;
   523 	        	}
   524     			
   525     		presets->GetAffectedSettingsL(iResultSet);
   526     		INFO_PRINTF2(_L("This preset affected %d settings"),  iResultSet.Count());
   527     		
   528     		// the array should not contain any unfamiliar uid for settings(after baseline) 
   529 	        for(TInt index =0; index < iResultSet.Count(); index++)
   530 				{
   531 				/** KUidECamEventCameraSettingAutoFocusType2UidValue is the baseline. Any settings with greater uid value means that it has 
   532 				been added in later versions */
   533 				if(iResultSet[index].iUid > KUidECamEventCameraSettingAutoFocusType2UidValue)
   534 					{
   535 					result = EFail;
   536 					}
   537 				}
   538     		
   539     		// get the alternative function
   540     		RArray<TUid> associatedSettings;
   541     		
   542     		presets->GetAssociatedSettingsL(iInputEventUid, associatedSettings);
   543 
   544 			if (iResultSet.Count()!=associatedSettings.Count())
   545 	        	{
   546 	        	result = EFail;
   547 	        	}
   548         	else
   549         		{
   550         		iResultSet.Reset();
   551         		}	
   552     		associatedSettings.Close();
   553 	    	CleanupStack::PopAndDestroy(presets);
   554 	    	}
   555 	    else
   556     		{
   557     		result = EFail;
   558     		}
   559 		CleanupStack::PopAndDestroy(camera);
   560 		}
   561 	else 
   562 		{
   563 		INFO_PRINTF2(_L("Unexpected %d return from CCamera::NewL(): observer 2"), error);
   564 		result = EFail;		
   565 		}
   566 	
   567 	__MM_HEAP_MARKEND;
   568 
   569 	return result;
   570 	}