emailservices/nmutilities/tsrc/unittests/unittest_nmcontacthistorymodel/unittest_nmcontacthistorymodel.cpp
changeset 74 6c59112cfd31
equal deleted inserted replaced
69:4e54af54a4a1 74:6c59112cfd31
       
     1 /*
       
     2  * Copyright (c) 2007-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:  unittests fro emailmru
       
    15  *
       
    16  */
       
    17 
       
    18 #include "nmcontacthistorymodel.h"
       
    19 #include "nmcontacthistorymodel_p.h"
       
    20 #include "unittest_nmcontacthistorymodel.h"
       
    21 
       
    22 bool constructorCalled;
       
    23 bool destructorCalled;
       
    24 bool rowcountCalled;
       
    25 bool dataCalled;
       
    26 bool modelcompletedCalled;
       
    27 bool queryCalled;
       
    28 bool refreshdatamodelCalled;
       
    29 bool handlequerycompletedCalled;
       
    30 
       
    31 /*!
       
    32      Constructor
       
    33  */
       
    34 TestNmContactHistoryModel::TestNmContactHistoryModel()
       
    35 {
       
    36 
       
    37 }
       
    38 
       
    39 /*!
       
    40      Destructor
       
    41  */
       
    42 TestNmContactHistoryModel::~TestNmContactHistoryModel()
       
    43 {
       
    44 
       
    45 }
       
    46 
       
    47 /*!
       
    48      Called before testcase
       
    49  */
       
    50 void TestNmContactHistoryModel::initTestCase()
       
    51 {
       
    52 }
       
    53 
       
    54 /*!
       
    55      Called after testcase
       
    56  */
       
    57 void TestNmContactHistoryModel::cleanupTestCase()
       
    58 {
       
    59 }
       
    60 
       
    61 /*!
       
    62      Called before every function
       
    63  */
       
    64 void TestNmContactHistoryModel::init()
       
    65 {
       
    66     constructorCalled = false;
       
    67     destructorCalled = false;
       
    68     rowcountCalled = false;
       
    69     dataCalled = false;
       
    70     modelcompletedCalled = false;
       
    71     queryCalled = false;
       
    72     refreshdatamodelCalled = false;
       
    73     handlequerycompletedCalled = false;
       
    74 
       
    75     mModel= new NmContactHistoryModel(EmailAddressModel);
       
    76     mSlotCalled = false;
       
    77 }
       
    78 
       
    79 /*!
       
    80      Called after everyfunction
       
    81  */
       
    82 void TestNmContactHistoryModel::cleanup()
       
    83 {
       
    84     delete mModel;
       
    85     mModel = NULL;
       
    86 }
       
    87 
       
    88 void TestNmContactHistoryModel::testConstructor()
       
    89 {
       
    90     QVERIFY(constructorCalled);
       
    91     QVERIFY(mModel->d_ptr != NULL);
       
    92 
       
    93     NmContactHistoryModelType modelType = mModel->d_ptr->mType;
       
    94     QVERIFY(modelType == EmailAddressModel);
       
    95 }
       
    96 
       
    97 void TestNmContactHistoryModel::testDestructor()
       
    98 {
       
    99     delete mModel;
       
   100     mModel = NULL;
       
   101     QVERIFY(destructorCalled);
       
   102 }
       
   103 
       
   104 void TestNmContactHistoryModel::testRowCount()
       
   105 {
       
   106     int rowCount = mModel->rowCount(QModelIndex());
       
   107     QVERIFY(rowCount == 0);
       
   108     QVERIFY(rowcountCalled);
       
   109 }
       
   110 
       
   111 void TestNmContactHistoryModel::testData()
       
   112 {
       
   113     mModel->data(QModelIndex(),0);
       
   114     QVERIFY(dataCalled);
       
   115 }
       
   116 
       
   117 void TestNmContactHistoryModel::testQuery()
       
   118 {
       
   119     mModel->query("TEST");
       
   120     QVERIFY(queryCalled);
       
   121 }
       
   122 
       
   123 void TestNmContactHistoryModel::test_modelCompleted(int err)
       
   124 {
       
   125     Q_UNUSED(err);
       
   126     mSlotCalled = true;
       
   127 }
       
   128 
       
   129 void TestNmContactHistoryModel::testHandleQueryCompleted()
       
   130 {
       
   131     mSlotCalled = false;
       
   132     QObject::connect(mModel, SIGNAL(modelCompleted(int)), this, SLOT(test_modelCompleted(int)));
       
   133     mModel->d_ptr->mPrivateItemList.append("TEST");
       
   134     mModel->handleQueryCompleted(0);
       
   135     QVERIFY(rowcountCalled);
       
   136     QVERIFY(refreshdatamodelCalled);
       
   137     QVERIFY(mSlotCalled);
       
   138     
       
   139     rowcountCalled = false;
       
   140     refreshdatamodelCalled = false;
       
   141     mSlotCalled = false;
       
   142     
       
   143     mModel->d_ptr->mPrivateItemList.clear();
       
   144     mModel->handleQueryCompleted(0);    
       
   145 
       
   146     QVERIFY(rowcountCalled);
       
   147     QVERIFY(refreshdatamodelCalled == FALSE);
       
   148     QVERIFY(mSlotCalled);
       
   149 }
       
   150 
       
   151 QTEST_MAIN( TestNmContactHistoryModel );
       
   152