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