camerauis/cameraxui/cxengine/tsrc/unit/unittest_cxesnapshotcontrol/unittest_cxesnapshotcontrol.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 23 61bc0f252b2b
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *
       
    16  */
       
    17 #include <QObject>
       
    18 #include <QTest>
       
    19 #include <QSignalSpy>
       
    20 #include <ecam/camerasnapshot.h>
       
    21 
       
    22 #include "cxefakecameradevice.h"
       
    23 #include "cxefakecameradevicecontrol.h"
       
    24 #include "cxeerror.h"
       
    25 #include "cxetestutils.h"
       
    26 #include "cxesnapshotcontrol.h"
       
    27 #include "cxesnapshotcontrolprivate.h"
       
    28 #include "unittest_cxesnapshotcontrol.h"
       
    29 
       
    30 
       
    31 UnitTestCxeSnapshotControl::UnitTestCxeSnapshotControl()
       
    32     : mSnapshotControl(NULL),
       
    33       mCameraDevice(NULL),
       
    34       mCameraDeviceControl(NULL)
       
    35 {
       
    36 }
       
    37 
       
    38 UnitTestCxeSnapshotControl::~UnitTestCxeSnapshotControl()
       
    39 {
       
    40     cleanup();
       
    41 }
       
    42 
       
    43 
       
    44 void UnitTestCxeSnapshotControl::init()
       
    45 {
       
    46     CX_DEBUG_ENTER_FUNCTION();
       
    47 
       
    48     mCameraDeviceControl = new CxeFakeCameraDeviceControl;
       
    49     mCameraDevice = new CxeFakeCameraDevice;
       
    50     mCameraDevice->newCamera(Cxe::PrimaryCameraIndex, mCameraDeviceControl);
       
    51     mCameraDeviceControl->setState(CxeCameraDeviceControl::Ready);
       
    52 
       
    53     mSnapshotControl = new CxeSnapshotControl(*mCameraDevice);
       
    54 
       
    55     CX_DEBUG_EXIT_FUNCTION();
       
    56 }
       
    57 
       
    58 void UnitTestCxeSnapshotControl::cleanup()
       
    59 {
       
    60     delete mSnapshotControl;
       
    61     mSnapshotControl = NULL;
       
    62 
       
    63     delete mCameraDevice;
       
    64     mCameraDevice = NULL;
       
    65 
       
    66     delete mCameraDeviceControl;
       
    67     mCameraDeviceControl = NULL;
       
    68 }
       
    69 
       
    70 void UnitTestCxeSnapshotControl::testState()
       
    71 {
       
    72     CX_DEBUG_ENTER_FUNCTION();
       
    73 
       
    74     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Idle);
       
    75 
       
    76     CX_DEBUG_EXIT_FUNCTION();
       
    77 }
       
    78 
       
    79 void UnitTestCxeSnapshotControl::testCalculateSnapshotSize()
       
    80 {
       
    81     CX_DEBUG_ENTER_FUNCTION();
       
    82 
       
    83     QSize snapshotSize;
       
    84     QSize displaySize;
       
    85 
       
    86     // 16:9 display, 4:3 capture format
       
    87     displaySize = QSize(1600, 900);
       
    88     snapshotSize = mSnapshotControl->calculateSnapshotSize(displaySize, Cxe::AspectRatio4to3);
       
    89     QVERIFY(snapshotSize == QSize(1200, 900));
       
    90 
       
    91     // 16:9 display, 16:9 capture format
       
    92     displaySize = QSize(640, 360);
       
    93     snapshotSize = mSnapshotControl->calculateSnapshotSize(displaySize, Cxe::AspectRatio16to9);
       
    94     QVERIFY(snapshotSize == QSize(640, 360));
       
    95 
       
    96 
       
    97     // 4:3 display, 16:9 capture format
       
    98     displaySize = QSize(640, 480);
       
    99     snapshotSize = mSnapshotControl->calculateSnapshotSize(displaySize, Cxe::AspectRatio16to9);
       
   100     QVERIFY(snapshotSize == QSize(640, 360));
       
   101 
       
   102     // 4:3 display, 4:3 capture format
       
   103     displaySize = QSize(640, 480);
       
   104     snapshotSize = mSnapshotControl->calculateSnapshotSize(displaySize, Cxe::AspectRatio4to3);
       
   105     QVERIFY(snapshotSize == QSize(640, 480));
       
   106 
       
   107     CX_DEBUG_EXIT_FUNCTION();
       
   108 }
       
   109 
       
   110 void UnitTestCxeSnapshotControl::testStart()
       
   111 {
       
   112     CX_DEBUG_ENTER_FUNCTION();
       
   113 
       
   114     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Idle);
       
   115     mSnapshotControl->start(QSize(640,360));
       
   116     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Active);
       
   117 
       
   118     CX_DEBUG_EXIT_FUNCTION();
       
   119 }
       
   120 
       
   121 void UnitTestCxeSnapshotControl::testStop()
       
   122 {
       
   123     CX_DEBUG_ENTER_FUNCTION();
       
   124 
       
   125     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Idle);
       
   126     mSnapshotControl->stop();
       
   127     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Idle);
       
   128     mSnapshotControl->start(QSize(640,360));
       
   129     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Active);
       
   130     mSnapshotControl->stop();
       
   131     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Idle);
       
   132 
       
   133     CX_DEBUG_EXIT_FUNCTION();
       
   134 }
       
   135 
       
   136 void UnitTestCxeSnapshotControl::testHandleCameraEvent()
       
   137 {
       
   138     CX_DEBUG_ENTER_FUNCTION();
       
   139 
       
   140     QSignalSpy spySnapshotReady(mSnapshotControl, SIGNAL(snapshotReady(CxeError::Id, const QImage&)));
       
   141 
       
   142     // Snapshot not started, camera events should not effect in any way.
       
   143     mSnapshotControl->handleCameraEvent(KUidECamEventSnapshotUidValue, KErrNone);
       
   144     QVERIFY(!CxeTestUtils::waitForSignal(spySnapshotReady, 1000));
       
   145 
       
   146     // After starting we are supposed to get the snapshotReady signal.
       
   147     mSnapshotControl->start(QSize(640,360));
       
   148     mSnapshotControl->handleCameraEvent(KUidECamEventSnapshotUidValue, KErrNone);
       
   149     QVERIFY(CxeTestUtils::waitForSignal(spySnapshotReady, 1000));
       
   150 
       
   151     CX_DEBUG_EXIT_FUNCTION();
       
   152 }
       
   153 
       
   154 QTEST_MAIN(UnitTestCxeSnapshotControl);
       
   155 
       
   156 // end of file