controlpanel/tsrc/unit/ut_cpplugin/src/ut_cpplugin.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 *
       
    16 */
       
    17 #include "ut_cpplugin.h"
       
    18 #include <hbmainwindow.h>
       
    19 #include <QGraphicsWidget>
       
    20 #include <qDebug>
       
    21 #include <QtTest/QtTest>
       
    22 #include <cpsettingformitemdata.h>
       
    23 
       
    24 #include <cppluginplatinterface.h>
       
    25 #include <cppluginloader.h>
       
    26 #include <cppluginlauncher.h>
       
    27 #include <cpitemdatahelper.h>
       
    28 
       
    29 //define plugin uids, need replaced by header file
       
    30 const int PluginUIDs[] =
       
    31 {
       
    32     //0X20025FE2,	 //viewplugin
       
    33     //0X20025FE4,  //tonesplugin		Y
       
    34     0X20025FDF,  //communicationplugin.pro  N
       
    35     0X20025FDC,  //applicationsettingsplugin.pro    N
       
    36     //0xEEF7E3EC,  //3rdpartyappsettingsplugin.pro    Y
       
    37     0X20025FE5,  //personalizationplugin.pro    N
       
    38     0X20025FE8,  //placeholderplugin    Y
       
    39 	0X20025FDD,  //placeholder no icon
       
    40 	0X20025FDE,  //key touch
       
    41 	0X20025FE0,  // look and feel
       
    42 	0X20025FDB, // theme
       
    43 	0X20025FE1, // privatcy
       
    44 
       
    45 
       
    46 };
       
    47 //define whether the plugin has exported view or not
       
    48 const int PluginHasView[] =
       
    49 {
       
    50     0, // communication
       
    51     0, // application
       
    52     0, //personalization
       
    53     1, //placeholder
       
    54     1, //placeholdernoicon
       
    55     0, //accountsplugin
       
    56     0, //privacy
       
    57 	0, //device
       
    58 	1, //theme
       
    59 	1, //keytouch
       
    60     0  // look and feel
       
    61 };
       
    62 
       
    63 void TestCpPlugin::initTestCase()
       
    64 {
       
    65     pLoader = new CpPluginLoader();
       
    66     mainWindow = new HbMainWindow;
       
    67     mainWindow->show();
       
    68 	pluginDlls  << "cpcommunicationplugin"
       
    69                 << "cpapplicationsettingsplugin"
       
    70                 << "cppersonalizationplugin"
       
    71                 << "cpplaceholderplugin"
       
    72 				<< "cpplaceholdernoiconplugin"
       
    73 				<< "cpaccountsplugin"
       
    74 				<< "cpprivacyplugin"
       
    75 				<< "cpdeviceplugin"
       
    76 				<< "cpthemeplugin"
       
    77 				<< "cpkeytouchfdbkplugin"
       
    78 				<< "cplookfeelplugin";
       
    79 }
       
    80 
       
    81 void TestCpPlugin::test_loadPluginsName()
       
    82 {
       
    83     
       
    84 
       
    85 
       
    86     int count = pluginDlls.size();
       
    87     for( int i=0; i<pluginDlls.size(); ++i )
       
    88     {
       
    89         CpPluginPlatInterface* plugin = pLoader->loadCpPlugin( pluginDlls[i] );
       
    90         qDebug()<< "<DEBUGINFO>Loading plugin ["
       
    91                 << pluginDlls[i]<< "],result is:"
       
    92                 << ( (plugin != 0)? "OK":"Fail" );
       
    93         QVERIFY( plugin!= 0 );
       
    94     }
       
    95 
       
    96 }
       
    97 void TestCpPlugin::test_loadPluginsName_N()
       
    98 {
       
    99     CpPluginPlatInterface* plugin = pLoader->loadCpPlugin( "" );
       
   100     qDebug()<< "<DEBUGINFO>Loading plugin ["
       
   101             << "(empty name)"<< "],result is:"
       
   102             << ( (plugin == 0)? "OK":"Fail" );
       
   103     QVERIFY( plugin == 0 );
       
   104 }
       
   105 
       
   106 void TestCpPlugin::test_createSettingFormItemData()
       
   107 {
       
   108     CpItemDataHelper *pHelper = new CpItemDataHelper();
       
   109 
       
   110     for( int i = 0; i< plist.count(); ++i)
       
   111     {
       
   112         CpPluginPlatInterface* plugin = plist[i];
       
   113         if(plugin)
       
   114         {
       
   115             CpSettingFormItemData *itemData = plugin->createSettingFormItemData(*pHelper);
       
   116             bool bToF = (itemData != 0);
       
   117             qDebug( "<DEBUGINFO>Plugin [0X%08X], result is %s", PluginUIDs[i], bToF?"OK":"Fail" );
       
   118            // delete itemData;
       
   119             QVERIFY( bToF );
       
   120         }
       
   121     }
       
   122     delete pHelper;
       
   123 }
       
   124 
       
   125 void TestCpPlugin::test_launcher_by_Name()
       
   126 {
       
   127     //clear all existing view firstly
       
   128     int vcount = mainWindow->viewCount();
       
   129     int i = 0;
       
   130     for ( i=vcount-1; i>=0; --i )
       
   131     {
       
   132         QGraphicsWidget * pwgt = mainWindow->removeView( i );
       
   133         delete pwgt;
       
   134     }
       
   135     //launch plugins list by name
       
   136     int count = pluginDlls.size();
       
   137     for( i=0; i<pluginDlls.size(); ++i )
       
   138     {
       
   139         bool bret = CpPluginLauncher::launchCpPluginView( pluginDlls[i] );
       
   140         if(!PluginHasView[i])   bret = !bret;
       
   141         qDebug()<< "<DEBUGINFO>Loading plugin ["
       
   142                 << pluginDlls[i]<< "],result is:"
       
   143                 << ( bret? "OK":"Fail" );
       
   144         QVERIFY( bret );
       
   145     }
       
   146 }
       
   147 void TestCpPlugin::test_launcher_by_Name_N()
       
   148 {
       
   149     bool bret = CpPluginLauncher::launchCpPluginView( "<not_existing>" );
       
   150     qDebug()<< "<DEBUGINFO>Loading plugin ["
       
   151             << "<not_existing>"<< "],result is:"
       
   152             << ( (!bret )? "OK":"Fail" );
       
   153         QVERIFY( !bret );
       
   154 }
       
   155 
       
   156 void TestCpPlugin::cleanupTestCase()
       
   157 {
       
   158     for (int i = 0; i < plist.count(); ++i)
       
   159     {
       
   160         CpPluginPlatInterface* plugin = plist[i];
       
   161         if (plugin)
       
   162         {
       
   163             delete plugin;
       
   164             plugin = 0;
       
   165         }
       
   166     }
       
   167     if (pLoader)
       
   168     {
       
   169         delete pLoader;
       
   170         pLoader = 0;
       
   171     }
       
   172     delete mainWindow;
       
   173     mainWindow = 0;
       
   174 }
       
   175 
       
   176 QTEST_MAIN(TestCpPlugin)