videocollection/videocollectionview/tsrc/testvideooperatorservice_p/src/testvideooperatorservice_p.cpp
changeset 55 4bfa887905cf
child 67 72c709219fcd
equal deleted inserted replaced
50:21fe8338c6bf 55:4bfa887905cf
       
     1 /**
       
     2 * Copyright (c) 2010 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: tests for VideoOperatorService
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <hbapplication.h>
       
    20 #include <hbmainwindow.h>
       
    21 #include <hbinstance.h>
       
    22 #include <qdebug.h>
       
    23 
       
    24 #include "testvideooperatorservice_p.h"
       
    25 #include "videocollectionviewutilsdata.h"
       
    26 
       
    27 #define private public
       
    28 #include "videooperatorservice_p.h"
       
    29 #undef private
       
    30 
       
    31 int main(int argc, char *argv[])
       
    32 {
       
    33     HbApplication app(argc, argv);
       
    34     HbMainWindow window;
       
    35     TestVideoOperatorServicePrivate tv;
       
    36     int res;
       
    37     if (argc > 1)
       
    38     {   
       
    39         res = QTest::qExec(&tv, argc, argv);
       
    40     }
       
    41     else
       
    42     {
       
    43         char *pass[3];
       
    44         pass[0] = argv[0];
       
    45         pass[1] = "-o";
       
    46         pass[2] = "c:\\data\\testvideooperatorservice_p.txt";
       
    47         res = QTest::qExec(&tv, 3, pass);
       
    48     }
       
    49     
       
    50     return res;
       
    51 }
       
    52 
       
    53 TestVideoOperatorServicePrivate::TestVideoOperatorServicePrivate():
       
    54     mTestObject(0)
       
    55 {
       
    56     
       
    57 }
       
    58 
       
    59 TestVideoOperatorServicePrivate::~TestVideoOperatorServicePrivate()
       
    60 {
       
    61     cleanup();
       
    62 }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // init
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void TestVideoOperatorServicePrivate::init()
       
    69 {
       
    70     TApaTask::mExistsReturnValue = false;
       
    71     TApaTaskList::mFindAppCallCount = 0;
       
    72     CCoeEnv::mStaticReturnsNull = false;
       
    73     CCoeEnv::mCCoeEnvCallCount = 0;
       
    74     TApaTask::mExistsReturnValue = true;
       
    75     TApaTask::mExistsCallCount = 0;
       
    76     TApaTask::mBringToForegroundCallcount = 0;
       
    77     RApaLsSession::mGetAppInfoCallCount = 0;
       
    78     TApaAppInfo::mConstructCount = 0;
       
    79     
       
    80     // create test object
       
    81     if (!mTestObject)
       
    82     {
       
    83         mTestObject = new VideoOperatorServicePrivate();
       
    84     }
       
    85 }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // cleanup
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void TestVideoOperatorServicePrivate::cleanup()
       
    92 {
       
    93     // delete test object
       
    94     delete mTestObject;
       
    95     mTestObject = 0;
       
    96 }
       
    97 
       
    98 // TEST CASES START ----------------------------------------------------------
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // testLoad
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void TestVideoOperatorServicePrivate::testLoad()
       
   105 {
       
   106     // Good case
       
   107     VideoCollectionViewUtilsData::mCenRepStringValues.append("test title");
       
   108     VideoCollectionViewUtilsData::mCenRepStringValues.append("test icon");
       
   109     VideoCollectionViewUtilsData::mCenRepStringValues.append("test uri");
       
   110     VideoCollectionViewUtilsData::mCenRepIntValues.append(5050);
       
   111     QVERIFY(mTestObject->load(0, 0, 0, 0) == true);
       
   112     QVERIFY(mTestObject->mTitle == "test title");
       
   113     QVERIFY(mTestObject->mIconResource == "test icon");
       
   114     QVERIFY(mTestObject->mServiceUri == "test uri");
       
   115     QCOMPARE(mTestObject->mApplicationUid, 5050);
       
   116     
       
   117     // Only icon is defined for service.
       
   118     VideoCollectionViewUtilsData::mCenRepStringValues.append(CENREP_NO_STRING);
       
   119     VideoCollectionViewUtilsData::mCenRepStringValues.append("test icon");
       
   120     QVERIFY(mTestObject->load(0, 0, 0, 0) == false);
       
   121     QVERIFY(mTestObject->mTitle == "");
       
   122     QVERIFY(mTestObject->mIconResource == "test icon");
       
   123     QVERIFY(mTestObject->mServiceUri == "");
       
   124     QCOMPARE(mTestObject->mApplicationUid, -1);
       
   125 
       
   126     // Only icon and uri are defined for service.
       
   127     VideoCollectionViewUtilsData::mCenRepStringValues.append(CENREP_NO_STRING);
       
   128     VideoCollectionViewUtilsData::mCenRepStringValues.append("test icon");
       
   129     VideoCollectionViewUtilsData::mCenRepStringValues.append("test uri");
       
   130     QVERIFY(mTestObject->load(0, 0, 0, 0) == true);
       
   131     QVERIFY(mTestObject->mTitle == "");
       
   132     QVERIFY(mTestObject->mIconResource == "test icon");
       
   133     QVERIFY(mTestObject->mServiceUri == "test uri");
       
   134     QCOMPARE(mTestObject->mApplicationUid, -1);
       
   135     
       
   136     // Only icon and app uid are defined for service.
       
   137     VideoCollectionViewUtilsData::mCenRepStringValues.append(CENREP_NO_STRING);
       
   138     VideoCollectionViewUtilsData::mCenRepStringValues.append("test icon");
       
   139     VideoCollectionViewUtilsData::mCenRepIntValues.append(5050);
       
   140     QVERIFY(mTestObject->load(0, 0, 0, 0) == true);
       
   141     QVERIFY(mTestObject->mTitle == "");
       
   142     QVERIFY(mTestObject->mIconResource == "test icon");
       
   143     QVERIFY(mTestObject->mServiceUri == "");
       
   144     QCOMPARE(mTestObject->mApplicationUid, 5050);
       
   145 }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // testTitle
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void TestVideoOperatorServicePrivate::testTitle()
       
   152 {
       
   153     mTestObject->mTitle = "test title";
       
   154     QVERIFY(mTestObject->title() == "test title");
       
   155 }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // testIconResource
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void TestVideoOperatorServicePrivate::testIconResource()
       
   162 {
       
   163     mTestObject->mIconResource = "test icon";
       
   164     QVERIFY(mTestObject->iconResource() == "test icon");
       
   165 }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // test
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 void TestVideoOperatorServicePrivate::testLaunchService()
       
   172 {
       
   173     // Good case.
       
   174     init();
       
   175     mTestObject->mApplicationUid = 123456;
       
   176     RApaLsSession::mFileName.Copy(_L("test.exe"));
       
   177     mTestObject->launchService();
       
   178     QCOMPARE(RApaLsSession::mGetAppInfoCallCount, 1);
       
   179     QCOMPARE(TApaAppInfo::mConstructCount, 1);
       
   180     QCOMPARE(TApaTask::mBringToForegroundCallcount, 0);
       
   181     QCOMPARE(TApaTaskList::mFindAppCallCount, 0);
       
   182     cleanup();
       
   183     
       
   184     // Uid returns empty string.
       
   185     init();
       
   186     mTestObject->mApplicationUid = 123456;
       
   187     RApaLsSession::mFileName.Copy(_L(""));
       
   188     mTestObject->launchService();
       
   189     QCOMPARE(RApaLsSession::mGetAppInfoCallCount, 1);
       
   190     QCOMPARE(TApaAppInfo::mConstructCount, 1);
       
   191     QCOMPARE(TApaTask::mBringToForegroundCallcount, 0);
       
   192     QCOMPARE(TApaTaskList::mFindAppCallCount, 0);
       
   193     cleanup();
       
   194     
       
   195     // Process exists and app already running. 
       
   196     init();
       
   197     TApaTask::mExistsReturnValue = true;
       
   198     mTestObject->mProcess = new QProcess();
       
   199     mTestObject->mApplicationUid = 123456;
       
   200     RApaLsSession::mFileName.Copy(_L("test.exe"));
       
   201     mTestObject->launchService();
       
   202     QCOMPARE(RApaLsSession::mGetAppInfoCallCount, 0);
       
   203     QCOMPARE(TApaAppInfo::mConstructCount, 0);
       
   204     QCOMPARE(TApaTask::mBringToForegroundCallcount, 1);
       
   205     QCOMPARE(TApaTaskList::mFindAppCallCount, 1);
       
   206     cleanup();
       
   207 
       
   208     // Process exists but app not running. 
       
   209     init();
       
   210     TApaTask::mExistsReturnValue = false;
       
   211     mTestObject->mProcess = new QProcess();
       
   212     mTestObject->mApplicationUid = 123456;
       
   213     RApaLsSession::mFileName.Copy(_L("test.exe"));
       
   214     mTestObject->mProcess = new QProcess();
       
   215     mTestObject->launchService();
       
   216     QCOMPARE(RApaLsSession::mGetAppInfoCallCount, 1);
       
   217     QCOMPARE(TApaAppInfo::mConstructCount, 1);
       
   218     QCOMPARE(TApaTask::mBringToForegroundCallcount, 0);
       
   219     QCOMPARE(TApaTaskList::mFindAppCallCount, 1);
       
   220     cleanup();
       
   221     
       
   222     // CCoeEnv is null
       
   223     init();
       
   224     CCoeEnv::mStaticReturnsNull = true;
       
   225     mTestObject->mApplicationUid = 123456;
       
   226     RApaLsSession::mFileName.Copy(_L("test.exe"));
       
   227     mTestObject->launchService();
       
   228     QCOMPARE(RApaLsSession::mGetAppInfoCallCount, 1);
       
   229     QCOMPARE(TApaAppInfo::mConstructCount, 1);
       
   230     QCOMPARE(TApaTask::mBringToForegroundCallcount, 0);
       
   231     QCOMPARE(TApaTaskList::mFindAppCallCount, 0);
       
   232     cleanup();
       
   233 }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // testSlots
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 void TestVideoOperatorServicePrivate::testSlots()
       
   240 {
       
   241     init();
       
   242     mTestObject->processError(QProcess::FailedToStart);
       
   243     // Nothing to verify
       
   244     
       
   245     mTestObject->processFinished(0, QProcess::NormalExit);
       
   246     // Nothing to verify
       
   247     cleanup();
       
   248 }
       
   249 
       
   250 // end of file