First public contribution.
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 
     2 // All rights reserved.
 
     3 // This component and the accompanying materials are made available
 
     4 // under the terms of "Eclipse Public License v1.0"
 
     5 // which accompanies this distribution, and is available
 
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
 
     8 // Initial Contributors:
 
     9 // Nokia Corporation - initial contribution.
 
    14 // The ECom impletementation of testing contact matching.
 
    17 #include "t_logcntmatchplugin.h"
 
    19 #include <ecom/implementationproxy.h>
 
    21 /** Creates a CLogTestCntMatch object
 
    23 CLogTestCntMatch* CLogTestCntMatch::NewL()
 
    25     RDebug::Print(_L("CLogTestCntMatch::NewL()"));
 
    26     CLogTestCntMatch* self = new (ELeave) CLogTestCntMatch;
 
    27     CleanupStack::PushL(self);
 
    29     CleanupStack::Pop(self);
 
    33 void CLogTestCntMatch::ConstructL()
 
    35     iTelNumbers = new(ELeave) CDesCArrayFlat(KNumberOfItems);
 
    36     iContactFirstNames = new(ELeave) CDesCArrayFlat(KNumberOfItems);
 
    37     iContactLastNames = new(ELeave) CDesCArrayFlat(KNumberOfItems);
 
    40 CLogTestCntMatch::CLogTestCntMatch()
 
    44 CLogTestCntMatch::~CLogTestCntMatch()
 
    47     delete iContactFirstNames;
 
    48     delete iContactLastNames;
 
    51 /** Interface of ECOM. In real phone, it should opens the contacts DB
 
    53 void CLogTestCntMatch::OpenContactsL()
 
    55     RDebug::Print(_L("Test Mock Contact Matching: OpenContactsL "));
 
    58     iContactFirstNames->Reset();
 
    59     iContactLastNames->Reset();
 
    61     iTelNumbers->AppendL(KNumber1);
 
    62     iContactFirstNames->AppendL(KFirstName1);
 
    63     iContactLastNames->AppendL(KLastName1); 
 
    65     iTelNumbers->AppendL(KNumber2);
 
    66     iContactFirstNames->AppendL(KFirstName2);
 
    67     iContactLastNames->AppendL(KLastName2);       
 
    69     iTelNumbers->AppendL(KNumber3);
 
    70     iContactFirstNames->AppendL(KFirstName3);
 
    71     iContactLastNames->AppendL(KLastName3);       
 
    73     iTelNumbers->AppendL(KNumber4);
 
    74     iContactFirstNames->AppendL(KFirstName4);
 
    75     iContactLastNames->AppendL(KLastName4);       
 
    77     iTelNumbers->AppendL(KNumber5);
 
    78     iContactFirstNames->AppendL(KFirstName5);
 
    79     iContactLastNames->AppendL(KLastName5);       
 
    81     iTelNumbers->AppendL(KNumber6);
 
    82     iContactFirstNames->AppendL(KFirstName6);
 
    83     iContactLastNames->AppendL(KLastName6);       
 
    85     iTelNumbers->AppendL(KNumber7);
 
    86     iContactFirstNames->AppendL(KFirstName7);
 
    87     iContactLastNames->AppendL(KLastName7);       
 
    90 /** Interface of ECOM. In real phone, it should closes the contacts DB
 
    92 void CLogTestCntMatch::CloseContacts()
 
    94     RDebug::Print(_L("OpenContactsL is called"));
 
    95     iContactFirstNames->Reset();
 
    96     iContactLastNames->Reset();
 
   100 /** Attempts to find a contact item ID for the contact items which contains
 
   101     the specified telephone number in a telephone, fax or SMS type field for tests.
 
   102     If more than one contact item contains the telephone number this should be 
 
   103     treated the same as no contact found.
 
   104     @param aNumber Phone number string
 
   105     @param aMatchLengthFromRight Number of digits from the right of the phone number to use. 
 
   106     @return The contact Id found that contains the phone number. KLogNullContactId if none or more than one is found.
 
   108 TLogContactItemId CLogTestCntMatch::MatchPhoneNumberL(const TDesC& aNumber, TInt aMatchLengthFromRight)
 
   110     RDebug::Print(_L("CLogTestCntMatch::MatchPhoneNumberL()"));
 
   111     __ASSERT_ALWAYS(iTelNumbers->Length() == KNumberOfItems && 
 
   112                 iContactFirstNames->Length()==KNumberOfItems &&
 
   113                 iContactLastNames->Length()==KNumberOfItems, _L("CLogTestCntMatch::MatchPhoneNumberL"));   
 
   115     TLogContactItemId contactId = KLogNullContactId;
 
   117     const TInt KMinLength = 7;
 
   119     if(aNumber.Length() >= KMinLength)
 
   121         for (TInt ii = 0; ii < KNumberOfItems && numHit < 2; ++ii)
 
   123              TPtrC number((*iTelNumbers)[ii]);
 
   124              TInt numDigToMatch = aNumber.Length()<aMatchLengthFromRight?aNumber.Length():aMatchLengthFromRight;
 
   125              if(number.Length() < numDigToMatch)
 
   126                  {//This is not matched
 
   129              if(number.Right(numDigToMatch).CompareF(aNumber.Right(numDigToMatch)) == 0)
 
   136         // Only set contactId if we have exactly one match
 
   139             contactId = static_cast<TLogContactItemId>(pos)+1;
 
   146 /** Gets the text data for the family and given name fields of a given contact Id for tests.
 
   148     @param aContactId Contact Id to find data for
 
   149     @param aName On return contains the family and given name in the desired format if found, leave with KErrNotFound otherwise.
 
   150     @param aNameFormat Desired format of returned string - Chinese or Western format
 
   152 void CLogTestCntMatch::ReadContactNameL(TLogContactItemId aContactId, TDes &aName, TLogContactNameFormat aNameFormat)
 
   154     RDebug::Print(_L("CLogTestCntMatch::ReadContactNameL()"));
 
   155     __ASSERT_ALWAYS(iTelNumbers->Length() == KNumberOfItems && 
 
   156                  iContactFirstNames->Length()==KNumberOfItems &&
 
   157                  iContactLastNames->Length()==KNumberOfItems, _L("CLogTestCntMatch::ReadContactNameL"));
 
   159     if(aContactId < 1 && aContactId > KNumberOfItems)
 
   161         User::Leave(KErrNotFound);
 
   163      if(aNameFormat == ELogWesternFormat)
 
   165         aName.Append((*iContactFirstNames)[aContactId-1]);
 
   167         aName.Append((*iContactLastNames)[aContactId-1]);
 
   169     else //ELogChineseFormat
 
   171         aName.Append((*iContactLastNames)[aContactId-1]); 
 
   172         aName.Append((*iContactFirstNames)[aContactId-1]);
 
   177 const TImplementationProxy ImplementationTable[] = 
 
   179 	IMPLEMENTATION_PROXY_ENTRY(0x2000862a, CLogTestCntMatch::NewL)
 
   182 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
 
   184     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
 
   185     return ImplementationTable;