controlpanel/tsrc/unit/ut_cpdataformlistentryviewitem/src/ut_cpdataformlistentryviewitem.cpp
branchRCL_3
changeset 54 7e0eff37aedb
parent 53 8ee96d21d9bf
child 57 e78c61e77b1a
equal deleted inserted replaced
53:8ee96d21d9bf 54:7e0eff37aedb
     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 *       test application for qt control panel public apis.
       
    16 */
       
    17 
       
    18 #include "ut_cpdataformlistentryviewitem.h"
       
    19 
       
    20 #include "cpdataformlistentryviewitem.h"
       
    21 #include "CpSettingFormEntryItemDataImpl.h"
       
    22 #include "mycpdataformlistentryviewitem.h"
       
    23 
       
    24 #include <QtTest/QtTest>
       
    25 #include <HbMainWindow>
       
    26 #include <hbdataform.h>
       
    27 #include <hbdataformmodel.h>
       
    28 #include <hbpushbutton.h>
       
    29 #include <cppluginutility.h>
       
    30 #include <cpbasesettingview.h>
       
    31 
       
    32 /*!
       
    33     \class TestCpDataFormListEntryViewItem
       
    34     \brief The TestCpDataFormListEntryViewItem class is designed for the unit testing for CpDataFormListEntryViewItem class.
       
    35     This unit test is supported by QTest.
       
    36     There are total 6 test cases in this unit.
       
    37  */
       
    38 
       
    39 void TestCpDataFormListEntryViewItem::initTestCase()
       
    40     {
       
    41     mainWindow = 0;
       
    42     }
       
    43 
       
    44 void TestCpDataFormListEntryViewItem::cleanupTestCase()
       
    45     {
       
    46     delete mainWindow;
       
    47     
       
    48     //if delete mainwindow, test app will be freezing
       
    49     QCoreApplication::processEvents();
       
    50     }
       
    51 
       
    52 /*!
       
    53  * Test Case Description:\n &nbsp;
       
    54  * 1. Fucntion Name: CpDataFormListEntryViewItem() \n&nbsp;
       
    55    2. Function Descrition: \n &nbsp;&nbsp;
       
    56        2.1 Create CpDataFormListEntryViewItem object with a HbDataForm pointer.\n &nbsp;&nbsp;
       
    57        2.2 verify object created successfully.\n &nbsp;&nbsp;
       
    58        2.3 delete the object.\n &nbsp;
       
    59    3. Input Parameters: \n&nbsp;
       
    60        @param: HbDataForm pointer.\n
       
    61        
       
    62    4. Expected result: \n&nbsp;&nbsp;
       
    63        case run without verify failed.\n 
       
    64  */
       
    65 void TestCpDataFormListEntryViewItem::testCpDataFormListEntryViewItemWithDataForm()
       
    66     {
       
    67     HbDataForm * form = new HbDataForm();
       
    68     QVERIFY( form != 0 );
       
    69     
       
    70     int count0 = form->itemPrototypes().count();
       
    71     CpPluginUtility::addCpItemPrototype(form);
       
    72     int count1 = form->itemPrototypes().count();
       
    73     QVERIFY( count0 + 2 == count1 );
       
    74     
       
    75     CpDataFormListEntryViewItem * item = new CpDataFormListEntryViewItem(form);
       
    76     QVERIFY(item != 0);
       
    77         
       
    78     delete form;
       
    79     }
       
    80 
       
    81 /*!
       
    82  * Test Case Description:\n &nbsp;
       
    83  * 1. Fucntion Name: CpDataFormListEntryViewItem() \n&nbsp;
       
    84    2. Function Descrition: \n &nbsp;&nbsp;
       
    85        2.1 Create CpDataFormListEntryViewItem object with a 0 pointer.\n &nbsp;&nbsp;
       
    86        2.2 verify object created successfully.\n &nbsp;&nbsp;
       
    87        2.3 delete the object.\n &nbsp;
       
    88    3. Input Parameters: \n&nbsp;
       
    89        @param: HbDataForm pointer.\n
       
    90        
       
    91    4. Expected result: \n&nbsp;&nbsp;
       
    92        case run without verify failed.\n 
       
    93  */
       
    94 void TestCpDataFormListEntryViewItem::testCpDataFormListEntryViewItemWithNullPointer()
       
    95     {
       
    96     CpDataFormListEntryViewItem * item = new CpDataFormListEntryViewItem();
       
    97     QVERIFY(item != 0);
       
    98     
       
    99     delete item;
       
   100     }
       
   101 
       
   102 /*!
       
   103  * Test Case Description:\n &nbsp;
       
   104  * 1. Fucntion Name:\n&nbsp;&nbsp;
       
   105        HbAbstractViewItem *createItem();\n&nbsp;
       
   106    2. Function Descrition: \n &nbsp;&nbsp;
       
   107        2.1 Create CpDataFormListEntryViewItem object.\n &nbsp;&nbsp;
       
   108        2.2 verify object created successfully.\n &nbsp;&nbsp;
       
   109        2.3 call createItem() to create a HbAbstractViewItem object.\n&nbsp;&nbsp;
       
   110        2.4 verify the object is not 0.\n&nbsp;&nbsp;
       
   111        2.5 delete both objects.\n &nbsp;
       
   112    3. Input Parameters: \n&nbsp;
       
   113        @param: none.\n
       
   114        
       
   115    4. Expected result: \n&nbsp;&nbsp;
       
   116        case run without verify failed.\n 
       
   117  */
       
   118 void TestCpDataFormListEntryViewItem::testCreateItemNoDataForm()
       
   119     {
       
   120     CpDataFormListEntryViewItem * item = new CpDataFormListEntryViewItem();
       
   121     QVERIFY(item != 0);
       
   122     
       
   123     HbAbstractViewItem * item1 = item->createItem();
       
   124     QVERIFY(item1 != 0);
       
   125     
       
   126     delete item1;
       
   127     delete item;
       
   128     }
       
   129 
       
   130 /*!
       
   131  * Test Case Description:\n &nbsp;
       
   132  * 1. Fucntion Name:\n&nbsp;&nbsp;
       
   133        HbAbstractViewItem *createItem();\n&nbsp;
       
   134    2. Function Descrition: \n &nbsp;&nbsp;
       
   135        2.1 Create CpDataFormListEntryViewItem object.\n &nbsp;&nbsp;
       
   136        2.2 verify object created successfully.\n &nbsp;&nbsp;
       
   137        2.3 call createItem() to create a HbAbstractViewItem object.\n&nbsp;&nbsp;
       
   138        2.4 verify the object is not 0.\n&nbsp;&nbsp;
       
   139        2.5 delete both objects.\n &nbsp;
       
   140    3. Input Parameters: \n&nbsp;
       
   141        @param: none.\n
       
   142        
       
   143    4. Expected result: \n&nbsp;&nbsp;
       
   144        case run without verify failed.\n 
       
   145  */
       
   146 void TestCpDataFormListEntryViewItem::testCreateItemWithDataForm()
       
   147     {
       
   148     HbDataForm * form = new HbDataForm();
       
   149     QVERIFY( form != 0 );
       
   150     
       
   151     CpDataFormListEntryViewItem * item = new CpDataFormListEntryViewItem(form);
       
   152     QVERIFY(item != 0);
       
   153     
       
   154     HbAbstractViewItem * item1 = item->createItem();
       
   155     QVERIFY(item1 != 0);
       
   156     
       
   157     delete item;
       
   158     }
       
   159 
       
   160 /*!
       
   161  * Test Case Description:\n &nbsp;
       
   162  * 1. Fucntion Name: CanSetModelIndex();\n&nbsp;&nbsp;
       
   163        
       
   164    2. Function Descrition: \n &nbsp;&nbsp;
       
   165 
       
   166    3. Input Parameters: \n&nbsp;
       
   167        @param: none.\n
       
   168        
       
   169    4. Expected result: \n&nbsp;&nbsp;
       
   170        case run without verify failed.\n 
       
   171  */
       
   172 void TestCpDataFormListEntryViewItem::testCanSetModelIndexWithDataForm()
       
   173     {
       
   174     HbDataForm * form = new HbDataForm();
       
   175     QVERIFY( form != 0 );
       
   176     
       
   177     int count0 = form->itemPrototypes().count();
       
   178     CpPluginUtility::addCpItemPrototype(form);
       
   179     int count1 = form->itemPrototypes().count();
       
   180     QVERIFY( count0 + 2 == count1 );
       
   181         
       
   182     CpSettingFormEntryItemDataImpl<CpBaseSettingView> *pdataimp1 = new CpSettingFormEntryItemDataImpl<CpBaseSettingView>( CpSettingFormEntryItemData::ListEntryItem, form, "text", "description" );
       
   183     QVERIFY( pdataimp1 !=0 );
       
   184     
       
   185     HbDataFormModel * model = new HbDataFormModel;
       
   186     QVERIFY( model != 0 );
       
   187     
       
   188     model->appendDataFormItem(pdataimp1);
       
   189     form->setModel(model);
       
   190     form->show();
       
   191     }
       
   192 
       
   193 /*!
       
   194  * Test Case Description:\n &nbsp;
       
   195  * 1. Fucntion Name: \n&nbsp;&nbsp;
       
   196       HbWidget* createCustomWidget();
       
   197        
       
   198    2. Function Descrition: \n &nbsp;&nbsp;
       
   199 
       
   200    3. Input Parameters: \n&nbsp;
       
   201        @param: none.\n
       
   202        
       
   203    4. Expected result: \n&nbsp;&nbsp;
       
   204        case run without verify failed.\n 
       
   205  */
       
   206 void TestCpDataFormListEntryViewItem::testCreateCustomedWidgetNoParam()
       
   207     {
       
   208     HbDataForm * form = new HbDataForm();
       
   209     QVERIFY( form != 0 );
       
   210     
       
   211     int count0 = form->itemPrototypes().count();
       
   212     CpPluginUtility::addCpItemPrototype(form);
       
   213     int count1 = form->itemPrototypes().count();
       
   214     QVERIFY( count0 + 2 == count1 );
       
   215         
       
   216     CpSettingFormEntryItemDataImpl<CpBaseSettingView> *pdataimp1 = new CpSettingFormEntryItemDataImpl<CpBaseSettingView>( CpSettingFormEntryItemData::ListEntryItem, form, "text", "description" );
       
   217     QVERIFY( pdataimp1 !=0 );
       
   218     
       
   219     HbDataFormModel * model = new HbDataFormModel;
       
   220     QVERIFY( model != 0 );
       
   221     
       
   222     model->appendDataFormItem(pdataimp1);
       
   223     form->setModel(model);
       
   224     
       
   225     mainWindow = new HbMainWindow;
       
   226     QVERIFY( mainWindow != 0 );
       
   227     
       
   228     CpBaseSettingView *mainView = new CpBaseSettingView(form);
       
   229     QVERIFY( mainView != 0 );
       
   230     
       
   231     QObject::connect(mainView,SIGNAL(aboutToClose()),qApp,SLOT(quit()));
       
   232     HbView * view = mainWindow->addView(mainView);
       
   233     QVERIFY( view != 0 );
       
   234     
       
   235     mainWindow->setCurrentView(mainView);
       
   236     HbView * curView = mainWindow->currentView();
       
   237     QVERIFY( curView == mainView );
       
   238     
       
   239     mainWindow->show();
       
   240     }
       
   241 
       
   242 QTEST_MAIN(TestCpDataFormListEntryViewItem)