videocollection/videocollectionview/tsrc/testhintwidget/src/testhintwidget.cpp
changeset 66 adb51f74b890
parent 63 4707a0db12f6
child 67 72c709219fcd
equal deleted inserted replaced
63:4707a0db12f6 66:adb51f74b890
     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:   tester for methods in VideoListWidget
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbicon.h>
       
    19 #include <hbmainwindow.h>
       
    20 #include <hbinstance.h>
       
    21 #include <hblabel.h>
       
    22 #include <hbpushbutton.h>
       
    23 #include <hbapplication.h>
       
    24 
       
    25 #include "videocollectionuiloader.h"
       
    26 #include "videocollectionviewutils.h"
       
    27 #include "videocollectionviewutilsdata.h"
       
    28 #include "videocollectionuiloaderdata.h"
       
    29 #include "testhintwidget.h"
       
    30 
       
    31 #define private public
       
    32 #include "videohintwidget.h"
       
    33 #undef private
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // main
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 int main(int argc, char *argv[])
       
    40 {
       
    41     HbApplication app(argc, argv);
       
    42     HbApplication::setKeypadNavigationEnabled(false);
       
    43     HbMainWindow mainWnd;
       
    44     hbInstance->mWindowses.append(&mainWnd);
       
    45 
       
    46     TestHintWidget tv;
       
    47     
       
    48     int res;
       
    49     if(argc > 1)
       
    50     {   
       
    51         res = QTest::qExec(&tv, argc, argv);
       
    52     }
       
    53     else
       
    54     {
       
    55         char *pass[3];
       
    56         pass[0] = argv[0];
       
    57         pass[1] = "-o";
       
    58         pass[2] = "c:\\data\\testhintwidget.txt";
       
    59         res = QTest::qExec(&tv, 3, pass);
       
    60     }
       
    61 
       
    62     return res;
       
    63 }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // constructor
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 TestHintWidget::TestHintWidget():
       
    70     mTestObject(0),
       
    71     mUiLoader(0)
       
    72 {
       
    73     // nop
       
    74 }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // destructor
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 TestHintWidget::~TestHintWidget()
       
    81 {
       
    82     cleanup();
       
    83 }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // init
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void TestHintWidget::init(bool callInitialize)
       
    90 {
       
    91     mUiLoader = new VideoCollectionUiLoader;
       
    92     
       
    93     HbDocumentLoader::mFindWidgetFails = false;
       
    94     bool ok(false);
       
    95     mUiLoader->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok);
       
    96     if(!ok)
       
    97     {
       
    98         cleanup();
       
    99         QFAIL("docml loading failed!");
       
   100     }
       
   101     
       
   102     mTestObject = mUiLoader->findObject<VideoHintWidget>(DOCML_NAME_VC_VIDEOHINTWIDGET);
       
   103     if(!mTestObject)
       
   104     {
       
   105         mTestObject = new VideoHintWidget(mUiLoader);
       
   106     }
       
   107     
       
   108     mTestObject->mHintText = "Go get some!";
       
   109     
       
   110     if (callInitialize)
       
   111     {
       
   112         mTestObject->mHintText = "";
       
   113         mTestObject->initialize();
       
   114     }
       
   115 }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // cleanup
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void TestHintWidget::cleanup()
       
   122 {
       
   123     if (mUiLoader)
       
   124     {
       
   125         VideoHintWidget* temp = mUiLoader->findObject<VideoHintWidget>(DOCML_NAME_VC_VIDEOHINTWIDGET);
       
   126         if (!temp)
       
   127         {
       
   128             // need to delete mTestObject as it is not owned by uiloader.
       
   129             delete mTestObject;
       
   130             mTestObject = 0;
       
   131         }
       
   132         mTestObject = 0;
       
   133 
       
   134         delete mUiLoader;
       
   135         mUiLoader = 0;
       
   136     }
       
   137 
       
   138     VideoCollectionViewUtilsData::reset();
       
   139     VideoCollectionUiLoaderData::reset();    
       
   140 }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // testInitialize
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void TestHintWidget::testInitialize()
       
   147 {
       
   148     init(false);
       
   149 
       
   150     // Fail
       
   151     mTestObject->mHintText = "";
       
   152     VideoCollectionViewUtilsData::mCenRepStringValues.append(""); 
       
   153     mTestObject->initialize();
       
   154     QVERIFY(mTestObject->mHintText.isEmpty());
       
   155 
       
   156     // Succeed
       
   157     VideoCollectionViewUtilsData::mCenRepStringValues.append("test"); 
       
   158     mTestObject->initialize();
       
   159     QVERIFY(!mTestObject->mHintText.isEmpty());
       
   160     
       
   161     cleanup();
       
   162 }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // testSetLevel
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void TestHintWidget::testSetLevel()
       
   169 {
       
   170     init(false);
       
   171     mTestObject->setVisible(false);
       
   172     
       
   173     mTestObject->setLevel(VideoHintWidget::Collection);
       
   174     QCOMPARE(mTestObject->mCurrentLevel, VideoHintWidget::Collection);
       
   175     
       
   176     mTestObject->setLevel(VideoHintWidget::AllVideos);
       
   177     QCOMPARE(mTestObject->mCurrentLevel, VideoHintWidget::AllVideos);
       
   178     
       
   179     mTestObject->setLevel(VideoHintWidget::AllVideos);
       
   180     QCOMPARE(mTestObject->mCurrentLevel, VideoHintWidget::AllVideos);
       
   181     
       
   182     mTestObject->setLevel(VideoHintWidget::Collection);
       
   183     QCOMPARE(mTestObject->mCurrentLevel, VideoHintWidget::Collection);
       
   184     cleanup();
       
   185 }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // testActivate
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void TestHintWidget::testActivate()
       
   192 {
       
   193     init(false);
       
   194 
       
   195     mTestObject->setVisible(false);
       
   196     
       
   197     // successful case.
       
   198     mTestObject->mActivated = false;
       
   199 
       
   200     HbLabel *noVideosLabel = mUiLoader->findWidget<HbLabel>(DOCML_NAME_NO_VIDEOS_LABEL);
       
   201     QVERIFY(noVideosLabel);
       
   202     noVideosLabel->setVisible(false);
       
   203     
       
   204     mTestObject->activate();
       
   205     QVERIFY(mTestObject->isVisible());
       
   206     QVERIFY(noVideosLabel->isVisible()); // checks that updateUiComponents() has been called.
       
   207     QVERIFY(mTestObject->mActivated == true);
       
   208     
       
   209     // second call
       
   210     noVideosLabel->setVisible(false);
       
   211     mTestObject->activate();
       
   212     QVERIFY(mTestObject->isVisible());    
       
   213     QVERIFY(!noVideosLabel->isVisible()); // shouldn't call updateUiComponents() again.
       
   214     QVERIFY(mTestObject->mActivated == true);
       
   215     
       
   216     cleanup();
       
   217 }
       
   218  
       
   219 // ---------------------------------------------------------------------------
       
   220 // testDeactivate
       
   221 // ---------------------------------------------------------------------------
       
   222 //
       
   223 void TestHintWidget::testDeactivate()
       
   224 {
       
   225     init(false);
       
   226     
       
   227     mTestObject->setVisible(true);
       
   228     mTestObject->mActivated = true;
       
   229     
       
   230     // when serviceButton does not exist
       
   231     HbDocumentLoader::mFindWidgetFails = true;
       
   232     mTestObject->deactivate();
       
   233     QVERIFY(mTestObject->mActivated == false);
       
   234     QVERIFY(mTestObject->isVisible() == false);
       
   235     
       
   236     // service button exists
       
   237     mTestObject->setVisible(true);
       
   238     mTestObject->mActivated = true;
       
   239     HbDocumentLoader::mFindWidgetFails = false;
       
   240     mTestObject->deactivate();
       
   241     QVERIFY(mTestObject->mActivated == false);
       
   242     QVERIFY(mTestObject->isVisible() == false);
       
   243     
       
   244     // second call. widget is not active.
       
   245     mTestObject->setVisible(true);
       
   246     mTestObject->deactivate();
       
   247     QVERIFY(mTestObject->mActivated == false);
       
   248     QVERIFY(mTestObject->isVisible());
       
   249     
       
   250     cleanup();
       
   251 }
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // testUpdateUiComponents
       
   255 // ---------------------------------------------------------------------------
       
   256 //
       
   257 void TestHintWidget::testUpdateUiComponents()
       
   258 {
       
   259     HbMainWindow *mainWnd = hbInstance->allMainWindows()[0];
       
   260     
       
   261     init(false);
       
   262     
       
   263     // when a widget cannot be found.
       
   264     mTestObject->mActivated = true;
       
   265     mTestObject->mButtonShown = true;
       
   266     HbDocumentLoader::mFindWidgetFails = true;
       
   267     mTestObject->setLevel(VideoHintWidget::AllVideos);
       
   268     // no verification possible except that it doesn't crash
       
   269     
       
   270     HbDocumentLoader::mFindWidgetFails = false;
       
   271     HbLabel *hintLabel = mUiLoader->findWidget<HbLabel>(DOCML_NAME_NO_VIDEOS_LABEL);
       
   272     QVERIFY(hintLabel);
       
   273     HbPushButton *serviceButton = mUiLoader->findWidget<HbPushButton>(DOCML_NAME_HINT_BUTTON);
       
   274     QVERIFY(serviceButton);
       
   275     
       
   276     // current level is all videos
       
   277     serviceButton->setVisible(false);
       
   278     mTestObject->setLevel(VideoHintWidget::AllVideos);
       
   279     QVERIFY(hintLabel->isVisible());
       
   280     QVERIFY(serviceButton->isVisible());
       
   281     
       
   282     // current level is not all videos
       
   283     serviceButton->setVisible(true);
       
   284     mTestObject->setLevel(VideoHintWidget::Collection);
       
   285     QVERIFY(hintLabel->isVisible());
       
   286     QVERIFY(serviceButton->isVisible() == false);
       
   287 
       
   288     // no hint text
       
   289     serviceButton->setVisible(true);
       
   290     mTestObject->mHintText = "";
       
   291     mTestObject->setLevel(VideoHintWidget::AllVideos);
       
   292     QVERIFY(hintLabel->isVisible());
       
   293     QVERIFY(serviceButton->isVisible() == false);
       
   294     
       
   295     cleanup();
       
   296 }
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 // testOrientationChangedSlot
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 void TestHintWidget::testOrientationChangedSlot()
       
   303 {
       
   304     // NOTE: This also checks that the signals are connected and
       
   305     // disconnected correctly.
       
   306     
       
   307     HbMainWindow *mainWnd = hbInstance->allMainWindows()[0];
       
   308     mainWnd->setOrientation(Qt::Horizontal);
       
   309     connect(this, SIGNAL(testSignal(Qt::Orientation)), mainWnd, SIGNAL(orientationChanged(Qt::Orientation)));
       
   310     
       
   311     init(false);
       
   312     
       
   313     HbLabel *noVideosLabel = mUiLoader->findWidget<HbLabel>(DOCML_NAME_NO_VIDEOS_LABEL);
       
   314     QVERIFY(noVideosLabel);
       
   315 
       
   316     // test that updateUiComponents is not called when only initialize has been called,
       
   317     // ie that no activate calls have been made yet.
       
   318     // mTestObject->setVisible is needed because othervise childs cannot be set visible, ie the 
       
   319     // serviceButton->setVisible does not work as expected.
       
   320     mTestObject->setVisible(true);
       
   321     noVideosLabel->setVisible(true);
       
   322     emit testSignal(Qt::Vertical);
       
   323     QVERIFY(noVideosLabel->isVisible());
       
   324     mTestObject->setVisible(false);
       
   325         
       
   326     // tests that updateUiComponents is called when widget is visible.
       
   327     mTestObject->activate();
       
   328     noVideosLabel->setVisible(false);
       
   329     emit testSignal(Qt::Horizontal);
       
   330     QVERIFY(noVideosLabel->isVisible());    
       
   331     mTestObject->deactivate();
       
   332     
       
   333     // tests that updateUiComponents is not called when widget is not visible:
       
   334     // mTestObject->setVisible is needed because othervise childs cannot be set visible, ie the 
       
   335     // serviceButton->setVisible does not work as expected.
       
   336     mTestObject->setVisible(true);    
       
   337     noVideosLabel->setVisible(true);
       
   338     emit testSignal(Qt::Vertical);
       
   339     QVERIFY(noVideosLabel->isVisible());
       
   340     
       
   341     cleanup();
       
   342 }
       
   343 
       
   344 // ---------------------------------------------------------------------------
       
   345 // testSetButtonShown
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 void TestHintWidget::testSetButtonShown()
       
   349 {
       
   350     HbMainWindow *mainWnd = hbInstance->allMainWindows()[0];
       
   351     
       
   352     init(true);
       
   353     
       
   354     HbLabel *noVideosLabel = mUiLoader->findWidget<HbLabel>(DOCML_NAME_NO_VIDEOS_LABEL);
       
   355     QVERIFY(noVideosLabel);
       
   356     
       
   357     mTestObject->mActivated = true;
       
   358     noVideosLabel->setVisible(false);
       
   359     mTestObject->setButtonShown(true);
       
   360     QVERIFY(noVideosLabel->isVisible());
       
   361     
       
   362     mTestObject->mActivated = false;
       
   363     noVideosLabel->setVisible(false);
       
   364     mTestObject->setButtonShown(false);
       
   365     QVERIFY(noVideosLabel->isVisible() == false);
       
   366 }
       
   367 
       
   368 // end of file