camerauis/cameraxui/cxengine/tsrc/unit/unittest_cxesnapshotcontrol/unittest_cxesnapshotcontrol.cpp
changeset 38 0f0b4c1d7744
child 37 64817133cd1d
equal deleted inserted replaced
28:3075d9b614e6 38:0f0b4c1d7744
       
     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     QSize captureResolution;
       
    86 
       
    87     // 16:9 display, 4:3 capture format
       
    88     displaySize = QSize(1600, 900);
       
    89     captureResolution = QSize(400, 300);
       
    90     snapshotSize = mSnapshotControl->calculateSnapshotSize(displaySize, captureResolution);
       
    91     QVERIFY(snapshotSize == QSize(1200, 900));
       
    92 
       
    93     // 16:9 display, 16:9 capture format
       
    94     displaySize = QSize(640, 360);
       
    95     captureResolution = QSize(4000, 2248);
       
    96     snapshotSize = mSnapshotControl->calculateSnapshotSize(displaySize, captureResolution);
       
    97     QVERIFY(snapshotSize == QSize(640, 360));
       
    98 
       
    99 
       
   100     // 4:3 display, 16:9 capture format
       
   101     displaySize = QSize(640, 480);
       
   102     captureResolution = QSize(4000, 2248);
       
   103     snapshotSize = mSnapshotControl->calculateSnapshotSize(displaySize, captureResolution);
       
   104     QVERIFY(snapshotSize == QSize(640, 360));
       
   105 
       
   106     // 4:3 display, 4:3 capture format
       
   107     displaySize = QSize(640, 480);
       
   108     captureResolution = QSize(2048, 1536);
       
   109     snapshotSize = mSnapshotControl->calculateSnapshotSize(displaySize, captureResolution);
       
   110     QVERIFY(snapshotSize == QSize(640, 480));
       
   111 
       
   112     CX_DEBUG_EXIT_FUNCTION();
       
   113 }
       
   114 
       
   115 void UnitTestCxeSnapshotControl::testStart()
       
   116 {
       
   117     CX_DEBUG_ENTER_FUNCTION();
       
   118 
       
   119     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Idle);
       
   120     mSnapshotControl->start(QSize(640,360));
       
   121     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Active);
       
   122 
       
   123     CX_DEBUG_EXIT_FUNCTION();
       
   124 }
       
   125 
       
   126 void UnitTestCxeSnapshotControl::testStop()
       
   127 {
       
   128     CX_DEBUG_ENTER_FUNCTION();
       
   129 
       
   130     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Idle);
       
   131     mSnapshotControl->stop();
       
   132     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Idle);
       
   133     mSnapshotControl->start(QSize(640,360));
       
   134     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Active);
       
   135     mSnapshotControl->stop();
       
   136     QVERIFY(mSnapshotControl->state() == CxeSnapshotControl::Idle);
       
   137 
       
   138     CX_DEBUG_EXIT_FUNCTION();
       
   139 }
       
   140 
       
   141 void UnitTestCxeSnapshotControl::testHandleCameraEvent()
       
   142 {
       
   143     CX_DEBUG_ENTER_FUNCTION();
       
   144 
       
   145     QSignalSpy spySnapshotReady(mSnapshotControl, SIGNAL(snapshotReady(CxeError::Id, const QPixmap&)));
       
   146 
       
   147     // Snapshot not started, camera events should not effect in any way.
       
   148     mSnapshotControl->handleCameraEvent(KUidECamEventSnapshotUidValue, KErrNone);
       
   149     QVERIFY(!CxeTestUtils::waitForSignal(spySnapshotReady, 1000));
       
   150 
       
   151     // After starting we are supposed to get the snapshotReady signal.
       
   152     mSnapshotControl->start(QSize(640,360));
       
   153     mSnapshotControl->handleCameraEvent(KUidECamEventSnapshotUidValue, KErrNone);
       
   154     QVERIFY(CxeTestUtils::waitForSignal(spySnapshotReady, 1000));
       
   155 
       
   156     CX_DEBUG_EXIT_FUNCTION();
       
   157 }
       
   158 
       
   159 QTEST_MAIN(UnitTestCxeSnapshotControl);
       
   160 
       
   161 // end of file