satui/satapp/tsrc/ut_satapp/src/ut_satappmenuprovider.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     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: Unit test for satappmainhandler
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbmainwindow.h>
       
    19 #include <hblistwidget.h>
       
    20 #include <hbaction.h>
       
    21 
       
    22 #include "ut_satappmenuprovider.h"
       
    23 #include "satappmenuprovider.h"
       
    24 #include "satappaction.h"
       
    25 
       
    26 
       
    27 
       
    28 // --------------------------------------------------------
       
    29 // The unit tests begin here
       
    30 // --------------------------------------------------------
       
    31 
       
    32 Ut_SatAppMenuProvider::Ut_SatAppMenuProvider(
       
    33         HbMainWindow* mainWindow, QObject *parent)
       
    34     :QObject(parent)
       
    35 {
       
    36     mMainWindow = mainWindow;
       
    37 }
       
    38 
       
    39 void Ut_SatAppMenuProvider::testResetState()
       
    40 {
       
    41     MenuProviderTest test(mMainWindow);
       
    42     test.mMenu->resetState();
       
    43 }
       
    44 
       
    45 void Ut_SatAppMenuProvider::testSetUpMenu_data()
       
    46 {
       
    47     QTest::addColumn<QString>("text");
       
    48     QTest::addColumn<int>("menuitems");
       
    49     QTest::addColumn<int>("selection");
       
    50 
       
    51     QTest::newRow("t1") << "title" << 1 << 0;
       
    52     QTest::newRow("t2") << "a very long title that does not fit to screen" << 2 << 1;
       
    53     QTest::newRow("t3") << "manyrows" << 999 << 444;
       
    54     QTest::newRow("t4") << "" << 1 << 0;
       
    55     QTest::newRow("t5") << "" << 10 << 1;
       
    56     QTest::newRow("t6") << "a" << 10 << 9;
       
    57 }
       
    58 
       
    59 void Ut_SatAppMenuProvider::testSetUpMenu()
       
    60 {
       
    61     QFETCH(QString, text);
       
    62     QFETCH(int, menuitems);
       
    63     QFETCH(int, selection);
       
    64 
       
    65     SatAppAction a(ESatSetUpMenuAction);
       
    66     a.set(KeyText,text);
       
    67     QStringList list;
       
    68     for(int i=0; i<menuitems; ++i) list<<QString::number(i);
       
    69     a.set(KeyMenu,list);
       
    70     
       
    71     MenuProviderTest test(mMainWindow);
       
    72     test.mMenu->setUpMenu(a);
       
    73 
       
    74     test.mItemIndexToBeSelected = selection;
       
    75     test.simulateItemSelected();
       
    76 
       
    77     QCOMPARE(a.response(), ESatSuccess);
       
    78     QVERIFY(a.hasValue(KeySelection));
       
    79 
       
    80 }
       
    81 
       
    82 void Ut_SatAppMenuProvider::testSetUpMenuAndReset()
       
    83 {
       
    84     SatAppAction a(ESatSetUpMenuAction);
       
    85     a.set(KeyText,"hello");
       
    86     QStringList list;
       
    87     for(int i=0; i<10; ++i) {list<<QString::number(i);}
       
    88     a.set(KeyMenu,list);
       
    89 
       
    90     MenuProviderTest test(mMainWindow);
       
    91     test.mMenu->setUpMenu(a);
       
    92     
       
    93     test.mMenu->resetState();
       
    94 
       
    95     QCOMPARE(a.response(), ESatSuccess);
       
    96 
       
    97 }
       
    98 
       
    99 void Ut_SatAppMenuProvider::testSetUpMenuAndDelete()
       
   100 {
       
   101     SatAppAction a(ESatSetUpMenuAction);
       
   102     a.set(KeyText,"hello");
       
   103     QStringList list;
       
   104     for(int i=0; i<10; ++i) {list<<QString::number(i);}
       
   105     a.set(KeyMenu,list);
       
   106 
       
   107     {
       
   108         MenuProviderTest test(mMainWindow);
       
   109         
       
   110         test.mMenu->setUpMenu(a);
       
   111     }
       
   112     // now SatAppMenuProvider is out of scope and deleted.
       
   113     QCOMPARE(a.response(), ESatSuccess);
       
   114 }
       
   115 
       
   116 void Ut_SatAppMenuProvider::testSelectItem_data()
       
   117 {
       
   118     QTest::addColumn<QString>("text");
       
   119     QTest::addColumn<int>("menuitems");
       
   120     QTest::addColumn<int>("defaultitem");
       
   121     QTest::addColumn<int>("selection");
       
   122 
       
   123     QTest::newRow("t1") << "title" << 1 << 0 << 0;
       
   124     QTest::newRow("t2") << "a very long title that does not fit to screen" << 2 << 0 << 1;
       
   125     QTest::newRow("t3") << "manyrows" << 999 << 333 << 444 ;
       
   126     QTest::newRow("t4") << "" << 3 << 2 << 1 ;
       
   127     QTest::newRow("t5") << "" << 4 << 3 << 0 ;
       
   128     QTest::newRow("t6") << "default out of range" << 5 << 7 << 1 ;
       
   129 }
       
   130 
       
   131 void Ut_SatAppMenuProvider::testSelectItem()
       
   132 {
       
   133     QFETCH(QString, text);
       
   134     QFETCH(int, menuitems);
       
   135     QFETCH(int, defaultitem);
       
   136     QFETCH(int, selection);
       
   137 
       
   138     SatAppAction a(ESatSelectItemAction);
       
   139     a.set(KeyText,text);
       
   140     QStringList list;
       
   141     for(int i=0; i<menuitems; ++i) {list<<QString::number(i);}
       
   142     a.set(KeyMenu,list);
       
   143     a.set(KeyDefault,defaultitem);
       
   144 
       
   145     MenuProviderTest test(mMainWindow);
       
   146     test.loadMainview();
       
   147     test.mMenu->selectItem(a);
       
   148 
       
   149     test.mItemIndexToBeSelected = selection;
       
   150     test.simulateItemSelected();
       
   151     
       
   152     QCOMPARE(a.response(), ESatSuccess);
       
   153     QVERIFY(a.hasValue(KeySelection));
       
   154 
       
   155 }
       
   156 
       
   157 void Ut_SatAppMenuProvider::testSelectItemAndBack()
       
   158 {
       
   159     SatAppAction a(ESatSelectItemAction);
       
   160     a.set(KeyText,"hello");
       
   161     QStringList list;
       
   162     for(int i=0; i<10; ++i) {list<<QString::number(i);}
       
   163     a.set(KeyMenu,list);
       
   164     a.set(KeyDefault,5);
       
   165 
       
   166     MenuProviderTest test(mMainWindow);
       
   167     test.loadMainview();
       
   168     test.mMenu->selectItem(a);
       
   169     test.simulateBackButtonClicked();
       
   170 
       
   171     QCOMPARE(a.response(), ESatBackwardModeRequestedByUser);
       
   172 
       
   173 }
       
   174 
       
   175 
       
   176 void Ut_SatAppMenuProvider::testSelectItemAndTimeout()
       
   177 {
       
   178     SatAppAction a(ESatSelectItemAction);
       
   179     a.set(KeyText,"hello");
       
   180     QStringList list;
       
   181     for(int i=0; i<10; ++i) {list<<QString::number(i);}
       
   182     a.set(KeyMenu,list);
       
   183     a.set(KeyDefault,5);
       
   184 
       
   185     MenuProviderTest test(mMainWindow);
       
   186     test.loadMainview();
       
   187     test.mMenu->selectItem(a);
       
   188     a.waitUntilCompleted(); // wait selectItem timeout
       
   189 
       
   190     QCOMPARE(a.response(), ESatNoResponseFromUser);
       
   191 
       
   192 }
       
   193 
       
   194 void Ut_SatAppMenuProvider::testSelectItemAndReset()
       
   195 {
       
   196     SatAppAction a(ESatSelectItemAction);
       
   197     a.set(KeyText,"hello");
       
   198     QStringList list;
       
   199     for(int i=0; i<10; ++i) {list<<QString::number(i);}
       
   200     a.set(KeyMenu,list);
       
   201     a.set(KeyDefault,5);
       
   202 
       
   203     MenuProviderTest test(mMainWindow);
       
   204     test.loadMainview();
       
   205     test.mMenu->selectItem(a);
       
   206     test.mMenu->resetState();
       
   207 
       
   208     QCOMPARE(a.response(), ESatSuccess);
       
   209    
       
   210 }
       
   211 
       
   212 void Ut_SatAppMenuProvider::testSelectItemAndDelete()
       
   213 {
       
   214     SatAppAction a(ESatSelectItemAction);
       
   215     a.set(KeyText,"hello");
       
   216     QStringList list;
       
   217     for(int i=0; i<10; ++i) {list<<QString::number(i);}
       
   218     a.set(KeyMenu,list);
       
   219     a.set(KeyDefault,5);
       
   220 
       
   221     {
       
   222         MenuProviderTest test(mMainWindow);
       
   223         test.loadMainview();
       
   224         test.mMenu->selectItem(a);
       
   225     }
       
   226 
       
   227     // object deleted, blocking function should return safely
       
   228     QCOMPARE(a.response(), ESatSuccess);
       
   229 }
       
   230 
       
   231 // ---------------------------------------------------------------
       
   232 // internal helper class
       
   233 // ---------------------------------------------------------------
       
   234 
       
   235 MenuProviderTest::MenuProviderTest(HbMainWindow* mainWindow)
       
   236 {
       
   237     mMenu = new SatAppMenuProvider(mainWindow,this);
       
   238 }
       
   239 
       
   240 MenuProviderTest::~MenuProviderTest()
       
   241 {
       
   242     cleanup();
       
   243 }
       
   244 
       
   245 void MenuProviderTest::loadMainview()
       
   246 {
       
   247     mMenu->loadMainView();
       
   248 }
       
   249 
       
   250 void MenuProviderTest::simulateItemSelected()
       
   251 {
       
   252     mMenu->menuItemSelected(mMenu->mSelectListWidget->item(
       
   253             mItemIndexToBeSelected));
       
   254 }
       
   255 
       
   256 void MenuProviderTest::simulateBackButtonClicked()
       
   257 {
       
   258     mMenu->mSoftKeyBackAction->trigger();
       
   259 }
       
   260 
       
   261 
       
   262 void MenuProviderTest::cleanup()
       
   263 {
       
   264     delete mMenu;
       
   265     mMenu = 0;
       
   266 }
       
   267 
       
   268 // End of file