Update contrib.
2 // GlobalEffectTest.cpp
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".
11 // Initial Contributors:
12 // Nokia Corporation - initial contribution.
19 #include "GlobalEffectTest.h"
20 #include "TestGlobalEffect.hrh"
21 #include "TestEffect.h"
23 #include <mmfstdglblaudioeffect.h>
27 // RGlobalEffectPrimitiveTest
30 RGlobalEffectPrimitiveTest* RGlobalEffectPrimitiveTest::NewL(TBool aAllocTest)
32 RGlobalEffectPrimitiveTest* self = new (ELeave) RGlobalEffectPrimitiveTest(aAllocTest);
36 RGlobalEffectPrimitiveTest::RGlobalEffectPrimitiveTest(TBool /*aAllocTest*/)
38 iTestStepName = _L("MM-MMF-GEF-U-001");
41 TVerdict RGlobalEffectPrimitiveTest::DoTestStepL()
43 INFO_PRINTF1(_L("Check can actually open test GlobalEffect plugin"));
44 TVerdict result = EPass;
48 CTestGlobalEffect* plugin = NULL;
50 TRAPD(error, plugin = CTestGlobalEffect::NewL(NULL));
54 INFO_PRINTF1(_L("plugin opened as expected"));
59 INFO_PRINTF2(_L("CreateImplementationL() failed - %d"), error);
69 // RGlobalEffectStdTest
72 RGlobalEffectStdTest* RGlobalEffectStdTest::NewL(TBool aAllocTest)
74 RGlobalEffectStdTest* self = new (ELeave) RGlobalEffectStdTest(aAllocTest);
78 RGlobalEffectStdTest::RGlobalEffectStdTest(TBool /*aAllocTest*/)
80 iTestStepName = _L("MM-MMF-GEF-U-002");
83 TVerdict RGlobalEffectStdTest::DoTestStepL()
85 INFO_PRINTF1(_L("Check standard plugins cleanup return errors"));
86 TVerdict result = EPass;
91 CMmfGlobalEqEffect* plugin = NULL;
93 TRAPD(error, plugin = CMmfGlobalEqEffect::NewL(NULL));
97 INFO_PRINTF1(_L("GlobalEq plugin opened managed to open!"));
101 else if (error==KErrNotSupported)
103 INFO_PRINTF1(_L("GlobalEq plugin not supported - as expected"));
107 INFO_PRINTF2(_L("GlobalEq CreateImplementationL() failed - %d"), error);
117 CMmfGlobalMegaEffect* plugin = NULL;
119 TRAPD(error, plugin = CMmfGlobalMegaEffect::NewL(NULL));
123 INFO_PRINTF1(_L("GlobalMega plugin opened managed to open!"));
127 else if (error==KErrNotSupported)
129 INFO_PRINTF1(_L("GlobalMega plugin not supported - as expected"));
133 INFO_PRINTF2(_L("GlobalMega CreateImplementationL() failed - %d"), error);
144 // RGlobalEffectMainTest
147 RGlobalEffectMainTest* RGlobalEffectMainTest::NewL(TBool aAllocTest)
149 RGlobalEffectMainTest* self = new (ELeave) RGlobalEffectMainTest(aAllocTest);
153 RGlobalEffectMainTest::RGlobalEffectMainTest(TBool /*aAllocTest*/)
155 iTestStepName = _L("MM-MMF-GEF-U-003");
158 TVerdict RGlobalEffectMainTest::DoTestStepL()
160 INFO_PRINTF1(_L("Check basic API calls on TestPlugin"));
161 TVerdict result = EPass;
165 CTestGlobalEffect* plugin = NULL;
167 TRAPD(error, plugin = CTestGlobalEffect::NewL(NULL));
171 INFO_PRINTF2(_L("CreateImplementationL() failed - %d"), error);
175 CleanupStack::PushL(plugin);
179 TUint value = plugin->Capability(EFalse);
182 INFO_PRINTF2(_L("Capability(EFalse): expected 0 got - %d"), value);
185 value = plugin->Capability(ETrue);
188 INFO_PRINTF2(_L("Capability(ETrue): expected -1 got - %d"), value);
193 // check settings by des, uid or value
194 HBufC8* tempDes = NULL;
197 TPckg<TInt> tempPackage (tempInt);
199 // initially (stage 1) nothing set, so SettingsByUidL() and ExtractValuesL()
200 // should leave KErrNotSupported, and SettingsByDesL() should return "1234"
202 TRAP(error, tempDes = plugin->SettingsByDesL());
205 CleanupStack::PushL(tempDes);
206 if (*tempDes!=_L8("1234"))
208 HBufC* tempDes16 = HBufC::NewMaxLC(tempDes->Length());
209 tempDes16->Des().Copy(*tempDes);
210 INFO_PRINTF2(_L("Stage1: SettingsByDesL() expected \"1234\" got \"%S\""), tempDes16);
212 CleanupStack::PopAndDestroy(tempDes16);
214 CleanupStack::PopAndDestroy(tempDes);
219 INFO_PRINTF2(_L("Stage1: SettingsByDesL() returned %d"), error);
223 TRAP(error, tempUid = plugin->SettingsByUidL());
224 if (error!=KErrNotSupported)
226 INFO_PRINTF3(_L("Stage1: SettingsByUidL() expected KErrNotSupported got %d(0x%x)"), error, tempUid.iUid);
230 TRAP(error, plugin->ExtractValuesL(tempPackage));
231 if (error!=KErrNotSupported)
233 INFO_PRINTF3(_L("Stage1: ExtractValuesL() expected KErrNotSupported got %d(%d)"), error, tempInt);
240 // at stage 2, we set a value by UID, so now SettingsByUid returns something sensible
241 TUid sampleUid = {0x1234567}; // any silly value will do
242 plugin->SetSettingsByUidL(sampleUid);
244 TRAP(error, tempDes = plugin->SettingsByDesL());
247 CleanupStack::PushL(tempDes);
248 if (*tempDes!=_L8("1234"))
250 HBufC* tempDes16 = HBufC::NewMaxLC(tempDes->Length());
251 tempDes16->Des().Copy(*tempDes);
252 INFO_PRINTF2(_L("Stage2: SettingsByDesL() expected \"1234\" got \"%S\""), tempDes16);
254 CleanupStack::PopAndDestroy(tempDes16);
256 CleanupStack::PopAndDestroy(tempDes);
261 INFO_PRINTF2(_L("Stage2: SettingsByDesL() returned %d"), error);
265 TRAP(error, tempUid = plugin->SettingsByUidL());
268 INFO_PRINTF3(_L("Stage2: SettingsByUidL() expected KErrNone got %d(0x%x)"), error, tempUid.iUid);
271 else if (tempUid != sampleUid)
273 INFO_PRINTF3(_L("Stage2: SettingsByUidL() expected return of 0x%x got 0x%x"), sampleUid.iUid, tempUid.iUid);
276 TRAP(error, plugin->ExtractValuesL(tempPackage));
277 if (error!=KErrNotSupported)
279 INFO_PRINTF3(_L("Stage2: ExtractValuesL() expected KErrNotSupported got %d(%d)"), error, tempInt);
286 // at stage 3, we set a value by des, so again only SettingsByDesL() gives valid results
287 _LIT8(KSampleDes, "89a");
288 plugin->SetSettingsByDesL(KSampleDes);
290 TRAP(error, tempDes = plugin->SettingsByDesL());
293 CleanupStack::PushL(tempDes);
294 if (*tempDes!=KSampleDes)
296 HBufC* tempDes16 = HBufC::NewMaxLC(tempDes->Length());
297 tempDes16->Des().Copy(*tempDes);
298 INFO_PRINTF2(_L("Stage3: SettingsByDesL() expected \"89a\" got \"%S\""), tempDes16);
300 CleanupStack::PopAndDestroy(tempDes16);
302 CleanupStack::PopAndDestroy(tempDes);
307 INFO_PRINTF2(_L("Stage3: SettingsByDesL() returned %d"), error);
311 TRAP(error, tempUid = plugin->SettingsByUidL());
312 if (error!=KErrNotSupported)
314 INFO_PRINTF3(_L("Stage3: SettingsByUidL() expected KErrNotSupported got %d(0x%x)"), error, tempUid.iUid);
318 TRAP(error, plugin->ExtractValuesL(tempPackage));
319 if (error!=KErrNotSupported)
321 INFO_PRINTF3(_L("Stage3: ExtractValuesL() expected KErrNotSupported got %d(%d)"), error, tempInt);
327 // at stage 4, we set a value by package buffer, so only that way returns valid value
328 const TInt sampleInt = 10;
329 TPckgC<TInt> sampleBuffer (sampleInt);
330 plugin->SetByValuesL(sampleBuffer);
332 TRAP(error, tempDes = plugin->SettingsByDesL());
335 CleanupStack::PushL(tempDes);
336 HBufC* tempDes16 = HBufC::NewMaxLC(tempDes->Length());
337 tempDes16->Des().Copy(*tempDes);
338 INFO_PRINTF2(_L("Stage4: SettingsByDesL() expected KErrNotSupported got \"%S\""), tempDes16);
340 CleanupStack::PopAndDestroy(2, tempDes);
343 else if (error!=KErrNotSupported)
345 INFO_PRINTF2(_L("Stage4: SettingsByDesL() expected KErrNotSupported returned %d"), error);
349 TRAP(error, tempUid = plugin->SettingsByUidL());
350 if (error!=KErrNotSupported)
352 INFO_PRINTF3(_L("Stage4: SettingsByUidL() expected KErrNotSupported got %d(0x%x)"), error, tempUid.iUid);
356 TRAP(error, plugin->ExtractValuesL(tempPackage));
359 INFO_PRINTF3(_L("Stage4: ExtractValuesL() expected KErrNone got %d(%d)"), error, tempInt);
362 else if (tempInt!=sampleInt)
364 INFO_PRINTF3(_L("Stage4: ExtractValuesL() expected %d got %d"), sampleInt, tempInt);
370 // Check for Enabled() and IsActive() - should be false to start. poke value and show have
371 // changed. Have to use custom command for SetActive() since not really the way to drive
372 // - this should relate to the underlying implementation
373 TBool enabled = plugin->IsEnabled();
374 TBool active = plugin->IsActive();
375 if (enabled!=EFalse || active!=EFalse)
377 INFO_PRINTF3(_L("Check1: active(%d) and enabled(%d) should have been false"), active, enabled);
380 plugin->SetEnabledL(ETrue);
381 plugin->SetActive(ETrue);
382 enabled = plugin->IsEnabled();
383 active = plugin->IsActive();
384 if (enabled==EFalse || active==EFalse)
386 INFO_PRINTF3(_L("Check2: active(%d) and enabled(%d) should have been true"), active, enabled);
392 // check preset - for test this ties up with the test plugin
393 const TInt KPresetsCount = 3;
394 MMmfGlobalAudioPresetList* list = plugin->KnownPresetsL();
396 // reproduce what the plugin will do and check
397 if (list->MdcaCount()!=KPresetsCount)
399 INFO_PRINTF3(_L("Expected %d presets, got %d"), KPresetsCount, list->MdcaCount());
404 for (TInt index=0; index<KPresetsCount; index++)
408 TUid tempUid={index};
410 TUid foundUid = list->GAPUidPoint(index);
411 const TPtrC foundName = list->MdcaPoint(index);
413 if (foundUid!=tempUid)
415 INFO_PRINTF4(_L("Index %d, expected %x found %x"), index, tempUid.iUid, foundUid.iUid);
418 if (foundName != name)
420 INFO_PRINTF4(_L("Index %d, expected %S found %S"), index, &name, &foundName);
428 CleanupStack::PopAndDestroy(plugin);
436 // RGlobalEffectCallbackTest
439 const TUid KUidTestGlbNotification = {KUidTestGlbNotificationDefine};
442 RGlobalEffectCallbackTest* RGlobalEffectCallbackTest::NewL(TBool aAllocTest)
444 RGlobalEffectCallbackTest* self = new (ELeave) RGlobalEffectCallbackTest(aAllocTest);
448 RGlobalEffectCallbackTest::RGlobalEffectCallbackTest(TBool /*aAllocTest*/)
450 iTestStepName = _L("MM-MMF-GEF-U-004");
453 void RGlobalEffectCallbackTest::GAEEventNotificationL(CMmfGlobalAudioEffect* aEffect,
455 const TDesC8& aParam)
457 INFO_PRINTF1(_L("Callback"));
458 if (aEffect!=iEffect)
460 INFO_PRINTF3(_L("Effect is %x, expected %d"), aEffect, iEffect);
463 if (KUidTestGlbNotification != aEventUid)
465 INFO_PRINTF3(_L("Uid is %x, expected %x"), aEventUid.iUid, KUidTestGlbNotification.iUid);
468 if (aParam != KNullDesC8)
470 INFO_PRINTF2(_L("Param=\"%S\", expected \"\""), &aParam);
477 TVerdict RGlobalEffectCallbackTest::DoTestStepL()
479 INFO_PRINTF1(_L("Check notification callback"));
484 iEffect = CTestGlobalEffect::NewL(this);
485 CleanupStack::PushL(iEffect);
487 // for test, just generate test synchronously
488 iEffect->RequestNotificationL(KUidTestGlbNotification);
489 iEffect->GenCallbackL();
493 INFO_PRINTF1(_L("Callback seemingly did not happen"));
497 CleanupStack::PopAndDestroy(iEffect);