controlpanelui/src/cpcategorymodel/tsrc/ut_categorymodelutility/src/ut_categorymodelutility.cpp
branchRCL_3
changeset 14 5f281e37a2f5
parent 13 90fe62538f66
equal deleted inserted replaced
13:90fe62538f66 14:5f281e37a2f5
     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 cpcategorymodel functions.
       
    16 */
       
    17 
       
    18 #include "ut_categorymodelutility.h"
       
    19 #include "cptestpluginentryitem.h"
       
    20 #include <cpsettingformentryitemData.h>
       
    21 #include "cpcategorysettingformitemdata.h"
       
    22 #include "cpcategorysettingformmodel.h"
       
    23 #include "cppluginconfig.h"
       
    24 #include "cpcategorymodelutility.h"
       
    25 #include <QtTest/QtTest>
       
    26 //#include <cpplaceholderitemdata.h>
       
    27 #include <cppluginconfigreader.h>
       
    28 #include <cpitemdatahelper.h>
       
    29 //#include <cpbasepath.h>
       
    30 //#include <cpevent.h>
       
    31 
       
    32 
       
    33 //the class for test
       
    34 #include "cpcategorymodelutility.h"
       
    35 /*!
       
    36       \class TestCpCategoryModelUtility \n
       
    37       \brief class name: TestCpCategoryModelUtility \n  
       
    38       type of test case: unit test \n
       
    39       test cases' number totally: 7 \n
       
    40  */
       
    41 
       
    42 void TestCpCategoryModelUtility::initTestCase()
       
    43 {
       
    44     // initialize public test data here
       
    45     
       
    46 }
       
    47 
       
    48 /*!
       
    49      Test Case Description: \n
       
    50      1. Fucntion Name: \n &nbsp;&nbsp;
       
    51          static bool setEntryItemContentIfEmpty(CpSettingFormItemData *itemData, 
       
    52                                                 const QString &displayName,
       
    53                                                 const QString &description) \n
       
    54      2. Case Descrition: \n &nbsp;&nbsp;
       
    55          Test the function when setting itemData as 0. \n
       
    56      3. Input Parameters:\n &nbsp;&nbsp;
       
    57          <1> itemData = 0, QString(), QString() \n              
       
    58      4. Expected result:  \n &nbsp;&nbsp;
       
    59          <1> bSetResult = false \n         
       
    60  */
       
    61 void TestCpCategoryModelUtility::testSetEntryItemReturnFalse()
       
    62 {
       
    63     bool bSetResult = CpCategoryModelUtility::setEntryItemContentIfEmpty(0, QString(), QString());
       
    64     QVERIFY(bSetResult == false);
       
    65 }
       
    66 
       
    67 /*!
       
    68      Test Case Description: \n
       
    69      1. Fucntion Name: \n &nbsp;&nbsp;
       
    70          static bool setEntryItemContentIfEmpty(CpSettingFormItemData *itemData, 
       
    71                                                 const QString &displayName,
       
    72                                                 const QString &description) \n
       
    73      2. Case Descrition: \n &nbsp;&nbsp;
       
    74          setEntryItemContentIfEmpty \n
       
    75      3. Input Parameters:\n &nbsp;&nbsp;
       
    76          new a subclass from CpSettingFormEntryItemData firstly. \n &nbsp;&nbsp;
       
    77          <1> itemData = new CpTestPluginEntryItemData(CpItemDataHelper, QString(XX), QString(XX),HbIcon(QString(XX))), \n &nbsp;&nbsp; 
       
    78              newText = QString(XX), \n &nbsp;&nbsp;
       
    79              newDes = QString(XX),\n &nbsp;&nbsp;
       
    80              newIconName = QString(XX).\n &nbsp;&nbsp;
       
    81          <2> itemData = new CpTestPluginEntryItemData(CpItemDataHelper, QString(),QString(), HbIcon())\n &nbsp;&nbsp;
       
    82              newText = QString(XX),\n &nbsp;&nbsp;
       
    83              newDes = QString(XX) \n 
       
    84      4. Expected result:  \n &nbsp;&nbsp;
       
    85          <1> bSetResult = true,\n &nbsp;&nbsp; 
       
    86          <2> bSetResult = true,   \n
       
    87  */
       
    88 void TestCpCategoryModelUtility::testSetEntryItemContent()
       
    89 {
       
    90     CpItemDataHelper *pHelper = new CpItemDataHelper();
       
    91     QString textNotEmpty = "TextNotEmpty";
       
    92     QString description = "descriptionNotEmpty";
       
    93     QString iconName = "iconNameNotEmpty";
       
    94     HbIcon icon = HbIcon(iconName);
       
    95     CpTestPluginEntryItemData *itemData1 = new CpTestPluginEntryItemData(*pHelper, textNotEmpty, description,icon);
       
    96     QString newText = "newSetText";
       
    97     QString newDes = "newSetdescription";
       
    98     bool bSetResult1 = CpCategoryModelUtility::setEntryItemContentIfEmpty(itemData1, newText, newDes);
       
    99     QVERIFY(bSetResult1 == true);
       
   100     // verify the text, description and icon name cannot be set when they are not empty.
       
   101     QVERIFY( itemData1->text() == textNotEmpty );
       
   102     QVERIFY( itemData1->description() == description );
       
   103     QVERIFY( itemData1->iconName() == iconName );
       
   104     delete itemData1;
       
   105     
       
   106     CpTestPluginEntryItemData *itemData2 = new CpTestPluginEntryItemData(*pHelper, QString(), QString(),HbIcon());
       
   107     bool bSetResult2 = CpCategoryModelUtility::setEntryItemContentIfEmpty(itemData2, newText, newDes);
       
   108     QVERIFY(bSetResult2 == true);
       
   109     // verify the text, description and icon name are set as default when they are empty.
       
   110     QVERIFY(itemData2->text() == newText);    
       
   111     QVERIFY( itemData2->description() == newDes );
       
   112     QString temp = itemData2->iconName();
       
   113     QString newIconName = QLatin1String(":/icon/qgn_prop_set_default_sub.svg");
       
   114     QVERIFY( itemData2->iconName() == newIconName );
       
   115     delete itemData2;
       
   116     delete pHelper;  
       
   117 }
       
   118 
       
   119 /*!
       
   120      Test Case Description: \n &nbsp;&nbsp;
       
   121      1. Fucntion Name: drives()\n
       
   122      2. Case Descrition: \n &nbsp;&nbsp;
       
   123          Verify that it can get all physical drives of the devices \n
       
   124      3. Input Parameters: none \n
       
   125      4. Expected result:  dirs.count() != 0 \n
       
   126  */
       
   127 void TestCpCategoryModelUtility::testDrives()
       
   128 {
       
   129     QStringList dirs = CpCategoryModelUtility::drives(); 
       
   130     // verify the drives "C:, D:, Z:" are contained in the string list.
       
   131     QVERIFY( dirs.contains( "C:", Qt::CaseSensitive ) );
       
   132     QVERIFY( dirs.contains( "D:", Qt::CaseSensitive ) );
       
   133     QVERIFY( dirs.contains( "Z:", Qt::CaseSensitive ) );
       
   134 }
       
   135 
       
   136 /*!
       
   137      Test Case Description:  \n
       
   138      1. Fucntion Name: configFileDirectories() \n
       
   139      2. Case Descrition:  \n
       
   140          Verify that it can get all config directories of the device \n
       
   141      3. Input Parameters: none \n
       
   142      4. Expected result:  dirs.count() != 0 \n
       
   143  */
       
   144 void TestCpCategoryModelUtility::testPluginDirectories()
       
   145 {
       
   146     QStringList dirs = CpCategoryModelUtility::pluginDirectories();
       
   147     qDebug() << dirs;
       
   148     // Verify the right plugin directory path is returned.
       
   149     QVERIFY( dirs.contains( QString( "C:/resource/qt/plugins/controlpanel" ) + QDir::separator(), Qt::CaseSensitive ) );
       
   150 }
       
   151 
       
   152 /*!
       
   153      Test Case Description:  \n
       
   154      1. Fucntion Name: configFileDirectories() \n
       
   155      2. Case Descrition: Verify that it can get all config directories of the device. \n
       
   156      3. Input Parameters: none \n
       
   157      4. Expected result:  dirs.count() != 0 \n
       
   158  */
       
   159 void TestCpCategoryModelUtility::testConfigFileDirectories()
       
   160 {
       
   161     QStringList dirs = CpCategoryModelUtility::configFileDirectories();
       
   162     qDebug() << dirs;
       
   163     // Verify the right config file directory path is returned.
       
   164     QVERIFY( dirs.contains( QString( "C:/resource/qt/plugins/controlpanel/config" ) + QDir::separator(), Qt::CaseSensitive ) );
       
   165 }
       
   166 
       
   167 /*!
       
   168      Test Case Description:  \n &nbsp;&nbsp;
       
   169      1. Fucntion Name: buildConfigPluginItems()\n &nbsp;&nbsp;
       
   170      2. Case Descrition: Verify that it can load the plugins via the plugin config file and create item data of the corresponding plugin succesfully.\n          
       
   171      3. Input Parameters:\n &nbsp;&nbsp;
       
   172         <1> parent = HbDataFormModelItem(), configFile = QString(XX), pHelper = new CpItemDataHelper(), startPosition = -10\n &nbsp;&nbsp;
       
   173         <2> parent = HbDataFormModelItem(), configFile = QString(), pHelper = new CpItemDataHelper(), startPosition = 1\n
       
   174 
       
   175      4. Expected result:  \n &nbsp;&nbsp;
       
   176         <1> parent->childCount() == 2 \n 
       
   177         <2> parent->childCount() == 2 \n 
       
   178  */
       
   179 void TestCpCategoryModelUtility::testBuildConfigPluginItems()
       
   180 {
       
   181 //    HbDataFormModelItem *parent = new HbDataFormModelItem();
       
   182 //    QString configFile = "configfiletestformodelutility.cpcfg";
       
   183 //    int startPosition = 1;
       
   184 //    
       
   185 //    CpItemDataHelper helper;
       
   186 //    CpCategoryModelUtility::buildConfigPluginItems(parent, configFile, helper, startPosition);
       
   187 //    int childCount = parent->childCount();
       
   188 //    // the configfiletestformodelutility.cpcfg contains two control panel plugins.
       
   189 //    QVERIFY( parent->childCount() == 2 );
       
   190 //    
       
   191 //    CpCategoryModelUtility::buildConfigPluginItems(parent, configFile, helper, -10);
       
   192 //    QVERIFY( parent->childCount() == 2 );
       
   193 //
       
   194 //    delete parent;
       
   195 }
       
   196 
       
   197 /*!
       
   198      Test Case Description: \n
       
   199      1. Fucntion Name: CreateCpPluginItemData() \n
       
   200      2. Case Descrition: \n
       
   201          
       
   202      3. Input Parameters: \n
       
   203          
       
   204      4. Expected result:  \n
       
   205          
       
   206  */
       
   207 void TestCpCategoryModelUtility::testCreateCpPluginItemData()
       
   208 {
       
   209     // 
       
   210 }
       
   211 
       
   212 /*!
       
   213     Descrition of what you will do in this function
       
   214  */
       
   215 void TestCpCategoryModelUtility::cleanupTestCase()
       
   216 {
       
   217     // release all test data
       
   218     QCoreApplication::processEvents();
       
   219 }
       
   220 
       
   221 QTEST_MAIN(TestCpCategoryModelUtility)