phoneuis/bubblemanager2/tsrc/unit/loctest/loctest.cpp
changeset 45 6b911d05207e
child 60 1eef62f5c541
equal deleted inserted replaced
37:ba76fc04e6c2 45:6b911d05207e
       
     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: Test cases to measure localisation metrics.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtGui>
       
    19 #include <QtTest/QtTest>
       
    20 
       
    21 #include <hbapplication.h>
       
    22 #include <hbmainwindow.h>
       
    23 #include <hbaction.h>
       
    24 #include <hbtoolbar.h>
       
    25 #include <hbview.h>
       
    26 #include <private/hbtextmeasurementutility_p.h> // hb "configure --developer" required
       
    27 #include <hbdeviceprofile.h>
       
    28 
       
    29 #include "bubbletest.h"
       
    30 #include "bubblemanager2.h"
       
    31 
       
    32 const int WAIT_TIME = 1000;
       
    33 
       
    34 class LocTest : public QObject
       
    35 {
       
    36     Q_OBJECT
       
    37 
       
    38 private slots:
       
    39     void initTestCase();
       
    40     void cleanupTestCase();
       
    41 
       
    42     void testPortraitStrings();
       
    43 
       
    44     void changeOrientation();
       
    45 
       
    46     void testLandscapeStrings();
       
    47 
       
    48 private:
       
    49     void testLabel(int bubbleId, const char *id);
       
    50     void testCli(int bubbleId, const char *id);
       
    51 
       
    52 private:
       
    53     HbMainWindow*  mainWindow;
       
    54     BubbleManager* bubbleManager; // widget under test
       
    55     HbAction*      toolbarAction;
       
    56     HbView*        view; // not owned
       
    57 };
       
    58 
       
    59 void LocTest::initTestCase()
       
    60 {
       
    61     mainWindow = new HbMainWindow;
       
    62 
       
    63     bubbleManager = new BubbleManager();
       
    64     connect(mainWindow,SIGNAL(orientationChanged(Qt::Orientation)),
       
    65             bubbleManager,SLOT(handleOrientationChange(Qt::Orientation)));
       
    66 
       
    67     view = mainWindow->addView( bubbleManager );
       
    68 
       
    69     HbToolBar *toolBar = new HbToolBar();
       
    70     toolbarAction = new HbAction(this);
       
    71     toolBar->addAction( toolbarAction );
       
    72     toolBar->addAction( toolbarAction );
       
    73     mainWindow->currentView()->setToolBar(toolBar);
       
    74 
       
    75     mainWindow->show();
       
    76     QTest::qWait( 3000 );
       
    77 }
       
    78 
       
    79 void LocTest::cleanupTestCase()
       
    80 {
       
    81     delete mainWindow;
       
    82     delete toolbarAction;
       
    83 }
       
    84 
       
    85 void LocTest::testPortraitStrings()
       
    86 {
       
    87     view->setTitle( "Measuring portrait" );
       
    88 
       
    89     // In portrait all text fields have same width, only font
       
    90     // is different between label and cli field.
       
    91 
       
    92     // create test bubble
       
    93     bubbleManager->startChanges();
       
    94     int bubbleId = bubbleManager->createCallHeader();
       
    95     bubbleManager->setState( bubbleId, BubbleManager::Incoming );
       
    96     HbAction action1("Answer", this);
       
    97     action1.setSoftKeyRole(QAction::PositiveSoftKey);
       
    98     bubbleManager->addAction( bubbleId, &action1 );
       
    99     HbAction action2("Reject", this);
       
   100     action2.setSoftKeyRole(QAction::NegativeSoftKey);
       
   101     bubbleManager->addAction( bubbleId, &action2 );
       
   102     bubbleManager->setCallObjectFromTheme(bubbleId);
       
   103     bubbleManager->endChanges();
       
   104 
       
   105     QTest::qWait( WAIT_TIME );
       
   106 
       
   107     // measure label texts
       
   108     testLabel(bubbleId,"txt_phone_other_calling");
       
   109 
       
   110     testLabel(bubbleId,"txt_phone_other_incoming_call");
       
   111 
       
   112     testLabel(bubbleId,"txt_phone_other_waiting");
       
   113 
       
   114     testLabel(bubbleId,"txt_phone_other_on_hold");
       
   115 
       
   116     testLabel(bubbleId,"txt_phone_other_disconnected");
       
   117 
       
   118     testLabel(bubbleId,"txt_phone_other_attempting");
       
   119 
       
   120     // measure cli texts
       
   121     testCli(bubbleId,"txt_phone_other_conference_call");
       
   122 
       
   123     testCli(bubbleId,"txt_phone_other_unknown_number");
       
   124 
       
   125     testCli(bubbleId,"txt_phone_other_remote_sim");
       
   126 
       
   127     testCli(bubbleId,"txt_phone_other_private_number");
       
   128 
       
   129     testCli(bubbleId,"txt_phone_other_emergency_call");
       
   130 
       
   131     // write results
       
   132     QTest::qWait( WAIT_TIME );
       
   133     HbDeviceProfile profile = HbDeviceProfile::profile(mainWindow);
       
   134     QFileInfo info(QCoreApplication::applicationFilePath());
       
   135     HbTextMeasurementUtility* utility = HbTextMeasurementUtility::instance();
       
   136     utility->writeReport(profile, info.baseName());
       
   137     utility->reset();
       
   138 
       
   139     QTest::qWait( WAIT_TIME );
       
   140     bubbleManager->startChanges();
       
   141     bubbleManager->removeCallHeader( bubbleId );
       
   142     bubbleManager->endChanges();
       
   143     QTest::qWait( WAIT_TIME );
       
   144 }
       
   145 
       
   146 void LocTest::changeOrientation()
       
   147 {
       
   148     view->setTitle( "Changing orientation" );
       
   149     mainWindow->setOrientation(Qt::Horizontal);
       
   150     mainWindow->resize(640,360);
       
   151     QTest::qWait(3000);
       
   152 }
       
   153 
       
   154 void LocTest::testLandscapeStrings()
       
   155 {
       
   156     view->setTitle( "Measuring landscape" );
       
   157 
       
   158     // In landscape text field width depends on call situation,
       
   159     // measure according to most narrow case.
       
   160 
       
   161     // create test bubble
       
   162     bubbleManager->startChanges();
       
   163     int bubbleId = bubbleManager->createCallHeader();
       
   164     bubbleManager->setState( bubbleId, BubbleManager::OnHold );
       
   165     HbAction action1("End call", this);
       
   166     action1.setSoftKeyRole(QAction::PositiveSoftKey);
       
   167     bubbleManager->addAction( bubbleId, &action1 );
       
   168     bubbleManager->setCallObjectFromTheme(bubbleId);
       
   169     bubbleManager->endChanges();
       
   170 
       
   171 
       
   172     // only in single call texts
       
   173     testLabel(bubbleId,"txt_phone_other_incoming_call");
       
   174 
       
   175     testLabel(bubbleId,"txt_phone_other_attempting");
       
   176 
       
   177     testCli(bubbleId,"txt_phone_other_emergency_call");
       
   178 
       
   179     // multicall
       
   180     bubbleManager->startChanges();
       
   181     int bubbleId2 = bubbleManager->createCallHeader();
       
   182     bubbleManager->setState( bubbleId2, BubbleManager::OnHold );
       
   183     int bubbleId3 = bubbleManager->createCallHeader();
       
   184     bubbleManager->setState( bubbleId3, BubbleManager::Waiting );
       
   185     HbAction action2("Replace", this);
       
   186     action2.setSoftKeyRole(QAction::PositiveSoftKey);
       
   187     bubbleManager->addAction( bubbleId3, &action1 );
       
   188     bubbleManager->setCallObjectFromTheme(bubbleId3);
       
   189     bubbleManager->endChanges();
       
   190 
       
   191     // measure label texts
       
   192     testLabel(bubbleId2,"txt_phone_other_calling");
       
   193 
       
   194     testLabel(bubbleId2,"txt_phone_other_waiting");
       
   195 
       
   196     testLabel(bubbleId2,"txt_phone_other_on_hold");
       
   197 
       
   198     testLabel(bubbleId2,"txt_phone_other_disconnected");
       
   199 
       
   200     // measure cli texts
       
   201     testCli(bubbleId2,"txt_phone_other_conference_call");
       
   202 
       
   203     testCli(bubbleId3,"txt_phone_other_unknown_number");
       
   204 
       
   205     testCli(bubbleId3,"txt_phone_other_remote_sim");
       
   206 
       
   207     testCli(bubbleId3,"txt_phone_other_private_number");
       
   208 
       
   209     // write results
       
   210     QTest::qWait( WAIT_TIME );
       
   211     HbDeviceProfile profile = HbDeviceProfile::profile(mainWindow);
       
   212     QFileInfo info(QCoreApplication::applicationFilePath());
       
   213     HbTextMeasurementUtility* utility = HbTextMeasurementUtility::instance();
       
   214     utility->writeReport(profile, info.baseName());
       
   215     utility->reset();
       
   216 
       
   217     QTest::qWait( WAIT_TIME );
       
   218     bubbleManager->startChanges();
       
   219     bubbleManager->removeCallHeader( bubbleId );
       
   220     bubbleManager->removeCallHeader( bubbleId2 );
       
   221     bubbleManager->removeCallHeader( bubbleId3 );
       
   222     bubbleManager->endChanges();
       
   223     QTest::qWait( WAIT_TIME );
       
   224 }
       
   225 
       
   226 void LocTest::testLabel(int bubbleId, const char *id)
       
   227 {
       
   228     HbTextMeasurementUtility* utility = HbTextMeasurementUtility::instance();
       
   229     bubbleManager->startChanges();
       
   230     bubbleManager->setLabel( bubbleId, hbTrId(id));
       
   231     bubbleManager->endChanges();
       
   232     utility->measureItems(100);
       
   233     QTest::qWait( WAIT_TIME );
       
   234     bubbleManager->startChanges();
       
   235     bubbleManager->setLabel( bubbleId, "");
       
   236     bubbleManager->endChanges();
       
   237 }
       
   238 
       
   239 void LocTest::testCli(int bubbleId, const char *id)
       
   240 {
       
   241     HbTextMeasurementUtility* utility = HbTextMeasurementUtility::instance();
       
   242     bubbleManager->startChanges();
       
   243     bubbleManager->setCli( bubbleId, hbTrId(id), Qt::ElideRight);
       
   244     bubbleManager->endChanges();
       
   245     utility->measureItems(100);
       
   246     QTest::qWait( WAIT_TIME );
       
   247     bubbleManager->startChanges();
       
   248     bubbleManager->setCli( bubbleId, "", Qt::ElideRight);
       
   249     bubbleManager->endChanges();
       
   250 }
       
   251 
       
   252 BUBBLE_TEST_MAIN(LocTest)
       
   253 #include "loctest.moc"
       
   254