mmsharing/livecommsui/lcuiengine/tsrc/ut_lcuieng/src/ut_lcuiengine.cpp
changeset 22 496ad160a278
child 25 53c1c4459a94
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     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 "ut_lcuiengine.h"
       
    18 #include "lcuiengine.h"
       
    19 #include "lcuiengine_p.h"
       
    20 #include "lcactivitymanager.h"
       
    21 
       
    22 #include "lcenginestub.h"
       
    23 #include "lcsessionstub.h"
       
    24 #include "lcvideoplayerstub.h"
       
    25 #include "lcuidefs.h"
       
    26 #include "qthighway_stub_helper.h"
       
    27 
       
    28 #include <QtTest/QtTest>
       
    29 #include <QMap>
       
    30 
       
    31 #include <hbmainwindow.h>
       
    32 #include <hbdialog.h>
       
    33 #include <hbprogressdialog.h>
       
    34 #include <hbmessagebox.h>
       
    35 #include <hbaction.h>
       
    36 #include <hblabel.h>
       
    37 #include <QSignalSpy>
       
    38 #include <hbview.h>
       
    39 
       
    40 const char lcutMultimediaSharingEng[] = "MultimediaSharing";
       
    41 const char lcutVideotelephonyEng[] = "Videotelephony";
       
    42 
       
    43 const char lcutMultimediaSharingApp[] = "Multimedia Sharing";
       
    44 const char lcutVideotelephonyApp[] = "Videotelephony";
       
    45 
       
    46 #define LC_ENGINE( uiengine )\
       
    47     (static_cast<CLcEngineStub*>( uiengine->d->mLiveCommsEngine ) )
       
    48 
       
    49 #define LC_SESSION( uiengine )\
       
    50     (LC_ENGINE(uiengine)->iSession)
       
    51 
       
    52 void UT_LcUiEngine::initTestCase()
       
    53 {
       
    54     lcutStub_LcEngine_reset();
       
    55     lcutStub_LcSession_reset();
       
    56     lcutStub_LcPlayer_reset();
       
    57 
       
    58 }
       
    59 
       
    60 void UT_LcUiEngine::cleanupTestCase()
       
    61 {
       
    62     lcutStub_LcEngine_reset();
       
    63     lcutStub_LcSession_reset();
       
    64     lcutStub_LcPlayer_reset();
       
    65 }
       
    66 
       
    67 
       
    68 void UT_LcUiEngine::init()
       
    69 {
       
    70     lcutStub_LcEngine_reset();
       
    71     lcutStub_LcSession_reset();
       
    72     lcutStub_LcPlayer_reset();
       
    73     mEngine = new LcUiEngine( lcutMultimediaSharingEng,
       
    74                               lcutMultimediaSharingApp );
       
    75     mInvitingNote = new HbProgressDialog();
       
    76     mWaitingNote = new HbProgressDialog();
       
    77     mAcceptQuery = new HbDialog();
       
    78     mRecipientQuery = new HbDialog();
       
    79     mShareOwnVideoQuery = new HbDialog();
       
    80     
       
    81 }
       
    82 
       
    83 void UT_LcUiEngine::cleanup()
       
    84 {
       
    85     lcutStub_LcEngine_reset();
       
    86     lcutStub_LcSession_reset();
       
    87     lcutStub_LcPlayer_reset();
       
    88     delete mEngine;
       
    89     delete mInvitingNote;
       
    90     delete mWaitingNote;
       
    91     delete mAcceptQuery;
       
    92     delete mRecipientQuery;
       
    93     delete mShareOwnVideoQuery;
       
    94 }
       
    95 
       
    96 void UT_LcUiEngine::testConstructor()
       
    97 {
       
    98     // "MuS plug-in" loaded
       
    99     QVERIFY( mEngine );
       
   100     QCOMPARE( mEngine->d->mViewLayout, Lc_IdleViewLayout );
       
   101     QVERIFY( !mEngine->d->mInvitingNote );
       
   102     QVERIFY( !mEngine->d->mWaitingNote );
       
   103     QVERIFY( !mEngine->d->mAcceptQuery );
       
   104     QVERIFY( !mEngine->d->mRecipientQuery );
       
   105     QVERIFY( !mEngine->d->mCloseTimer );
       
   106     QVERIFY( mEngine->d->mLiveCommsEngine );
       
   107     QCOMPARE( mEngine->d->mEngineName, QByteArray( lcutMultimediaSharingEng ) );
       
   108     QVERIFY( mEngine->d->recipient() != hbTrId("txt_vt_custom_unknown_number") );
       
   109     QCOMPARE( mEngine->d->sessionTitle(), QString( lcutMultimediaSharingApp ) );
       
   110     int engineWindowParam = 0;
       
   111     QVERIFY( LC_SESSION( mEngine )->mParams.contains( engineWindowParam ) );
       
   112     QVERIFY( mEngine->d->mActivityManager );
       
   113     QVERIFY( !mEngine->d->mActivityManager->isActivitySimulationEnabled() );
       
   114     QVERIFY( !mEngine->d->mShareOwnVideoQuery );
       
   115     
       
   116     // "VT plug-in" loaded
       
   117     lcutStub_LcEngine_reset();
       
   118     lcutStub_LcSession_reset();    
       
   119     delete mEngine;
       
   120     mEngine = 0;
       
   121     mEngine = new LcUiEngine( lcutVideotelephonyEng,
       
   122                               lcutVideotelephonyApp );
       
   123     QVERIFY( mEngine );
       
   124     QCOMPARE( mEngine->d->mViewLayout, Lc_AllInOneViewLayout );
       
   125     QVERIFY( !mEngine->d->mInvitingNote );
       
   126     QVERIFY( !mEngine->d->mWaitingNote );
       
   127     QVERIFY( !mEngine->d->mAcceptQuery );
       
   128     QVERIFY( !mEngine->d->mRecipientQuery );
       
   129     QVERIFY( !mEngine->d->mCloseTimer );
       
   130     QVERIFY( mEngine->d->mLiveCommsEngine );
       
   131     QCOMPARE( mEngine->d->mEngineName, QByteArray( lcutVideotelephonyEng ) );
       
   132     QVERIFY( mEngine->d->recipient() != hbTrId("txt_vt_custom_unknown_number") );
       
   133     QCOMPARE( mEngine->d->sessionTitle(), QString( lcutVideotelephonyApp ) );
       
   134     QVERIFY( LC_SESSION( mEngine )->mParams.contains( engineWindowParam ) );
       
   135     QVERIFY( !mEngine->d->mFullScreen );
       
   136     QVERIFY( mEngine->d->mActivityManager );
       
   137     QVERIFY( !mEngine->d->mActivityManager->isActivitySimulationEnabled() );
       
   138     QVERIFY( !mEngine->d->mShareOwnVideoQuery );
       
   139 }
       
   140 
       
   141 void UT_LcUiEngine::testFeatureSupported()
       
   142 {
       
   143     // Engine not loaded
       
   144     CLcEngine* enginePtr = mEngine->d->mLiveCommsEngine;
       
   145     mEngine->d->mLiveCommsEngine = 0;
       
   146     QVERIFY( !mEngine->d->featureSupported( CLcEngine::ELcShowAcceptQuery ) );
       
   147     
       
   148     // Engine loaded, feature not supported
       
   149     mEngine->d->mLiveCommsEngine = enginePtr;
       
   150     QVERIFY( !mEngine->d->featureSupported( CLcEngine::ELcShowAcceptQuery ) );
       
   151     
       
   152     // Feature supported
       
   153     lcutStub_LcEngine_setLcFeatureSupported( true );
       
   154     QVERIFY( mEngine->d->featureSupported( CLcEngine::ELcShowAcceptQuery ) );
       
   155 }
       
   156 
       
   157 void UT_LcUiEngine::testEstablishSession()
       
   158 {
       
   159     // Leave 
       
   160     lcutStub_LcEngine_setFailure( -1 );
       
   161     QCOMPARE( mEngine->d->establishSession(), -1 );
       
   162     QVERIFY( !mEngine->d->mCloseTimer );
       
   163     
       
   164     // No leave
       
   165     lcutStub_LcEngine_reset();
       
   166     QCOMPARE( mEngine->d->establishSession(), 0 );
       
   167     QVERIFY( mEngine->d->mCloseTimer );
       
   168 }
       
   169 
       
   170 void UT_LcUiEngine::testTerminateSession()
       
   171 {
       
   172     // Leave 
       
   173     lcutStub_LcEngine_setFailure( -1 );
       
   174     QCOMPARE( mEngine->d->terminateSession(), -1 );
       
   175     
       
   176     // No leave
       
   177     lcutStub_LcEngine_reset();
       
   178     QCOMPARE( mEngine->d->establishSession(), 0 );
       
   179 }
       
   180 
       
   181 void UT_LcUiEngine::testSetWindowRect()
       
   182 {
       
   183     TRect rect;
       
   184     MLcVideoPlayer* player = 
       
   185         mEngine->d->mLiveCommsEngine->Session().LocalVideoPlayer();
       
   186     
       
   187     // No player
       
   188     QCOMPARE( mEngine->d->setWindowRect( 0, rect ), -1 );
       
   189     
       
   190     // Leave
       
   191     lcutStub_LcEngine_setFailure( -2 );
       
   192     QCOMPARE( mEngine->d->setWindowRect( player, rect ), -2 );    
       
   193     
       
   194     // No leave
       
   195     lcutStub_LcEngine_reset();
       
   196     QCOMPARE( mEngine->d->setWindowRect( player, rect ), 0 );
       
   197 }
       
   198 
       
   199 void UT_LcUiEngine::testEnableWindow()
       
   200 {
       
   201     MLcVideoPlayer* player = 
       
   202         mEngine->d->mLiveCommsEngine->Session().LocalVideoPlayer();
       
   203     
       
   204     // No player
       
   205     QCOMPARE( mEngine->d->enableWindow( 0, true ), -1 );
       
   206     
       
   207     // Leave
       
   208     lcutStub_LcEngine_setFailure( -2 );
       
   209     QCOMPARE( mEngine->d->enableWindow( player, true ), -2 );    
       
   210     
       
   211     // No leave
       
   212     lcutStub_LcEngine_reset();
       
   213     QCOMPARE( mEngine->d->enableWindow( player, true ), 0 );
       
   214 }
       
   215 
       
   216 void UT_LcUiEngine::testPlay()
       
   217 {
       
   218     MLcVideoPlayer* player = 
       
   219         mEngine->d->mLiveCommsEngine->Session().LocalVideoPlayer();
       
   220     
       
   221     // No player
       
   222     QCOMPARE( mEngine->d->play( 0 ), -1 );
       
   223     
       
   224     // Leave
       
   225     lcutStub_LcEngine_setFailure( -2 );
       
   226     QCOMPARE( mEngine->d->play( player ), -2 );    
       
   227     
       
   228     // No leave
       
   229     lcutStub_LcEngine_reset();
       
   230     QVERIFY( !player->LcIsPlayingL() );
       
   231     QCOMPARE( mEngine->d->play( player ), 0 );
       
   232     QVERIFY( player->LcIsPlayingL() );
       
   233 }
       
   234 
       
   235 void UT_LcUiEngine::testPause()
       
   236 {
       
   237     MLcVideoPlayer* player = 
       
   238         mEngine->d->mLiveCommsEngine->Session().LocalVideoPlayer();
       
   239     
       
   240     // No player
       
   241     QCOMPARE( mEngine->d->pause( 0 ), -1 );
       
   242     
       
   243     // Leave
       
   244     lcutStub_LcEngine_setFailure( -2 );
       
   245     QCOMPARE( mEngine->d->pause( player ), -2 );    
       
   246     
       
   247     // No leave
       
   248     lcutStub_LcEngine_reset();
       
   249     QCOMPARE( mEngine->d->play( player ), 0 );
       
   250     QVERIFY( player->LcIsPlayingL() );
       
   251     QCOMPARE( mEngine->d->pause( player ), 0 );
       
   252     QVERIFY( !player->LcIsPlayingL() );    
       
   253 }
       
   254 
       
   255 void UT_LcUiEngine::testEnableSpeaker()
       
   256 {
       
   257     // Leave 
       
   258     lcutStub_LcEngine_setFailure( -1 );
       
   259     QCOMPARE( mEngine->d->enableSpeaker( true ), -1 );
       
   260     QVERIFY( !mEngine->d->isSpeakerOn() );
       
   261     
       
   262     // No leave
       
   263     lcutStub_LcEngine_reset();
       
   264     QCOMPARE( mEngine->d->enableSpeaker( true ), 0 );
       
   265     QVERIFY( mEngine->d->isSpeakerOn() );
       
   266 }
       
   267 
       
   268 void UT_LcUiEngine::testMuteMic()
       
   269 {
       
   270     // Leave 
       
   271     lcutStub_LcEngine_setFailure( -1 );
       
   272     QCOMPARE( mEngine->d->muteMic( true ), -1 );
       
   273     lcutStub_LcEngine_reset();
       
   274     QVERIFY( !mEngine->d->isMuted() );
       
   275     
       
   276     // No leave
       
   277     QCOMPARE( mEngine->d->muteMic( true ), 0 );
       
   278     QVERIFY( mEngine->d->isMuted() );
       
   279 }
       
   280 
       
   281 void UT_LcUiEngine::testStartLiveContent()
       
   282 {
       
   283     // mInvitingNote not set
       
   284     mInvitingNote->hide();
       
   285     mEngine->d->startLiveContent();
       
   286     QVERIFY( !mInvitingNote->isVisible() );
       
   287     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_establishSession ) );
       
   288     
       
   289     // mInvitingNote set, but the engine does not support the feature
       
   290     lcutStub_LcSession_reset();
       
   291     mEngine->d->mInvitingNote = mInvitingNote;
       
   292     mEngine->d->startLiveContent();
       
   293     QVERIFY( !mInvitingNote->isVisible() );
       
   294     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_establishSession ) );    
       
   295     
       
   296     // mInvitingNote set and the engine supports the feature
       
   297     lcutStub_LcSession_reset();
       
   298     lcutStub_LcEngine_setLcFeatureSupported( true );
       
   299     mEngine->d->startLiveContent();
       
   300     QVERIFY( mInvitingNote->isVisible() );
       
   301     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_establishSession ) ); 
       
   302 }
       
   303 
       
   304 void UT_LcUiEngine::testStart()
       
   305 {    
       
   306     LC_SESSION( mEngine )->iState = MLcSession::EReceived;
       
   307     mEngine->d->start();
       
   308     QVERIFY( mEngine->d->mActivityManager->isActivitySimulationEnabled() );
       
   309     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_NoCall ) );
       
   310     
       
   311     lcutStub_LcSession_reset();
       
   312     lcutStub_LcPlayer_reset();
       
   313     
       
   314     LC_SESSION( mEngine )->iState = MLcSession::EInitialized;
       
   315     mEngine->d->start();
       
   316     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_establishSession ) );
       
   317 
       
   318     lcutStub_LcSession_reset();
       
   319     lcutStub_LcPlayer_reset();
       
   320     
       
   321     mEngine->d->setUiComponents( mInvitingNote, mWaitingNote,
       
   322                               mAcceptQuery, mRecipientQuery,mShareOwnVideoQuery );
       
   323     LC_SESSION( mEngine )->iState = MLcSession::EInitialized;
       
   324     mEngine->d->start();
       
   325     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_establishSession ) );
       
   326 }
       
   327     
       
   328 void UT_LcUiEngine::testSetUiComponents()
       
   329 {
       
   330     QVERIFY( !mEngine->d->mInvitingNote );
       
   331     QVERIFY( !mEngine->d->mWaitingNote );
       
   332     QVERIFY( !mEngine->d->mAcceptQuery );
       
   333     QVERIFY( !mEngine->d->mRecipientQuery );
       
   334     
       
   335     mEngine->d->setUiComponents(0,0,0,0,0);
       
   336     
       
   337     QVERIFY( !mEngine->d->mInvitingNote );
       
   338     QVERIFY( !mEngine->d->mWaitingNote );
       
   339     QVERIFY( !mEngine->d->mAcceptQuery );
       
   340     QVERIFY( !mEngine->d->mRecipientQuery );
       
   341     
       
   342     mEngine->d->setUiComponents(mInvitingNote,mWaitingNote,mAcceptQuery,mRecipientQuery,mShareOwnVideoQuery);
       
   343     QVERIFY( mEngine->d->mInvitingNote );
       
   344     QVERIFY( mEngine->d->mWaitingNote );
       
   345     QVERIFY( mEngine->d->mAcceptQuery );
       
   346     QVERIFY( mEngine->d->mRecipientQuery );
       
   347 }
       
   348 
       
   349 void UT_LcUiEngine::testSessionStateChanged()
       
   350 {        
       
   351     LC_SESSION( mEngine )->iState = MLcSession::EUninitialized;
       
   352     mEngine->d->StateChanged( *LC_SESSION( mEngine ) );
       
   353     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_NoCall ) );
       
   354         
       
   355     lcutStub_LcSession_reset();
       
   356     lcutStub_LcPlayer_reset();
       
   357     
       
   358     QVERIFY( mEngine->d->mSessionDurationTimerId == 0 );
       
   359     LC_SESSION( mEngine )->iState = MLcSession::EOpen;
       
   360     mEngine->d->StateChanged( *LC_SESSION( mEngine ) );
       
   361     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_NoCall ) );
       
   362     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_EnableLcWindowL ) );
       
   363     // Session duration is started when session opened
       
   364     QVERIFY( mEngine->d->mSessionDurationTimerId != 0 );
       
   365 
       
   366     lcutStub_LcSession_reset();
       
   367     lcutStub_LcPlayer_reset();
       
   368     
       
   369     LC_SESSION( mEngine )->iState = MLcSession::EClosed;
       
   370     QSignalSpy spy(mEngine, SIGNAL(stopped()));
       
   371     mEngine->d->StateChanged( *LC_SESSION( mEngine ) );
       
   372     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_NoCall ) );
       
   373     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   374     QCOMPARE( spy.count(), 1 );
       
   375     
       
   376     // mAcceptQuery not set
       
   377     lcutStub_LcSession_reset();
       
   378     lcutStub_LcPlayer_reset();    
       
   379     mAcceptQuery->hide();
       
   380     LC_SESSION( mEngine )->iState = MLcSession::EReceived;
       
   381     mEngine->d->StateChanged( *LC_SESSION( mEngine ) );
       
   382     QVERIFY( !mAcceptQuery->isVisible() );
       
   383     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_establishSession ) );
       
   384     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   385     
       
   386     // mAcceptQuery set, but the engine does not support the feature
       
   387     lcutStub_LcSession_reset();
       
   388     lcutStub_LcPlayer_reset();
       
   389     LC_SESSION( mEngine )->iState = MLcSession::EReceived;
       
   390     mEngine->d->mAcceptQuery = mAcceptQuery;
       
   391     mEngine->d->StateChanged( *LC_SESSION( mEngine ) );
       
   392     QVERIFY( !mAcceptQuery->isVisible() );
       
   393     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_establishSession ) );
       
   394     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   395     
       
   396     // mAcceptQuery set and the engine supports the feature
       
   397     lcutStub_LcSession_reset();
       
   398     lcutStub_LcPlayer_reset();
       
   399     LC_SESSION( mEngine )->iState = MLcSession::EReceived;
       
   400     lcutStub_LcEngine_setLcFeatureSupported( true );
       
   401     mEngine->d->StateChanged( *LC_SESSION( mEngine ) );
       
   402     QVERIFY( mAcceptQuery->isVisible() );
       
   403     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_NoCall ) );
       
   404     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );    
       
   405     
       
   406     // MT call and sharing own video not allowed by default , popup query shown    
       
   407     lcutStub_LcSession_reset();
       
   408     lcutStub_LcPlayer_reset();
       
   409     mShareOwnVideoQuery->hide();
       
   410     mEngine->d->setUiComponents(mInvitingNote,mWaitingNote,mAcceptQuery,mRecipientQuery,mShareOwnVideoQuery);
       
   411     LC_SESSION( mEngine )->iState = MLcSession::EOpen;
       
   412     lcutStub_LcEngine_setLcFeatureSupported( true );
       
   413     mEngine->d->StateChanged( *LC_SESSION( mEngine ) );
       
   414     QVERIFY( mEngine->d->mShareOwnVideoQuery );
       
   415     QVERIFY( mEngine->d->mShareOwnVideoQuery->isVisible() );
       
   416     CLcVideoPlayer* localPlayer = LC_SESSION( mEngine )->iLocalPlayer;
       
   417     //QVERIFY( localPlayer->iState == MLcVideoPlayer::EPaused );
       
   418     
       
   419     // MO call and sharing own video allowed by default , popup query not shown
       
   420     lcutStub_LcSession_reset();
       
   421     lcutStub_LcPlayer_reset();
       
   422     mShareOwnVideoQuery->hide();
       
   423     mEngine->d->setUiComponents(mInvitingNote,mWaitingNote,mAcceptQuery,mRecipientQuery,mShareOwnVideoQuery);
       
   424     LC_SESSION( mEngine )->iState = MLcSession::EOpen;
       
   425     lcutStub_LcEngine_setLcFeatureSupported( false );
       
   426     mEngine->d->StateChanged( *LC_SESSION( mEngine ) );    
       
   427     QVERIFY( mEngine->d->mShareOwnVideoQuery );
       
   428     QVERIFY( !mEngine->d->mShareOwnVideoQuery->isVisible() );
       
   429     localPlayer = LC_SESSION( mEngine )->iLocalPlayer;
       
   430     QVERIFY( localPlayer->iState == MLcVideoPlayer::EPlaying );
       
   431         
       
   432 }
       
   433 
       
   434 void UT_LcUiEngine::testPlayerStateChanged()
       
   435 {
       
   436     CLcVideoPlayer* localPlayer = LC_SESSION( mEngine )->iLocalPlayer;
       
   437     QVERIFY( localPlayer != NULL );
       
   438     QSignalSpy localPlayerSignalSpy( mEngine, SIGNAL( localPlayerPlaying() ) );
       
   439     QSignalSpy localPlayerSignalSpy2( mEngine, SIGNAL( localPlayerPreparing() ) );
       
   440     QSignalSpy localPlayerSignalSpy3( mEngine, SIGNAL( localPlayerBuffering() ) );
       
   441     QSignalSpy localPlayerSignalSpy4( mEngine, SIGNAL( localPlayerPaused() ) );
       
   442     QSignalSpy localPlayerSignalSpy5( mEngine, SIGNAL( localPlayerUnavailable() ) );
       
   443     
       
   444     CLcVideoPlayer* remotePlayer = LC_SESSION( mEngine )->iRemotePlayer;
       
   445     QVERIFY( remotePlayer != NULL );
       
   446     QSignalSpy remotePlayerSignalSpy( mEngine, SIGNAL( remotePlayerPlaying() ) );
       
   447     QSignalSpy remotePlayerSignalSpy2( mEngine, SIGNAL( remotePlayerPreparing() ) );
       
   448     QSignalSpy remotePlayerSignalSpy3( mEngine, SIGNAL( remotePlayerBuffering() ) );
       
   449     QSignalSpy remotePlayerSignalSpy4( mEngine, SIGNAL( remotePlayerPaused() ) );
       
   450     QSignalSpy remotePlayerSignalSpy5( mEngine, SIGNAL( remotePlayerUnavailable() ) );
       
   451 
       
   452     // Use local player, player not playing
       
   453     mEngine->d->StateChanged( *localPlayer );
       
   454     QCOMPARE( localPlayerSignalSpy.count(), 0 );
       
   455     QCOMPARE( localPlayerSignalSpy2.count(), 0 );
       
   456     QCOMPARE( localPlayerSignalSpy3.count(), 0 );
       
   457     QCOMPARE( localPlayerSignalSpy4.count(), 0 );
       
   458     QCOMPARE( localPlayerSignalSpy5.count(), 0 );
       
   459     
       
   460     // Use local player, player preparing
       
   461     localPlayer->iState = MLcVideoPlayer::EPreparing;
       
   462     mEngine->d->StateChanged( *localPlayer );
       
   463     QCOMPARE( localPlayerSignalSpy2.count(), 1 );
       
   464 
       
   465     // Use local player, player buffering
       
   466     localPlayer->iState = MLcVideoPlayer::EBuffering;
       
   467     mEngine->d->StateChanged( *localPlayer );
       
   468     QCOMPARE( localPlayerSignalSpy3.count(), 1 );
       
   469 
       
   470     // Use local player, player playing
       
   471     localPlayer->iState = MLcVideoPlayer::EPlaying;
       
   472     mEngine->d->StateChanged( *localPlayer );
       
   473     QCOMPARE( localPlayerSignalSpy.count(), 1 );
       
   474     
       
   475     // Use local player, player paused
       
   476     localPlayer->iState = MLcVideoPlayer::EPaused;
       
   477     mEngine->d->StateChanged( *localPlayer );
       
   478     QCOMPARE( localPlayerSignalSpy4.count(), 1 );
       
   479     
       
   480     // Use local player, player unavailable
       
   481     localPlayer->iState = MLcVideoPlayer::EUnavailable;
       
   482     mEngine->d->StateChanged( *localPlayer );
       
   483     QCOMPARE( localPlayerSignalSpy5.count(), 1 );
       
   484     
       
   485     // Use remote player, no waiting note
       
   486     mEngine->d->StateChanged( *remotePlayer );
       
   487     QVERIFY( mWaitingNote->isVisible() );
       
   488     QCOMPARE( remotePlayerSignalSpy.count(), 0 );
       
   489     QCOMPARE( remotePlayerSignalSpy2.count(), 0 );  
       
   490     QCOMPARE( remotePlayerSignalSpy3.count(), 0 );  
       
   491     QCOMPARE( remotePlayerSignalSpy4.count(), 0 );  
       
   492     QCOMPARE( remotePlayerSignalSpy5.count(), 0 );  
       
   493 
       
   494     // Use remote player, waiting note present, player not playing
       
   495     mEngine->d->mWaitingNote = mWaitingNote;
       
   496     mEngine->d->StateChanged( *remotePlayer );
       
   497     QVERIFY( mWaitingNote->isVisible() );
       
   498     QCOMPARE( remotePlayerSignalSpy.count(), 0 );
       
   499     QCOMPARE( remotePlayerSignalSpy2.count(), 0 );  
       
   500     QCOMPARE( remotePlayerSignalSpy3.count(), 0 );  
       
   501     QCOMPARE( remotePlayerSignalSpy4.count(), 0 );  
       
   502     QCOMPARE( remotePlayerSignalSpy5.count(), 0 );  
       
   503 
       
   504     // Use remote player, player preparing
       
   505     remotePlayer->iState = MLcVideoPlayer::EPreparing;
       
   506     mEngine->d->StateChanged( *remotePlayer );
       
   507     QVERIFY( mWaitingNote->isVisible() );
       
   508     QCOMPARE( remotePlayerSignalSpy2.count(), 1 );  
       
   509     
       
   510     // Use remote player, player buffering
       
   511     remotePlayer->iState = MLcVideoPlayer::EBuffering;
       
   512     mEngine->d->StateChanged( *remotePlayer );
       
   513     QVERIFY( mWaitingNote->isVisible() );
       
   514     QCOMPARE( remotePlayerSignalSpy3.count(), 1 );  
       
   515 
       
   516     // Use remote player, waiting note present, player playing
       
   517     remotePlayer->iState = MLcVideoPlayer::EPlaying;
       
   518     mEngine->d->StateChanged( *remotePlayer );
       
   519     QVERIFY( !mWaitingNote->isVisible() );
       
   520     QCOMPARE( remotePlayerSignalSpy.count(), 1 );  
       
   521 
       
   522     // Use remote player, waiting note present, player playing
       
   523     remotePlayer->iState = MLcVideoPlayer::EUnavailable;
       
   524     mEngine->d->StateChanged( *remotePlayer );
       
   525     QVERIFY( !mWaitingNote->isVisible() );
       
   526     QCOMPARE( remotePlayerSignalSpy5.count(), 1 );  
       
   527 
       
   528     // Use remote player, player paused
       
   529     remotePlayer->iState = MLcVideoPlayer::EPaused;
       
   530     mEngine->d->StateChanged( *remotePlayer );
       
   531     QVERIFY( !mWaitingNote->isVisible() );
       
   532     QCOMPARE( remotePlayerSignalSpy4.count(), 1 );  
       
   533 
       
   534     QCOMPARE( localPlayerSignalSpy.count(), 1 );
       
   535     QCOMPARE( localPlayerSignalSpy2.count(), 1 );
       
   536     QCOMPARE( localPlayerSignalSpy3.count(), 1 );
       
   537     QCOMPARE( localPlayerSignalSpy4.count(), 1 );
       
   538     QCOMPARE( localPlayerSignalSpy5.count(), 1 );
       
   539 
       
   540     QCOMPARE( remotePlayerSignalSpy.count(), 1 );
       
   541     QCOMPARE( remotePlayerSignalSpy2.count(), 1 );  
       
   542     QCOMPARE( remotePlayerSignalSpy3.count(), 1 );  
       
   543     QCOMPARE( remotePlayerSignalSpy4.count(), 1 );  
       
   544     QCOMPARE( remotePlayerSignalSpy5.count(), 1 );  
       
   545     
       
   546 }
       
   547 
       
   548 void UT_LcUiEngine::testSetContentAreas()
       
   549 {
       
   550     QRectF shared;
       
   551     QRectF received;
       
   552     
       
   553     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer );
       
   554     QVERIFY( LC_SESSION( mEngine )->iRemotePlayer );
       
   555     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer->iRect.iTl.iX != 0);
       
   556     QVERIFY( LC_SESSION( mEngine )->iRemotePlayer->iRect.iTl.iX != 0);
       
   557     
       
   558     mEngine->d->setContentAreas( shared, received );
       
   559     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_SetLcWindowRectL ) );
       
   560     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer->iRect.iTl.iX == 0);
       
   561     QVERIFY( LC_SESSION( mEngine )->iRemotePlayer->iRect.iTl.iX == 0);
       
   562     
       
   563     lcutStub_LcSession_reset();
       
   564     lcutStub_LcPlayer_reset();
       
   565     
       
   566     mEngine->d->setContentAreas( shared, received );
       
   567     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   568     
       
   569     lcutStub_LcSession_reset();
       
   570     lcutStub_LcPlayer_reset();
       
   571     
       
   572     shared.setHeight(100);
       
   573     received.setHeight(100);
       
   574     
       
   575     mEngine->d->setContentAreas( shared, received );
       
   576     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_SetLcWindowRectL ) );
       
   577     
       
   578     lcutStub_LcSession_reset();
       
   579     lcutStub_LcPlayer_reset();
       
   580     
       
   581     delete LC_SESSION( mEngine )->iLocalPlayer;
       
   582     LC_SESSION( mEngine )->iLocalPlayer = 0;
       
   583     delete LC_SESSION( mEngine )->iRemotePlayer;
       
   584     LC_SESSION( mEngine )->iRemotePlayer = 0;
       
   585     
       
   586     mEngine->d->setContentAreas( shared, received );
       
   587     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   588 }
       
   589 
       
   590 void UT_LcUiEngine::testSetOrientation()
       
   591 {
       
   592     bool ok( false );
       
   593 
       
   594     //1. setting landscape
       
   595     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer );
       
   596     QVERIFY( LC_SESSION( mEngine )->iRemotePlayer );
       
   597     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer->iOrientation == MLcWindow::EPortrait );
       
   598     QVERIFY( LC_SESSION( mEngine )->iRemotePlayer->iOrientation == MLcWindow::EPortrait );
       
   599 
       
   600     ok = mEngine->d->setOrientation( Qt::Horizontal );
       
   601     QVERIFY( ok );
       
   602     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_SetLcWindowOrientationL ) );
       
   603     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer->iOrientation == MLcWindow::ELandscape );
       
   604     QVERIFY( LC_SESSION( mEngine )->iRemotePlayer->iOrientation == MLcWindow::ELandscape );
       
   605 
       
   606     
       
   607     //2. setting portrait
       
   608     lcutStub_LcPlayer_reset();
       
   609     ok = mEngine->d->setOrientation( Qt::Vertical );
       
   610     QVERIFY( ok );
       
   611     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_SetLcWindowOrientationL ) );
       
   612     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer->iOrientation == MLcWindow::EPortrait );
       
   613     QVERIFY( LC_SESSION( mEngine )->iRemotePlayer->iOrientation == MLcWindow::EPortrait );
       
   614     
       
   615     //3. setting layout failed
       
   616     // Leave
       
   617     lcutStub_LcEngine_setFailure( -1 );
       
   618     lcutStub_LcPlayer_reset();
       
   619     ok = mEngine->d->setOrientation( Qt::Horizontal );
       
   620     QVERIFY( !ok );
       
   621     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   622     
       
   623     //4. setting layout with no players
       
   624     lcutStub_LcEngine_reset();
       
   625     lcutStub_LcPlayer_reset();
       
   626     delete LC_SESSION( mEngine )->iLocalPlayer;
       
   627     LC_SESSION( mEngine )->iLocalPlayer = 0;
       
   628     delete LC_SESSION( mEngine )->iRemotePlayer;
       
   629     LC_SESSION( mEngine )->iRemotePlayer = 0;
       
   630     
       
   631     ok = mEngine->d->setOrientation( Qt::Horizontal );
       
   632     QVERIFY( ok );
       
   633     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );    
       
   634 }
       
   635 
       
   636 void UT_LcUiEngine::testToggleMute()
       
   637 {
       
   638     QSignalSpy mutedSpy(mEngine, SIGNAL(muted()));
       
   639     QSignalSpy unmutedSpy(mEngine, SIGNAL(unmuted()));
       
   640     
       
   641     
       
   642     // Leave from isMuted
       
   643     mEngine->d->toggleMute();
       
   644     QVERIFY( mEngine->d->isMuted() );
       
   645     lcutStub_LcEngine_setFailure( -2 );
       
   646     QVERIFY( !mEngine->d->isMuted() );
       
   647     
       
   648     // No leave
       
   649     lcutStub_LcEngine_reset();
       
   650     lcutStub_LcSession_reset();
       
   651     lcutStub_LcPlayer_reset();
       
   652     mutedSpy.clear();
       
   653     unmutedSpy.clear();
       
   654     
       
   655     mEngine->d->toggleMute();
       
   656     QVERIFY( !mEngine->d->isMuted() );
       
   657     mutedSpy.clear();
       
   658     unmutedSpy.clear();
       
   659     
       
   660     mEngine->d->toggleMute();
       
   661     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_MuteLcMicL ) );
       
   662     QVERIFY( mEngine->d->isMuted() );
       
   663     QCOMPARE(mutedSpy.count(), 1); // make sure the signal was emitted exactly one time
       
   664     lcutStub_LcSession_reset();
       
   665     lcutStub_LcPlayer_reset();
       
   666     mutedSpy.clear();
       
   667     unmutedSpy.clear();
       
   668     
       
   669     mEngine->d->toggleMute();
       
   670     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_MuteLcMicL ) );
       
   671     QVERIFY( !mEngine->d->isMuted() );
       
   672     QCOMPARE(unmutedSpy.count(), 1); // make sure the signal was emitted exactly one time
       
   673     
       
   674     lcutStub_LcSession_reset();
       
   675     lcutStub_LcPlayer_reset();
       
   676     mutedSpy.clear();
       
   677     unmutedSpy.clear();
       
   678     
       
   679     // test async mute
       
   680     lcutStub_LcPlayer_asyncCompletion( true );
       
   681     mEngine->d->toggleMute();
       
   682     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_MuteLcMicL ) );
       
   683     QVERIFY( mEngine->d->isMuted() );
       
   684     QVERIFY( mEngine->d->mBlocked );
       
   685     QVERIFY( mEngine->d->mPendingAction == "muted" );
       
   686     
       
   687     // nothing yet signaled as completion is pending
       
   688     QCOMPARE(mutedSpy.count(), 0);
       
   689     QCOMPARE(unmutedSpy.count(), 0);
       
   690     
       
   691     
       
   692     lcutStub_LcPlayer_asyncCompletion( false );
       
   693 }
       
   694 
       
   695 void UT_LcUiEngine::testToggleSpeaker()
       
   696 {
       
   697     QSignalSpy speakerEnabledSpy(mEngine, SIGNAL(speakerEnabled()));
       
   698     QSignalSpy speakerDisabledSpy(mEngine, SIGNAL(speakerDisabled()));
       
   699 
       
   700     QVERIFY( !mEngine->d->isSpeakerOn() );
       
   701 
       
   702     mEngine->d->toggleSpeaker();
       
   703     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_EnableLcLoudspeakerL ) );
       
   704     QVERIFY( mEngine->d->isSpeakerOn() );
       
   705     QCOMPARE(speakerEnabledSpy.count(), 1);
       
   706 
       
   707     
       
   708     lcutStub_LcSession_reset();
       
   709     lcutStub_LcPlayer_reset();
       
   710     speakerEnabledSpy.clear();
       
   711     speakerDisabledSpy.clear();
       
   712     
       
   713     mEngine->d->toggleSpeaker();
       
   714     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_EnableLcLoudspeakerL ) );
       
   715     QVERIFY( !mEngine->d->isSpeakerOn() );
       
   716     QCOMPARE(speakerDisabledSpy.count(), 1);
       
   717     
       
   718     lcutStub_LcSession_reset();
       
   719     lcutStub_LcPlayer_reset();
       
   720     speakerEnabledSpy.clear();
       
   721     speakerDisabledSpy.clear();
       
   722     
       
   723     // test asynch speaker functionality.
       
   724     
       
   725     lcutStub_LcPlayer_asyncCompletion( true );
       
   726     mEngine->d->toggleSpeaker();
       
   727     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_EnableLcLoudspeakerL ) );
       
   728     QVERIFY( mEngine->d->isSpeakerOn() );
       
   729     QVERIFY( mEngine->d->mBlocked );
       
   730     QVERIFY( mEngine->d->mPendingAction == "speakerEnabled" );
       
   731     
       
   732     // nothing yet signaled as completion is pending
       
   733     QCOMPARE(speakerEnabledSpy.count(), 0);
       
   734     QCOMPARE(speakerDisabledSpy.count(), 0);
       
   735     
       
   736     lcutStub_LcPlayer_asyncCompletion( false );
       
   737 }
       
   738 
       
   739 void UT_LcUiEngine::testToggleDisableCamera()
       
   740 {   
       
   741     QSignalSpy enabledSpy(mEngine, SIGNAL(cameraEnabled()));
       
   742     QSignalSpy disabledSpy(mEngine, SIGNAL(cameraDisabled()));
       
   743 
       
   744     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer );
       
   745     LC_SESSION( mEngine )->iLocalPlayer->iPlaying = ETrue;    
       
   746     LC_SESSION( mEngine )->iRemotePlayer->iState = MLcVideoPlayer::EPlaying;
       
   747     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer->iPlaying );
       
   748         
       
   749     mEngine->d->toggleDisableCamera();
       
   750     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_LcPauseL ) );
       
   751     QVERIFY( !LC_SESSION( mEngine )->iLocalPlayer->iPlaying );
       
   752     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer->iState == MLcVideoPlayer::EPaused );
       
   753     QCOMPARE(enabledSpy.count(), 0);
       
   754     QCOMPARE(disabledSpy.count(), 1);
       
   755 
       
   756     mEngine->d->toggleDisableCamera();
       
   757     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_LcPlayL ) );   
       
   758     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer->iPlaying );
       
   759     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer->iState == MLcVideoPlayer::EPlaying );
       
   760     QCOMPARE(enabledSpy.count(), 1);
       
   761     QCOMPARE(disabledSpy.count(), 1);
       
   762 }
       
   763 
       
   764 void UT_LcUiEngine::testToggleCamera()
       
   765 {
       
   766     // Leave
       
   767     lcutStub_LcEngine_setFailure( -1 );
       
   768     mEngine->d->toggleCamera();
       
   769     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   770     
       
   771     // No leave
       
   772     lcutStub_LcEngine_reset();
       
   773     mEngine->d->toggleCamera();
       
   774     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_ToggleLcCameraL ) );
       
   775 }
       
   776 
       
   777 void UT_LcUiEngine::testStartReceiving()
       
   778 {
       
   779     // mAcceptQuery not set, mWaitingNote not set
       
   780     mAcceptQuery->show();
       
   781     mWaitingNote->hide();
       
   782     mEngine->d->startReceiving();
       
   783     QVERIFY( mAcceptQuery->isVisible() );
       
   784     QVERIFY( !mWaitingNote->isVisible() );
       
   785     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_establishSession ) );    
       
   786     
       
   787     // mAcceptQuery set, mWaitingNote not set
       
   788     lcutStub_LcSession_reset();
       
   789     mEngine->d->mAcceptQuery = mAcceptQuery;
       
   790     mEngine->d->startReceiving();
       
   791     QVERIFY( !mAcceptQuery->isVisible() );
       
   792     QVERIFY( !mWaitingNote->isVisible() );
       
   793     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_establishSession ) );
       
   794     
       
   795     // mWaitingNote set, but the engine does not support the feature
       
   796     lcutStub_LcSession_reset();
       
   797     mEngine->d->mWaitingNote = mWaitingNote;
       
   798     mEngine->d->startReceiving();
       
   799     QVERIFY( !mAcceptQuery->isVisible() );
       
   800     QVERIFY( !mWaitingNote->isVisible() );
       
   801     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_establishSession ) );    
       
   802     
       
   803     // mWaitingNote set and the engine supports the feature
       
   804     lcutStub_LcSession_reset();
       
   805     lcutStub_LcEngine_setLcFeatureSupported( true );
       
   806     mEngine->d->startReceiving();
       
   807     QVERIFY( !mAcceptQuery->isVisible() );
       
   808     QVERIFY( mWaitingNote->isVisible() );
       
   809     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_establishSession ) );
       
   810 }
       
   811 
       
   812 void UT_LcUiEngine::testStartPlayback()
       
   813 {   
       
   814     mEngine->d->startPlayback();
       
   815     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_NoCall ) );
       
   816     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_EnableLcWindowL,0 ) );
       
   817     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_EnableLcWindowL,1 ) );
       
   818     
       
   819     lcutStub_LcSession_reset();
       
   820     lcutStub_LcPlayer_reset();
       
   821     
       
   822     delete LC_SESSION( mEngine )->iLocalPlayer;
       
   823     LC_SESSION( mEngine )->iLocalPlayer = 0;
       
   824     mEngine->d->startPlayback();
       
   825     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_NoCall ) );
       
   826     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_EnableLcWindowL,0 ) );
       
   827     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall,1 ) );
       
   828     
       
   829     lcutStub_LcSession_reset();
       
   830     lcutStub_LcPlayer_reset();
       
   831     
       
   832     delete LC_SESSION( mEngine )->iRemotePlayer;
       
   833     LC_SESSION( mEngine )->iRemotePlayer = 0;
       
   834     
       
   835     mEngine->d->startPlayback();
       
   836     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_NoCall ) );
       
   837     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall,0 ) );
       
   838     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall,1 ) );
       
   839 }
       
   840 
       
   841 void UT_LcUiEngine::testStop()
       
   842 {
       
   843     // Ensure that in MLcSession::EClosing state, "stopped" signal won't be emited
       
   844     // Check also that session duration timer is stopped
       
   845     LC_SESSION( mEngine )->iState = MLcSession::EClosing;
       
   846     mEngine->d->startSessionDurationTimer();
       
   847     QVERIFY( mEngine->d->mSessionDurationTimerId != 0 );
       
   848     QSignalSpy spy(mEngine, SIGNAL(stopped()));
       
   849     mEngine->d->mActivityManager->enableActivitySimulation(true);
       
   850     mEngine->d->stop();
       
   851     QVERIFY( !mEngine->d->mActivityManager->isActivitySimulationEnabled() );
       
   852     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_terminateSession ) );
       
   853     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   854     QCOMPARE( spy.count(), 0 );
       
   855     QVERIFY( mEngine->d->mSessionDurationTimerId == 0 );
       
   856 
       
   857     // Ensure that any other state than MLcSession::EClosing, will cause emition
       
   858     // of "stopped" signal
       
   859     lcutStub_LcSession_reset();
       
   860     lcutStub_LcPlayer_reset();
       
   861     LC_SESSION( mEngine )->iState = MLcSession::EInitialized;
       
   862     mEngine->d->stop();
       
   863     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_terminateSession ) );
       
   864     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   865     QCOMPARE( spy.count(), 1 );
       
   866 }
       
   867 
       
   868 void UT_LcUiEngine::testSetViewLayout()
       
   869 {
       
   870     QVERIFY( LC_SESSION( mEngine )->iLocalPlayer );
       
   871     QVERIFY( LC_SESSION( mEngine )->iRemotePlayer );
       
   872     QVERIFY( !LC_SESSION( mEngine )->iLocalPlayer->iPlaying );
       
   873     QVERIFY( !LC_SESSION( mEngine )->iRemotePlayer->iPlaying );
       
   874     LC_SESSION( mEngine )->iRemotePlayer->iState = MLcVideoPlayer::EPaused;
       
   875     QVERIFY( !mEngine->d->usingVideoTelephoneEngine() );
       
   876     
       
   877     mEngine->d->setViewLayout();
       
   878     QVERIFY( mEngine->d->viewLayout() == Lc_IdleViewLayout );
       
   879     
       
   880     LC_SESSION( mEngine )->iLocalPlayer->iPlaying = ETrue;
       
   881     
       
   882     mEngine->d->setViewLayout();
       
   883     QVERIFY( mEngine->d->viewLayout() == Lc_SharedViewLayout );
       
   884     
       
   885     LC_SESSION( mEngine )->iLocalPlayer->iPlaying = EFalse;
       
   886     LC_SESSION( mEngine )->iRemotePlayer->iState = MLcVideoPlayer::EPlaying;
       
   887     
       
   888     mEngine->d->setViewLayout();
       
   889     QVERIFY( mEngine->d->viewLayout() == Lc_ReceivedViewLayout );
       
   890     
       
   891     LC_SESSION( mEngine )->iLocalPlayer->iPlaying = ETrue;
       
   892     LC_SESSION( mEngine )->iRemotePlayer->iState = MLcVideoPlayer::EPlaying;
       
   893     
       
   894     mEngine->d->setViewLayout();
       
   895     QVERIFY( mEngine->d->viewLayout() == Lc_TwowayViewLayout );
       
   896     
       
   897     delete LC_SESSION( mEngine )->iLocalPlayer;
       
   898     LC_SESSION( mEngine )->iLocalPlayer = 0;
       
   899     
       
   900     mEngine->d->setViewLayout();
       
   901     QVERIFY( mEngine->d->viewLayout() == Lc_ReceivedOnlyViewLayout );
       
   902     
       
   903     delete LC_SESSION( mEngine )->iRemotePlayer;
       
   904     LC_SESSION( mEngine )->iRemotePlayer = 0;
       
   905     
       
   906     mEngine->d->setViewLayout();
       
   907     QVERIFY( mEngine->d->viewLayout() == Lc_IdleViewLayout );
       
   908     
       
   909     mEngine->d->mEngineName = lcutVideotelephonyApp;
       
   910     QVERIFY( mEngine->d->usingVideoTelephoneEngine() );
       
   911     
       
   912     mEngine->d->setViewLayout();
       
   913     QVERIFY( mEngine->d->viewLayout() == Lc_AllInOneViewLayout );   
       
   914 }
       
   915 
       
   916 void UT_LcUiEngine::testHideNotes()
       
   917 {
       
   918     // Notes not set
       
   919     mEngine->d->hideNotes( true );
       
   920     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_NoCall ) );
       
   921     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   922     QVERIFY( mInvitingNote->isVisible() );
       
   923     QVERIFY( mWaitingNote->isVisible() );
       
   924     QVERIFY( mAcceptQuery->isVisible() );
       
   925     QVERIFY( mRecipientQuery->isVisible() );    
       
   926     
       
   927     // Notes set, hide all
       
   928     mEngine->d->setUiComponents( mInvitingNote, mWaitingNote,
       
   929                               mAcceptQuery, mRecipientQuery,mShareOwnVideoQuery );
       
   930     mEngine->d->hideNotes( true );
       
   931     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_NoCall ) );
       
   932     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   933     QVERIFY( !mInvitingNote->isVisible() );
       
   934     QVERIFY( !mWaitingNote->isVisible() );
       
   935     QVERIFY( !mAcceptQuery->isVisible() );
       
   936     QVERIFY( !mRecipientQuery->isVisible() );
       
   937 
       
   938     // Notes not set, do not hide waiting note
       
   939     mInvitingNote->show();
       
   940     mWaitingNote->show();
       
   941     mAcceptQuery->show();
       
   942     mRecipientQuery->show();       
       
   943     mEngine->d->hideNotes( false );
       
   944     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_NoCall ) );
       
   945     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   946     QVERIFY( !mInvitingNote->isVisible() );
       
   947     QVERIFY( mWaitingNote->isVisible() );
       
   948     QVERIFY( !mAcceptQuery->isVisible() );
       
   949     QVERIFY( !mRecipientQuery->isVisible() ); 
       
   950 }
       
   951 
       
   952 void UT_LcUiEngine::testZoom()
       
   953 {
       
   954     LcControlValues zoomData;
       
   955     
       
   956     // Leave
       
   957     lcutStub_LcEngine_setFailure( -1 );
       
   958     mEngine->d->zoom( 1 );
       
   959     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   960     QCOMPARE( mEngine->d->zoomValues( zoomData ), -1 );
       
   961     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_NoCall ) );
       
   962     
       
   963     // No leave
       
   964     lcutStub_LcEngine_reset();
       
   965     lcutStub_LcPlayer_reset();
       
   966     QCOMPARE( mEngine->d->zoomValues( zoomData ), 0 );
       
   967     mEngine->d->zoom( 2 );
       
   968     mEngine->d->zoom( 1 );
       
   969     mEngine->d->zoom( 3 );
       
   970     
       
   971     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_SetLcZoomValueL, 0 ) );
       
   972     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_SetLcZoomValueL, 1 ) );
       
   973     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcPlayer_SetLcZoomValueL, 2 ) );
       
   974     QVERIFY( lcutStub_LcPlayer_expectCall( lcutStub_LcSession_NoCall, 3 ) );
       
   975 }
       
   976 
       
   977 void UT_LcUiEngine::testBlockUi()
       
   978 {
       
   979     QSignalSpy blockedSpy(mEngine, SIGNAL(blocked()));
       
   980     QSignalSpy unblockedSpy(mEngine, SIGNAL(unblocked()));
       
   981     QSignalSpy mutedSpy(mEngine, SIGNAL(muted()));
       
   982     
       
   983     mEngine->d->BlockUi( ETrue );
       
   984 
       
   985     QCOMPARE(blockedSpy.count(), 1);
       
   986     QCOMPARE(unblockedSpy.count(), 0);
       
   987     QCOMPARE(mutedSpy.count(), 0);
       
   988     
       
   989     // no pending action once unblocked
       
   990     blockedSpy.clear();
       
   991     
       
   992     mEngine->d->BlockUi( EFalse );
       
   993     QCOMPARE(blockedSpy.count(), 0);
       
   994     QCOMPARE(unblockedSpy.count(), 1);
       
   995     QCOMPARE(mutedSpy.count(), 0);
       
   996     
       
   997     
       
   998     // pending action once unblocked
       
   999     unblockedSpy.clear();
       
  1000     mEngine->d->setPendingAction( "muted" );
       
  1001     mEngine->d->BlockUi( EFalse );
       
  1002     QCOMPARE(blockedSpy.count(), 0);
       
  1003     QCOMPARE(unblockedSpy.count(), 1);
       
  1004     QCOMPARE(mutedSpy.count(), 1);
       
  1005     QVERIFY( mEngine->d->mPendingAction.isEmpty() );  
       
  1006 }
       
  1007 
       
  1008 void UT_LcUiEngine::testCloseTimer()
       
  1009 {
       
  1010     // Try to cancel without timer
       
  1011     mEngine->d->cancelCloseTimer();
       
  1012     QVERIFY( !mEngine->d->mCloseTimer );
       
  1013     
       
  1014     // Try to cancel without timer being active
       
  1015     mEngine->d->startCloseTimer();
       
  1016     QVERIFY( mEngine->d->mCloseTimer );
       
  1017     QVERIFY( mEngine->d->mCloseTimer->isActive() );
       
  1018     mEngine->d->mCloseTimer->stop();
       
  1019     QVERIFY( !mEngine->d->mCloseTimer->isActive() );
       
  1020     mEngine->d->cancelCloseTimer();
       
  1021     QVERIFY( mEngine->d->mCloseTimer );
       
  1022     QVERIFY( !mEngine->d->mCloseTimer->isActive() );
       
  1023     
       
  1024     // Cancel an active timer
       
  1025     mEngine->d->startCloseTimer();
       
  1026     QVERIFY( mEngine->d->mCloseTimer );
       
  1027     QVERIFY( mEngine->d->mCloseTimer->isActive() );
       
  1028     mEngine->d->cancelCloseTimer();
       
  1029     QVERIFY( mEngine->d->mCloseTimer );
       
  1030     QVERIFY( !mEngine->d->mCloseTimer->isActive() );    
       
  1031 }
       
  1032 
       
  1033 
       
  1034 void UT_LcUiEngine::testfullScreenMode()
       
  1035 {
       
  1036     QVERIFY( !mEngine->d->fullScreenMode() );
       
  1037 }
       
  1038 
       
  1039 
       
  1040 void UT_LcUiEngine::testsetFullScreenMode()
       
  1041 {
       
  1042     mEngine->d->setFullScreenMode(true);
       
  1043     QVERIFY( mEngine->d->fullScreenMode() );
       
  1044 }
       
  1045 
       
  1046 void UT_LcUiEngine::testTimerEvent()
       
  1047 {
       
  1048     mEngine->d->startSessionDurationTimer();
       
  1049     QSignalSpy spy(mEngine, SIGNAL(sessionDurationChanged(const QString &)));
       
  1050     
       
  1051     QTimerEvent wrongTimerEvent(9999);
       
  1052     mEngine->d->timerEvent(&wrongTimerEvent);
       
  1053     QVERIFY( spy.count() == 0 );
       
  1054     
       
  1055     QTimerEvent correctTimerEvent(mEngine->d->mSessionDurationTimerId);
       
  1056     mEngine->d->timerEvent(&correctTimerEvent);
       
  1057     QVERIFY( spy.count() == 1 );
       
  1058     QVERIFY( spy.at(0).count() == 1 ); // one arg which is duration as string
       
  1059     QTime currDuration = QTime::fromString(spy.at(0).at(0).toString());
       
  1060     QVERIFY( currDuration.isValid() );
       
  1061 }
       
  1062 
       
  1063 void UT_LcUiEngine::testFillRemoteInfo()
       
  1064 {
       
  1065     QSignalSpy recipientSpy(mEngine, SIGNAL(recipientChanged(const QString &)));
       
  1066     QSignalSpy numberSpy(mEngine, SIGNAL(phoneNumberChanged(const QString &)));
       
  1067     
       
  1068     // test filling without signal emitting
       
  1069     
       
  1070     // number and name changed 
       
  1071     mEngine->d->mRecipient = "";
       
  1072     mEngine->d->mPhoneNumber = "";
       
  1073     mEngine->d->fillRemoteInfo( false );
       
  1074     QVERIFY( mEngine->d->mRecipient.length() > 0 );
       
  1075     QVERIFY( mEngine->d->mPhoneNumber.length() > 0 );
       
  1076     QVERIFY( recipientSpy.count() == 0 );
       
  1077     QVERIFY( numberSpy.count() == 0 );
       
  1078     
       
  1079     // nothing changed
       
  1080     QString prevRecipient = mEngine->d->mRecipient;
       
  1081     QString prevNumber = mEngine->d->mPhoneNumber;
       
  1082     mEngine->d->fillRemoteInfo( false );
       
  1083     QVERIFY( mEngine->d->mRecipient == prevRecipient );
       
  1084     QVERIFY( mEngine->d->mPhoneNumber == prevNumber );
       
  1085     QVERIFY( recipientSpy.count() == 0 );
       
  1086     QVERIFY( numberSpy.count() == 0 );
       
  1087     
       
  1088     // test filling with signal emitting
       
  1089     
       
  1090     // number and name changed
       
  1091     mEngine->d->mRecipient = "";
       
  1092     mEngine->d->mPhoneNumber = "";
       
  1093     mEngine->d->fillRemoteInfo( true );
       
  1094     QVERIFY( mEngine->d->mRecipient == prevRecipient );
       
  1095     QVERIFY( mEngine->d->mPhoneNumber == prevNumber );
       
  1096     QVERIFY( recipientSpy.count() == 1 );
       
  1097     QVERIFY( numberSpy.count() == 1 );
       
  1098     
       
  1099     // state is opened and name not found and no number, unknown name is used
       
  1100     LC_SESSION( mEngine )->iState = MLcSession::EOpen;
       
  1101     delete LC_SESSION( mEngine )->iRemoteDisplayName;
       
  1102     LC_SESSION( mEngine )->iRemoteDisplayName = NULL;
       
  1103     LC_SESSION( mEngine )->iRemoteDisplayName = KNullDesC().AllocL();
       
  1104     delete LC_SESSION( mEngine )->iRemoteDetails;
       
  1105     LC_SESSION( mEngine )->iRemoteDetails = NULL;
       
  1106     LC_SESSION( mEngine )->iRemoteDetails = KNullDesC().AllocL();
       
  1107     mEngine->d->mPhoneNumber = "";
       
  1108     mEngine->d->fillRemoteInfo( true );
       
  1109     QVERIFY( mEngine->d->mRecipient == hbTrId("txt_vt_custom_unknown_number") );
       
  1110     QVERIFY( mEngine->d->mPhoneNumber.isEmpty() );
       
  1111     QVERIFY( recipientSpy.count() == 2 );
       
  1112     QVERIFY( numberSpy.count() == 1 );
       
  1113     
       
  1114     // name not found but number exists, number is used at opened state as recipient
       
  1115     mEngine->d->mRecipient = "";
       
  1116     mEngine->d->mPhoneNumber = "";
       
  1117     delete LC_SESSION( mEngine )->iRemoteDetails;
       
  1118     LC_SESSION( mEngine )->iRemoteDetails = NULL;
       
  1119     LC_SESSION( mEngine )->iRemoteDetails = _L("123445").AllocL();
       
  1120     mEngine->d->fillRemoteInfo( true );
       
  1121     QVERIFY( mEngine->d->mRecipient == "123445" );
       
  1122     QVERIFY( mEngine->d->mPhoneNumber == "123445" );
       
  1123     QVERIFY( recipientSpy.count() == 3 );
       
  1124     QVERIFY( numberSpy.count() == 2 );
       
  1125     
       
  1126 }
       
  1127 
       
  1128 void UT_LcUiEngine::testUpdateSession()
       
  1129 {
       
  1130     mEngine->d->updateSession();
       
  1131     QVERIFY( lcutStub_LcSession_expectCall( lcutStub_LcSession_updateSession ) );
       
  1132 }
       
  1133 
       
  1134 void UT_LcUiEngine::testIsLocalPlayerPlaying()
       
  1135 {
       
  1136     // Not playing
       
  1137     QVERIFY( !mEngine->d->isLocalPlayerPlaying() );
       
  1138 
       
  1139     // Playing
       
  1140     LC_SESSION( mEngine )->iLocalPlayer->LcPlayL();
       
  1141     QVERIFY( mEngine->d->isLocalPlayerPlaying() );
       
  1142 }
       
  1143 
       
  1144 void UT_LcUiEngine::testIsRemotePlayerPlaying()
       
  1145 {
       
  1146     // Not playing
       
  1147     QVERIFY( !mEngine->d->isRemotePlayerPlaying() );
       
  1148     
       
  1149     // Playing
       
  1150     LC_SESSION( mEngine )->iRemotePlayer->LcPlayL();
       
  1151     QVERIFY( mEngine->d->isRemotePlayerPlaying() );
       
  1152 }
       
  1153 
       
  1154 void UT_LcUiEngine::testMinimized()
       
  1155 {  
       
  1156     mEngine->minimize();    
       
  1157     QVERIFY( mEngine->isMinimized() );
       
  1158     mEngine->minimize(); // Doing nothing
       
  1159     QVERIFY( mEngine->isMinimized() );
       
  1160 }
       
  1161 
       
  1162 void UT_LcUiEngine::testMaximized()
       
  1163 {    
       
  1164     mEngine->maximize();    
       
  1165     QVERIFY(mEngine->isMaximized() ); 
       
  1166     mEngine->maximize(); // Doing nothing
       
  1167     QVERIFY(mEngine->isMaximized() );
       
  1168 }
       
  1169 
       
  1170 void UT_LcUiEngine::testIsMinimized()
       
  1171 {
       
  1172     mEngine->minimize();
       
  1173     QVERIFY( mEngine->isMinimized() );    
       
  1174 }
       
  1175 
       
  1176 void UT_LcUiEngine::testHandleForegroundStatus()
       
  1177 {
       
  1178     QtHighwayStubHelper::reset();
       
  1179     
       
  1180     // First time to foreground, engine is not set to foreground until viewReady signal
       
  1181     // or simulation timeout occurs
       
  1182     HbView currView;
       
  1183     mEngine->d->setCurrentView(&currView);
       
  1184     QVERIFY( mEngine->d->mViewReadySimulationTimerId == 0 );
       
  1185     QVERIFY( !mEngine->d->mActivityManager->isActivitySimulationEnabled() );
       
  1186     mEngine->d->HandleForegroundStatus(ETrue);
       
  1187     QVERIFY( mEngine->d->mActivityManager->isActivitySimulationEnabled() );
       
  1188     QVERIFY( !mEngine->d->session().IsBackgroundStartup() ); // Stub returns fg status in this
       
  1189     QVERIFY( !QtHighwayStubHelper::isAtBg() );
       
  1190     QVERIFY( mEngine->d->mViewReadySimulationTimerId != 0 );
       
  1191     //  Simulate timeout
       
  1192     QTimerEvent viewReadySimulationEvent(mEngine->d->mViewReadySimulationTimerId);
       
  1193     mEngine->d->timerEvent(&viewReadySimulationEvent);
       
  1194     QVERIFY( mEngine->d->session().IsBackgroundStartup() ); // Stub returns fg status in this
       
  1195     QVERIFY( !mEngine->d->mFirstForegroundSwitch );
       
  1196     QVERIFY( mEngine->d->mViewReadySimulationTimerId == 0 );
       
  1197        
       
  1198     // Bg switch
       
  1199     QtHighwayStubHelper::reset();
       
  1200     QVERIFY( mEngine->d->mActivityManager->isActivitySimulationEnabled() );
       
  1201     mEngine->d->HandleForegroundStatus(EFalse);
       
  1202     QVERIFY( !mEngine->d->mActivityManager->isActivitySimulationEnabled() );
       
  1203     QVERIFY( QtHighwayStubHelper::isAtBg() );
       
  1204     QVERIFY( !mEngine->d->session().IsBackgroundStartup() ); // Stub returns fg status in this
       
  1205 
       
  1206 }
       
  1207 
       
  1208 
       
  1209 void UT_LcUiEngine::testSendDialTone()
       
  1210 {
       
  1211     //Dumy test: Ensure Conversion does not cause any problem.
       
  1212     QVERIFY( mEngine->d->SendDialTone('3') );
       
  1213 }
       
  1214 
       
  1215