os/mm/imagingandcamerafws/cameraunittest/src/TSU_ECM_ADV/ecamdirectviewfindertest.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/imagingandcamerafws/cameraunittest/src/TSU_ECM_ADV/ecamdirectviewfindertest.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,314 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <ecamuids.hrh>
1.20 +#include <ecom/ecomresolverparams.h>
1.21 +#include "ecamdirectviewfindertest.h"
1.22 +#include "ECamUnitTestPluginUids.hrh"
1.23 +#include "ECamUnitTestPlugin.h"
1.24 +#include <ecam/ecamcommonuids.hrh>
1.25 +
1.26 +/*--------------------------------------------------------
1.27 + DirectViewFinder : RECamDirectViewFinderTest
1.28 + *--------------------------------------------------------*/
1.29 +RECamDirectViewFinderTest* RECamDirectViewFinderTest::NewL(const TDesC& aTestStep)
1.30 + {
1.31 + RECamDirectViewFinderTest* self = new (ELeave) RECamDirectViewFinderTest(aTestStep);
1.32 + return self;
1.33 + }
1.34 +
1.35 +RECamDirectViewFinderTest::RECamDirectViewFinderTest(const TDesC& aTestStep)
1.36 + {
1.37 + iTestStepName.Copy(aTestStep);
1.38 + }
1.39 +
1.40 +TVerdict RECamDirectViewFinderTest::DoTestStepL()
1.41 + {
1.42 + if(!iTestStepName.Compare(_L("MM-ECM-ADV-U-044-HP")))
1.43 + {
1.44 + return DoTestStep_44L();
1.45 + }
1.46 + else if(!iTestStepName.Compare(_L("MM-ECM-ADV-U-045-HP")))
1.47 + {
1.48 + return DoTestStep_45L();
1.49 + }
1.50 + return EInconclusive;
1.51 + }
1.52 +
1.53 +TVerdict RECamDirectViewFinderTest::DoTestStep_44L()
1.54 + {
1.55 +
1.56 + TVerdict verdict = EFail;
1.57 + INFO_PRINTF1(_L("Alloc test"));
1.58 + TInt i;
1.59 + TInt err;
1.60 + for (i = 1 ; ; i++)
1.61 + {
1.62 + __MM_HEAP_MARK;
1.63 +
1.64 + if (i % 5 == 0)
1.65 + {
1.66 + INFO_PRINTF2(_L("Fail count = %d"), i);
1.67 + }
1.68 +
1.69 + __UHEAP_SETFAIL(RHeap::EFailNext, i);
1.70 +
1.71 + TRAP(err, verdict = DoTestStep_Alloc_44L());
1.72 +
1.73 + TAny* testAlloc = NULL;
1.74 + testAlloc = User::Alloc(1);
1.75 + TBool heapTestingComplete = (testAlloc == NULL) && (err==KErrNone);
1.76 + User::Free(testAlloc);
1.77 +
1.78 + __UHEAP_RESET;
1.79 + __MM_HEAP_MARKEND;
1.80 +
1.81 + if ((err != KErrNoMemory && verdict == EPass ) || heapTestingComplete)
1.82 + {
1.83 + INFO_PRINTF4(_L("err = %d, verdict = %d, Fail count = %d"), err, verdict, i);
1.84 + INFO_PRINTF1(_L("Alloc testing completed successfully"));
1.85 + verdict = EPass;
1.86 + break;
1.87 + }
1.88 + }
1.89 + return verdict;
1.90 +
1.91 + }
1.92 +
1.93 +TVerdict RECamDirectViewFinderTest::DoTestStep_Alloc_44L()
1.94 + {
1.95 + TVerdict result = EPass;
1.96 + CCamera* camera = NULL;
1.97 +
1.98 + MCameraObserver* observer = NULL;
1.99 + TInt error = KErrNone;
1.100 + CCamera::CCameraDirectViewFinder* directviewfinder = NULL;
1.101 +
1.102 + // using observer
1.103 + __MM_HEAP_MARK;
1.104 + INFO_PRINTF1(_L("Create camera using Camera::NewL() and MCameraObserver"));
1.105 +
1.106 + TRAP(error, camera = CCamera::NewL(*observer, 0));
1.107 +
1.108 + if (error==KErrNone)
1.109 + {
1.110 + CleanupStack::PushL(camera);
1.111 + INFO_PRINTF1(_L("KErrNone return from CCamera::NewL()"));
1.112 + directviewfinder = static_cast<CCamera::CCameraDirectViewFinder*> (camera->CustomInterface(KECamDirectViewFinderUid));
1.113 + if (directviewfinder!= NULL)
1.114 + {
1.115 + CleanupStack::PushL(directviewfinder);
1.116 + INFO_PRINTF1(_L("CCameraDirectViewFinder object was created"));
1.117 + CleanupStack::PopAndDestroy(directviewfinder);
1.118 + }
1.119 + else
1.120 + {
1.121 + INFO_PRINTF1(_L("CCameraDirectViewFinder object wasn't created"));
1.122 + result = EFail;
1.123 + CleanupStack::PopAndDestroy(camera);
1.124 + User::Leave (KErrNoMemory);
1.125 + }
1.126 + CleanupStack::PopAndDestroy(camera);
1.127 + }
1.128 + else
1.129 + {
1.130 + INFO_PRINTF2(_L("Unexpected %d return from CCamera::NewL()"), error);
1.131 + result = EFail;
1.132 + User::Leave (KErrNoMemory);
1.133 + }
1.134 + __MM_HEAP_MARKEND;
1.135 +
1.136 + // using observer 2
1.137 + MCameraObserver2* observer2 = NULL;
1.138 +
1.139 + __MM_HEAP_MARK;
1.140 + INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
1.141 +
1.142 + TRAP(error, camera = CCamera::New2L(*observer2, 0,0));
1.143 +
1.144 + if (error==KErrNone)
1.145 + {
1.146 + CleanupStack::PushL(camera);
1.147 + INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
1.148 + directviewfinder = static_cast<CCamera::CCameraDirectViewFinder*> (camera->CustomInterface(KECamDirectViewFinderUid));
1.149 + if (directviewfinder!= NULL)
1.150 + {
1.151 + CleanupStack::PushL(directviewfinder);
1.152 + INFO_PRINTF1(_L("CCameraDirectViewFinder object was created"));
1.153 + CleanupStack::PopAndDestroy(directviewfinder);
1.154 + }
1.155 + else
1.156 + {
1.157 + INFO_PRINTF1(_L("CCameraDirectViewFinder object wasn't created"));
1.158 + result = EFail;
1.159 + CleanupStack::PopAndDestroy(camera);
1.160 + User::Leave (KErrNoMemory);
1.161 + }
1.162 + CleanupStack::PopAndDestroy(camera);
1.163 + }
1.164 + else
1.165 + {
1.166 + INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
1.167 + result = EFail;
1.168 + User::Leave (KErrNoMemory);
1.169 + }
1.170 + __MM_HEAP_MARKEND;
1.171 +
1.172 + // create a directviewfinder object using New2L
1.173 + __MM_HEAP_MARK;
1.174 + INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
1.175 +
1.176 + TRAP(error, camera = CCamera::New2L(*observer2, 0,0));
1.177 +
1.178 + if (error==KErrNone)
1.179 + {
1.180 + CleanupStack::PushL(camera);
1.181 + INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
1.182 + TRAP(error, directviewfinder = CCamera::CCameraDirectViewFinder::NewL(*camera));
1.183 +
1.184 + if (error==KErrNone)
1.185 + {
1.186 + CleanupStack::PushL(directviewfinder);
1.187 + INFO_PRINTF1(_L("CCameraDirectViewFinder object was created using NewL"));
1.188 + CleanupStack::PopAndDestroy(directviewfinder);
1.189 + }
1.190 + else
1.191 + {
1.192 + INFO_PRINTF1(_L("CCameraDirectViewFinder object was not created using NewL"));
1.193 + result = EFail;
1.194 + CleanupStack::PopAndDestroy(camera);
1.195 + User::Leave (KErrNoMemory);
1.196 + }
1.197 + CleanupStack::PopAndDestroy(camera);
1.198 + }
1.199 + else
1.200 + {
1.201 + INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
1.202 + result = EFail;
1.203 + User::Leave (KErrNoMemory);
1.204 + }
1.205 + __MM_HEAP_MARKEND;
1.206 +
1.207 + return result;
1.208 + }
1.209 +TVerdict RECamDirectViewFinderTest::DoTestStep_45L()
1.210 + {
1.211 + TVerdict result = EPass;
1.212 + CCamera* camera = NULL;
1.213 +
1.214 + TInt error = KErrNone;
1.215 + CCamera::CCameraDirectViewFinder* directviewfinder = NULL;
1.216 +
1.217 + // create a directviewfinder object using New2L
1.218 + __MM_HEAP_MARK;
1.219 + MCameraObserver2* observer2 = NULL;
1.220 + INFO_PRINTF1(_L("Create camera using Camera::New2L() and MCameraObserver2"));
1.221 +
1.222 + TRAP(error, camera = CCamera::New2L(*observer2, 0,0));
1.223 +
1.224 + if (error==KErrNone)
1.225 + {
1.226 + CleanupStack::PushL(camera);
1.227 + INFO_PRINTF1(_L("KErrNone return from CCamera::New2L()"));
1.228 + TRAP(error, directviewfinder = CCamera::CCameraDirectViewFinder::NewL(*camera));
1.229 +
1.230 + if (error==KErrNone)
1.231 + {
1.232 + INFO_PRINTF1(_L("CCameraDirectViewFinder object was created using NewL"));
1.233 + }
1.234 + else
1.235 + {
1.236 + INFO_PRINTF1(_L("CCameraDirectViewFinder object was not created using NewL"));
1.237 + return EFail;
1.238 + }
1.239 + }
1.240 + else
1.241 + {
1.242 + INFO_PRINTF2(_L("Unexpected %d return from CCamera::New2L(): observer 2"), error);
1.243 + result = EFail;
1.244 + }
1.245 +
1.246 + if (directviewfinder!= NULL)
1.247 + {
1.248 + CleanupStack::PushL(directviewfinder);
1.249 +
1.250 + // get the default viewfinder state
1.251 + CCamera::CCameraDirectViewFinder::TViewFinderState vfstate;
1.252 + vfstate = directviewfinder->ViewFinderState();
1.253 +
1.254 + // the vfstate should be EViewFinderInActive
1.255 + if (vfstate != CCamera::CCameraDirectViewFinder::EViewFinderInActive)
1.256 + {
1.257 + INFO_PRINTF1(_L("Direct Viewfinder state incorrectly set"));
1.258 + return EFail;
1.259 + }
1.260 +
1.261 + // Assumption is that meanwhile direct viewfinder has been started. This would be done by calling CCamera::StartViewFinderDirectL().
1.262 + // This function starts the direct viewfinder and hence changes the state to active.
1.263 + // Also performs initial boundary checking that 'viewfinder remains inactive before its called'. So, the vfstate changes to active.
1.264 + // The next step is to pause the direct viewfinder
1.265 +
1.266 + TRAP(error, directviewfinder->PauseViewFinderDirectL());
1.267 +
1.268 + if(error==KErrNone)
1.269 + {
1.270 + INFO_PRINTF1(_L("View finder paused successfully"));
1.271 + }
1.272 + else
1.273 + {
1.274 + INFO_PRINTF2(_L("direct viewfinder pause - %d"), error);
1.275 + return EFail;
1.276 + }
1.277 +
1.278 + vfstate = directviewfinder->ViewFinderState();
1.279 +
1.280 + // the vfstate should be changed to EViewFinderPause
1.281 + if (vfstate != CCamera::CCameraDirectViewFinder::EViewFinderPause)
1.282 + {
1.283 + INFO_PRINTF1(_L("Direct Viewfinder state incorrectly set after pausing"));
1.284 + return EFail;
1.285 + }
1.286 +
1.287 + // The next step is to resume the direct viewfinder
1.288 +
1.289 + TRAP(error, directviewfinder->ResumeViewFinderDirectL());
1.290 +
1.291 + if(error==KErrNone)
1.292 + {
1.293 + INFO_PRINTF1(_L("View finder resumed successfully"));
1.294 + }
1.295 + else
1.296 + {
1.297 + INFO_PRINTF2(_L("direct viewfinder resume - %d"), error);
1.298 + return EFail;
1.299 + }
1.300 +
1.301 + vfstate = directviewfinder->ViewFinderState();
1.302 +
1.303 + // the vfstate should be changed to EViewFinderActive
1.304 + if (vfstate != CCamera::CCameraDirectViewFinder::EViewFinderActive)
1.305 + {
1.306 + INFO_PRINTF1(_L("Direct Viewfinder state incorrectly set after resuming"));
1.307 + return EFail;
1.308 + }
1.309 +
1.310 + CleanupStack::PopAndDestroy(directviewfinder);
1.311 + }
1.312 + CleanupStack::PopAndDestroy(camera);
1.313 +
1.314 + __MM_HEAP_MARKEND;
1.315 +
1.316 + return result;
1.317 + }