videoplayback/videoplaybackview/tsrc/testvideodisplayhandler/src/testvideodisplayhandler.cpp
author hgs
Mon, 23 Aug 2010 14:27:29 +0300
changeset 55 4bfa887905cf
parent 50 21fe8338c6bf
child 66 adb51f74b890
permissions -rw-r--r--
201033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44
hgs
parents:
diff changeset
     1
/**
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:   tester for methods in Video Display Handler
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <e32err.h>
hgs
parents:
diff changeset
    19
#include <w32std.h>
hgs
parents:
diff changeset
    20
#include <eikenv.h>
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
#include <hbapplication.h>
hgs
parents:
diff changeset
    23
#include <hbinstance.h>
hgs
parents:
diff changeset
    24
#include <QDebug>
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
#include <mpxplaybackutility.h>
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
#include "testvideodisplayhandler.h"
hgs
parents:
diff changeset
    29
#include "../stub/inc/videobaseplaybackview.h"
hgs
parents:
diff changeset
    30
#include "../stub/inc/videoplaybackviewfiledetails.h"
hgs
parents:
diff changeset
    31
#include "mpxvideoviewwrapper.h"
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
#define private public
55
hgs
parents: 50
diff changeset
    34
#include "videoplaybackdisplayhandler.h"
44
hgs
parents:
diff changeset
    35
#undef private
hgs
parents:
diff changeset
    36
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    39
// main
hgs
parents:
diff changeset
    40
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    41
//
hgs
parents:
diff changeset
    42
int main(int argc, char *argv[])
hgs
parents:
diff changeset
    43
{
hgs
parents:
diff changeset
    44
    HbApplication app(argc, argv);
hgs
parents:
diff changeset
    45
    HbMainWindow window;
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
    TestVideoDisplayHandler tv;
hgs
parents:
diff changeset
    48
hgs
parents:
diff changeset
    49
    char *pass[3];
hgs
parents:
diff changeset
    50
    pass[0] = argv[0];
hgs
parents:
diff changeset
    51
    pass[1] = "-o";
hgs
parents:
diff changeset
    52
    pass[2] = "c:\\data\\testvideodisplayhandler.txt";
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
    int res = QTest::qExec(&tv, 3, pass);
hgs
parents:
diff changeset
    55
hgs
parents:
diff changeset
    56
    return res;
hgs
parents:
diff changeset
    57
}
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
hgs
parents:
diff changeset
    60
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    61
// init
hgs
parents:
diff changeset
    62
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    63
//
hgs
parents:
diff changeset
    64
void TestVideoDisplayHandler::init()
hgs
parents:
diff changeset
    65
{
hgs
parents:
diff changeset
    66
    mPlaybackUtility = MMPXPlaybackUtility::UtilityL( KPbModeDefault );
hgs
parents:
diff changeset
    67
55
hgs
parents: 50
diff changeset
    68
    mBaseVideoView    = new VideoBasePlaybackView();
hgs
parents: 50
diff changeset
    69
    mVideoViewWrapper = CMPXVideoViewWrapper::NewL( mBaseVideoView );
44
hgs
parents:
diff changeset
    70
55
hgs
parents: 50
diff changeset
    71
    mDispHdlr = CVideoPlaybackDisplayHandler::NewL(mPlaybackUtility, mVideoViewWrapper);
44
hgs
parents:
diff changeset
    72
}
hgs
parents:
diff changeset
    73
hgs
parents:
diff changeset
    74
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    75
// cleanup
hgs
parents:
diff changeset
    76
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    77
//
hgs
parents:
diff changeset
    78
void TestVideoDisplayHandler::cleanup()
hgs
parents:
diff changeset
    79
{
hgs
parents:
diff changeset
    80
    if ( mPlaybackUtility )
hgs
parents:
diff changeset
    81
    {
hgs
parents:
diff changeset
    82
        mPlaybackUtility->Close();
hgs
parents:
diff changeset
    83
        mPlaybackUtility = NULL;
hgs
parents:
diff changeset
    84
    }
hgs
parents:
diff changeset
    85
hgs
parents:
diff changeset
    86
    delete mDispHdlr;
hgs
parents:
diff changeset
    87
    mDispHdlr = NULL;
hgs
parents:
diff changeset
    88
hgs
parents:
diff changeset
    89
    delete mVideoViewWrapper;
hgs
parents:
diff changeset
    90
    mVideoViewWrapper = NULL;
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
    delete mBaseVideoView;
hgs
parents:
diff changeset
    93
    mBaseVideoView = NULL;
hgs
parents:
diff changeset
    94
}
hgs
parents:
diff changeset
    95
hgs
parents:
diff changeset
    96
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    97
// setup
hgs
parents:
diff changeset
    98
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    99
//
hgs
parents:
diff changeset
   100
void TestVideoDisplayHandler::setup()
hgs
parents:
diff changeset
   101
{
hgs
parents:
diff changeset
   102
    init();
hgs
parents:
diff changeset
   103
hgs
parents:
diff changeset
   104
    RWindow *window = mBaseVideoView->getWindow();
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
    TRect displayRect = TRect( window->Position().iX,
hgs
parents:
diff changeset
   107
                               window->Position().iY,
hgs
parents:
diff changeset
   108
                               window->Position().iX + window->Size().iWidth,
hgs
parents:
diff changeset
   109
                               window->Position().iY + window->Size().iHeight );
hgs
parents:
diff changeset
   110
hgs
parents:
diff changeset
   111
    mDispHdlr->CreateDisplayWindowL( CCoeEnv::Static()->WsSession(),
hgs
parents:
diff changeset
   112
                                     *(CCoeEnv::Static()->ScreenDevice()),
hgs
parents:
diff changeset
   113
                                     *window,
hgs
parents:
diff changeset
   114
                                     displayRect);
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
    QCOMPARE( mDispHdlr->iWindowRect, displayRect);
hgs
parents:
diff changeset
   117
hgs
parents:
diff changeset
   118
}
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
hgs
parents:
diff changeset
   121
void TestVideoDisplayHandler::testCreateDisplayWindowL()
hgs
parents:
diff changeset
   122
{
hgs
parents:
diff changeset
   123
    setup();
hgs
parents:
diff changeset
   124
hgs
parents:
diff changeset
   125
    cleanup();
hgs
parents:
diff changeset
   126
}
hgs
parents:
diff changeset
   127
hgs
parents:
diff changeset
   128
void TestVideoDisplayHandler::testRemoveDisplayWindow()
hgs
parents:
diff changeset
   129
{
hgs
parents:
diff changeset
   130
    setup();
hgs
parents:
diff changeset
   131
hgs
parents:
diff changeset
   132
    mDispHdlr->RemoveDisplayWindow();
hgs
parents:
diff changeset
   133
hgs
parents:
diff changeset
   134
    QVERIFY( mDispHdlr->iVideoContainer == NULL );
hgs
parents:
diff changeset
   135
hgs
parents:
diff changeset
   136
    cleanup();
hgs
parents:
diff changeset
   137
}
hgs
parents:
diff changeset
   138
hgs
parents:
diff changeset
   139
void TestVideoDisplayHandler::testHandleSurfaceCreatedMessageL()
hgs
parents:
diff changeset
   140
{
hgs
parents:
diff changeset
   141
    setup();
hgs
parents:
diff changeset
   142
hgs
parents:
diff changeset
   143
    CMPXMessage* message = NULL;
hgs
parents:
diff changeset
   144
    TRAP_IGNORE
hgs
parents:
diff changeset
   145
    (
hgs
parents:
diff changeset
   146
        message = CMPXMessage::NewL();
hgs
parents:
diff changeset
   147
        message->SetTObjectValueL<TMPXVideoDisplayCommand>
hgs
parents:
diff changeset
   148
                    ( KMPXMediaVideoDisplayCommand, EPbMsgVideoSurfaceCreated );
hgs
parents:
diff changeset
   149
    );
hgs
parents:
diff changeset
   150
hgs
parents:
diff changeset
   151
    mDispHdlr->HandleVideoDisplayMessageL( message );
hgs
parents:
diff changeset
   152
hgs
parents:
diff changeset
   153
    QVERIFY( ! mDispHdlr->iSurfaceId.IsNull() );
50
hgs
parents: 44
diff changeset
   154
    QVERIFY( mDispHdlr->iViewWrapper->iAttatched );
44
hgs
parents:
diff changeset
   155
hgs
parents:
diff changeset
   156
    mDispHdlr->RemoveDisplayWindow();
hgs
parents:
diff changeset
   157
    cleanup();
hgs
parents:
diff changeset
   158
}
hgs
parents:
diff changeset
   159
hgs
parents:
diff changeset
   160
void TestVideoDisplayHandler::testHandleSurfaceChangedMessageL()
hgs
parents:
diff changeset
   161
{
hgs
parents:
diff changeset
   162
    setup();
hgs
parents:
diff changeset
   163
hgs
parents:
diff changeset
   164
    CMPXMessage* message = NULL;
hgs
parents:
diff changeset
   165
    TRAP_IGNORE
hgs
parents:
diff changeset
   166
    (
hgs
parents:
diff changeset
   167
        message = CMPXMessage::NewL();
hgs
parents:
diff changeset
   168
        message->SetTObjectValueL<TMPXVideoDisplayCommand>
hgs
parents:
diff changeset
   169
                    ( KMPXMediaVideoDisplayCommand, EPbMsgVideoSurfaceChanged );
hgs
parents:
diff changeset
   170
    );
hgs
parents:
diff changeset
   171
hgs
parents:
diff changeset
   172
    mDispHdlr->HandleVideoDisplayMessageL( message );
hgs
parents:
diff changeset
   173
hgs
parents:
diff changeset
   174
    QVERIFY( ! mDispHdlr->iSurfaceId.IsNull() );
hgs
parents:
diff changeset
   175
hgs
parents:
diff changeset
   176
    mDispHdlr->RemoveDisplayWindow();
hgs
parents:
diff changeset
   177
    cleanup();
hgs
parents:
diff changeset
   178
}
hgs
parents:
diff changeset
   179
hgs
parents:
diff changeset
   180
void TestVideoDisplayHandler::testHandleVideoRemovedMessageL()
hgs
parents:
diff changeset
   181
{
hgs
parents:
diff changeset
   182
    setup();
hgs
parents:
diff changeset
   183
hgs
parents:
diff changeset
   184
    CMPXMessage* message = NULL;
hgs
parents:
diff changeset
   185
    TRAP_IGNORE
hgs
parents:
diff changeset
   186
    (
hgs
parents:
diff changeset
   187
        message = CMPXMessage::NewL();
hgs
parents:
diff changeset
   188
        message->SetTObjectValueL<TMPXVideoDisplayCommand>
hgs
parents:
diff changeset
   189
                    ( KMPXMediaVideoDisplayCommand, EPbMsgVideoSurfaceRemoved );
hgs
parents:
diff changeset
   190
    );
hgs
parents:
diff changeset
   191
hgs
parents:
diff changeset
   192
    mDispHdlr->HandleVideoDisplayMessageL( message );
hgs
parents:
diff changeset
   193
hgs
parents:
diff changeset
   194
    QVERIFY( mDispHdlr->iSurfaceId.IsNull() );
50
hgs
parents: 44
diff changeset
   195
    QVERIFY( ! mDispHdlr->iViewWrapper->iAttatched );
44
hgs
parents:
diff changeset
   196
hgs
parents:
diff changeset
   197
    mDispHdlr->RemoveDisplayWindow();
hgs
parents:
diff changeset
   198
    cleanup();
hgs
parents:
diff changeset
   199
}
hgs
parents:
diff changeset
   200
hgs
parents:
diff changeset
   201
void TestVideoDisplayHandler::testSetAspectRatioL()
hgs
parents:
diff changeset
   202
{
hgs
parents:
diff changeset
   203
    setup();
hgs
parents:
diff changeset
   204
hgs
parents:
diff changeset
   205
    int aspectRatio = mDispHdlr->SetAspectRatioL( EPbCmdNaturalAspectRatio );
hgs
parents:
diff changeset
   206
hgs
parents:
diff changeset
   207
    QVERIFY( aspectRatio == EMMFNatural );
hgs
parents:
diff changeset
   208
hgs
parents:
diff changeset
   209
    mDispHdlr->RemoveDisplayWindow();
hgs
parents:
diff changeset
   210
    cleanup();
hgs
parents:
diff changeset
   211
}
hgs
parents:
diff changeset
   212
hgs
parents:
diff changeset
   213
void TestVideoDisplayHandler::testSetDefaultAspectRatioL()
hgs
parents:
diff changeset
   214
{
hgs
parents:
diff changeset
   215
    setup();
hgs
parents:
diff changeset
   216
hgs
parents:
diff changeset
   217
    //
hgs
parents:
diff changeset
   218
    // get window size
hgs
parents:
diff changeset
   219
    //
hgs
parents:
diff changeset
   220
    RWindow *window = mBaseVideoView->getWindow();
hgs
parents:
diff changeset
   221
    TRect displayRect = TRect( TPoint( window->Position() ), TSize( window->Size() ) );
hgs
parents:
diff changeset
   222
hgs
parents:
diff changeset
   223
    //
hgs
parents:
diff changeset
   224
    // get window aspect ratio
hgs
parents:
diff changeset
   225
    //   if device is in landscape mode, width > height
hgs
parents:
diff changeset
   226
    //   if device is in portrait mode, width < height
hgs
parents:
diff changeset
   227
    //
hgs
parents:
diff changeset
   228
    TReal32 width = (TReal32) displayRect.Width();
hgs
parents:
diff changeset
   229
    TReal32 height = (TReal32) displayRect.Height();
hgs
parents:
diff changeset
   230
    TReal32 displayAspectRatio = (width > height)? (width / height) : (height / width);
hgs
parents:
diff changeset
   231
hgs
parents:
diff changeset
   232
    //
hgs
parents:
diff changeset
   233
    // aspect ratio zoom
hgs
parents:
diff changeset
   234
    //
hgs
parents:
diff changeset
   235
    mFileDetails = new VideoPlaybackViewFileDetails();
hgs
parents:
diff changeset
   236
    mFileDetails->mVideoHeight = 280;
hgs
parents:
diff changeset
   237
    mFileDetails->mVideoWidth  = 600;
hgs
parents:
diff changeset
   238
hgs
parents:
diff changeset
   239
    int aspectRatio = mDispHdlr->SetDefaultAspectRatioL( mFileDetails, displayAspectRatio );
hgs
parents:
diff changeset
   240
hgs
parents:
diff changeset
   241
    QVERIFY( aspectRatio == EMMFZoom );
hgs
parents:
diff changeset
   242
hgs
parents:
diff changeset
   243
    //
hgs
parents:
diff changeset
   244
    // aspect ratio stretch
hgs
parents:
diff changeset
   245
    //
hgs
parents:
diff changeset
   246
    mFileDetails->mVideoHeight = 144;
hgs
parents:
diff changeset
   247
    mFileDetails->mVideoWidth  = 220;
hgs
parents:
diff changeset
   248
hgs
parents:
diff changeset
   249
    aspectRatio = mDispHdlr->SetDefaultAspectRatioL( mFileDetails, displayAspectRatio );
hgs
parents:
diff changeset
   250
hgs
parents:
diff changeset
   251
    QVERIFY( aspectRatio == EMMFStretch );
hgs
parents:
diff changeset
   252
hgs
parents:
diff changeset
   253
    mDispHdlr->RemoveDisplayWindow();
hgs
parents:
diff changeset
   254
hgs
parents:
diff changeset
   255
    cleanup();
hgs
parents:
diff changeset
   256
}
hgs
parents:
diff changeset
   257
hgs
parents:
diff changeset
   258
void TestVideoDisplayHandler::testUpdateVideoRectL()
hgs
parents:
diff changeset
   259
{
hgs
parents:
diff changeset
   260
    setup();
hgs
parents:
diff changeset
   261
hgs
parents:
diff changeset
   262
    RWindow *window = mBaseVideoView->getWindow();
hgs
parents:
diff changeset
   263
hgs
parents:
diff changeset
   264
    TRect displayRect = TRect( 0, 0, 200, 300 );
hgs
parents:
diff changeset
   265
hgs
parents:
diff changeset
   266
    mDispHdlr->UpdateVideoRectL( displayRect, false );
hgs
parents:
diff changeset
   267
hgs
parents:
diff changeset
   268
    QCOMPARE( mDispHdlr->iWindowRect, displayRect);
hgs
parents:
diff changeset
   269
hgs
parents:
diff changeset
   270
    mDispHdlr->RemoveDisplayWindow();
hgs
parents:
diff changeset
   271
    cleanup();
hgs
parents:
diff changeset
   272
}
hgs
parents:
diff changeset
   273
hgs
parents:
diff changeset
   274
// End of file
hgs
parents:
diff changeset
   275