camerauis/cameraxui/cxui/tsrc/cxuiviewmanagertest.cpp
branchRCL_3
changeset 54 bac7acad7cb3
parent 53 61bc0f252b2b
child 57 2c87b2808fd7
equal deleted inserted replaced
53:61bc0f252b2b 54: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 <QTest>
       
    18 #include <QSignalSpy>
       
    19 #include <hbmainwindow.h>
       
    20 #include "cxutils.h"
       
    21 #include "cxuiviewmanager.h"
       
    22 #include "cxuifakeengine.h"
       
    23 #include "cxuitest.h"
       
    24 #include "cxuienums.h"
       
    25 
       
    26 
       
    27 // Tests only that correct view is activated
       
    28 void TestCxUi::testViewManager()
       
    29     {
       
    30     CX_DEBUG(("testViewManager"));
       
    31     //mEngineFake->initModeFake(Cxe::ImageMode);
       
    32     mEngineFake->initMode(Cxe::ImageMode);
       
    33     //QTest::qWait(5000);
       
    34 
       
    35     connect(this, SIGNAL(toPostcaptureView()), mViewManager, SLOT(changeToPostcaptureView()));
       
    36     connect(this, SIGNAL(toPrecaptureView()), mViewManager, SLOT(changeToPrecaptureView()));
       
    37 
       
    38     // Test if we are in still VF
       
    39     QVERIFY(mMainWindow->currentViewIndex() == CxUi::StillPreCaptureView );
       
    40     
       
    41     emit toPostcaptureView();
       
    42     // Test if image review activated
       
    43     QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPostCaptureView );
       
    44     
       
    45     emit toPrecaptureView();
       
    46     // Test if still VF view active
       
    47     QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPreCaptureView );
       
    48     
       
    49     mEngineFake->initModeFake(Cxe::VideoMode);
       
    50     emit toPrecaptureView();
       
    51     // Test if video VF view active
       
    52     QVERIFY( mMainWindow->currentViewIndex() == CxUi::VideoPreCaptureView );
       
    53     
       
    54     emit toPostcaptureView();
       
    55     // Test if video review active
       
    56     QVERIFY( mMainWindow->currentViewIndex() == CxUi::VideoPostCaptureView );
       
    57     
       
    58     emit toPrecaptureView();
       
    59     // Test if video VF view active
       
    60     QVERIFY( mMainWindow->currentViewIndex() == CxUi::VideoPreCaptureView ); 
       
    61     
       
    62     // Go back to original state...
       
    63     mEngineFake->initModeFake(Cxe::ImageMode);
       
    64     mEngineFake->initMode(Cxe::ImageMode);
       
    65     emit toPrecaptureView();
       
    66     QTest::qWait(5000);
       
    67     }
       
    68 
       
    69 // Tests capture key in still mode
       
    70 void TestCxUi::testCaptureKeyInImageMode()
       
    71     {   
       
    72     // Test if we are in still VF
       
    73     QVERIFY(mMainWindow->currentViewIndex() == CxUi::StillPreCaptureView );    
       
    74     CX_DEBUG(("testCaptureKey in still capture mode"));
       
    75     
       
    76     QSignalSpy deviceStateSpy(&mEngineFake->stillCaptureControl(), 
       
    77             SIGNAL(snapshotReady(int)));   
       
    78     
       
    79     sendCameraKeyEvent();
       
    80     QVERIFY( deviceStateSpy.isValid() );        
       
    81     QCOMPARE( deviceStateSpy.count(), 1 );
       
    82     if (deviceStateSpy.count() > 0) {
       
    83         // Expect zero error code
       
    84         QList<QVariant> initModeArguments = deviceStateSpy.takeFirst();
       
    85         QVERIFY( initModeArguments.at(0).toInt() == 0 );
       
    86     }    
       
    87     QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPostCaptureView );
       
    88     
       
    89     CX_DEBUG(("Test to get back viewfinder with capture key"));
       
    90     sendCameraKeyEvent();
       
    91     QVERIFY(mMainWindow->currentViewIndex() == CxUi::StillPreCaptureView );
       
    92     
       
    93     // Test capture key in wrong engine state?
       
    94     CX_DEBUG(("testCaptureKey in uninitialezed engine state, capture pending"));
       
    95     mEngineFake->fakeStillCaptureControl().setFakeState(CxeStillCaptureControl::Uninitialized);
       
    96     sendCameraKeyEvent();     
       
    97     
       
    98     CX_DEBUG(("Change engine in ready state"));    
       
    99     mEngineFake->fakeStillCaptureControl().setFakeState(CxeStillCaptureControl::Ready);
       
   100     QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPostCaptureView );
       
   101     
       
   102     QSignalSpy autofocusStateSpy(&mEngineFake->autoFocusControl(), 
       
   103                 SIGNAL(stateChanged(CxeAutoFocusControl::State, CxeError::Id)));          
       
   104     QVERIFY( autofocusStateSpy.isValid() );  
       
   105     
       
   106     CX_DEBUG(("test halfkey press to go back"));
       
   107     sendAutofocusKeyEvent(QEvent::KeyPress); 
       
   108     //QTest::qWait(1000);
       
   109     sendAutofocusKeyEvent(QEvent::KeyRelease);    
       
   110     QVERIFY(mMainWindow->currentViewIndex() == CxUi::StillPreCaptureView );
       
   111     
       
   112     QCOMPARE( autofocusStateSpy.count(), 3 );
       
   113     if (autofocusStateSpy.count() > 0) {
       
   114         QList<QVariant> initModeArguments = autofocusStateSpy.takeFirst();
       
   115         QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::InProgress );
       
   116         QVERIFY( initModeArguments.at(1).toInt() == 0 );
       
   117         CX_DEBUG(("testAutoFocus_2a"));
       
   118         initModeArguments = autofocusStateSpy.takeAt(0);
       
   119         QVERIFY( initModeArguments.at(1).toInt() == 0 );
       
   120         QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Canceling );
       
   121         initModeArguments = autofocusStateSpy.takeAt(0);
       
   122         QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Unknown );
       
   123         QVERIFY( initModeArguments.at(1).toInt() == 0 );  
       
   124     }
       
   125     
       
   126     mEngineFake->fakeStillCaptureControl().setFakeState(CxeStillCaptureControl::Capturing);
       
   127     sendCameraKeyEvent();
       
   128     // Nothing should happen
       
   129     QVERIFY(mMainWindow->currentViewIndex() == CxUi::StillPreCaptureView );  
       
   130     }
       
   131 
       
   132 // Tests capture key in video mode
       
   133 void TestCxUi::testCaptureKeyInVideoMode()
       
   134 { 
       
   135 
       
   136     /*connect(this, SIGNAL(toPrecaptureView()), mViewManager, SLOT(changeToPrecaptureView()));
       
   137 
       
   138     QSignalSpy deviceStateSpy(&mEngineFake->videoCaptureControl(), 
       
   139             SIGNAL(stateChanged(CxeVideoCaptureControl::State, int)));    
       
   140     QVERIFY( deviceStateSpy.isValid() ); 
       
   141     emit toPrecaptureView();
       
   142     QTest::qWait(500);
       
   143     // Test if we are in still VF
       
   144     QVERIFY(mMainWindow->currentViewIndex() == CxUi::VideoPreCaptureView );
       
   145 
       
   146     // Generate camera key event to start recording
       
   147     QKeyEvent* captureKeyEvent = QKeyEvent::createExtendedKeyEvent(
       
   148             QEvent::KeyPress, 
       
   149             Qt::Key_unknown, 
       
   150             0, 
       
   151             0xab, 
       
   152             0,
       
   153             0);    
       
   154     
       
   155     QApplication::postEvent(mMainWindow, captureKeyEvent);
       
   156     captureKeyEvent = QKeyEvent::createExtendedKeyEvent(
       
   157                        QEvent::KeyRelease, Qt::Key_unknown, 0, 0xab, 0,0);
       
   158     QApplication::postEvent(mMainWindow, captureKeyEvent);
       
   159     QTest::qWait(5000);
       
   160     
       
   161     // Generate camera key event to stop recording
       
   162     captureKeyEvent = QKeyEvent::createExtendedKeyEvent(
       
   163             QEvent::KeyPress, 
       
   164             Qt::Key_unknown, 
       
   165             0, 
       
   166             0xab, 
       
   167             0,
       
   168             0);
       
   169     QApplication::postEvent(mMainWindow, captureKeyEvent);
       
   170     captureKeyEvent = QKeyEvent::createExtendedKeyEvent(
       
   171                            QEvent::KeyRelease, Qt::Key_unknown, 0, 0xab, 0,0);
       
   172     QApplication::postEvent(mMainWindow, captureKeyEvent);
       
   173     QTest::qWait(3000);
       
   174 
       
   175 
       
   176         QCOMPARE( deviceStateSpy.count(), 3 );
       
   177         
       
   178         QList<QVariant> initModeArguments = deviceStateSpy.takeAt(0);
       
   179         QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Recording );
       
   180         QVERIFY( initModeArguments.at(1).toInt() == 0 );
       
   181         initModeArguments = deviceStateSpy.takeAt(0);
       
   182         QVERIFY( initModeArguments.at(1).toInt() == 0 );
       
   183         QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Stopping );
       
   184         initModeArguments = deviceStateSpy.takeAt(0);
       
   185         QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Idle );
       
   186         QVERIFY( initModeArguments.at(1).toInt() == 0 );  
       
   187     
       
   188     QVERIFY( mMainWindow->currentViewIndex()== CxUi::VideoPostCaptureView );
       
   189     
       
   190     CX_DEBUG(("Test to get back viewfinder with capture key"));
       
   191     captureKeyEvent = QKeyEvent::createExtendedKeyEvent(
       
   192             QEvent::KeyPress, Qt::Key_unknown, 0, 0xab, 0,0);    
       
   193     QApplication::postEvent(mMainWindow, captureKeyEvent);
       
   194     captureKeyEvent = QKeyEvent::createExtendedKeyEvent(
       
   195             QEvent::KeyRelease, Qt::Key_unknown, 0, 0xab, 0,0);
       
   196     QApplication::postEvent(mMainWindow, captureKeyEvent);
       
   197     QTest::qWait(1000); 
       
   198     QVERIFY( mMainWindow->currentViewIndex()== CxUi::VideoPreCaptureView );*/
       
   199 }
       
   200