os/mm/imagingandcamerafws/cameraunittest/src/TSU_ECM_ADV/ecamdirectviewfindertest.cpp
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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>
23 /*--------------------------------------------------------
24 DirectViewFinder : RECamDirectViewFinderTest
25 *--------------------------------------------------------*/
26 RECamDirectViewFinderTest* RECamDirectViewFinderTest::NewL(const TDesC& aTestStep)
28 RECamDirectViewFinderTest* self = new (ELeave) RECamDirectViewFinderTest(aTestStep);
32 RECamDirectViewFinderTest::RECamDirectViewFinderTest(const TDesC& aTestStep)
34 iTestStepName.Copy(aTestStep);
37 TVerdict RECamDirectViewFinderTest::DoTestStepL()
39 if(!iTestStepName.Compare(_L("MM-ECM-ADV-U-044-HP")))
41 return DoTestStep_44L();
43 else if(!iTestStepName.Compare(_L("MM-ECM-ADV-U-045-HP")))
45 return DoTestStep_45L();
50 TVerdict RECamDirectViewFinderTest::DoTestStep_44L()
53 TVerdict verdict = EFail;
54 INFO_PRINTF1(_L("Alloc test"));
63 INFO_PRINTF2(_L("Fail count = %d"), i);
66 __UHEAP_SETFAIL(RHeap::EFailNext, i);
68 TRAP(err, verdict = DoTestStep_Alloc_44L());
70 TAny* testAlloc = NULL;
71 testAlloc = User::Alloc(1);
72 TBool heapTestingComplete = (testAlloc == NULL) && (err==KErrNone);
73 User::Free(testAlloc);
78 if ((err != KErrNoMemory && verdict == EPass ) || heapTestingComplete)
80 INFO_PRINTF4(_L("err = %d, verdict = %d, Fail count = %d"), err, verdict, i);
81 INFO_PRINTF1(_L("Alloc testing completed successfully"));
90 TVerdict RECamDirectViewFinderTest::DoTestStep_Alloc_44L()
92 TVerdict result = EPass;
93 CCamera* camera = NULL;
95 MCameraObserver* observer = NULL;
96 TInt error = KErrNone;
97 CCamera::CCameraDirectViewFinder* directviewfinder = NULL;
101 INFO_PRINTF1(_L("Create camera using Camera::NewL() and MCameraObserver"));
103 TRAP(error, camera = CCamera::NewL(*observer, 0));
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)
112 CleanupStack::PushL(directviewfinder);
113 INFO_PRINTF1(_L("CCameraDirectViewFinder object was created"));
114 CleanupStack::PopAndDestroy(directviewfinder);
118 INFO_PRINTF1(_L("CCameraDirectViewFinder object wasn't created"));
120 CleanupStack::PopAndDestroy(camera);
121 User::Leave (KErrNoMemory);
123 CleanupStack::PopAndDestroy(camera);
127 INFO_PRINTF2(_L("Unexpected %d return from CCamera::NewL()"), error);
129 User::Leave (KErrNoMemory);
134 MCameraObserver2* observer2 = NULL;
137 INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
139 TRAP(error, camera = CCamera::New2L(*observer2, 0,0));
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)
148 CleanupStack::PushL(directviewfinder);
149 INFO_PRINTF1(_L("CCameraDirectViewFinder object was created"));
150 CleanupStack::PopAndDestroy(directviewfinder);
154 INFO_PRINTF1(_L("CCameraDirectViewFinder object wasn't created"));
156 CleanupStack::PopAndDestroy(camera);
157 User::Leave (KErrNoMemory);
159 CleanupStack::PopAndDestroy(camera);
163 INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
165 User::Leave (KErrNoMemory);
169 // create a directviewfinder object using New2L
171 INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
173 TRAP(error, camera = CCamera::New2L(*observer2, 0,0));
177 CleanupStack::PushL(camera);
178 INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
179 TRAP(error, directviewfinder = CCamera::CCameraDirectViewFinder::NewL(*camera));
183 CleanupStack::PushL(directviewfinder);
184 INFO_PRINTF1(_L("CCameraDirectViewFinder object was created using NewL"));
185 CleanupStack::PopAndDestroy(directviewfinder);
189 INFO_PRINTF1(_L("CCameraDirectViewFinder object was not created using NewL"));
191 CleanupStack::PopAndDestroy(camera);
192 User::Leave (KErrNoMemory);
194 CleanupStack::PopAndDestroy(camera);
198 INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
200 User::Leave (KErrNoMemory);
206 TVerdict RECamDirectViewFinderTest::DoTestStep_45L()
208 TVerdict result = EPass;
209 CCamera* camera = NULL;
211 TInt error = KErrNone;
212 CCamera::CCameraDirectViewFinder* directviewfinder = NULL;
214 // create a directviewfinder object using New2L
216 MCameraObserver2* observer2 = NULL;
217 INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
219 TRAP(error, camera = CCamera::New2L(*observer2, 0,0));
223 CleanupStack::PushL(camera);
224 INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
225 TRAP(error, directviewfinder = CCamera::CCameraDirectViewFinder::NewL(*camera));
229 INFO_PRINTF1(_L("CCameraDirectViewFinder object was created using NewL"));
233 INFO_PRINTF1(_L("CCameraDirectViewFinder object was not created using NewL"));
239 INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
243 if (directviewfinder!= NULL)
245 CleanupStack::PushL(directviewfinder);
247 // get the default viewfinder state
248 CCamera::CCameraDirectViewFinder::TViewFinderState vfstate;
249 vfstate = directviewfinder->ViewFinderState();
251 // the vfstate should be EViewFinderInActive
252 if (vfstate != CCamera::CCameraDirectViewFinder::EViewFinderInActive)
254 INFO_PRINTF1(_L("Direct Viewfinder state incorrectly set"));
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
263 TRAP(error, directviewfinder->PauseViewFinderDirectL());
267 INFO_PRINTF1(_L("View finder paused successfully"));
271 INFO_PRINTF2(_L("direct viewfinder pause - %d"), error);
275 vfstate = directviewfinder->ViewFinderState();
277 // the vfstate should be changed to EViewFinderPause
278 if (vfstate != CCamera::CCameraDirectViewFinder::EViewFinderPause)
280 INFO_PRINTF1(_L("Direct Viewfinder state incorrectly set after pausing"));
284 // The next step is to resume the direct viewfinder
286 TRAP(error, directviewfinder->ResumeViewFinderDirectL());
290 INFO_PRINTF1(_L("View finder resumed successfully"));
294 INFO_PRINTF2(_L("direct viewfinder resume - %d"), error);
298 vfstate = directviewfinder->ViewFinderState();
300 // the vfstate should be changed to EViewFinderActive
301 if (vfstate != CCamera::CCameraDirectViewFinder::EViewFinderActive)
303 INFO_PRINTF1(_L("Direct Viewfinder state incorrectly set after resuming"));
307 CleanupStack::PopAndDestroy(directviewfinder);
309 CleanupStack::PopAndDestroy(camera);