phoneengine/phonecntfinder2/tsrc/u_cphcntmatcherimpl2/u_cphcntmatcherimpl2.cpp
changeset 36 2eacb6118286
parent 30 ebdbd102c78a
child 37 ba76fc04e6c2
equal deleted inserted replaced
30:ebdbd102c78a 36:2eacb6118286
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtGui>
       
    19 #include <QtTest/QtTest>
       
    20 #include <QDebug>
       
    21 #include <qcontactfields.h>
       
    22 #include <qcontact.h>
       
    23 #include "qcontactmanager_moc.h"
       
    24 #include "cphcntmatch2.h"
       
    25 #include "cphcntcontactidimpl2.h"
       
    26 #include "cphcntmatcherimpl2.h"
       
    27 
       
    28 
       
    29 
       
    30 
       
    31 //---- test class
       
    32 
       
    33 class U_CPhCntMatcherImpl2: public QObject
       
    34 {
       
    35 Q_OBJECT
       
    36 
       
    37 public:
       
    38     U_CPhCntMatcherImpl2();
       
    39 	~U_CPhCntMatcherImpl2();
       
    40 
       
    41 private slots:
       
    42 	void initTestCase();
       
    43     void cleanupTestCase();
       
    44     void test_MatchNumberFalse(); //test basic match
       
    45     void test_MatchNumberExact(); //1 exact match
       
    46     void test_MatchNumberSeveralReturned(); //returns 2 matches
       
    47     void test_MatchNumber1(); //test match when contacid is given
       
    48     void test_MatchNumber2(); //test match 3 overload
       
    49     void test_MatchVoipNumber();
       
    50     void test_MatchVoipNumber1(); // test 2nd overload
       
    51     void test_HasCSNumbers();
       
    52 	void test_MatchNumberWithContactId(); //now happy day scenario, cannot test if the contact is valid
       
    53 	
       
    54 private:
       
    55 	
       
    56     CPhCntMatcherImpl2* mMatcher; // implementation under test
       
    57     QContactManager_Moc* mManager;
       
    58 
       
    59 };
       
    60 
       
    61 //--- testing
       
    62 
       
    63 U_CPhCntMatcherImpl2::U_CPhCntMatcherImpl2()
       
    64     {
       
    65     }
       
    66 
       
    67 U_CPhCntMatcherImpl2::~U_CPhCntMatcherImpl2()
       
    68     {
       
    69     }
       
    70 
       
    71 void U_CPhCntMatcherImpl2::initTestCase()
       
    72     {
       
    73     mManager = new QContactManager_Moc();
       
    74     TRAP_IGNORE( mMatcher = CPhCntMatcherImpl2::NewL(mManager) ); //the ownership is transferred
       
    75 	
       
    76     }
       
    77 
       
    78 void U_CPhCntMatcherImpl2::cleanupTestCase()
       
    79     {
       
    80 	delete mMatcher;
       
    81     }
       
    82 
       
    83 void U_CPhCntMatcherImpl2::test_MatchNumberFalse()
       
    84     {
       
    85     MPhCntMatch* match = NULL;
       
    86     TInt err = KErrNotSupported;
       
    87     mManager->setExpectedResult(0); //no match
       
    88     _LIT(KNumber, "123456");
       
    89     TRAP_IGNORE( err = mMatcher->MatchNumber(match, KNumber()) );
       
    90     
       
    91     Q_ASSERT(err == KErrNotFound);
       
    92     Q_ASSERT(!match);
       
    93     }
       
    94 
       
    95 void U_CPhCntMatcherImpl2::test_MatchNumberExact()
       
    96     {
       
    97     MPhCntMatch* match = NULL;
       
    98     TInt err = KErrNotSupported;
       
    99     mManager->setExpectedResult(1); //1 exact match
       
   100     _LIT(KNumber, "123456");
       
   101     TRAP_IGNORE( err = mMatcher->MatchNumber(match, KNumber()));
       
   102      Q_ASSERT(err==KErrNone);
       
   103      Q_ASSERT(match);
       
   104     }
       
   105 void U_CPhCntMatcherImpl2::test_MatchNumberSeveralReturned()
       
   106     {
       
   107     MPhCntMatch* match = NULL;
       
   108     TInt err = KErrNotSupported;
       
   109     mManager->setExpectedResult(2); //2 matches returned
       
   110     _LIT(KNumber, "123456");
       
   111     TRAP_IGNORE( err = mMatcher->MatchNumber(match, KNumber()) );
       
   112      Q_ASSERT(err==KErrNotFound);
       
   113      Q_ASSERT(!match);   
       
   114     }
       
   115 
       
   116 void U_CPhCntMatcherImpl2::test_MatchNumber1()
       
   117     {
       
   118     
       
   119     MPhCntMatch* match = NULL;
       
   120     TInt err = KErrNotFound;
       
   121     _LIT(KNumber, "1234567890");
       
   122     CPhCntContactIdImpl2* cnt = NULL;
       
   123     QContact contact;
       
   124     TRAP_IGNORE( cnt = CPhCntContactIdImpl2::NewL(contact) );
       
   125     TRAP_IGNORE( err = mMatcher->MatchNumber(match, KNumber(), *cnt ) );
       
   126     Q_ASSERT(err == KErrNone);
       
   127     Q_ASSERT(!match);
       
   128     delete cnt;
       
   129     }
       
   130 
       
   131 void U_CPhCntMatcherImpl2::test_MatchNumber2()
       
   132     {
       
   133     MPhCntMatch* match = NULL;
       
   134     TInt err = KErrNotFound;
       
   135     TFieldId field (989);
       
   136     _LIT(KNumber, "1234567890");
       
   137     CPhCntContactIdImpl2* cnt = NULL;
       
   138     QContact contact;
       
   139     TRAP_IGNORE( cnt = CPhCntContactIdImpl2::NewL(contact) );
       
   140     TRAP_IGNORE( err = mMatcher->MatchNumber(match, KNumber(), *cnt, field ) );
       
   141     Q_ASSERT(err == KErrNone);
       
   142     Q_ASSERT(!match);
       
   143     delete cnt;
       
   144     }
       
   145 
       
   146 
       
   147 void U_CPhCntMatcherImpl2::test_MatchVoipNumber()
       
   148     {
       
   149     MPhCntMatch* match = NULL;
       
   150     TInt err = KErrNotSupported;
       
   151     _LIT(KNumber, "sip:user@domain.com");
       
   152     TRAP_IGNORE( err = mMatcher->MatchVoipNumber(match, KNumber(), ETrue) );
       
   153     Q_ASSERT(err == KErrNotFound);
       
   154     Q_ASSERT(!match);
       
   155     }
       
   156 
       
   157 void U_CPhCntMatcherImpl2::test_MatchVoipNumber1()
       
   158     {
       
   159     MPhCntMatch* match = NULL;
       
   160     TInt err = KErrNotSupported;
       
   161     CPhCntContactIdImpl2* cnt = NULL;
       
   162     QContact contact;
       
   163     TRAP_IGNORE( cnt = CPhCntContactIdImpl2::NewL(contact) );  
       
   164     TRAP_IGNORE( err = mMatcher->MatchVoipNumber(match, *cnt) );
       
   165     Q_ASSERT(err == KErrNotFound);
       
   166     Q_ASSERT(!match);
       
   167     delete cnt;
       
   168     }
       
   169 
       
   170 void U_CPhCntMatcherImpl2::test_HasCSNumbers()
       
   171     {
       
   172     CPhCntContactIdImpl2* cnt = NULL;
       
   173     QContact contact;
       
   174     TRAP_IGNORE(cnt = CPhCntContactIdImpl2::NewL(contact) );
       
   175     TBool has = ETrue;
       
   176     TRAP_IGNORE( has = mMatcher->HasCSNumbers(*cnt) );
       
   177     Q_ASSERT(has==EFalse);
       
   178     delete cnt;
       
   179     }
       
   180 	
       
   181 void U_CPhCntMatcherImpl2::test_MatchNumberWithContactId()
       
   182 	{
       
   183 	 MPhCntMatch* match = NULL;
       
   184     _LIT(KNumber, "123456");
       
   185 	 TInt id = 765;
       
   186 	 TInt err = KErrNotFound;
       
   187 	 TRAP_IGNORE( err = mMatcher->MatchNumber(match, KNumber(), id) );
       
   188      Q_ASSERT(match);
       
   189 	 Q_ASSERT(match->Number() == KNumber());
       
   190 	 Q_ASSERT(err == KErrNone);
       
   191 
       
   192 	}
       
   193 
       
   194 QTEST_MAIN(U_CPhCntMatcherImpl2)
       
   195 #include "u_cphcntmatcherimpl2.moc"