controlpanel/tsrc/unit/ut_cpapi/src/ut_cpapi.cpp
changeset 68 13e71d907dc3
parent 40 6465d5bb863a
equal deleted inserted replaced
40:6465d5bb863a 68:13e71d907dc3
     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_cpapi.h"
       
    18 
       
    19 #include <hbmainwindow.h>
       
    20 #include <QGraphicsWidget>
       
    21 #include <qDebug>
       
    22 #include <QtTest/QtTest>
       
    23 #include <QtAlgorithms>
       
    24 #include <HbView.h>
       
    25 #include <hbdataform.h>
       
    26 #include <hbdataformmodel.h>
       
    27 #include <hbdataformmodelitem.h>
       
    28 #include <hbdataformviewitem.h>
       
    29 #include <hbabstractviewitem.h>
       
    30 #include <hbpushbutton.h>
       
    31 //testing following classes
       
    32 
       
    33 #include "cpbasesettingview.h"
       
    34 #include "cpsettingformentryitemdata.h"
       
    35 #include "cpsettingformentryitemdataimpl.h"
       
    36 #include <cpsettingformitemdata.h>
       
    37 #include <cpitemdatahelper.h>
       
    38 #include <cppluginutility.h>
       
    39 #include <cppluginloader.h>
       
    40 #include <cpplugininterface.h>
       
    41 #include <cplogger.h>
       
    42 
       
    43 void TestCpAPI::initTestCase()
       
    44 {    
       
    45 	//mainWindow = new HbMainWindow;
       
    46   //mainWindow->show();
       
    47 }
       
    48 
       
    49 void TestCpAPI::cleanupTestCase()
       
    50 {
       
    51 	//delete mainWindow;
       
    52 	//mainWindow = 0;
       
    53 	//if delete mainwindow, test app will be freezing
       
    54 	QCoreApplication::processEvents();
       
    55 }
       
    56 void TestCpAPI::testCpBaseSettingView()
       
    57 {
       
    58 	CpBaseSettingView * pview = new CpBaseSettingView(0);
       
    59 	QVERIFY( pview != 0 );
       
    60         HbDataForm *pForm = new HbDataForm(0);
       
    61         pview->setWidget(pForm);
       
    62         QVERIFY( qobject_cast<HbDataForm *>(pview->widget()) == pForm );
       
    63 	delete pview;
       
    64 	HbPushButton *widget = new HbPushButton();
       
    65 	QVERIFY(widget != 0);
       
    66 	CpBaseSettingView *pView1 = new CpBaseSettingView(widget);
       
    67 	QVERIFY(pView1!=0);
       
    68 	HbPushButton *button = qobject_cast<HbPushButton *>(pView1->widget());
       
    69 	QVERIFY(button != 0);
       
    70 	delete pView1;
       
    71 	
       
    72 }
       
    73 
       
    74 void TestCpAPI::testCpSettingFormEntryItemDataImpl()
       
    75 {
       
    76 	CpItemDataHelper *pHelper = new CpItemDataHelper();
       
    77         CpSettingFormEntryItemDataImpl<CpBaseSettingView> *pdataimp = new CpSettingFormEntryItemDataImpl<CpBaseSettingView>( *pHelper, "text", "description"  );
       
    78 	QVERIFY( pdataimp !=0 );
       
    79 	QString strtxt = "input texts";
       
    80 	pdataimp->setText(strtxt);
       
    81 	QVERIFY( pdataimp->text() == strtxt );
       
    82 	
       
    83 	QString strDes = "input descriptions";
       
    84 	pdataimp->setDescription(strDes);
       
    85 	QVERIFY( pdataimp->description() == strDes);
       
    86 	delete pdataimp;
       
    87         delete pHelper;
       
    88 }
       
    89 void TestCpAPI::testCpSettingFormItemData()
       
    90 {
       
    91         CpSettingFormItemData *pdata = new CpSettingFormItemData( HbDataFormModelItem::TextItem, "label" );
       
    92         QVERIFY( pdata !=0 );
       
    93         delete pdata;
       
    94         pdata = 0;
       
    95         pdata = new CpSettingFormItemData( HbDataFormModelItem::SliderItem, "label" );
       
    96         QVERIFY( pdata !=0 );
       
    97         delete pdata;
       
    98         pdata = 0;
       
    99         pdata = new CpSettingFormItemData( HbDataFormModelItem::VolumeSliderItem, "label" );
       
   100         QVERIFY( pdata !=0 );
       
   101         delete pdata;
       
   102         pdata = new CpSettingFormItemData( HbDataFormModelItem::CheckBoxItem, "label" );
       
   103         QVERIFY( pdata !=0 );
       
   104         delete pdata;
       
   105         pdata = 0;
       
   106         pdata = new CpSettingFormItemData( HbDataFormModelItem::ToggleValueItem, "label" );
       
   107         QVERIFY( pdata !=0 );
       
   108         delete pdata;
       
   109         pdata = 0;
       
   110         pdata = new CpSettingFormItemData( HbDataFormModelItem::RadioButtonListItem, "label" );
       
   111         QVERIFY( pdata !=0 );
       
   112         delete pdata;
       
   113         pdata = 0;
       
   114         pdata = new CpSettingFormItemData( HbDataFormModelItem::MultiselectionItem, "label" );
       
   115         QVERIFY( pdata !=0 );
       
   116         delete pdata;
       
   117         pdata = 0;
       
   118         pdata = new CpSettingFormItemData( HbDataFormModelItem::ComboBoxItem, "label" );
       
   119         QVERIFY( pdata !=0 );
       
   120         delete pdata;
       
   121         pdata = 0;
       
   122 }
       
   123 void TestCpAPI::testItemDataHelper()
       
   124 {
       
   125     HbDataForm* form = new HbDataForm();
       
   126     HbDataFormModel *model = new HbDataFormModel();
       
   127     HbDataFormModelItem *general = model->appendDataFormPage(QString("General"));
       
   128     CpItemDataHelper *phelper = new CpItemDataHelper();
       
   129     phelper->addConnection( general, "hello",form,"hello");
       
   130     phelper->removeConnection(general,"hello",form, "hello");
       
   131     phelper->bindToForm(form);
       
   132     HbDataFormViewItem *pitem = new HbDataFormViewItem();
       
   133     phelper->addItemPrototype(pitem);
       
   134     delete phelper;
       
   135 }
       
   136 void TestCpAPI::testCpPluginUtility()
       
   137 {
       
   138     HbDataForm* form = new HbDataForm();
       
   139     QList<HbAbstractViewItem *> oldList = form->itemPrototypes();
       
   140     CpPluginUtility::addCpItemPrototype(form);
       
   141     QList<HbAbstractViewItem *> newList = form->itemPrototypes();
       
   142     QVERIFY( oldList.count() < newList.count() );
       
   143 }
       
   144 
       
   145 void TestCpAPI::testCpPluginLoader()
       
   146 {
       
   147     CpPluginInterface *plugin = CpPluginLoader::loadCpPluginInterface("non_existing_plugin.dll");
       
   148     QVERIFY(plugin == 0);
       
   149 
       
   150     plugin = CpPluginLoader::loadCpPluginInterface("cppersonalizationplugin");
       
   151     QVERIFY(plugin != 0);
       
   152 
       
   153     plugin = CpPluginLoader::loadCpPluginInterface("cppersonalizationplugin.dll");
       
   154     QVERIFY(plugin != 0);
       
   155 
       
   156     plugin = CpPluginLoader::loadCpPluginInterface("cppersonalizationplugin.qtplugin");
       
   157     QVERIFY(plugin != 0);
       
   158 }
       
   159 
       
   160 void TestCpAPI::testCpPluginInterface()
       
   161 {
       
   162     CpPluginInterface *plugin = CpPluginLoader::loadCpPluginInterface("cppersonalizationplugin.dll");
       
   163     if (plugin) {
       
   164         CpItemDataHelper helper;
       
   165         QList<CpSettingFormItemData*> itemData = plugin->createSettingFormItemData(helper);
       
   166         QVERIFY(itemData.size() > 0);
       
   167         qDeleteAll(itemData.begin(),itemData.end());
       
   168         itemData.clear();
       
   169     }
       
   170 }
       
   171 
       
   172 void TestCpAPI::testCpLogger()
       
   173 {
       
   174     const QString logConf = "C:/data/.config/ut_cpapi/controlpanellog.conf";
       
   175     Logger::instance(CPFW_LOGGER_NAME)->configure(logConf,QSettings::IniFormat);
       
   176     CPFW_LOG("Hello World!");
       
   177     Logger::closeAll();
       
   178 }
       
   179 
       
   180