phoneplugins/infowidgetplugin/infowidgetprovider/tsrc/ut_infowidgetlayoutmanager/src/ut_infowidgetlayoutmanager.cpp
branchGCC_SURGE
changeset 51 f39ed5e045e0
parent 40 bab96b7ed1a4
parent 46 bc5a64e5bc3c
equal deleted inserted replaced
40:bab96b7ed1a4 51:f39ed5e045e0
     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_infowidgetlayoutmanager.h"
       
    18 #include <QGraphicsWidget>
       
    19 #include <hbmarqueeitem>
       
    20 #include <hbstyle>
       
    21 #define private public
       
    22 #include "infowidgetlayoutmanager.h"
       
    23 #include "qtestmains60.h"
       
    24 
       
    25 
       
    26 
       
    27 const int KNumOfSettingsDisplayRoles = 6;
       
    28 const int KNumOfInfoDisplayRoles = 7;
       
    29 const QString KInfoWidgetDocmlFile = ":/resource/infowidget.docml";
       
    30 const QString KMargueeItemClassName = HbMarqueeItem::staticMetaObject.className();
       
    31 
       
    32 //class HbStyle;
       
    33 /*!
       
    34   UT_InfoWidgetLayoutManager::UT_InfoWidgetLayoutManager
       
    35  */
       
    36 UT_InfoWidgetLayoutManager::UT_InfoWidgetLayoutManager() 
       
    37     : 
       
    38     m_layoutManager(NULL),
       
    39     m_documentLoader(NULL)
       
    40 {
       
    41     m_checkBoxPtr = new QGraphicsWidget;  
       
    42     m_iconPtr = new QGraphicsWidget; 
       
    43     m_marqueeItemPtr = new QGraphicsWidget; 
       
    44     m_labelPtr = new QGraphicsWidget; 
       
    45     m_graphicsWidgetPtr = new QGraphicsWidget;
       
    46 }
       
    47 
       
    48 
       
    49 /*!
       
    50   UT_InfoWidgetLayoutManager::~UT_InfoWidgetLayoutManager
       
    51  */
       
    52 UT_InfoWidgetLayoutManager::~UT_InfoWidgetLayoutManager()
       
    53 {
       
    54     delete m_layoutManager;
       
    55     delete m_checkBoxPtr;  
       
    56     delete m_iconPtr; 
       
    57     delete m_marqueeItemPtr; 
       
    58     delete m_labelPtr; 
       
    59     delete m_graphicsWidgetPtr; 
       
    60 }
       
    61 
       
    62 
       
    63 /*!
       
    64   UT_InfoWidgetLayoutManager::init
       
    65  */
       
    66 void UT_InfoWidgetLayoutManager::init()
       
    67 {
       
    68     initialize();
       
    69     
       
    70     QObjectList objectList;
       
    71     EXPECT(HbDocumentLoader::load)
       
    72         .with(KInfoWidgetDocmlFile, false)
       
    73         .returns(&objectList);
       
    74     EXPECT(HbDocumentLoader::load)
       
    75         .with(KInfoWidgetDocmlFile, false)
       
    76         .returns(&objectList);
       
    77     m_layoutManager = new InfoWidgetLayoutManager();
       
    78     
       
    79     m_documentLoader = new InfoWidgetDocumentLoader; 
       
    80     
       
    81     QVERIFY(verify());
       
    82 }
       
    83 
       
    84 
       
    85 /*!
       
    86   UT_InfoWidgetLayoutManager::cleanup
       
    87  */
       
    88 void UT_InfoWidgetLayoutManager::cleanup()
       
    89 {
       
    90     reset();
       
    91     
       
    92     delete m_layoutManager;
       
    93     m_layoutManager = NULL; 
       
    94     
       
    95     delete m_documentLoader; 
       
    96     m_documentLoader = NULL; 
       
    97 }
       
    98 
       
    99 /*!
       
   100   UT_InfoWidgetLayoutManager::fillDisplayContainers
       
   101  */
       
   102 void UT_InfoWidgetLayoutManager::fillDisplayContainers()
       
   103 {
       
   104     InfoWidgetLayoutManager::LayoutItemRole currentRole; 
       
   105     
       
   106     QList<InfoWidgetLayoutManager::LayoutItemRole> infoDisplayWidgetRoles = 
       
   107             m_layoutManager->widgetRoles(InfoWidgetLayoutManager::InfoDisplay); 
       
   108     foreach (currentRole, infoDisplayWidgetRoles) {
       
   109         m_layoutManager->m_infoDisplayWidgets.insert(currentRole, m_graphicsWidgetPtr);    
       
   110     }
       
   111      
       
   112     QList<InfoWidgetLayoutManager::LayoutItemRole> settingsDisplayWidgetRoles = 
       
   113             m_layoutManager->widgetRoles(InfoWidgetLayoutManager::SettingsDisplay); 
       
   114     foreach (currentRole, settingsDisplayWidgetRoles) {
       
   115         m_layoutManager->m_settingsDisplayWidgets.insert(currentRole, m_graphicsWidgetPtr);    
       
   116     }
       
   117 
       
   118 }
       
   119 
       
   120 /*!
       
   121   UT_InfoWidgetLayoutManager::fillParams
       
   122  */
       
   123 void UT_InfoWidgetLayoutManager::fillParams(const QString & fileName,
       
   124         bool * ok){
       
   125     Q_UNUSED(fileName)
       
   126     *ok = true;
       
   127 }
       
   128 
       
   129 /*!
       
   130   UT_InfoWidgetLayoutManager::fillCurrentWidgetsContainer
       
   131  */
       
   132 void UT_InfoWidgetLayoutManager::fillCurrentWidgetsContainer()
       
   133 {
       
   134     InfoWidgetLayoutManager::LayoutItemRole currentRole; 
       
   135     
       
   136     QList<InfoWidgetLayoutManager::LayoutItemRole> infoDisplayWidgetRoles = 
       
   137             m_layoutManager->widgetRoles(InfoWidgetLayoutManager::InfoDisplay); 
       
   138     foreach (currentRole, infoDisplayWidgetRoles) {
       
   139         m_layoutManager->m_widgets.insert(currentRole, m_graphicsWidgetPtr);    
       
   140     }
       
   141 }
       
   142 
       
   143 /*!
       
   144   UT_InfoWidgetLayoutManager::t_currentDisplayRole
       
   145  */
       
   146 void UT_InfoWidgetLayoutManager::t_currentDisplayRole()
       
   147 {
       
   148     InfoWidgetLayoutManager::DisplayRole role =
       
   149         m_layoutManager->currentDisplayRole();
       
   150     
       
   151     QVERIFY(InfoWidgetLayoutManager::InfoDisplay == role);
       
   152 }
       
   153 
       
   154 
       
   155 /*!
       
   156   UT_InfoWidgetLayoutManager::t_currentWidgetRoles
       
   157  */
       
   158 void UT_InfoWidgetLayoutManager::t_currentWidgetRoles()
       
   159 {
       
   160     // Initial state after layout manager construction 
       
   161     QList<InfoWidgetLayoutManager::LayoutItemRole> roles =
       
   162         m_layoutManager->currentWidgetRoles();
       
   163     QVERIFY(roles.count() == 0);
       
   164     
       
   165     // Fill display container data 
       
   166     fillDisplayContainers();
       
   167     
       
   168     QGraphicsLayout *activeLayout;    
       
   169     activeLayout= m_layoutManager->layoutInfoDisplay(); 
       
   170     QVERIFY(!activeLayout);
       
   171     
       
   172     roles = m_layoutManager->currentWidgetRoles();
       
   173             
       
   174     QVERIFY(roles.count() == KNumOfInfoDisplayRoles);
       
   175     if (roles.count() == KNumOfInfoDisplayRoles) {
       
   176         QVERIFY(0 <= roles.indexOf(
       
   177             InfoWidgetLayoutManager::RoleContent));
       
   178         QVERIFY(0 <= roles.indexOf(
       
   179             InfoWidgetLayoutManager::RoleSpnLabel));
       
   180         QVERIFY(0 <= roles.indexOf(
       
   181             InfoWidgetLayoutManager::RoleMcnMarqueeItem));
       
   182         QVERIFY(0 <= roles.indexOf(
       
   183             InfoWidgetLayoutManager::RoleSatMarqueeItem));
       
   184         QVERIFY(0 <= roles.indexOf(
       
   185             InfoWidgetLayoutManager::RoleSpnIcon));
       
   186         QVERIFY(0 <= roles.indexOf(
       
   187             InfoWidgetLayoutManager::RoleMcnIcon));
       
   188         QVERIFY(0 <= roles.indexOf(
       
   189             InfoWidgetLayoutManager::RoleSatTextIcon));
       
   190     }
       
   191     
       
   192     activeLayout= m_layoutManager->layoutSettingsDisplay(); 
       
   193     QVERIFY(!activeLayout);
       
   194 
       
   195     roles = m_layoutManager->currentWidgetRoles();
       
   196     int dVar = roles.count();  
       
   197     QVERIFY(roles.count() == KNumOfSettingsDisplayRoles);
       
   198 
       
   199 }
       
   200 
       
   201 
       
   202 /*!
       
   203   UT_InfoWidgetLayoutManager::t_layoutRows
       
   204  */
       
   205 void UT_InfoWidgetLayoutManager::t_layoutRows()
       
   206 {
       
   207     int rows = m_layoutManager->layoutRows();
       
   208     QVERIFY(0 == rows);
       
   209 }
       
   210 
       
   211 
       
   212 /*!
       
   213   UT_InfoWidgetLayoutManager::t_setLayoutRows
       
   214  */
       
   215 void UT_InfoWidgetLayoutManager::t_setLayoutRows()
       
   216 {
       
   217     const int KLayoutRows = 1;
       
   218     m_layoutManager->setLayoutRows(KLayoutRows);
       
   219     QVERIFY(KLayoutRows == m_layoutManager->layoutRows());
       
   220 }
       
   221 
       
   222 /*!
       
   223   UT_InfoWidgetLayoutManager::t_setLayoutRows
       
   224  */
       
   225 void UT_InfoWidgetLayoutManager::t_rowHeight()
       
   226 {
       
   227     bool b = false;
       
   228     EXPECT(HbStyle::parameter).returns(b);
       
   229     m_layoutManager->rowHeight();
       
   230     
       
   231     b = true;
       
   232     EXPECT(HbStyle::parameter).returns(b);
       
   233     m_layoutManager->rowHeight();
       
   234     
       
   235     QVERIFY(verify()); 
       
   236 }
       
   237 
       
   238 /*!
       
   239   UT_InfoWidgetLayoutManager::t_layoutInfoDisplay
       
   240  */
       
   241 void UT_InfoWidgetLayoutManager::t_layoutInfoDisplay()
       
   242 {
       
   243     QVERIFY(!m_layoutManager->layoutInfoDisplay());
       
   244 }
       
   245 
       
   246 
       
   247 /*!
       
   248   UT_InfoWidgetLayoutManager::t_layoutSettingsDisplay
       
   249  */
       
   250 void UT_InfoWidgetLayoutManager::t_layoutSettingsDisplay()
       
   251 {
       
   252     QVERIFY(!m_layoutManager->layoutSettingsDisplay());
       
   253 }
       
   254 
       
   255 /*!
       
   256   UT_InfoWidgetLayoutManager::t_widgetRoles
       
   257  */
       
   258 void UT_InfoWidgetLayoutManager::t_widgetRoles()
       
   259 {
       
   260     const QList<InfoWidgetLayoutManager::LayoutItemRole> settingDisplayRoles =
       
   261         m_layoutManager->widgetRoles(InfoWidgetLayoutManager::SettingsDisplay);
       
   262     
       
   263     QVERIFY(settingDisplayRoles.count() == KNumOfSettingsDisplayRoles);
       
   264     if (settingDisplayRoles.count() == KNumOfSettingsDisplayRoles) {
       
   265         QVERIFY(0 <= settingDisplayRoles.indexOf(
       
   266             InfoWidgetLayoutManager::RoleContent));
       
   267         QVERIFY(0 <= settingDisplayRoles.indexOf(
       
   268             InfoWidgetLayoutManager::RoleSpnCheckBox));
       
   269         QVERIFY(0 <= settingDisplayRoles.indexOf(
       
   270             InfoWidgetLayoutManager::RoleMcnCheckBox));
       
   271         QVERIFY(0 <= settingDisplayRoles.indexOf(
       
   272             InfoWidgetLayoutManager::RoleSatTextCheckBox));
       
   273         QVERIFY(0 <= settingDisplayRoles.indexOf(
       
   274             InfoWidgetLayoutManager::RoleOkButton));
       
   275         QVERIFY(0 <= settingDisplayRoles.indexOf(
       
   276             InfoWidgetLayoutManager::RoleSettingsContainer));
       
   277     }
       
   278     
       
   279     const QList<InfoWidgetLayoutManager::LayoutItemRole> infoDisplayRoles =
       
   280         m_layoutManager->widgetRoles(InfoWidgetLayoutManager::InfoDisplay);
       
   281     QVERIFY(infoDisplayRoles.count() == KNumOfInfoDisplayRoles);
       
   282     if (infoDisplayRoles.count() == KNumOfInfoDisplayRoles) {
       
   283         QVERIFY(0 <= infoDisplayRoles.indexOf(
       
   284             InfoWidgetLayoutManager::RoleContent));
       
   285         QVERIFY(0 <= infoDisplayRoles.indexOf(
       
   286             InfoWidgetLayoutManager::RoleSpnLabel));
       
   287         QVERIFY(0 <= infoDisplayRoles.indexOf(
       
   288             InfoWidgetLayoutManager::RoleMcnMarqueeItem));
       
   289         QVERIFY(0 <= infoDisplayRoles.indexOf(
       
   290             InfoWidgetLayoutManager::RoleSatMarqueeItem));
       
   291         QVERIFY(0 <= infoDisplayRoles.indexOf(
       
   292             InfoWidgetLayoutManager::RoleSpnIcon));
       
   293         QVERIFY(0 <= infoDisplayRoles.indexOf(
       
   294             InfoWidgetLayoutManager::RoleMcnIcon));
       
   295         QVERIFY(0 <= infoDisplayRoles.indexOf(
       
   296             InfoWidgetLayoutManager::RoleSatTextIcon));
       
   297     }
       
   298 }
       
   299 
       
   300 /*!
       
   301   UT_InfoWidgetLayoutManager::t_loadWidgets
       
   302  */
       
   303 void UT_InfoWidgetLayoutManager::t_loadWidgets()
       
   304 {
       
   305     QObjectList list = QObjectList();
       
   306     EXPECT(HbDocumentLoader::load)
       
   307         .willOnce(invoke(this, &fillParams)).returns(list);
       
   308     
       
   309     const QList<InfoWidgetLayoutManager::LayoutItemRole> settingDisplayRoles =
       
   310             m_layoutManager->widgetRoles(InfoWidgetLayoutManager::SettingsDisplay);
       
   311     bool loadResult = m_layoutManager->loadWidgets(InfoWidgetLayoutManager::SettingsDisplay, 
       
   312             settingDisplayRoles,
       
   313             m_layoutManager->m_infoDisplayWidgets); 
       
   314     
       
   315     QVERIFY(!loadResult);
       
   316 }
       
   317 
       
   318 /*!
       
   319   UT_InfoWidgetLayoutManager::t_loadWidget
       
   320  */
       
   321 void UT_InfoWidgetLayoutManager::t_loadWidget()
       
   322 {
       
   323     QGraphicsWidget *currentWidget; 
       
   324     InfoWidgetLayoutManager::LayoutItemRole currentRole; 
       
   325     
       
   326     QList<InfoWidgetLayoutManager::LayoutItemRole> 
       
   327         infoDisplayWidgetRoles = m_layoutManager->widgetRoles(
       
   328                 InfoWidgetLayoutManager::InfoDisplay); 
       
   329     
       
   330     infoDisplayWidgetRoles.append(InfoWidgetLayoutManager::RoleUndefined); 
       
   331     infoDisplayWidgetRoles.append(InfoWidgetLayoutManager::RoleContainer);
       
   332     
       
   333 
       
   334     foreach (currentRole, infoDisplayWidgetRoles) {
       
   335         currentWidget = m_layoutManager->loadWidget(*m_documentLoader,
       
   336                 InfoWidgetLayoutManager::InfoDisplay,
       
   337                 currentRole);
       
   338         QVERIFY(!currentWidget);
       
   339     }
       
   340     
       
   341     QList<InfoWidgetLayoutManager::LayoutItemRole> 
       
   342         settingsDisplayWidgetRoles = m_layoutManager->widgetRoles(
       
   343                 InfoWidgetLayoutManager::SettingsDisplay); 
       
   344     
       
   345     foreach (currentRole, settingsDisplayWidgetRoles) {
       
   346         currentWidget = m_layoutManager->loadWidget(*m_documentLoader,
       
   347                 InfoWidgetLayoutManager::SettingsDisplay,
       
   348                 currentRole);
       
   349         QVERIFY(!currentWidget);
       
   350     }
       
   351     
       
   352     currentWidget = m_layoutManager->loadWidget(*m_documentLoader,
       
   353                 (InfoWidgetLayoutManager::DisplayRole)2,
       
   354                         InfoWidgetLayoutManager::RoleLastEnum );
       
   355     
       
   356     QVERIFY(!currentWidget);
       
   357 }
       
   358 
       
   359 /*!
       
   360   UT_InfoWidgetLayoutManager::t_getWidget
       
   361  */
       
   362 void UT_InfoWidgetLayoutManager::t_getWidget()
       
   363 {
       
   364     fillCurrentWidgetsContainer();
       
   365     
       
   366     QVERIFY(!m_layoutManager->getWidget(InfoWidgetLayoutManager::RoleUndefined));
       
   367     QVERIFY(m_layoutManager->getWidget(InfoWidgetLayoutManager::RoleContent));
       
   368     QVERIFY(!m_layoutManager->getWidget(InfoWidgetLayoutManager::RoleLastEnum));
       
   369 }
       
   370 
       
   371 /*!
       
   372   UT_InfoWidgetLayoutManager::t_removeWidget
       
   373  */
       
   374 void UT_InfoWidgetLayoutManager::t_removeWidget()
       
   375 {
       
   376     fillCurrentWidgetsContainer();
       
   377         
       
   378     m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleUndefined);
       
   379     m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleContent);
       
   380     m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleLastEnum);
       
   381     
       
   382     QVERIFY(verify());
       
   383 }
       
   384 
       
   385 
       
   386 /*!
       
   387   UT_InfoWidgetLayoutManager::t_contentWidget
       
   388  */
       
   389 void UT_InfoWidgetLayoutManager::t_contentWidget()
       
   390 {
       
   391     fillCurrentWidgetsContainer();
       
   392     
       
   393     QVERIFY(m_layoutManager->contentWidget());
       
   394 }
       
   395 
       
   396 
       
   397 /*!
       
   398   UT_InfoWidgetLayoutManager::t_hideWidget
       
   399  */
       
   400 void UT_InfoWidgetLayoutManager::t_hideWidget()
       
   401 {
       
   402     fillCurrentWidgetsContainer();
       
   403     
       
   404     m_layoutManager->hideWidget(InfoWidgetLayoutManager::RoleUndefined);
       
   405     m_layoutManager->hideWidget(InfoWidgetLayoutManager::RoleContent);
       
   406     m_layoutManager->hideWidget(InfoWidgetLayoutManager::RoleLastEnum);
       
   407     
       
   408     QVERIFY(verify());
       
   409 }
       
   410 
       
   411 
       
   412 /*!
       
   413   UT_InfoWidgetLayoutManager::t_hideAll
       
   414  */
       
   415 void UT_InfoWidgetLayoutManager::t_hideAll()
       
   416 {
       
   417     m_layoutManager->hideAll();
       
   418     
       
   419     QVERIFY(verify());
       
   420 }
       
   421 
       
   422 
       
   423 /*!
       
   424   UT_InfoWidgetLayoutManager::t_showAll
       
   425  */
       
   426 void UT_InfoWidgetLayoutManager::t_showAll()
       
   427 {
       
   428     fillCurrentWidgetsContainer();//times 2 HbDocumentLoader::load
       
   429     m_layoutManager->showAll();
       
   430     
       
   431     QVERIFY(verify());
       
   432 }
       
   433 
       
   434 /*!
       
   435   UT_InfoWidgetLayoutManager::t_reloadWidgets
       
   436  */
       
   437 void UT_InfoWidgetLayoutManager::t_reloadWidgets()
       
   438 {
       
   439     QVERIFY(!m_layoutManager->reloadWidgets(InfoWidgetLayoutManager::SettingsDisplay));
       
   440     QVERIFY(!m_layoutManager->reloadWidgets((InfoWidgetLayoutManager::DisplayRole)101));
       
   441 }
       
   442 
       
   443 /*!
       
   444   UT_InfoWidgetLayoutManager::t_destroyObjects
       
   445  */
       
   446 void UT_InfoWidgetLayoutManager::t_destroyObjects()
       
   447 {
       
   448     m_layoutManager->destroyObjects();
       
   449     
       
   450     QGraphicsWidget *widgetInfo = new QGraphicsWidget();
       
   451     QGraphicsWidget *widgetSettings = new QGraphicsWidget(); 
       
   452     m_layoutManager->m_infoDisplayWidgets.insert(InfoWidgetLayoutManager::RoleContent, widgetInfo);
       
   453     m_layoutManager->m_settingsDisplayWidgets.insert(InfoWidgetLayoutManager::RoleContent, widgetSettings);
       
   454     m_layoutManager->destroyObjects();
       
   455     
       
   456     QVERIFY(verify());
       
   457 }
       
   458 
       
   459 /*!
       
   460   UT_InfoWidgetLayoutManager::t_createObject
       
   461  */
       
   462 void UT_InfoWidgetLayoutManager::t_createObject()
       
   463 {
       
   464     QObject *object = m_documentLoader->createObject(QString(), QString());
       
   465     QVERIFY(!object);
       
   466     object = m_documentLoader->createObject(KMargueeItemClassName, QString());
       
   467     QVERIFY(object);
       
   468     delete object;
       
   469     
       
   470     //For destructor coverage
       
   471     delete m_layoutManager->m_documentLoader;
       
   472     m_layoutManager->m_documentLoader = NULL;
       
   473 }
       
   474 
       
   475 QTEST_MAIN_S60(UT_InfoWidgetLayoutManager)