homescreenapp/widgetplugins/hsclockwidgetplugin/tsrc/t_hsclockwidgetplugin/src/t_hsclockwidget.cpp
changeset 90 3ac3aaebaee5
child 98 e6f74eb7f69f
equal deleted inserted replaced
86:e4f038c420f7 90:3ac3aaebaee5
       
     1 /*
       
     2 * Copyright (c) 2008, 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 code
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <QtTest/QtTest>
       
    21 #include <QGraphicsItem>
       
    22 #include <QGraphicsSceneMouseEvent>
       
    23 #include <QPainter>
       
    24 #include <QComboBox>
       
    25 #include <QMap>
       
    26 
       
    27 #include "t_hsclockwidget.h"
       
    28 #include "hsclockwidget.h"
       
    29 #include "hsanalogclockwidget.h"
       
    30 #include "hsdigitalclockwidget.h"
       
    31 #include "hsclockwidgettimer.h"
       
    32 
       
    33 #ifdef Q_OS_SYMBIAN
       
    34 #include <bacntf.h> // TLocale
       
    35 #include <apgtask.h>
       
    36 #include <eikenv.h>
       
    37 #endif //Q_OS_SYMBIAN
       
    38 
       
    39 namespace
       
    40 {
       
    41     const char ANALOG[] = "analog";
       
    42     const char DIGITAL[] = "digital";
       
    43     const char TIME12[] = "TIME12";
       
    44     const char TIME24[] = "TIME24";
       
    45 }
       
    46 
       
    47 
       
    48 #ifdef Q_OS_SYMBIAN
       
    49 #define KClockApUid TUid::Uid(0x10005903)
       
    50 #endif //Q_OS_SYMBIAN
       
    51 
       
    52 void TestClockWidget::initTestCase()
       
    53     {
       
    54 #ifdef Q_OS_SYMBIAN
       
    55     TLocale locale;
       
    56     mClockFormat = locale.ClockFormat();
       
    57     mTimeFormat = locale.TimeFormat();
       
    58 #endif
       
    59     }
       
    60 
       
    61 void TestClockWidget::cleanupTestCase()
       
    62     {
       
    63 #ifdef Q_OS_SYMBIAN
       
    64     TLocale locale;
       
    65     locale.SetClockFormat(mClockFormat);
       
    66     locale.SetTimeFormat(mTimeFormat);
       
    67     locale.Set();
       
    68 #endif
       
    69     }
       
    70 
       
    71 void TestClockWidget::init()
       
    72     {
       
    73     QGraphicsWidget *hostWidget = new QGraphicsWidget();
       
    74     mClockWidget = new HsClockWidget(hostWidget);
       
    75     mClockWidget->resize(100,100);
       
    76     QVERIFY( mClockWidget );
       
    77     }
       
    78 
       
    79 void TestClockWidget::cleanup()
       
    80     {
       
    81     //delete mClockWidget->parentItem();
       
    82     delete mClockWidget;
       
    83     mClockWidget = 0;
       
    84 
       
    85     }
       
    86 
       
    87 void TestClockWidget::createClockWidget()
       
    88     {
       
    89     }
       
    90 
       
    91 
       
    92 void TestClockWidget::toggleAnalogDigital()
       
    93     {
       
    94     mClockWidget->onInitialize();
       
    95     QString clockType = mClockWidget->mClockType;
       
    96     
       
    97     mClockWidget->onClockTapped();
       
    98 
       
    99 #ifndef Q_OS_SYMBIAN
       
   100     // toggles analog/digital on windows
       
   101     if (clockType == DIGITAL) {
       
   102         QCOMPARE( mClockWidget->mClockType, QString(ANALOG));
       
   103     } else {
       
   104         QCOMPARE( mClockWidget->mClockType, QString(DIGITAL));
       
   105     }
       
   106 
       
   107     clockType = mClockWidget->mClockType;
       
   108 
       
   109     mClockWidget->onClockTapped();
       
   110 
       
   111     if (clockType == DIGITAL) {
       
   112         QCOMPARE( mClockWidget->mClockType, QString(ANALOG));
       
   113     } else {
       
   114         QCOMPARE( mClockWidget->mClockType, QString(DIGITAL));
       
   115     }
       
   116 #else    
       
   117     QCOMPARE( mClockWidget->mClockType, clockType);   
       
   118     QTest::qWait(6000);
       
   119     TApaTaskList taskList(CEikonEnv::Static()->WsSession());    
       
   120     TApaTask task = taskList.FindApp(KClockApUid);    
       
   121     if (task.Exists()){
       
   122         task.SendToBackground();        
       
   123     }    
       
   124     else {
       
   125         QWARN("Clock application start failed");
       
   126     }
       
   127 #endif
       
   128     }
       
   129 
       
   130 
       
   131 void TestClockWidget::testClockOnInitalize()
       
   132 {
       
   133     mClockWidget->onInitialize();
       
   134     QVERIFY(mClockWidget->mWidget);
       
   135 }
       
   136 
       
   137 void TestClockWidget::testClockOnShow()
       
   138 {
       
   139     mClockWidget->onInitialize();
       
   140     QVERIFY(mClockWidget->mWidget);
       
   141     QVERIFY(!HsClockWidgetTimer::instance()->mTimer->isActive());
       
   142     mClockWidget->onShow();
       
   143     QVERIFY(HsClockWidgetTimer::instance()->mTimer->isActive());
       
   144 
       
   145     QSignalSpy updateSpy(HsClockWidgetTimer::instance()->mTimer,SIGNAL(timeout()));
       
   146     QEventLoop waitUntilTimeoutSignaled;
       
   147     QTimer eventLoopTimer;
       
   148     eventLoopTimer.setInterval(1500);
       
   149     eventLoopTimer.setSingleShot(true);
       
   150     connect(HsClockWidgetTimer::instance()->mTimer, SIGNAL(timeout()),
       
   151             &waitUntilTimeoutSignaled, SLOT(quit()));
       
   152     connect(&eventLoopTimer, SIGNAL(timeout()), &waitUntilTimeoutSignaled, SLOT(quit()));
       
   153     eventLoopTimer.start();
       
   154     waitUntilTimeoutSignaled.exec();
       
   155 
       
   156     //Verify timeout was received instead of eventLoopTimer has elapsed.
       
   157     QCOMPARE(updateSpy.count(), 1);
       
   158     QVERIFY(eventLoopTimer.isActive());
       
   159     eventLoopTimer.stop();
       
   160 
       
   161 }
       
   162 
       
   163 void TestClockWidget::testClockOnHide()
       
   164 {
       
   165     mClockWidget->onInitialize();
       
   166     mClockWidget->onShow();
       
   167     mClockWidget->onHide();
       
   168 }
       
   169 
       
   170 void TestClockWidget::testOnUninitialize()
       
   171 {
       
   172     mClockWidget->onInitialize(); 
       
   173     mClockWidget->onUninitialize();
       
   174 }
       
   175 
       
   176 
       
   177 void TestClockWidget::testOnSettingsChanged()
       
   178 {
       
   179     mClockWidget->mClockType = QString(ANALOG);
       
   180     mClockWidget->mTimeType = QString(TIME12);
       
   181 
       
   182     mClockWidget->onInitialize();
       
   183     mClockWidget->onShow();
       
   184     mClockWidget->onSettingsChanged(QString(DIGITAL), QString(TIME24));
       
   185     mClockWidget->onSettingsChanged(QString(DIGITAL), QString(TIME12));
       
   186     mClockWidget->onSettingsChanged(QString(ANALOG), QString(TIME24));
       
   187     mClockWidget->onSettingsChanged(QString(ANALOG), QString(TIME12));
       
   188 }
       
   189 
       
   190 void TestClockWidget::testClockShape()
       
   191 {
       
   192     mClockWidget->onInitialize();
       
   193     mClockWidget->shape();	
       
   194 }
       
   195 
       
   196 QTEST_MAIN(TestClockWidget)
       
   197 
       
   198 // end of file