os/mm/mmlibs/mmfw/tsrc/mmfunittest/GEF/src/GlobalEffectTest.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/GEF/src/GlobalEffectTest.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,503 @@
     1.4 +
     1.5 +// GlobalEffectTest.cpp
     1.6 +
     1.7 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.8 +// All rights reserved.
     1.9 +// This component and the accompanying materials are made available
    1.10 +// under the terms of "Eclipse Public License v1.0"
    1.11 +// which accompanies this distribution, and is available
    1.12 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.13 +//
    1.14 +// Initial Contributors:
    1.15 +// Nokia Corporation - initial contribution.
    1.16 +//
    1.17 +// Contributors:
    1.18 +//
    1.19 +// Description:
    1.20 +//
    1.21 +
    1.22 +#include "GlobalEffectTest.h"
    1.23 +#include "TestGlobalEffect.hrh"
    1.24 +#include "TestEffect.h"
    1.25 +
    1.26 +#include <mmfstdglblaudioeffect.h>
    1.27 +
    1.28 +
    1.29 +//
    1.30 +// RGlobalEffectPrimitiveTest
    1.31 +//
    1.32 +
    1.33 +RGlobalEffectPrimitiveTest* RGlobalEffectPrimitiveTest::NewL(TBool aAllocTest)
    1.34 +	{
    1.35 +	RGlobalEffectPrimitiveTest* self = new (ELeave) RGlobalEffectPrimitiveTest(aAllocTest);
    1.36 +	return self;	
    1.37 +	}
    1.38 +	
    1.39 +RGlobalEffectPrimitiveTest::RGlobalEffectPrimitiveTest(TBool /*aAllocTest*/)
    1.40 +	{
    1.41 +	iTestStepName = _L("MM-MMF-GEF-U-001");
    1.42 +	}
    1.43 +	
    1.44 +TVerdict RGlobalEffectPrimitiveTest::DoTestStepL()
    1.45 +	{
    1.46 +	INFO_PRINTF1(_L("Check can actually open test GlobalEffect plugin"));
    1.47 +	TVerdict result = EPass;
    1.48 +	
    1.49 +	__MM_HEAP_MARK;
    1.50 +
    1.51 +	CTestGlobalEffect* plugin = NULL;
    1.52 +	
    1.53 +	TRAPD(error, plugin = CTestGlobalEffect::NewL(NULL));
    1.54 +	
    1.55 +	if (error==KErrNone)
    1.56 +		{
    1.57 +		INFO_PRINTF1(_L("plugin opened as expected"));
    1.58 +		delete plugin;
    1.59 +		}
    1.60 +	else
    1.61 +		{
    1.62 +		INFO_PRINTF2(_L("CreateImplementationL() failed - %d"), error);
    1.63 +		result = EFail;
    1.64 +		}
    1.65 +	
    1.66 +	__MM_HEAP_MARKEND;
    1.67 +	
    1.68 +	return result;
    1.69 +	}
    1.70 +	
    1.71 +//
    1.72 +// RGlobalEffectStdTest
    1.73 +//
    1.74 +
    1.75 +RGlobalEffectStdTest* RGlobalEffectStdTest::NewL(TBool aAllocTest)
    1.76 +	{
    1.77 +	RGlobalEffectStdTest* self = new (ELeave) RGlobalEffectStdTest(aAllocTest);
    1.78 +	return self;	
    1.79 +	}
    1.80 +	
    1.81 +RGlobalEffectStdTest::RGlobalEffectStdTest(TBool /*aAllocTest*/)
    1.82 +	{
    1.83 +	iTestStepName = _L("MM-MMF-GEF-U-002");
    1.84 +	}
    1.85 +	
    1.86 +TVerdict RGlobalEffectStdTest::DoTestStepL()
    1.87 +	{
    1.88 +	INFO_PRINTF1(_L("Check standard plugins cleanup return errors"));
    1.89 +	TVerdict result = EPass;
    1.90 +	
    1.91 +	{
    1.92 +	__MM_HEAP_MARK;
    1.93 +
    1.94 +	CMmfGlobalEqEffect* plugin = NULL;
    1.95 +	
    1.96 +	TRAPD(error, plugin = CMmfGlobalEqEffect::NewL(NULL));
    1.97 +	
    1.98 +	if (error==KErrNone)
    1.99 +		{
   1.100 +		INFO_PRINTF1(_L("GlobalEq plugin opened managed to open!"));
   1.101 +		delete plugin;
   1.102 +		result = EFail;
   1.103 +		}
   1.104 +	else if (error==KErrNotSupported)
   1.105 +		{
   1.106 +		INFO_PRINTF1(_L("GlobalEq plugin not supported - as expected"));		
   1.107 +		}
   1.108 +	else
   1.109 +		{
   1.110 +		INFO_PRINTF2(_L("GlobalEq CreateImplementationL() failed - %d"), error);
   1.111 +		result = EFail;
   1.112 +		}
   1.113 +	
   1.114 +	__MM_HEAP_MARKEND;
   1.115 +	}
   1.116 +	
   1.117 +	{
   1.118 +	__MM_HEAP_MARK;
   1.119 +
   1.120 +	CMmfGlobalMegaEffect* plugin = NULL;
   1.121 +	
   1.122 +	TRAPD(error, plugin = CMmfGlobalMegaEffect::NewL(NULL));
   1.123 +	
   1.124 +	if (error==KErrNone)
   1.125 +		{
   1.126 +		INFO_PRINTF1(_L("GlobalMega plugin opened managed to open!"));
   1.127 +		delete plugin;
   1.128 +		result = EFail;
   1.129 +		}
   1.130 +	else if (error==KErrNotSupported)
   1.131 +		{
   1.132 +		INFO_PRINTF1(_L("GlobalMega plugin not supported - as expected"));		
   1.133 +		}
   1.134 +	else
   1.135 +		{
   1.136 +		INFO_PRINTF2(_L("GlobalMega CreateImplementationL() failed - %d"), error);
   1.137 +		result = EFail;
   1.138 +		}
   1.139 +	
   1.140 +	__MM_HEAP_MARKEND;
   1.141 +	}
   1.142 +	
   1.143 +	return result;
   1.144 +	}
   1.145 +	
   1.146 +//
   1.147 +// RGlobalEffectMainTest
   1.148 +//
   1.149 +
   1.150 +RGlobalEffectMainTest* RGlobalEffectMainTest::NewL(TBool aAllocTest)
   1.151 +	{
   1.152 +	RGlobalEffectMainTest* self = new (ELeave) RGlobalEffectMainTest(aAllocTest);
   1.153 +	return self;	
   1.154 +	}
   1.155 +	
   1.156 +RGlobalEffectMainTest::RGlobalEffectMainTest(TBool /*aAllocTest*/)
   1.157 +	{
   1.158 +	iTestStepName = _L("MM-MMF-GEF-U-003");
   1.159 +	}
   1.160 +	
   1.161 +TVerdict RGlobalEffectMainTest::DoTestStepL()
   1.162 +	{
   1.163 +	INFO_PRINTF1(_L("Check basic API calls on TestPlugin"));
   1.164 +	TVerdict result = EPass;
   1.165 +	
   1.166 +	__MM_HEAP_MARK;
   1.167 +
   1.168 +	CTestGlobalEffect* plugin = NULL;
   1.169 +	
   1.170 +	TRAPD(error, plugin = CTestGlobalEffect::NewL(NULL));
   1.171 +	
   1.172 +	if (error!=KErrNone)
   1.173 +		{
   1.174 +		INFO_PRINTF2(_L("CreateImplementationL() failed - %d"), error);
   1.175 +		return EFail;
   1.176 +		}
   1.177 +		
   1.178 +	CleanupStack::PushL(plugin);
   1.179 +	
   1.180 +	{
   1.181 +	// check Capability
   1.182 +	TUint value = plugin->Capability(EFalse);
   1.183 +	if (value!=0)
   1.184 +		{
   1.185 +		INFO_PRINTF2(_L("Capability(EFalse): expected 0 got - %d"), value);
   1.186 +		result = EFail;
   1.187 +		}
   1.188 +	value = plugin->Capability(ETrue);
   1.189 +	if (value!=0xffff)
   1.190 +		{
   1.191 +		INFO_PRINTF2(_L("Capability(ETrue): expected -1 got - %d"), value);
   1.192 +		result = EFail;
   1.193 +		}
   1.194 +	}
   1.195 +	
   1.196 +	// check settings by des, uid or value
   1.197 +	HBufC8* tempDes = NULL;
   1.198 +	TUid tempUid;
   1.199 +	TInt tempInt;
   1.200 +	TPckg<TInt> tempPackage (tempInt);
   1.201 +	{
   1.202 +	// initially (stage 1) nothing set, so SettingsByUidL() and ExtractValuesL()
   1.203 +	// should leave KErrNotSupported, and SettingsByDesL() should return "1234"
   1.204 +	
   1.205 +	TRAP(error, tempDes = plugin->SettingsByDesL());
   1.206 +	if (error==KErrNone)
   1.207 +		{
   1.208 +		CleanupStack::PushL(tempDes);
   1.209 +		if (*tempDes!=_L8("1234"))
   1.210 +			{
   1.211 +			HBufC* tempDes16 = HBufC::NewMaxLC(tempDes->Length());
   1.212 +			tempDes16->Des().Copy(*tempDes);
   1.213 +			INFO_PRINTF2(_L("Stage1: SettingsByDesL() expected \"1234\" got \"%S\""), tempDes16);
   1.214 +			result = EFail;
   1.215 +			CleanupStack::PopAndDestroy(tempDes16);
   1.216 +			}
   1.217 +		CleanupStack::PopAndDestroy(tempDes);	
   1.218 +		tempDes = NULL;	
   1.219 +		}
   1.220 +	else
   1.221 +		{
   1.222 +		INFO_PRINTF2(_L("Stage1: SettingsByDesL() returned %d"), error);
   1.223 +		result = EFail;
   1.224 +		}
   1.225 +	
   1.226 +	TRAP(error, tempUid = plugin->SettingsByUidL());	
   1.227 +	if (error!=KErrNotSupported)
   1.228 +		{
   1.229 +		INFO_PRINTF3(_L("Stage1: SettingsByUidL() expected KErrNotSupported got %d(0x%x)"), error, tempUid.iUid);
   1.230 +		result = EFail;
   1.231 +		}
   1.232 +		
   1.233 +	TRAP(error, plugin->ExtractValuesL(tempPackage));
   1.234 +	if (error!=KErrNotSupported)
   1.235 +		{
   1.236 +		INFO_PRINTF3(_L("Stage1: ExtractValuesL() expected KErrNotSupported got %d(%d)"), error, tempInt);
   1.237 +		result = EFail;
   1.238 +		}
   1.239 +	
   1.240 +	}
   1.241 +		
   1.242 +	{
   1.243 +	// at stage 2, we set a value by UID, so now SettingsByUid returns something sensible
   1.244 +	TUid sampleUid = {0x1234567}; // any silly value will do
   1.245 +	plugin->SetSettingsByUidL(sampleUid);
   1.246 +	
   1.247 +	TRAP(error, tempDes = plugin->SettingsByDesL());
   1.248 +	if (error==KErrNone)
   1.249 +		{
   1.250 +		CleanupStack::PushL(tempDes);
   1.251 +		if (*tempDes!=_L8("1234"))
   1.252 +			{
   1.253 +			HBufC* tempDes16 = HBufC::NewMaxLC(tempDes->Length());
   1.254 +			tempDes16->Des().Copy(*tempDes);
   1.255 +			INFO_PRINTF2(_L("Stage2: SettingsByDesL() expected \"1234\" got \"%S\""), tempDes16);
   1.256 +			result = EFail;
   1.257 +			CleanupStack::PopAndDestroy(tempDes16);
   1.258 +			}
   1.259 +		CleanupStack::PopAndDestroy(tempDes);	
   1.260 +		tempDes = NULL;	
   1.261 +		}
   1.262 +	else
   1.263 +		{
   1.264 +		INFO_PRINTF2(_L("Stage2: SettingsByDesL() returned %d"), error);
   1.265 +		result = EFail;
   1.266 +		}
   1.267 +	
   1.268 +	TRAP(error, tempUid = plugin->SettingsByUidL());	
   1.269 +	if (error!=KErrNone)
   1.270 +		{
   1.271 +		INFO_PRINTF3(_L("Stage2: SettingsByUidL() expected KErrNone got %d(0x%x)"), error, tempUid.iUid);
   1.272 +		result = EFail;
   1.273 +		}
   1.274 +	else if (tempUid != sampleUid)
   1.275 +		{
   1.276 +		INFO_PRINTF3(_L("Stage2: SettingsByUidL() expected return of 0x%x got 0x%x"), sampleUid.iUid, tempUid.iUid);		
   1.277 +		}
   1.278 +		
   1.279 +	TRAP(error, plugin->ExtractValuesL(tempPackage));
   1.280 +	if (error!=KErrNotSupported)
   1.281 +		{
   1.282 +		INFO_PRINTF3(_L("Stage2: ExtractValuesL() expected KErrNotSupported got %d(%d)"), error, tempInt);
   1.283 +		result = EFail;
   1.284 +		}
   1.285 +	
   1.286 +	}
   1.287 +		
   1.288 +	{
   1.289 +	// at stage 3, we set a value by des, so again only SettingsByDesL() gives valid results
   1.290 +	_LIT8(KSampleDes, "89a");
   1.291 +	plugin->SetSettingsByDesL(KSampleDes);
   1.292 +	
   1.293 +	TRAP(error, tempDes = plugin->SettingsByDesL());
   1.294 +	if (error==KErrNone)
   1.295 +		{
   1.296 +		CleanupStack::PushL(tempDes);
   1.297 +		if (*tempDes!=KSampleDes)
   1.298 +			{
   1.299 +			HBufC* tempDes16 = HBufC::NewMaxLC(tempDes->Length());
   1.300 +			tempDes16->Des().Copy(*tempDes);
   1.301 +			INFO_PRINTF2(_L("Stage3: SettingsByDesL() expected \"89a\" got \"%S\""), tempDes16);
   1.302 +			result = EFail;
   1.303 +			CleanupStack::PopAndDestroy(tempDes16);
   1.304 +			}
   1.305 +		CleanupStack::PopAndDestroy(tempDes);	
   1.306 +		tempDes = NULL;	
   1.307 +		}
   1.308 +	else
   1.309 +		{
   1.310 +		INFO_PRINTF2(_L("Stage3: SettingsByDesL() returned %d"), error);
   1.311 +		result = EFail;
   1.312 +		}
   1.313 +	
   1.314 +	TRAP(error, tempUid = plugin->SettingsByUidL());	
   1.315 +	if (error!=KErrNotSupported)
   1.316 +		{
   1.317 +		INFO_PRINTF3(_L("Stage3: SettingsByUidL() expected KErrNotSupported got %d(0x%x)"), error, tempUid.iUid);
   1.318 +		result = EFail;
   1.319 +		}
   1.320 +		
   1.321 +	TRAP(error, plugin->ExtractValuesL(tempPackage));
   1.322 +	if (error!=KErrNotSupported)
   1.323 +		{
   1.324 +		INFO_PRINTF3(_L("Stage3: ExtractValuesL() expected KErrNotSupported got %d(%d)"), error, tempInt);
   1.325 +		result = EFail;
   1.326 +		}
   1.327 +	}
   1.328 +		
   1.329 +	{
   1.330 +	// at stage 4, we set a value by package buffer, so only that way returns valid value
   1.331 +	const TInt sampleInt = 10;
   1.332 +	TPckgC<TInt> sampleBuffer (sampleInt);
   1.333 +	plugin->SetByValuesL(sampleBuffer);
   1.334 +	
   1.335 +	TRAP(error, tempDes = plugin->SettingsByDesL());
   1.336 +	if (error==KErrNone)
   1.337 +		{
   1.338 +		CleanupStack::PushL(tempDes);
   1.339 +		HBufC* tempDes16 = HBufC::NewMaxLC(tempDes->Length());
   1.340 +		tempDes16->Des().Copy(*tempDes);
   1.341 +		INFO_PRINTF2(_L("Stage4: SettingsByDesL() expected KErrNotSupported got \"%S\""), tempDes16);
   1.342 +		result = EFail;
   1.343 +		CleanupStack::PopAndDestroy(2, tempDes);	
   1.344 +		tempDes = NULL;	
   1.345 +		}
   1.346 +	else if (error!=KErrNotSupported)
   1.347 +		{
   1.348 +		INFO_PRINTF2(_L("Stage4: SettingsByDesL() expected KErrNotSupported returned %d"), error);
   1.349 +		result = EFail;
   1.350 +		}
   1.351 +	
   1.352 +	TRAP(error, tempUid = plugin->SettingsByUidL());	
   1.353 +	if (error!=KErrNotSupported)
   1.354 +		{
   1.355 +		INFO_PRINTF3(_L("Stage4: SettingsByUidL() expected KErrNotSupported got %d(0x%x)"), error, tempUid.iUid);
   1.356 +		result = EFail;
   1.357 +		}
   1.358 +		
   1.359 +	TRAP(error, plugin->ExtractValuesL(tempPackage));
   1.360 +	if (error!=KErrNone)
   1.361 +		{
   1.362 +		INFO_PRINTF3(_L("Stage4: ExtractValuesL() expected KErrNone got %d(%d)"), error, tempInt);
   1.363 +		result = EFail;
   1.364 +		}
   1.365 +	else if (tempInt!=sampleInt)
   1.366 +		{
   1.367 +		INFO_PRINTF3(_L("Stage4: ExtractValuesL() expected %d got %d"), sampleInt, tempInt);
   1.368 +		result = EFail;
   1.369 +		}
   1.370 +	}
   1.371 +	
   1.372 +	{
   1.373 +	// Check for Enabled() and IsActive() - should be false to start. poke value and show have
   1.374 +	// changed. Have to use custom command for SetActive() since not really the way to drive
   1.375 +	// - this should relate to the underlying implementation
   1.376 +	TBool enabled = plugin->IsEnabled();
   1.377 +	TBool active = plugin->IsActive();
   1.378 +	if (enabled!=EFalse || active!=EFalse)
   1.379 +		{
   1.380 +		INFO_PRINTF3(_L("Check1: active(%d) and enabled(%d) should have been false"), active, enabled);
   1.381 +		result = EFail;
   1.382 +		}
   1.383 +	plugin->SetEnabledL(ETrue);
   1.384 +	plugin->SetActive(ETrue);
   1.385 +	enabled = plugin->IsEnabled();
   1.386 +	active = plugin->IsActive();
   1.387 +	if (enabled==EFalse || active==EFalse)
   1.388 +		{
   1.389 +		INFO_PRINTF3(_L("Check2: active(%d) and enabled(%d) should have been true"), active, enabled);
   1.390 +		result = EFail;
   1.391 +		}
   1.392 +	}
   1.393 +	
   1.394 +	{
   1.395 +	// check preset - for test this ties up with the test plugin
   1.396 +	const TInt KPresetsCount = 3;
   1.397 +	MMmfGlobalAudioPresetList* list = plugin->KnownPresetsL();
   1.398 +
   1.399 +	// reproduce what the plugin will do and check
   1.400 +	if (list->MdcaCount()!=KPresetsCount)
   1.401 +		{
   1.402 +		INFO_PRINTF3(_L("Expected %d presets, got %d"), KPresetsCount, list->MdcaCount());
   1.403 +		result = EFail;
   1.404 +		}
   1.405 +	else
   1.406 +		{
   1.407 +		for (TInt index=0; index<KPresetsCount; index++)
   1.408 +			{
   1.409 +			TBuf<10> name;
   1.410 +			name.Num(index);
   1.411 +			TUid tempUid={index};
   1.412 +			
   1.413 +			TUid foundUid = list->GAPUidPoint(index);
   1.414 +			const TPtrC foundName = list->MdcaPoint(index);
   1.415 +			
   1.416 +			if (foundUid!=tempUid)
   1.417 +				{
   1.418 +				INFO_PRINTF4(_L("Index %d, expected %x found %x"), index, tempUid.iUid, foundUid.iUid);
   1.419 +				result = EFail;
   1.420 +				}
   1.421 +			if (foundName != name)
   1.422 +				{
   1.423 +				INFO_PRINTF4(_L("Index %d, expected %S found %S"), index, &name, &foundName);
   1.424 +				result = EFail;
   1.425 +				}
   1.426 +			}
   1.427 +		
   1.428 +		}
   1.429 +	}
   1.430 +
   1.431 +	CleanupStack::PopAndDestroy(plugin);
   1.432 +	
   1.433 +	__MM_HEAP_MARKEND;
   1.434 +	
   1.435 +	return result;
   1.436 +	}
   1.437 +	
   1.438 +//
   1.439 +// RGlobalEffectCallbackTest
   1.440 +//
   1.441 +
   1.442 +const TUid KUidTestGlbNotification = {KUidTestGlbNotificationDefine};
   1.443 +
   1.444 +
   1.445 +RGlobalEffectCallbackTest* RGlobalEffectCallbackTest::NewL(TBool aAllocTest)
   1.446 +	{
   1.447 +	RGlobalEffectCallbackTest* self = new (ELeave) RGlobalEffectCallbackTest(aAllocTest);
   1.448 +	return self;	
   1.449 +	}
   1.450 +	
   1.451 +RGlobalEffectCallbackTest::RGlobalEffectCallbackTest(TBool /*aAllocTest*/)
   1.452 +	{
   1.453 +	iTestStepName = _L("MM-MMF-GEF-U-004");
   1.454 +	}
   1.455 +	
   1.456 +void RGlobalEffectCallbackTest::GAEEventNotificationL(CMmfGlobalAudioEffect* aEffect, 
   1.457 +                                                      TUid aEventUid, 
   1.458 +                                                      const TDesC8& aParam)
   1.459 +	{
   1.460 +	INFO_PRINTF1(_L("Callback"));
   1.461 +	if (aEffect!=iEffect)
   1.462 +		{
   1.463 +		INFO_PRINTF3(_L("Effect is %x, expected %d"), aEffect, iEffect);
   1.464 +		iResult = EFail;
   1.465 +		}
   1.466 +	if (KUidTestGlbNotification != aEventUid)
   1.467 +		{
   1.468 +		INFO_PRINTF3(_L("Uid is %x, expected %x"), aEventUid.iUid, KUidTestGlbNotification.iUid);
   1.469 +		iResult = EFail;
   1.470 +		}
   1.471 +	if (aParam != KNullDesC8)
   1.472 +		{
   1.473 +		INFO_PRINTF2(_L("Param=\"%S\", expected \"\""), &aParam);
   1.474 +		iResult = EFail;
   1.475 +		}
   1.476 +	iCalledBack = ETrue;
   1.477 +	}
   1.478 +
   1.479 +	
   1.480 +TVerdict RGlobalEffectCallbackTest::DoTestStepL()
   1.481 +	{
   1.482 +	INFO_PRINTF1(_L("Check notification callback"));
   1.483 +	iResult = EPass;
   1.484 +	
   1.485 +	__MM_HEAP_MARK;
   1.486 +
   1.487 +	iEffect = CTestGlobalEffect::NewL(this);
   1.488 +	CleanupStack::PushL(iEffect);
   1.489 +	
   1.490 +	// for test, just generate test synchronously
   1.491 +	iEffect->RequestNotificationL(KUidTestGlbNotification);
   1.492 +	iEffect->GenCallbackL();
   1.493 +	
   1.494 +	if (!iCalledBack)
   1.495 +		{
   1.496 +		INFO_PRINTF1(_L("Callback seemingly did not happen"));
   1.497 +		iResult = EFail;
   1.498 +		}
   1.499 +	
   1.500 +	CleanupStack::PopAndDestroy(iEffect);
   1.501 +	
   1.502 +	__MM_HEAP_MARKEND;
   1.503 +	
   1.504 +	return iResult;
   1.505 +	}
   1.506 +