phoneuis/bubblemanager2/tsrc/unit/loctest/loctest.cpp
branchRCL_3
changeset 61 41a7f70b3818
equal deleted inserted replaced
58:40a3f856b14d 61:41a7f70b3818
       
     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 <restricted/hbtextmeasurementutility_r.h> // hb "configure --developer" required
       
    27 #include <restricted/hbfeaturemanager_r.h>
       
    28 #include <hbdeviceprofile.h>
       
    29 
       
    30 #include "bubbletest.h"
       
    31 #include "bubblemanager2.h"
       
    32 
       
    33 const int WAIT_TIME = 1000;
       
    34 
       
    35 class LocTest : public QObject
       
    36 {
       
    37     Q_OBJECT
       
    38 
       
    39 private slots:
       
    40     void initTestCase();
       
    41     void cleanupTestCase();
       
    42 
       
    43     void testPortraitStrings();
       
    44     void changeOrientation();
       
    45     void testLandscapeStrings();
       
    46 
       
    47 private:
       
    48     void testLabel(int bubbleId, const char *id);
       
    49     void testCli(int bubbleId, const char *id);
       
    50 
       
    51 private:
       
    52     HbMainWindow*  mainWindow;
       
    53     BubbleManager* bubbleManager; // widget under test
       
    54     HbAction*      toolbarAction;
       
    55     HbView*        view; // not owned
       
    56 };
       
    57 
       
    58 void LocTest::initTestCase()
       
    59 {
       
    60     mainWindow = new HbMainWindow;
       
    61 
       
    62     bubbleManager = new BubbleManager();
       
    63     connect(mainWindow,SIGNAL(orientationChanged(Qt::Orientation)),
       
    64             bubbleManager,SLOT(handleOrientationChange(Qt::Orientation)));
       
    65 
       
    66     view = mainWindow->addView( bubbleManager );
       
    67 
       
    68     HbToolBar *toolBar = new HbToolBar();
       
    69     toolbarAction = new HbAction(this);
       
    70     toolBar->addAction( toolbarAction );
       
    71     toolBar->addAction( toolbarAction );
       
    72     mainWindow->currentView()->setToolBar(toolBar);
       
    73 
       
    74     mainWindow->show();
       
    75 
       
    76     HbFeatureManager::instance()->setFeatureStatus(
       
    77         HbFeatureManager::TextMeasurement, true);
       
    78 
       
    79     QTest::qWait( 3000 );
       
    80 }
       
    81 
       
    82 void LocTest::cleanupTestCase()
       
    83 {
       
    84     delete mainWindow;
       
    85     delete toolbarAction;
       
    86 }
       
    87 
       
    88 void LocTest::testPortraitStrings()
       
    89 {
       
    90     view->setTitle( "Measuring portrait" );
       
    91 
       
    92     // texts fields are measured according to most narrow situation
       
    93 
       
    94     // create test bubble
       
    95     bubbleManager->startChanges();
       
    96     int bubbleId = bubbleManager->createCallHeader();
       
    97     bubbleManager->setState( bubbleId, BubbleManager::Incoming );
       
    98     HbAction action1("Answer", this);
       
    99     action1.setSoftKeyRole(QAction::PositiveSoftKey);
       
   100     bubbleManager->addAction( bubbleId, &action1 );
       
   101     HbAction action2("Reject", this);
       
   102     action2.setSoftKeyRole(QAction::NegativeSoftKey);
       
   103     bubbleManager->addAction( bubbleId, &action2 );
       
   104     bubbleManager->setCallObjectFromTheme(bubbleId);
       
   105     bubbleManager->setCallFlag(bubbleId,BubbleManagerIF::NoCiphering,true);
       
   106     bubbleManager->endChanges();
       
   107 
       
   108     QTest::qWait( WAIT_TIME );
       
   109 
       
   110     // measure label texts
       
   111 
       
   112     // First line texts with ciphering indicator
       
   113     bubbleManager->startChanges();
       
   114     bubbleManager->setState( bubbleId, BubbleManager::Outgoing );
       
   115     bubbleManager->endChanges();
       
   116 
       
   117     testLabel(bubbleId,"txt_phone_other_calling");
       
   118 
       
   119     testLabel(bubbleId,"txt_phone_other_attempting");
       
   120 
       
   121     // Second line texts, no indicators -> full width
       
   122     bubbleManager->startChanges();
       
   123     bubbleManager->setState( bubbleId, BubbleManager::Incoming );
       
   124     bubbleManager->endChanges();
       
   125 
       
   126     testLabel(bubbleId,"txt_phone_other_incoming_call");
       
   127 
       
   128     testLabel(bubbleId,"txt_phone_other_waiting");
       
   129 
       
   130     testLabel(bubbleId,"txt_phone_other_on_hold");
       
   131 
       
   132     testLabel(bubbleId,"txt_phone_other_disconnected");
       
   133 
       
   134     testLabel(bubbleId,"txt_phone_other_incoming_video_call");
       
   135 
       
   136     testLabel(bubbleId,"txt_phone_other_incoming_l1_call");
       
   137 
       
   138     // First line CLI texts with ciphering indicator
       
   139     testCli(bubbleId,"txt_phone_other_conference_call");
       
   140 
       
   141     testCli(bubbleId,"txt_phone_other_remote_sim");
       
   142 
       
   143     testCli(bubbleId,"txt_phone_other_emergency_call");
       
   144 
       
   145     // First line CLI texts with ciphering and divert indicators
       
   146     bubbleManager->startChanges();
       
   147     bubbleManager->setCallFlag( bubbleId, BubbleManager::Diverted, true );
       
   148     bubbleManager->endChanges();
       
   149 
       
   150     testCli(bubbleId,"txt_phone_other_unknown_number");
       
   151 
       
   152     testCli(bubbleId,"txt_phone_other_private_number");
       
   153 
       
   154     testCli(bubbleId,"txt_phone_other_payphone");
       
   155 
       
   156     bubbleManager->startChanges();
       
   157     bubbleManager->setCallFlag( bubbleId, BubbleManager::Diverted, false );
       
   158     bubbleManager->endChanges();
       
   159 
       
   160     // write results
       
   161     QTest::qWait( WAIT_TIME );
       
   162     HbDeviceProfile profile = HbDeviceProfile::profile(mainWindow);
       
   163     QFileInfo info(QCoreApplication::applicationFilePath());
       
   164     HbTextMeasurementUtility* utility = HbTextMeasurementUtility::instance();
       
   165     utility->writeReport(profile, info.baseName());
       
   166     utility->reset();
       
   167 
       
   168     QTest::qWait( WAIT_TIME );
       
   169     bubbleManager->startChanges();
       
   170     bubbleManager->removeCallHeader( bubbleId );
       
   171     bubbleManager->endChanges();
       
   172     QTest::qWait( WAIT_TIME );
       
   173 }
       
   174 
       
   175 void LocTest::changeOrientation()
       
   176 {
       
   177     view->setTitle( "Changing orientation" );
       
   178     mainWindow->resize(640,360);
       
   179     mainWindow->setOrientation(Qt::Horizontal);
       
   180     QTest::qWait(3000);
       
   181 }
       
   182 
       
   183 void LocTest::testLandscapeStrings()
       
   184 {
       
   185     view->setTitle( "Measuring landscape" );
       
   186 
       
   187     // texts fields are measured according to most narrow situation
       
   188 
       
   189     // create test bubble
       
   190     bubbleManager->startChanges();
       
   191     int bubbleId = bubbleManager->createCallHeader();
       
   192     bubbleManager->setState( bubbleId, BubbleManager::Incoming );
       
   193     HbAction action1("End call", this);
       
   194     action1.setSoftKeyRole(QAction::PositiveSoftKey);
       
   195     bubbleManager->addAction( bubbleId, &action1 );
       
   196     bubbleManager->setCallObjectFromTheme(bubbleId);
       
   197     bubbleManager->setCallFlag( bubbleId, BubbleManager::NoCiphering, true );
       
   198     bubbleManager->endChanges();
       
   199 
       
   200     // Single call "only" texts
       
   201 
       
   202     // Second line texts, no indicators -> full width
       
   203     testLabel(bubbleId,"txt_phone_other_incoming_call");
       
   204 
       
   205     testLabel(bubbleId,"txt_phone_other_incoming_video_call");
       
   206 
       
   207     testLabel(bubbleId,"txt_phone_other_incoming_l1_call");
       
   208 
       
   209     bubbleManager->startChanges();
       
   210     bubbleManager->setState( bubbleId, BubbleManager::Outgoing );
       
   211     bubbleManager->endChanges();
       
   212 
       
   213     // First line texts, with ciphering indicator
       
   214     testLabel(bubbleId,"txt_phone_other_attempting");
       
   215 
       
   216     testLabel(bubbleId,"txt_phone_other_calling");
       
   217 
       
   218     bubbleManager->startChanges();
       
   219     bubbleManager->setState( bubbleId, BubbleManager::Active );
       
   220     bubbleManager->endChanges();
       
   221 
       
   222     testCli(bubbleId,"txt_phone_other_emergency_call");
       
   223 
       
   224     // Add another call
       
   225     bubbleManager->startChanges();
       
   226     int bubbleId2 = bubbleManager->createCallHeader();
       
   227     bubbleManager->setState( bubbleId, BubbleManager::OnHold );
       
   228     bubbleManager->setState( bubbleId2, BubbleManager::Active );
       
   229     bubbleManager->setCallObjectFromTheme(bubbleId2);
       
   230     bubbleManager->endChanges();
       
   231 
       
   232     testLabel(bubbleId,"txt_phone_other_on_hold");
       
   233 
       
   234     testLabel(bubbleId,"txt_phone_other_disconnected");
       
   235 
       
   236     testCli(bubbleId,"txt_phone_other_conference_call");
       
   237 
       
   238     testCli(bubbleId,"txt_phone_other_remote_sim");
       
   239 
       
   240     // Add ciphering indicator
       
   241     bubbleManager->startChanges();
       
   242     bubbleManager->setState( bubbleId, BubbleManager::Waiting );
       
   243     bubbleManager->setCallFlag( bubbleId, BubbleManager::Diverted, true );
       
   244     bubbleManager->endChanges();
       
   245 
       
   246     testCli(bubbleId,"txt_phone_other_unknown_number");
       
   247 
       
   248     testCli(bubbleId,"txt_phone_other_private_number");
       
   249 
       
   250     testCli(bubbleId,"txt_phone_other_payphone");
       
   251 
       
   252     testLabel(bubbleId,"txt_phone_other_waiting");
       
   253 
       
   254     // write results
       
   255     QTest::qWait( WAIT_TIME );
       
   256     HbDeviceProfile profile = HbDeviceProfile::profile(mainWindow);
       
   257     QFileInfo info(QCoreApplication::applicationFilePath());
       
   258     HbTextMeasurementUtility* utility = HbTextMeasurementUtility::instance();
       
   259     utility->writeReport(profile, info.baseName());
       
   260     utility->reset();
       
   261 
       
   262     QTest::qWait( WAIT_TIME );
       
   263     bubbleManager->startChanges();
       
   264     bubbleManager->removeCallHeader( bubbleId );
       
   265     bubbleManager->removeCallHeader( bubbleId2 );
       
   266     bubbleManager->endChanges();
       
   267     QTest::qWait( WAIT_TIME );
       
   268 }
       
   269 
       
   270 void LocTest::testLabel(int bubbleId, const char *id)
       
   271 {
       
   272     HbTextMeasurementUtility* utility = HbTextMeasurementUtility::instance();
       
   273     bubbleManager->startChanges();
       
   274     bubbleManager->setLabel( bubbleId, hbTrId(id));
       
   275     bubbleManager->endChanges();
       
   276     utility->measureItems(100);
       
   277     QTest::qWait( WAIT_TIME );
       
   278     bubbleManager->startChanges();
       
   279     bubbleManager->setLabel( bubbleId, "");
       
   280     bubbleManager->endChanges();
       
   281 }
       
   282 
       
   283 void LocTest::testCli(int bubbleId, const char *id)
       
   284 {
       
   285     HbTextMeasurementUtility* utility = HbTextMeasurementUtility::instance();
       
   286     bubbleManager->startChanges();
       
   287     bubbleManager->setCli( bubbleId, hbTrId(id), Qt::ElideRight);
       
   288     bubbleManager->endChanges();
       
   289     utility->measureItems(100);
       
   290     QTest::qWait( WAIT_TIME );
       
   291     bubbleManager->startChanges();
       
   292     bubbleManager->setCli( bubbleId, "", Qt::ElideRight);
       
   293     bubbleManager->endChanges();
       
   294 }
       
   295 
       
   296 BUBBLE_TEST_MAIN(LocTest)
       
   297 #include "loctest.moc"
       
   298