controlpanelplugins/langandregplugin/t_languageplugin/src/t_languageplugin.cpp
changeset 40 593f946f4fec
equal deleted inserted replaced
22:a5692c68d772 40:593f946f4fec
       
     1 /*
       
     2 * Copyright (c) 2010 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:  Main test class for Control Panel's Language plugin.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "t_languageplugin.h"
       
    19 #include <QtTest/QtTest>
       
    20 #include <QModelIndex>
       
    21 #include <hbmainwindow.h>
       
    22 #include <hbinputsettingproxy.h>
       
    23 #include <hblocaleutil.h>
       
    24 #include <hbinpututils.h>
       
    25 #include <cpsettingformentryitemdataimpl.h>
       
    26 #include <cpitemdatahelper.h>
       
    27 #include "cplanguageplugin.h"
       
    28 #include "extendedlocaleutil.h"
       
    29 #include "cplanguageview.h"
       
    30 #include "cplanguagepluginutil.h"
       
    31 
       
    32 /*!
       
    33     Initialize test case.
       
    34     Called before each testfunction is executed.
       
    35 */
       
    36 void TestLanguagePlugin::init() 
       
    37 {   
       
    38     mMainWindow = new HbMainWindow();
       
    39     QVERIFY(mMainWindow);
       
    40     
       
    41     mPlugin = new CpLanguagePlugin;
       
    42     QVERIFY(mPlugin);
       
    43     // Note: we get different values for condition coverage of CpLanguageView()
       
    44     // depending on which values have been selected in Control Panel settings. 
       
    45 	mView = new CpLanguageView();
       
    46 	QVERIFY(mView);
       
    47 	
       
    48 	CpItemDataHelper itemDataHelper;
       
    49 	QList<CpSettingFormItemData*> itemData = mPlugin->createSettingFormItemData(itemDataHelper); 
       
    50 	mEntryItemData = qobject_cast<CpSettingFormEntryItemData*>(itemData.front());
       
    51 }
       
    52 
       
    53 /*!
       
    54     Cleanup test case.
       
    55     Called after every testfunction.
       
    56 */
       
    57 void TestLanguagePlugin::cleanup()
       
    58 {
       
    59 	delete mView;
       
    60 	mView = 0;
       
    61 	
       
    62 	delete mPlugin;
       
    63     mPlugin = 0;  	
       
    64     
       
    65     delete mEntryItemData;
       
    66     mEntryItemData = 0;
       
    67     
       
    68     delete mMainWindow;
       
    69     mMainWindow = 0;
       
    70 }
       
    71 
       
    72 /* ---------------------------------------------------------------------------
       
    73  * Unit test cases 
       
    74  * ---------------------------------------------------------------------------*/
       
    75 
       
    76 /*!
       
    77  *  test CpLanguagePlugin::createSettingFormItemData
       
    78  */
       
    79 void TestLanguagePlugin::test_CpLanguagePlugin_createSettingFormItemData()
       
    80 {    
       
    81 	CpItemDataHelper itemDataHelper;
       
    82     QList<CpSettingFormItemData*> itemData = mPlugin->createSettingFormItemData(itemDataHelper); 
       
    83     QVERIFY(itemData.count() == 1);     
       
    84     
       
    85     CpSettingFormEntryItemData *entryItemData = qobject_cast<CpSettingFormEntryItemData*>(itemData.front());
       
    86     QVERIFY(entryItemData != 0);
       
    87     QVERIFY(entryItemData->type() == static_cast<HbDataFormModelItem::DataItemType>(CpSettingFormEntryItemData::ListEntryItem) );
       
    88 }
       
    89 
       
    90 /*!
       
    91  * test CpLanguagePlugin::updateEntryItem
       
    92  */
       
    93 void TestLanguagePlugin::test_CpLanguagePlugin_updateEntryItem()
       
    94 {
       
    95     CpLanguagePlugin::updateEntryItem();
       
    96     
       
    97     QString localisedLanguage = HbLocaleUtil::localisedLanguageName(HbLocaleUtil::currentLanguage());
       
    98     
       
    99     QVERIFY(mEntryItemData->description() == localisedLanguage);
       
   100 }
       
   101 
       
   102 /*!
       
   103  * test ExtendedLocaleUtil::localeMappings
       
   104  */
       
   105 void TestLanguagePlugin::test_ExtendedLocaleUtil_localeMappings()
       
   106 {
       
   107     QList<LanguageRegionMapping> allMaps = ExtendedLocaleUtil::localeMappings(false);
       
   108     QVERIFY(allMaps.count() > 0);
       
   109     
       
   110     QList<LanguageRegionMapping> supportedMaps = ExtendedLocaleUtil::localeMappings(true);
       
   111     QVERIFY(supportedMaps.count() > 0);
       
   112     
       
   113     QVERIFY(allMaps.count() >= supportedMaps.count());
       
   114 }
       
   115 
       
   116 /*!
       
   117  * test CpLanguagePluginUtil::localizedLanguageNames
       
   118  */
       
   119 void TestLanguagePlugin::test_CpLanguagePluginUtil_localizedLanguageNames()
       
   120 {
       
   121     QStringList supportLanguages = HbLocaleUtil::supportedLanguages();
       
   122     QStringList localisedLanguages = CpLanguagePluginUtil::localizedLanguageNames(supportLanguages);
       
   123     
       
   124     QVERIFY (supportLanguages.count() == localisedLanguages.count());
       
   125 }
       
   126 
       
   127 /*!
       
   128  * test CpLanguagePluginUtil::localizedRegionNames
       
   129  */
       
   130 void TestLanguagePlugin::test_CpLanguagePluginUtil_localizedRegionNames()
       
   131 {
       
   132     QStringList supportedRegions = HbLocaleUtil::supportedRegions();
       
   133     QStringList localisedRegions = CpLanguagePluginUtil::localizedRegionNames(supportedRegions);
       
   134     
       
   135     QVERIFY (supportedRegions.count() == localisedRegions.count());
       
   136 }
       
   137 
       
   138 /*
       
   139  * test CpLanguagePluginUtil::localizedInputLanguageNames
       
   140  */
       
   141 void TestLanguagePlugin::test_CpLanguagePluginUtil_localizedInputLanguageNames()
       
   142 {
       
   143     QList<HbInputLanguage> supportedInputLanguages;
       
   144     HbInputUtils::listSupportedInputLanguages(supportedInputLanguages);
       
   145     
       
   146     QStringList localisedInputLanguages = CpLanguagePluginUtil::localizedInputLanguageNames(supportedInputLanguages);
       
   147     QVERIFY(supportedInputLanguages.count() == localisedInputLanguages.count());
       
   148 }
       
   149 
       
   150 /*!
       
   151  * test CpLanguagePluginUtil::isChineseVariant
       
   152  */
       
   153 void TestLanguagePlugin::test_CpLanguagePluginUtil_isChineseVariant()
       
   154 {
       
   155     bool isChineseVariant = CpLanguagePluginUtil::isChineseVariant();
       
   156     
       
   157     QStringList supportedLanguages = HbLocaleUtil::supportedLanguages();
       
   158     foreach(const QString &language, supportedLanguages) {
       
   159         if (QLocale(language).language() == QLocale::Chinese) {
       
   160             QVERIFY (isChineseVariant);
       
   161             return;
       
   162         }
       
   163     }
       
   164     
       
   165     QVERIFY (!isChineseVariant);
       
   166 }
       
   167 
       
   168 /*!
       
   169  * test new CpLanguageView
       
   170  */
       
   171 void TestLanguagePlugin::test_CpLanguageView_new()
       
   172 {
       
   173     CpLanguageView* view = new CpLanguageView();
       
   174     QVERIFY(view != 0);
       
   175     delete view;
       
   176 }
       
   177 
       
   178 /*!
       
   179  * test CpLanguageView::onRegionChanged(int index)
       
   180  */
       
   181 void TestLanguagePlugin::test_CpLanguageView_onRegionChanged()
       
   182 {
       
   183     QString oldRegion = HbLocaleUtil::currentRegion();
       
   184     
       
   185     QStringList allRegions = mView->mSupportedRegions;
       
   186     QVERIFY(allRegions.count() > 0);
       
   187     
       
   188     for(int i = 0; i < allRegions.count();i++) {
       
   189         if (!allRegions.at(i).trimmed().isEmpty()) {
       
   190             mView->onRegionChanged(i);
       
   191             QVERIFY(HbLocaleUtil::currentRegion() == allRegions.at(i));
       
   192         }
       
   193     }
       
   194     
       
   195     HbLocaleUtil::changeRegion(oldRegion);
       
   196     QVERIFY(HbLocaleUtil::currentRegion() == oldRegion);
       
   197     
       
   198     mView->onRegionChanged(-1);
       
   199     QVERIFY(HbLocaleUtil::currentRegion() == oldRegion);
       
   200     
       
   201     mView->onRegionChanged(allRegions.count());
       
   202     QVERIFY(HbLocaleUtil::currentRegion() == oldRegion);
       
   203 }
       
   204 
       
   205 /*!
       
   206  * test CpLanguageView::onPrimaryInputLanguageChanged(int index)
       
   207  */
       
   208 void TestLanguagePlugin::test_CpLanguageView_onPrimaryInputLanguageChanged()
       
   209 {
       
   210     HbInputLanguage oldPrimaryInputLanguage = HbInputSettingProxy::instance()->globalInputLanguage();
       
   211     
       
   212     QList<HbInputLanguage> supportedInputLanguages = mView->mPrimaryInputLanguages;
       
   213     
       
   214     QVERIFY(supportedInputLanguages.count() > 0);
       
   215     for (int i = 0; i < supportedInputLanguages.count();i++) {
       
   216         mView->onPrimaryInputLanguageChanged(i);
       
   217         QVERIFY(HbInputSettingProxy::instance()->globalInputLanguage() == supportedInputLanguages.at(i));
       
   218     }
       
   219     
       
   220     HbInputSettingProxy::instance()->setGlobalInputLanguage(oldPrimaryInputLanguage);
       
   221     QVERIFY(HbInputSettingProxy::instance()->globalInputLanguage() == oldPrimaryInputLanguage);
       
   222     
       
   223     mView->onPrimaryInputLanguageChanged(-1);
       
   224     QVERIFY(HbInputSettingProxy::instance()->globalInputLanguage() == oldPrimaryInputLanguage);
       
   225     
       
   226     mView->onPrimaryInputLanguageChanged(supportedInputLanguages.count());
       
   227     QVERIFY(HbInputSettingProxy::instance()->globalInputLanguage() == oldPrimaryInputLanguage);
       
   228 }
       
   229 
       
   230 /*!
       
   231  * test CpLanguageView::onSecondaryInputLanguageChanged(int index)
       
   232  */
       
   233 void TestLanguagePlugin::test_CpLanguageView_onSecondaryInputLanguageChanged()
       
   234 {
       
   235     HbInputLanguage primaryInputLanguage = HbInputSettingProxy::instance()->globalInputLanguage();
       
   236     HbInputLanguage oldSecondaryInputLanguage = HbInputSettingProxy::instance()->globalSecondaryInputLanguage();
       
   237     
       
   238     QList<HbInputLanguage> supportedInputLanguages = mView->mSecondaryInputLanguages;
       
   239     
       
   240     QVERIFY(supportedInputLanguages.count() > 0);
       
   241     for (int i = 0; i < supportedInputLanguages.count();i++) {
       
   242         if ( supportedInputLanguages.at(i) != primaryInputLanguage) {
       
   243             mView->onSecondaryInputLanguageChanged(i);
       
   244             QVERIFY(HbInputSettingProxy::instance()->globalSecondaryInputLanguage() == supportedInputLanguages.at(i));
       
   245         }
       
   246     }
       
   247     
       
   248     HbInputSettingProxy::instance()->setGlobalSecondaryInputLanguage(oldSecondaryInputLanguage);
       
   249     QVERIFY(HbInputSettingProxy::instance()->globalSecondaryInputLanguage() == oldSecondaryInputLanguage);
       
   250     
       
   251     mView->onSecondaryInputLanguageChanged(-1);
       
   252     QVERIFY(HbInputSettingProxy::instance()->globalSecondaryInputLanguage() == oldSecondaryInputLanguage);
       
   253     
       
   254     mView->onSecondaryInputLanguageChanged(supportedInputLanguages.count());
       
   255     QVERIFY(HbInputSettingProxy::instance()->globalSecondaryInputLanguage() == oldSecondaryInputLanguage);
       
   256 }
       
   257 
       
   258 /*!
       
   259  * test CpLanguageView::onPrimaryInputLanguageChanged(const HbInputLanguage &inputLanguage)
       
   260  */
       
   261 void TestLanguagePlugin::test_CpLanguageView_onPrimaryInputLanguageChanged2()
       
   262 {
       
   263     int oldIndex = mView->mCurrentPrimaryInputLanguageItem->contentWidgetData("currentIndex").toInt();
       
   264     
       
   265     QList<HbInputLanguage> supportedInputLanguages = mView->mPrimaryInputLanguages;
       
   266     
       
   267     QVERIFY(supportedInputLanguages.count() > 0);
       
   268     for (int i = 0; i < supportedInputLanguages.count();i++) {
       
   269         mView->onPrimaryInputLanguageChanged(supportedInputLanguages.at(i));
       
   270         QVERIFY( mView->mCurrentPrimaryInputLanguageItem->contentWidgetData("currentIndex").toInt() == i );
       
   271     }
       
   272     
       
   273     mView->mCurrentPrimaryInputLanguageItem->setContentWidgetData("currentIndex",oldIndex);
       
   274     
       
   275     QVERIFY(oldIndex == mView->mCurrentPrimaryInputLanguageItem->contentWidgetData("currentIndex").toInt());
       
   276 }
       
   277 
       
   278 /*!
       
   279  * test CpLanguageView::onSecondaryInputLanguageChanged(const HbInputLanguage &inputLanguage)
       
   280  */
       
   281 void TestLanguagePlugin::test_CpLanguageView_onSecondaryInputLanguageChanged2()
       
   282 {
       
   283     int oldIndex = mView->mCurrentSecondaryInputLanguageItem->contentWidgetData("currentIndex").toInt();
       
   284     
       
   285     QList<HbInputLanguage> supportedInputLanguages = mView->mSecondaryInputLanguages;
       
   286     
       
   287     QVERIFY(supportedInputLanguages.count() > 0);
       
   288     for (int i = 0; i < supportedInputLanguages.count();i++) {
       
   289         mView->onSecondaryInputLanguageChanged(supportedInputLanguages.at(i));
       
   290         QVERIFY( mView->mCurrentSecondaryInputLanguageItem->contentWidgetData("currentIndex").toInt() == i );
       
   291     }
       
   292     
       
   293     mView->mCurrentSecondaryInputLanguageItem->setContentWidgetData("currentIndex",oldIndex);
       
   294     
       
   295     QVERIFY(oldIndex == mView->mCurrentSecondaryInputLanguageItem->contentWidgetData("currentIndex").toInt());
       
   296 }
       
   297 
       
   298 /*!
       
   299  * test CpLanguageView::launchRegionalSettingsView()
       
   300  */
       
   301 void TestLanguagePlugin::test_CpLanguageView_launchRegionalSettingsView()
       
   302 {
       
   303     mView->launchRegionalSettingsView();
       
   304     QVERIFY(mView->mClockPluginLoader != 0);
       
   305 }
       
   306 
       
   307 /*!
       
   308  * test CpLanguageView::onDataFormItemActivated(const QModelIndex &modelIndex)
       
   309  */
       
   310 void TestLanguagePlugin::test_CpLanguageView_onDataFormItemActivated()
       
   311 {
       
   312     QVERIFY(true);
       
   313 }
       
   314 
       
   315 /*!
       
   316  * test CpLanguageView::close()
       
   317  */
       
   318 void TestLanguagePlugin::test_CpLanguageView_close()
       
   319 {
       
   320     QVERIFY(true);
       
   321 }
       
   322 
       
   323 /*!
       
   324  * test CpLanguageView::fillDataFormComboBoxItem
       
   325  */
       
   326 void TestLanguagePlugin::test_CpLanguageView_fillDataFormComboBoxItem()
       
   327 {
       
   328     QStringList supportedRegions = HbLocaleUtil::supportedRegions();
       
   329     QStringList localizedRegions = CpLanguagePluginUtil::localizedRegionNames(supportedRegions);
       
   330     
       
   331     int regionIndex = supportedRegions.indexOf(HbLocaleUtil::currentRegion());
       
   332     
       
   333     mView->fillDataFormComboBoxItem(mView->mCurrentRegionItem,localizedRegions,regionIndex);
       
   334     
       
   335     QVERIFY(mView->mCurrentRegionItem->contentWidgetData("currentIndex").toInt() == regionIndex);
       
   336     QVERIFY(mView->mCurrentRegionItem->contentWidgetData("items").toStringList() == localizedRegions);
       
   337 }
       
   338 
       
   339 /*!
       
   340  * test CpLanguageView::updateSecondaryInputLanguageItem
       
   341  */
       
   342 void TestLanguagePlugin::test_CpLanguageView_updateSecondaryInputLanguageItem()
       
   343 {
       
   344     QList<HbInputLanguage> supportedInputLanguages;
       
   345     HbInputUtils::listSupportedInputLanguages(supportedInputLanguages);
       
   346     
       
   347     HbInputLanguage primaryInputLanguage = HbInputSettingProxy::instance()->globalInputLanguage();
       
   348     HbInputLanguage secondaryInputLanguage = HbInputSettingProxy::instance()->globalSecondaryInputLanguage();
       
   349     
       
   350     QVERIFY(supportedInputLanguages.count() > 0);
       
   351     
       
   352     HbInputSettingProxy::instance()->setGlobalInputLanguage(supportedInputLanguages.front());
       
   353     HbInputSettingProxy::instance()->setGlobalSecondaryInputLanguage(supportedInputLanguages.front());
       
   354     
       
   355     mView->updateSecondaryInputLanguageItem();
       
   356     
       
   357     QVERIFY(mView->mCurrentSecondaryInputLanguageItem->contentWidgetData("currentIndex").toInt() == 0);
       
   358     
       
   359 }
       
   360 
       
   361 /*!
       
   362  * test CpLanguageView::promptRestart
       
   363  */
       
   364 void TestLanguagePlugin::test_CpLanguageView_promptRestart()
       
   365 {
       
   366     QVERIFY(true);
       
   367 }
       
   368 
       
   369 /*!
       
   370  * test CpLanguageView::restartDevice
       
   371  */
       
   372 void TestLanguagePlugin::test_CpLanguageView_restartDevice()
       
   373 {
       
   374     QVERIFY(true);
       
   375 }
       
   376 
       
   377 /*!
       
   378  * test CpLanguageView::languageRegionMapping
       
   379  */
       
   380 void TestLanguagePlugin::test_CpLanguageView_languageRegionMapping()
       
   381 {
       
   382     QStringList supportedLanguages = HbLocaleUtil::supportedLanguages();
       
   383     foreach(const QString &language,supportedLanguages) {
       
   384         LanguageRegionMapping *entry = mView->languageRegionMapping(language);
       
   385         QVERIFY(entry != 0);
       
   386     }
       
   387 }
       
   388 
       
   389 QTEST_MAIN(TestLanguagePlugin)