controlpanel/tsrc/unit/ut_cpapi/src/ut_cpapi.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:  test application for qt control panel public apis.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "ut_cpapi.h"
       
    19 #include "cptestpluginentryitem.h"
       
    20 #include "cptestview.h"
       
    21 
       
    22 //#include <hbmainwindow.h>
       
    23 #include <QGraphicsWidget>
       
    24 #include <qDebug>
       
    25 #include <QtTest/QtTest>
       
    26 #include <QtAlgorithms>
       
    27 #include <HbView.h>
       
    28 #include <hbdataform.h>
       
    29 #include <hbdataformmodel.h>
       
    30 #include <hbdataformmodelitem.h>
       
    31 #include <hbdataformviewitem.h>
       
    32 #include <hbabstractviewitem.h>
       
    33 #include <hbpushbutton.h>
       
    34 //testing following classes
       
    35 #include <cpbasesettingview.h>
       
    36 #include "cpsettingformentryitemdata.h"
       
    37 #include "cpsettingformentryitemdataimpl.h"
       
    38 #include <cpsettingformitemdata.h>
       
    39 #include <cpitemdatahelper.h>
       
    40 #include <cppluginutility.h>
       
    41 #include <cppluginloader.h>
       
    42 #include <cpplugininterface.h>
       
    43 #include <cplauncherinterface.h>
       
    44 #include <cplogger.h>
       
    45 /*!
       
    46      \class TestCpAPI 
       
    47      \brief class name: TestCpAPI \n
       
    48       class's description: \n
       
    49       type of test case: API class test \n
       
    50       test cases' number totally: 9 \n
       
    51  */
       
    52 void TestCpAPI::initTestCase()
       
    53 {    
       
    54 
       
    55 }
       
    56 
       
    57 void TestCpAPI::cleanupTestCase()
       
    58 {
       
    59 	QCoreApplication::processEvents();
       
    60 }
       
    61 /*!
       
    62     <b>Test Case Description:</b> \n&nbsp;&nbsp;
       
    63         Verify the class CpBaseSettingView can created corresponding views via different parameters.\n
       
    64      1. Fucntion Name: \n &nbsp;&nbsp;
       
    65 		<1> CpBaseSettingView::CpBaseSettingView(QGraphicsWidget *widget,QGraphicsItem *parent)\n &nbsp;&nbsp;
       
    66 		<2> virtual void close()\n
       
    67      2. Case Descrition: \n&nbsp;&nbsp;
       
    68 		<1> test the constructor function\n &nbsp;&nbsp;
       
    69 		<2> Test the close() function. \n
       
    70      3. Input Parameters: \n&nbsp;&nbsp;
       
    71 		<1> widget = 0 , parent = 0 \n &nbsp;&nbsp;
       
    72           widget = 0, parent = new HbWidget () \n &nbsp;&nbsp;&nbsp;&nbsp;
       
    73           widget = new Hbpushbuton (), parent = 0 \n &nbsp;&nbsp;&nbsp;&nbsp;
       
    74           widget = new hbpushbutton(), parent  = new HbWidget() \n &nbsp;&nbsp;
       
    75 	   <2> none \n
       
    76      4. Expected result:  \n &nbsp;&nbsp;
       
    77 		<1> pview != 0, no crash \n &nbsp;&nbsp;
       
    78 		<2> no crash \n
       
    79  */
       
    80 void TestCpAPI::testCpBaseSettingView()
       
    81 {
       
    82 	//set the parameters as 0
       
    83     CpBaseSettingView * pview = new CpBaseSettingView(0);
       
    84 	QVERIFY( pview != 0 );	
       
    85     HbDataForm *pForm = new HbDataForm(0);
       
    86     pview->setWidget(pForm);
       
    87     QVERIFY( qobject_cast<HbDataForm *>(pview->widget()) == pForm );
       
    88 	delete pview;
       
    89 	pview = 0;
       
    90 	
       
    91 	HbPushButton *widget = new HbPushButton();
       
    92 	QVERIFY(widget != 0);
       
    93 	// set the first parameter as widget
       
    94 	CpBaseSettingView *pView1 = new CpBaseSettingView(widget);
       
    95 	QVERIFY(pView1!=0);
       
    96 	HbPushButton *button = qobject_cast<HbPushButton *>(pView1->widget());
       
    97 	QVERIFY(button != 0);	
       
    98 	delete pView1;	
       
    99 	pView1 = 0;
       
   100 	
       
   101 	// test close() function in CpBaseSettingView class.
       
   102 	CpTestView *pview3 = new CpTestView();
       
   103 	pview3->testClose();
       
   104 	delete pview3;
       
   105 	pview3 = 0;
       
   106 }
       
   107 /*!
       
   108      <b>Test Case Description:</b> \n
       
   109      .	Verify this class could create the corresponding control panel defined HbDataFormModelItem. \n\n
       
   110      <b>Function 1:</b> \n
       
   111 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   112       CpSettingFormItemData(HbDataFormModelItem::DataItemType type, const QString &label, const HbDataFormModelItem *parent = 0) \n
       
   113      2. Case Descrition: \n &nbsp;&nbsp;
       
   114 		Test the constructor function. \n
       
   115      3. Input Parameters: \n &nbsp;&nbsp;
       
   116       <1> type = HbDataFormModelItem::DataItemType,  label = QString, parent = new HbDataFormModelItem(), \n&nbsp;&nbsp;
       
   117       <2> type =  (HbDataFormModelItem::DataItemType) invaildValue, label = 0, parent = 0 \n
       
   118      4. Expected result: \n &nbsp;&nbsp;
       
   119             <1> pdata != 0, pdata->type() == type \n &nbsp;&nbsp;
       
   120             <2> no crash  \n
       
   121      <b>Function 2:</b> \n
       
   122      1. Fucntion Name: \n &nbsp;&nbsp;
       
   123             CpSettingFormItemData(const HbDataFormModelItem *parent = 0) \n
       
   124      2. Case Descrition: \n &nbsp;&nbsp;
       
   125             Test the constructor function. \n
       
   126      3. Input Parameters: \n &nbsp;&nbsp;
       
   127             none \n
       
   128      4. Expected result: \n &nbsp;&nbsp;
       
   129             pdata != 0 & no crash \n
       
   130 	 <b>Function 3:</b> \n
       
   131      1. Fucntion Name: \n &nbsp;&nbsp;
       
   132             QString text() const; \n
       
   133      2. Case Descrition: \n &nbsp;&nbsp;
       
   134             Verify it returns the right text string. \n
       
   135      3. Input Parameters: \n &nbsp;&nbsp;
       
   136             none \n
       
   137      4. Expected result: \n &nbsp;&nbsp;
       
   138             return the correct text string \n
       
   139 	 <b>Function 4:</b> \n
       
   140      1. Fucntion Name: \n &nbsp;&nbsp;
       
   141             void setText(const QString &text); \n
       
   142      2. Case Descrition: \n &nbsp;&nbsp;
       
   143             Verify that the text can be set via this function. \n
       
   144      3. Input Parameters: \n &nbsp;&nbsp;
       
   145             text = QString(xx)
       
   146      4. Expected result: \n &nbsp;&nbsp;
       
   147             pItemData->text() ==  text \n
       
   148      <b>Function 5:</b> \n
       
   149 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   150             QString description() const; \n
       
   151      2. Case Descrition: \n &nbsp;&nbsp;
       
   152             Verify that it returns the correct description name. \n
       
   153      3. Input Parameters: \n &nbsp;&nbsp;
       
   154             none \n
       
   155      4. Expected result: \n &nbsp;&nbsp;
       
   156             return the correct text string \n
       
   157      <b>Function 6:</b> \n
       
   158 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   159             void setDescription(const QString &description); \n
       
   160      2. Case Descrition: \n &nbsp;&nbsp;
       
   161             Verify it can set description successfully. \n
       
   162      3. Input Parameters: \n &nbsp;&nbsp;
       
   163             description = QString(xx)
       
   164      4. Expected result: \n &nbsp;&nbsp;
       
   165             pItemData->description() ==  description \n
       
   166      <b>Function 7:</b> \n
       
   167 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   168             QString iconName() const;\n
       
   169      2. Case Descrition: \n &nbsp;&nbsp;
       
   170             Verify it can return the right icon name. \n
       
   171      3. Input Parameters: \n &nbsp;&nbsp;
       
   172             none \n
       
   173      4. Expected result: \n &nbsp;&nbsp;
       
   174             return the correct icon name \n
       
   175      <b>Function 8:</b> \n
       
   176 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   177             void setIconName(const QString &icon); \n
       
   178      2. Case Descrition: \n &nbsp;&nbsp;
       
   179             Verify it can set the given icon name successfully.\n
       
   180      3. Input Parameters: \n &nbsp;&nbsp;
       
   181             iconName = QString(xx)
       
   182      4. Expected result: \n &nbsp;&nbsp;
       
   183             pItemData->iconNmae() ==  iconName \n
       
   184      <b>Function 9:</b> \n
       
   185 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   186             void setEntryItemIcon(const HbIcon &icon); \n
       
   187      2. Case Descrition: \n &nbsp;&nbsp;
       
   188             Verify it can set the item icon successfully. \n
       
   189      3. Input Parameters: \n &nbsp;&nbsp;
       
   190             icon = HbIcon()
       
   191      4. Expected result: \n &nbsp;&nbsp;
       
   192             entryItemIcon() == icon \n            
       
   193 */
       
   194 void TestCpAPI::testCpSettingFormEntryItemData()
       
   195 {
       
   196     // create CpTestPluginEntryItemData class firstly
       
   197     CpItemDataHelper *pHelper = new CpItemDataHelper();   
       
   198     HbIcon pIcon = HbIcon("icon");
       
   199     
       
   200     // test the first constructor
       
   201     CpTestPluginEntryItemData *pItemData = new CpTestPluginEntryItemData(0);
       
   202     QVERIFY (pItemData!=0);
       
   203     delete pItemData;
       
   204     pItemData = 0;    
       
   205     
       
   206     // The second constructor
       
   207     pItemData = new CpTestPluginEntryItemData(*pHelper, "test","test", pIcon, 0);
       
   208     QVERIFY (pItemData!=0);
       
   209     
       
   210     // test settext() and text() function
       
   211     QString aText = "strText";
       
   212     pItemData->setText(aText);
       
   213     QString aTextTemp = pItemData->text();
       
   214     QVERIFY( aTextTemp == aText);
       
   215     
       
   216     // test setDescription() and description() function    
       
   217     QString aDescription = "strDescription";
       
   218     pItemData->setDescription(aDescription);
       
   219     QString aDesTemp = pItemData->description();
       
   220     QVERIFY( aDesTemp == aDescription);
       
   221     
       
   222     // test setIconName() and iconName() function    
       
   223     QString aIconName = "strIconName";
       
   224     pItemData->setIconName(aIconName);
       
   225     QString aIconTemp = pItemData->iconName();
       
   226     QVERIFY( aIconTemp == aIconName);
       
   227     
       
   228     // test setEntryItemIcon() and entryItemIcon() function 
       
   229     pItemData->setEntryItemIcon(pIcon);
       
   230     HbIcon pIconTemp = pItemData->entryItemIcon();
       
   231     QVERIFY( pIconTemp == pIcon);
       
   232     
       
   233     // test onLaunchView() function
       
   234     pItemData->onLaunchView();
       
   235     
       
   236     delete pItemData;
       
   237     pItemData = 0;
       
   238     delete pHelper;
       
   239     pHelper = 0;
       
   240 }
       
   241 
       
   242 /*!
       
   243      Test Case Description: \n
       
   244          Verify this class could create the corresponding CpSettingFormEntryItemData. \n
       
   245 	 <b>Function 1:</b> \n
       
   246      1. Fucntion Name: \n &nbsp;&nbsp;
       
   247             explicit CpSettingFormEntryItemDataImpl(CpItemDataHelper &itemDataHelper,const QString &text = QString(), \n
       
   248                                                     const QString &description = QString(),const HbIcon &icon = HbIcon(), \n
       
   249                                                     const HbDataFormModelItem *parent = 0) \n
       
   250      2. Case Descrition: \n &nbsp;&nbsp;
       
   251             Test the first constructor function. \n
       
   252      3. Input Parameters: \n &nbsp;&nbsp;
       
   253             <1> itemDataHelper = CpItemDataHelper, text = Qstring(XX),description = Qstring(XX),
       
   254             	  icon = HbIcon(), parent = new HbDataFormModelItem() \n &nbsp;&nbsp;
       
   255             <2> itemDataHelper = CpItemDataHelper , text = Qstring(),
       
   256             	  description = Qstring(), icon = HbIcon(), parent = 0 \n
       
   257      4. Expected result: \n &nbsp;&nbsp;
       
   258             <1>  pdataimp != 0 \n &nbsp;&nbsp;
       
   259             <2> no crash  \n
       
   260     <b>Function 2:</b> \n
       
   261 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   262         explicit CpSettingFormEntryItemDataImpl(HbDataForm *dataForm,const QString &text = QString(), \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
       
   263         																				const QString &description = QString(),const HbIcon &icon = HbIcon(), \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
       
   264         																				   const HbDataFormModelItem *parent = 0) \n 
       
   265      2.  Case Descrition: \n &nbsp;&nbsp;
       
   266          Test the second constructor function. \n
       
   267      3.  Input Parameters: \n &nbsp;&nbsp;
       
   268             <1> dataform = new HbDataForm(), text = Qstring(XX), description Qstring(XX), 
       
   269             	  icon = HbIcon(XX), parent = new HbDataFormModelItem(), \n &nbsp;&nbsp;
       
   270 						<2> dataForm = 0, text = Qstring(), description Qstring(), icon = HbIcon(), parent = 0 \n
       
   271      4.  Expected result: \n &nbsp;&nbsp;
       
   272             pdata != 0 \n      
       
   273      <b>Function 3:</b> \n
       
   274 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   275          explicit CpSettingFormEntryItemDataImpl(EntryItemType type,CpItemDataHelper &itemDataHelper, \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
       
   276          																				 const QString &text = QString(),const QString &description = QString(), \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
       
   277          																				 const QString &icon = QString(),const HbDataFormModelItem *parent = 0)  \n 
       
   278      2. Case Descrition: \n &nbsp;&nbsp;
       
   279          Test the third constructor function. \n
       
   280      3. Input Parameters: \n &nbsp;&nbsp;
       
   281             <1> type = HbDataFormModelItem::DataItemType,  itemDataHelper = CpItemDataHelper, \n &nbsp;&nbsp; &nbsp;&nbsp;
       
   282             	  text = QString(XX),  description = QString(XX),  icon = QString(XX), parent = new HbDataFormModelItem() \n &nbsp;&nbsp;
       
   283 			<2> type = HbDataFormModelItem::DataItemType,  itemDataHelper = CpItemDataHelper default, \n &nbsp;&nbsp;
       
   284 							  text = QString(),  description = QString(),  icon = QString(), parent = 0 \n
       
   285      4. Expected result: \n &nbsp;&nbsp;
       
   286             <1> pdataimp != 0, pdataimp->icon() != icon,\n &nbsp;&nbsp;
       
   287 			<2> pdataimp != 0, pdataimp->icon() == 0, \n            
       
   288      <b>Function 4:</b> \n
       
   289 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   290          explicit CpSettingFormEntryItemDataImpl(EntryItemType type,HbDataForm *dataForm,const QString &text = QString(),\n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
       
   291             																		 const QString &description = QString(),const QString &icon = QString(),\n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
       
   292             																		 const HbDataFormModelItem *parent = 0) \n
       
   293      2. Case Descrition: \n &nbsp;&nbsp;
       
   294          Test the forth constructor function. \n
       
   295      3. Input Parameters: \n &nbsp;&nbsp;
       
   296             <1> type = HbDataFormModelItem::DataItemType, dataform = new HbDataForm(),   \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
       
   297             	  text = QString(XX),  description = QString(XX),  icon = QString(XX), parent = new HbDataFormModelItem() \n &nbsp;&nbsp;
       
   298             <2> type = HbDataFormModelItem::DataItemType,  dataform = 0, text = QString(),   \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
       
   299             		description = QString(),  icon = QString(), parent = 0 \n
       
   300      4. Expected result: \n &nbsp;&nbsp;
       
   301             <1> pdataimp != 0, pdataimp->icon() != icon,\n &nbsp;&nbsp;
       
   302 			<2> pdataimp != 0, pdataimp->icon() == 0, \n   						    
       
   303 */
       
   304 void TestCpAPI::testCpSettingFormEntryItemDataImpl()
       
   305 {
       
   306     //Define the parameters for the constructors.
       
   307     QString strText = "testText";
       
   308     QString strDes = "testDescription";
       
   309     QString strIcon = "iconString";
       
   310     CpItemDataHelper *pHelper = new CpItemDataHelper();
       
   311     HbDataFormModelItem *aParent = new HbDataFormModelItem();
       
   312     HbIcon icon = HbIcon("icon");  
       
   313     HbDataForm *pDataform = new HbDataForm();
       
   314     CpSettingFormEntryItemData::EntryItemType EType1 = CpSettingFormEntryItemData::ListEntryItem;
       
   315     CpSettingFormEntryItemData::EntryItemType EType2 = CpSettingFormEntryItemData::ButtonEntryItem;
       
   316     // test the first constructor function.
       
   317     CpSettingFormEntryItemDataImpl<CpBaseSettingView> *pdataimp =
       
   318             new CpSettingFormEntryItemDataImpl<CpBaseSettingView>( *pHelper, strText, strDes, icon, aParent ); // first constructor
       
   319     QVERIFY (pdataimp != 0);
       
   320     QVERIFY( pdataimp->text() == strText );
       
   321     QVERIFY( pdataimp->description()==strDes );
       
   322     QVERIFY( pdataimp->icon() == icon.iconName() );
       
   323     delete pdataimp;
       
   324     pdataimp = 0; 
       
   325     pdataimp = new CpSettingFormEntryItemDataImpl<CpBaseSettingView>( *pHelper, QString(), QString(), icon, 0);
       
   326     QVERIFY (pdataimp != 0);
       
   327     delete pdataimp;
       
   328     pdataimp = 0; 
       
   329         
       
   330     pdataimp = new CpSettingFormEntryItemDataImpl<CpBaseSettingView>(0); // set parameter as "0"
       
   331     QVERIFY (pdataimp != 0);
       
   332     QVERIFY( pdataimp->text() == 0 );
       
   333     QVERIFY( pdataimp->description()==0 );
       
   334     delete pdataimp;
       
   335     pdataimp = 0;
       
   336     // test the second constructor function.
       
   337     pdataimp = new CpSettingFormEntryItemDataImpl <CpBaseSettingView> ( pDataform,strText, strDes, icon, aParent ); //second contructor
       
   338     QVERIFY( pdataimp->text() == strText );
       
   339     QVERIFY( pdataimp->description()==strDes );
       
   340     QVERIFY( pdataimp->icon() == icon.iconName() );
       
   341     delete pdataimp;
       
   342     pdataimp = 0;
       
   343     pdataimp = new CpSettingFormEntryItemDataImpl <CpBaseSettingView> ( 0, QString(), QString(), icon, 0 );
       
   344     QVERIFY (pdataimp != 0);
       
   345     delete pdataimp;
       
   346     pdataimp = 0; 
       
   347     // test the third constructor function.
       
   348     pdataimp = new CpSettingFormEntryItemDataImpl<CpBaseSettingView>( EType1,*pHelper, strText, strDes, strIcon, aParent );// the third constructor
       
   349     HbDataFormModelItem::DataItemType EdataItmeTypeTemp1 = pdataimp->type();
       
   350     QVERIFY (EdataItmeTypeTemp1 == EType1);
       
   351     QVERIFY( pdataimp->text() == strText );
       
   352     QVERIFY( pdataimp->description()==strDes );
       
   353     QVERIFY( pdataimp->icon() == strIcon );
       
   354     delete pdataimp;
       
   355     pdataimp = 0;    
       
   356     // test the forth constructor function.
       
   357     pdataimp = new CpSettingFormEntryItemDataImpl<CpBaseSettingView>(EType2,pDataform, strText, strDes, strIcon, aParent );// the fourth constructor
       
   358     CpSettingFormEntryItemData::DataItemType EdataItmeTypeTemp2 = pdataimp->type();
       
   359     QVERIFY (EdataItmeTypeTemp2 == EType2);
       
   360     QVERIFY( pdataimp->text() == strText );
       
   361     QVERIFY( pdataimp->description()==strDes );
       
   362     QVERIFY( pdataimp->icon() == strIcon );
       
   363     delete pdataimp;
       
   364     pdataimp = 0;
       
   365   
       
   366     delete pHelper;
       
   367     pHelper=0;
       
   368     delete pDataform;
       
   369     pDataform = 0;
       
   370 }
       
   371 /*!
       
   372 		provide test data for the testCpSettingFormItemData()
       
   373 */
       
   374 void TestCpAPI::testCpSettingFormItemData_data()
       
   375 {
       
   376     // add the test data as below
       
   377     QTest::addColumn<int>("aType");
       
   378     QTest::addColumn<QString>("aLabel");
       
   379     QTest::newRow("FormPageItem value") << (int)HbDataFormModelItem::FormPageItem << "FormPageItem Label";
       
   380     QTest::newRow("GroupItem value") << (int)HbDataFormModelItem::GroupItem << "GroupItem Label";
       
   381     QTest::newRow("GroupPageItem value") << (int)HbDataFormModelItem::GroupPageItem << "GroupPageItem Label";
       
   382     QTest::newRow("TextItem value") << (int)HbDataFormModelItem::TextItem << "TextItem Label";
       
   383     QTest::newRow("SliderItem value") << (int)HbDataFormModelItem::SliderItem << "SliderItem Label";
       
   384     QTest::newRow("VolumeSliderItem value") << (int)HbDataFormModelItem::VolumeSliderItem << "VolumeSliderItem Label";
       
   385     QTest::newRow("CheckBoxItem value") << (int)HbDataFormModelItem::CheckBoxItem << "CheckBoxItem Label";
       
   386     QTest::newRow("ToggleValueItem value") << (int)HbDataFormModelItem::ToggleValueItem << "ToggleValueItem Label";
       
   387     QTest::newRow("RadioButtonListItem value") << (int)HbDataFormModelItem::RadioButtonListItem << "RadioButtonListItem Label";
       
   388     QTest::newRow("MultiselectionItem value") << (int)HbDataFormModelItem::MultiselectionItem << "MultiselectionItem Label";
       
   389     QTest::newRow("ComboBoxItem value") << (int)HbDataFormModelItem::ComboBoxItem << "ComboBoxItem Label";    
       
   390 }
       
   391 /*!
       
   392      <b>Test Case Description:</b> \n &nbsp;&nbsp;
       
   393          Verify this class could create the corresponding control panel defined HbDataFormModelItem. \n
       
   394      <b>Function 1:</b> \n
       
   395 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   396             CpSettingFormItemData(HbDataFormModelItem::DataItemType type, const QString &label,const HbDataFormModelItem *parent = 0); \n
       
   397      2. Case Descrition: \n &nbsp;&nbsp;
       
   398             Test the first constructor function. \n
       
   399      3. Input Parameters: \n &nbsp;&nbsp;
       
   400             <1> type = HbDataFormModelItem::DataItemType,  label = QString, parent = new HbDataFormModelItem() \n &nbsp;&nbsp;
       
   401 			<2> type = (HbDataFormModelItem::DataItemType) invaildValue, label = 0, parent = 0 \n
       
   402      4. Expected result: \n &nbsp;&nbsp;
       
   403             <1> pdata != 0, pdata->type() == type \n &nbsp;&nbsp;
       
   404 			<2> no crash \n	
       
   405      <b>Function 2:</b> \n
       
   406 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   407             CpSettingFormItemData(const HbDataFormModelItem *parent = 0 \n
       
   408      2. Case Descrition: \n &nbsp;&nbsp;
       
   409             Test the second constructor function. \n
       
   410      3. Input Parameters: \n &nbsp;&nbsp;
       
   411             <1> parent = new HbDataFormModelItem() \n
       
   412      4. Expected result: \n &nbsp;&nbsp;
       
   413 			<1> pdata != 0, no crash \n										    
       
   414 */
       
   415 void TestCpAPI::testCpSettingFormItemData()
       
   416 {
       
   417     // Fectch the test data from testCpSettingFormItemData_data()
       
   418     QFETCH(int, aType);    
       
   419     QFETCH(QString, aLabel);
       
   420     // test the constructor using the above data
       
   421     HbDataFormModelItem::DataItemType itemType = (HbDataFormModelItem::DataItemType)aType;
       
   422     CpSettingFormItemData *pdata=new CpSettingFormItemData(itemType,aLabel);
       
   423     QVERIFY( pdata !=0 );
       
   424     HbDataFormModelItem::DataItemType itemTemp=pdata->type();
       
   425     QVERIFY(itemType==itemTemp);
       
   426     delete pdata;
       
   427     pdata=0;
       
   428 }
       
   429 /*!
       
   430      <b>Test Case Description:</b> \n &nbsp;&nbsp;
       
   431          To verify all the functions in CpItemdataHelper class. \n
       
   432      <b>Function 1:</b> \n
       
   433 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   434             explicit CpItemDataHelper(HbDataForm *form = 0) \n
       
   435      2. Case Descrition: \n &nbsp;&nbsp;
       
   436             Test the first constructor function. \n
       
   437      3. Input Parameters: \n &nbsp;&nbsp;
       
   438             <1> form = 0 \n
       
   439 						<2> form = new HbDataForm() \n
       
   440      4. Expected result: \n &nbsp;&nbsp;
       
   441             <1> pHelper != 0 \n &nbsp;&nbsp;
       
   442             <2> pHelper != 0 \n 
       
   443      <b>Function 2:</b> \n
       
   444 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   445             void bindToForm(HbDataForm *form) \n
       
   446      2. Input Parameters: \n &nbsp;&nbsp;
       
   447             <1> form = 0 \n &nbsp;&nbsp;
       
   448 			<2> form = new HbDataForm() \n
       
   449      3. Expected result: \n &nbsp;&nbsp;
       
   450 			no crash \n				
       
   451      <b>Function 3:</b> \n
       
   452 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   453             void addItemPrototype(HbAbstractViewItem *prototype) \n 
       
   454      2. Input Parameters: \n &nbsp;&nbsp;
       
   455             <1> prototype = HbDataFormViewItem() \n &nbsp;&nbsp;
       
   456 			<2> prototype = 0 \n
       
   457      3. Expected result: \n &nbsp;&nbsp;
       
   458 			no crash \n				
       
   459      <b>Function 4:</b> \n
       
   460 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   461             void addConnection(HbDataFormModelItem *item, const char *signal,  QObject *receiver,const char *method) \n
       
   462      2. Input Parameters: \n &nbsp;&nbsp;
       
   463             <1> item = new HbDataFormModelItem(), signal = char*, receiver = Qobject*, method = const char* \n &nbsp;&nbsp;
       
   464 			<2> set all parameters as '0' \n
       
   465      3. Expected result: \n &nbsp;&nbsp;
       
   466 			no crash \n									
       
   467      <b>Function 5:</b> \n
       
   468 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   469             void removeConnection(HbDataFormModelItem *item, const char *signal, Qobject *receiver, const char *method) \n
       
   470      2. Input Parameters: \n &nbsp;&nbsp;
       
   471             <1> item = new HbDataFormModelItem(), signal = char*, receiver = Qobject*, method = const char*\n &nbsp;&nbsp;
       
   472 			<2> set all parameters as '0'
       
   473      3. Expected result: \n &nbsp;&nbsp;
       
   474 			no crash \n	
       
   475      <b>Function 6:</b> \n
       
   476 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   477             void connectToForm(const char *signal, QObject *receiver, const char *method) \n
       
   478      2. Input Parameters: \n &nbsp;&nbsp;
       
   479             <1> signal = char*, receiver = Qobject*, method = const char* \n &nbsp;&nbsp;
       
   480 			<2> set all parameters as '0' \n
       
   481      3. Expected result: \n &nbsp;&nbsp;
       
   482 			no crash \n						
       
   483      <b>Function 7:</b> \n
       
   484 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   485             HbWidget *widgetFromModelIndex(const QModelIndex &index) \n
       
   486      2. Input Parameters: \n &nbsp;&nbsp;
       
   487             <1>  index = const QModelIndex \n						
       
   488      3. Expected result: \n &nbsp;&nbsp;
       
   489 			no crash \n			
       
   490      <b>Function 8:</b> \n
       
   491 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   492             HbDataFormModelItem *modelItemFromModelIndex(const QModelIndex &index) \n
       
   493      2. Input Parameters: \n &nbsp;&nbsp;
       
   494             <1> index =  const QModelIndex() \n &nbsp;&nbsp;
       
   495 			<2> set all parameters as '0' \n			
       
   496      3. Expected result: \n &nbsp;&nbsp;
       
   497 			no crash \n																													    
       
   498 */
       
   499 void TestCpAPI::testItemDataHelper()
       
   500 {
       
   501     HbDataForm* form = new HbDataForm(); // create a dataform
       
   502     HbDataFormModel *model = new HbDataFormModel(); 
       
   503     HbDataFormModelItem *general = model->appendDataFormPage(QString("General")); // add a dataformpage
       
   504     CpSettingFormItemData *mItem = new CpSettingFormItemData(HbDataFormModelItem::SliderItem,
       
   505             QString("New Slider")); 
       
   506     general->appendChild(mItem); // add a slider to the dataformgroup, use it as a parameter when testing addConnection() function
       
   507     form->setModel(model);    
       
   508         
       
   509     // test constructor using default parameter
       
   510     CpItemDataHelper *phelperdefault = new CpItemDataHelper(0);
       
   511     QVERIFY (phelperdefault!=0);
       
   512     
       
   513     // test constructor using a HbDataForm parameter
       
   514     CpItemDataHelper *phelperForm = new CpItemDataHelper(form);
       
   515     QVERIFY (phelperForm!=0);
       
   516     
       
   517     // test bindtoForm()
       
   518     phelperForm->bindToForm(0);
       
   519     phelperForm->bindToForm(form);
       
   520     
       
   521     // test the addItemPrototype() function
       
   522     int oldProtoTypeListNr = form->itemPrototypes().count();
       
   523     HbDataFormViewItem *pitem = new HbDataFormViewItem();
       
   524     phelperForm->addItemPrototype(pitem); 
       
   525     int newProtoTypeListNr = form->itemPrototypes().count();
       
   526     //Verify that the prototype is added to the prototypelist
       
   527     QVERIFY( newProtoTypeListNr == oldProtoTypeListNr + 1 );    
       
   528     
       
   529     phelperForm->addItemPrototype(0); // pitem = 0
       
   530     
       
   531     // test addConnection() function     
       
   532     char aSignal[] = "asignal";
       
   533     char aMethod[] = "amethod";
       
   534     phelperForm->addConnection( general, aSignal,mItem,aMethod);    
       
   535     phelperForm->removeConnection(general,aSignal,mItem, aMethod);    
       
   536     phelperForm->addConnection( 0,0,0,0 );
       
   537     phelperForm->removeConnection(0,0,0,0);
       
   538     phelperdefault->addConnection(general, aSignal,mItem,aMethod);
       
   539     
       
   540     // test connectToForm() function
       
   541     phelperForm->connectToForm(aSignal,mItem, aMethod);
       
   542     phelperForm->disconnectFromForm(aSignal,mItem, aMethod);
       
   543     phelperForm->connectToForm(0,0,0);
       
   544     phelperForm->disconnectFromForm(0,0,0); 
       
   545     phelperdefault->connectToForm(aSignal,mItem, aMethod);
       
   546     
       
   547     // test widgetFromModelIndex() function
       
   548     QModelIndex aIndex = model->indexFromItem(mItem);
       
   549     HbWidget * widget = phelperForm->widgetFromModelIndex(aIndex);
       
   550     QVERIFY( widget->type() == Hb::ItemType_Slider );
       
   551     
       
   552     // test modelItemFromModelIndex() function
       
   553     HbDataFormModelItem *itemTest = phelperForm->modelItemFromModelIndex(aIndex);
       
   554     HbDataFormModelItem *itemGeneral = model->itemFromIndex(aIndex);
       
   555     QVERIFY(itemTest == itemGeneral);
       
   556   
       
   557     delete phelperdefault;
       
   558     phelperdefault = 0;
       
   559     delete phelperForm;
       
   560     phelperForm = 0;
       
   561     delete form;
       
   562     form = 0;
       
   563     delete model;
       
   564     
       
   565 }
       
   566 /*!
       
   567      <b>Test Case Description:</b> \n &nbsp;&nbsp;
       
   568          Verify the class can add the control panel's proto type of setting items( only entry item currently) to the settingForm \n
       
   569      1. Fucntion Name: \n &nbsp;&nbsp;
       
   570             static void addCpItemPrototype(HbDataForm *settingForm) \n
       
   571      2. Case Descrition: \n &nbsp;&nbsp;
       
   572             Verify it can add the control panel's proto type of setting items( only entry item currently) to the settingForm \n
       
   573      3. Input Parameters: \n &nbsp;&nbsp;
       
   574             <1> settingForm = new HbDataForm () \n
       
   575 						<2> settingForm = 0 \n
       
   576      4. Expected result: \n &nbsp;&nbsp;
       
   577             <1> The proto type is added to the prototype list \n						    
       
   578 */
       
   579 void TestCpAPI::testCpPluginUtility()
       
   580 {
       
   581     HbDataForm* form = new HbDataForm();
       
   582     int oldListNr = form->itemPrototypes().count();
       
   583     CpPluginUtility::addCpItemPrototype(form); // set settingForm = new HbDataForm ()
       
   584     int newListNr = form->itemPrototypes().count();
       
   585     QVERIFY( newListNr = oldListNr + 1 );
       
   586     
       
   587     CpPluginUtility::addCpItemPrototype(0); // set settingForm = 0
       
   588 }
       
   589 /*!
       
   590      <b>Test Case Description:</b> \n &nbsp;&nbsp;
       
   591          To verify the class could load the control panel plugin. \n
       
   592      <b>Function 1:</b> \n
       
   593 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   594             static CpPluginInterface *loadCpPluginInterface(const QString &pluginFile) \n
       
   595      2. Case Descrition: \n &nbsp;&nbsp;
       
   596             Verify that it can load the cp interface successfully. \n
       
   597      3. Input Parameters: \n &nbsp;&nbsp;
       
   598             <1> pluginFile = const Qstring (a vaild plugin file) \n &nbsp;&nbsp;
       
   599 			<2> pluginFile = const Qstring (an invaild plugin file) \n  &nbsp;&nbsp;
       
   600 			<3> pluginFile = 0 \n
       
   601      4. Expected result: \n &nbsp;&nbsp;
       
   602             no crash	\n			
       
   603      <b>Function 2:</b> \n
       
   604 	 1. Fucntion Name: \n &nbsp;&nbsp;
       
   605             static CpLauncherInterface   *loadCpLauncherInterface(const QString &pluginFile) \n
       
   606      2. Case Descrition: \n &nbsp;&nbsp;
       
   607             Verify that it can load the cp cplaucher interface successfully. \n
       
   608      3. Input Parameters: \n &nbsp;&nbsp;
       
   609             <1> pluginFile = const Qstring (a vaild plugin file) \n &nbsp;&nbsp;
       
   610 			<2> pluginFile = const Qstring (an invaild plugin file) \n  &nbsp;&nbsp;
       
   611 			<3> pluginFile = 0 \n
       
   612      4. Expected result: \n &nbsp;&nbsp;
       
   613             no crash					            	    
       
   614 */
       
   615 void TestCpAPI::testCpPluginLoader()
       
   616 {
       
   617     // the plugins for test are created via the codes in tsrc/unit/pluginfortest.
       
   618     QString aInvaildFile = "non_existing_plugin.dll";
       
   619     QString aVaildFile1 = "firstpluginfortest";
       
   620     QString aVaildFile2 = "secondpluginfortest.dll";
       
   621     QString aVaildFile3 = "thirdpluginfortest.qtplugin";
       
   622 
       
   623     CpPluginInterface *pluginInterface = CpPluginLoader::loadCpPluginInterface(aVaildFile1);
       
   624     QVERIFY(pluginInterface != 0);
       
   625 
       
   626     pluginInterface = CpPluginLoader::loadCpPluginInterface(aVaildFile2);
       
   627     QVERIFY(pluginInterface != 0);
       
   628 
       
   629     pluginInterface = CpPluginLoader::loadCpPluginInterface(aVaildFile3);
       
   630     QVERIFY(pluginInterface != 0);
       
   631 
       
   632     //Test the 'loadCpLauncherInterface' function
       
   633     CpLauncherInterface *pluginLauncherInterface = CpPluginLoader::loadCpLauncherInterface(aInvaildFile);
       
   634     QVERIFY(pluginLauncherInterface == 0);  
       
   635 
       
   636     pluginLauncherInterface = CpPluginLoader::loadCpLauncherInterface(aVaildFile1);
       
   637     QVERIFY(pluginLauncherInterface != 0);
       
   638 
       
   639     pluginLauncherInterface = CpPluginLoader::loadCpLauncherInterface(aVaildFile2);
       
   640     QVERIFY(pluginLauncherInterface != 0);
       
   641 
       
   642     pluginLauncherInterface = CpPluginLoader::loadCpLauncherInterface(aVaildFile3);
       
   643     QVERIFY(pluginLauncherInterface != 0);
       
   644 }
       
   645 /*!
       
   646      <b>Test Case Description:</b> \n &nbsp;&nbsp;
       
   647         Test the CP interface can work well. \n
       
   648      1. Fucntion Name: \n &nbsp;&nbsp;
       
   649             virtual QList<CpSettingFormItemData*> createSettingFormItemData(CpItemDataHelper &itemDataHelper) const \n
       
   650      2. Case Descrition: \n &nbsp;&nbsp;
       
   651             Test the create settingformItemData() function, it's a pure vitual function. Define a simple class  and test its interface. \n
       
   652      3. Input Parameters: \n &nbsp;&nbsp;
       
   653             <1> itemDataHelper = CpItemDataHelper \n
       
   654      4. Expected result: \n &nbsp;&nbsp;
       
   655             <1> no crash \n    					            	    
       
   656 */
       
   657 void TestCpAPI::testCpPluginInterface()
       
   658 {
       
   659     CpItemDataHelper *helper = new CpItemDataHelper();
       
   660     CpPluginInterface *plugin = CpPluginLoader::loadCpPluginInterface("firstpluginfortest");
       
   661     QVERIFY( plugin != 0 );
       
   662     QList<CpSettingFormItemData*> itemData = plugin->createSettingFormItemData(*helper);
       
   663     QVERIFY( itemData.size() == 1 );
       
   664     qDeleteAll(itemData.begin(),itemData.end());
       
   665     itemData.clear();
       
   666 }
       
   667 /*!
       
   668      <b>Test Case Description:</b> \n &nbsp;&nbsp;
       
   669         Test the CP launcher interface can work well.\n
       
   670      1. Fucntion Name: \n &nbsp;&nbsp;
       
   671             virtual CpBaseSettingView *createSettingView(const QVariant &hint) const  \n
       
   672      2. Case Descrition: \n &nbsp;&nbsp;
       
   673             Test it can create setting view after loading the plugin. \n
       
   674      3. Input Parameters: \n &nbsp;&nbsp;
       
   675             <1> hint = Qvariant() \n
       
   676      4. Expected result: \n &nbsp;&nbsp;
       
   677             <1> no crash \n     					            	    
       
   678 */
       
   679 void TestCpAPI::testCpLancherInterface()
       
   680 {
       
   681     QVariant hint = QVariant();
       
   682     CpLauncherInterface *plugin = CpPluginLoader::loadCpLauncherInterface("secondpluginfortest");
       
   683     QVERIFY( plugin != 0 );
       
   684     CpBaseSettingView *testView = plugin->createSettingView(hint);    
       
   685     QVERIFY( testView != 0 );
       
   686     delete testView;
       
   687     testView = 0; 
       
   688 }
       
   689 
       
   690 void TestCpAPI::testCpLogger()
       
   691 {
       
   692 }
       
   693 
       
   694 QTEST_MAIN(TestCpAPI)