locationdataharvester/maptileservice/tsrc/ut_maptileservice/ut_maptileservice.cpp
branchGCC_SURGE
changeset 32 9bd2e0ffe298
parent 25 a4fe51dd4d22
parent 31 8db05346071b
equal deleted inserted replaced
25:a4fe51dd4d22 32:9bd2e0ffe298
     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: maptile service unit test cases
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtTest/QtTest>
       
    19 #include <QtGui>
       
    20 #include <QString>
       
    21 #include <qtcontacts.h>
       
    22 #include <qcontactmanager.h>
       
    23 
       
    24 
       
    25 #include "maptileservice.h"
       
    26 
       
    27 
       
    28 //Maximum maptile processing time
       
    29 const int KMapTileFetchTime  = 150000;
       
    30 
       
    31 QTM_USE_NAMESPACE
       
    32 
       
    33 
       
    34 //Maptile test interface class
       
    35 class MaptileServiceTest: public QObject
       
    36 {
       
    37     Q_OBJECT
       
    38     
       
    39 private slots:
       
    40     
       
    41     void checkLocationFeature();
       
    42     void getPreferredAddressMapTilePath();
       
    43     void getWorkAddressMapTilePath();
       
    44     void getHomeAddressMapTilePath();
       
    45     void checkInvalidContactId();
       
    46  
       
    47 };
       
    48 
       
    49 
       
    50 //Checks whether location feature enabled or disabled
       
    51 void MaptileServiceTest::checkLocationFeature()
       
    52 {
       
    53    
       
    54     QVERIFY( CntMapTileService::isLocationFeatureEnabled() == 1 );
       
    55 }
       
    56 
       
    57 //Checks the maptile path retrieval for preferred address
       
    58 void MaptileServiceTest::getPreferredAddressMapTilePath()
       
    59 {
       
    60     
       
    61     QContact* contact = new QContact();
       
    62     
       
    63     //Add contact name   
       
    64     QContactName* name = new QContactName();
       
    65     name->setFirst("Raj");
       
    66     contact->saveDetail( name );
       
    67     
       
    68     //Add address
       
    69     QContactAddress* address = new QContactAddress();
       
    70     address->setPostOfficeBox("87640");
       
    71     address->setStreet("Torstrasse");
       
    72     address->setPostcode("12345");
       
    73     address->setLocality("Berlin");
       
    74     address->setCountry("Germany");
       
    75     contact->saveDetail(address);
       
    76     
       
    77     //Save the contact
       
    78     QContactManager* contactManager = NULL;
       
    79     contactManager = new QContactManager("symbian");
       
    80     contactManager->saveContact( contact );
       
    81     
       
    82     //Wait till maptile operation complete
       
    83     QTest::qWait( KMapTileFetchTime );
       
    84     
       
    85    
       
    86     //Get the saved id
       
    87     QContactId savedId = contact->id();
       
    88     TUint32 contactId = savedId.localId();
       
    89     
       
    90     //Get the maptile 
       
    91     QString string = CntMapTileService::getMapTileImage( contactId, CntMapTileService::AddressPreference );
       
    92     
       
    93     //Construct the QPimap from reference bitmap
       
    94     QImage referenceBitmap( "c:\\maptiletest\\preferredaddressmap.png" );
       
    95     
       
    96     //Construct the QPixmap from new retrieved bitmap
       
    97     QImage retrievedBitmap( string );
       
    98     
       
    99       
       
   100     //delete the contact
       
   101     contactManager->removeContact( contactId );
       
   102     
       
   103     delete contact;
       
   104     delete name;
       
   105     delete address;
       
   106     delete contactManager;
       
   107     
       
   108 }
       
   109 
       
   110 //Checks the maptile path retrieval for work address
       
   111 void MaptileServiceTest::getWorkAddressMapTilePath()
       
   112 {
       
   113     
       
   114     QContact* contact = new QContact();
       
   115     
       
   116     //Set name
       
   117     QContactName* name = new QContactName();
       
   118     name->setFirst("Mike");
       
   119     contact->saveDetail(name);
       
   120     
       
   121     //Set address
       
   122     QContactAddress* address = new QContactAddress();
       
   123     address->setPostOfficeBox("2345");
       
   124     address->setPostcode("29834");
       
   125     address->setStreet("Domlur");
       
   126     address->setLocality("Bangalore");
       
   127     address->setCountry("India");
       
   128     address->setContexts(QContactDetail::ContextWork);
       
   129     contact->saveDetail(address);
       
   130     
       
   131     //Save the contact
       
   132     QContactManager* contactManager = NULL;
       
   133     contactManager = new QContactManager("symbian");
       
   134     contactManager->saveContact( contact );
       
   135       
       
   136     //Wait till maptile operation complete
       
   137     QTest::qWait( KMapTileFetchTime );
       
   138     
       
   139      
       
   140     //Get the saved id
       
   141     QContactId savedId = contact->id();
       
   142     TUint32 contactId = savedId.localId();
       
   143     
       
   144     //Get the maptile 
       
   145     QString string = CntMapTileService::getMapTileImage( contactId, CntMapTileService::AddressWork );
       
   146     
       
   147     //Construct the QPimap from already stored bitmap
       
   148     QImage referenceBitmap( "c:\\maptiletest\\workaddressmap.png" );
       
   149     
       
   150     //Construct the QPixmap from new retrieved bitmap
       
   151     QImage retrievedBitmap( string );
       
   152     
       
   153     //check results are same
       
   154     QVERIFY( retrievedBitmap == referenceBitmap );
       
   155     
       
   156         
       
   157     contactManager->removeContact( contactId );
       
   158     
       
   159     delete contact;
       
   160     delete name;
       
   161     delete address;
       
   162     delete contactManager;
       
   163     
       
   164 }
       
   165 
       
   166 //Checks the maptile path retrieval for home address
       
   167 void MaptileServiceTest::getHomeAddressMapTilePath()
       
   168 {
       
   169     
       
   170     QContact* contact = new QContact();
       
   171         
       
   172     QContactName* name = new QContactName();
       
   173     name->setFirst("first");
       
   174     contact->saveDetail(name);
       
   175     
       
   176     QContactAddress* address = new QContactAddress();
       
   177     address->setContexts(QContactDetail::ContextHome);
       
   178     address->setPostOfficeBox("81282");
       
   179     address->setStreet("Keilalahdentie");
       
   180     address->setPostcode("67890");
       
   181     address->setLocality("Espoo");
       
   182     address->setCountry("Finland");
       
   183     contact->saveDetail(address);
       
   184     
       
   185     //Save the contact
       
   186     QContactManager* contactManager = NULL;
       
   187     contactManager = new QContactManager("symbian");
       
   188     contactManager->saveContact( contact );
       
   189     
       
   190     //Wait till maptile operation complete
       
   191     QTest::qWait( KMapTileFetchTime );
       
   192     
       
   193     //Get the saved id
       
   194     QContactId savedId = contact->id();
       
   195     TUint32 contactId = savedId.localId();
       
   196     
       
   197     //Get the maptile 
       
   198     QString string = CntMapTileService::getMapTileImage( contactId, CntMapTileService::AddressHome );
       
   199     
       
   200     //Construct the QPimap from already stored bitmap
       
   201     QImage referenceBitmap( "c:\\maptiletest\\homeaddressmap.png" );
       
   202     
       
   203     //Construct the QPixmap from new retrieved bitmap
       
   204     QImage retrievedBitmap( string );
       
   205     
       
   206     //comapre the bitmaps
       
   207     QVERIFY( retrievedBitmap == referenceBitmap );
       
   208     
       
   209       
       
   210     contactManager->removeContact( contactId );
       
   211     
       
   212     delete contact;
       
   213     delete name;
       
   214     delete address;
       
   215     delete contactManager;
       
   216     
       
   217 }
       
   218 
       
   219 //Checks the maptile path retrieval returns NULL for invalid address
       
   220 void  MaptileServiceTest::checkInvalidContactId()
       
   221 {
       
   222     
       
   223     QContact* contact = new QContact();
       
   224    
       
   225     QContactName* name = new QContactName();
       
   226     name->setFirst("first");
       
   227     contact->saveDetail(name);
       
   228     
       
   229     //Add some invalid address
       
   230     QContactAddress* address = new QContactAddress();
       
   231     address->setPostOfficeBox("11111");
       
   232     address->setStreet("htrtfdsk");
       
   233     address->setPostcode("98989");
       
   234     address->setLocality("ghwdxnkwnn");
       
   235     address->setCountry("Fbsjwskws");
       
   236     contact->saveDetail(address);
       
   237     
       
   238     //Save the contact
       
   239     QContactManager* contactManager = NULL;
       
   240     contactManager = new QContactManager("symbian");
       
   241     contactManager->saveContact( contact );
       
   242     
       
   243     //Wait till maptile operation complete
       
   244     QTest::qWait( KMapTileFetchTime );
       
   245     
       
   246      
       
   247     //Get the saved id
       
   248     QContactId savedId = contact->id();
       
   249     TUint32 contactId = savedId.localId();
       
   250     
       
   251     //Get the maptile 
       
   252     QString string = CntMapTileService::getMapTileImage( contactId, CntMapTileService::AddressPreference );
       
   253     
       
   254     contactManager->removeContact( contactId );
       
   255     
       
   256     //Maptile path should be NULL for invalid address
       
   257     QVERIFY( string.isNull() );
       
   258     
       
   259     delete contact;
       
   260     delete name;
       
   261     delete address;
       
   262     delete contactManager;
       
   263     
       
   264   
       
   265 }
       
   266 
       
   267 
       
   268 QTEST_MAIN(MaptileServiceTest)
       
   269 #include "ut_maptileservice.moc"
       
   270 
       
   271