loggingservices/eventlogger/test/src/t_logcntmatchplugin.cpp
branchRCL_3
changeset 14 04ec7606545c
equal deleted inserted replaced
12:6b6fd149daa2 14:04ec7606545c
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // The ECom impletementation of testing contact matching.
       
    15 //
       
    16 
       
    17 #include "t_logcntmatchplugin.h"
       
    18 #include <e32def.h>
       
    19 #include <ecom/implementationproxy.h>
       
    20    
       
    21 /** Creates a CLogTestCntMatch object
       
    22 */
       
    23 CLogTestCntMatch* CLogTestCntMatch::NewL()
       
    24     {
       
    25     RDebug::Print(_L("CLogTestCntMatch::NewL()"));
       
    26     CLogTestCntMatch* self = new (ELeave) CLogTestCntMatch;
       
    27     CleanupStack::PushL(self);
       
    28     self->ConstructL();
       
    29     CleanupStack::Pop(self);
       
    30     return self;
       
    31     }
       
    32 
       
    33 void CLogTestCntMatch::ConstructL()
       
    34     {
       
    35     iTelNumbers = new(ELeave) CDesCArrayFlat(KNumberOfItems);
       
    36     iContactFirstNames = new(ELeave) CDesCArrayFlat(KNumberOfItems);
       
    37     iContactLastNames = new(ELeave) CDesCArrayFlat(KNumberOfItems);
       
    38     }
       
    39 
       
    40 CLogTestCntMatch::CLogTestCntMatch()
       
    41     {
       
    42     }
       
    43 
       
    44 CLogTestCntMatch::~CLogTestCntMatch()
       
    45     {
       
    46     delete iTelNumbers;
       
    47     delete iContactFirstNames;
       
    48     delete iContactLastNames;
       
    49     }
       
    50 
       
    51 /** Interface of ECOM. In real phone, it should opens the contacts DB
       
    52 */
       
    53 void CLogTestCntMatch::OpenContactsL()
       
    54     {
       
    55     RDebug::Print(_L("Test Mock Contact Matching: OpenContactsL "));
       
    56     
       
    57     iTelNumbers->Reset();
       
    58     iContactFirstNames->Reset();
       
    59     iContactLastNames->Reset();
       
    60     
       
    61     iTelNumbers->AppendL(KNumber1);
       
    62     iContactFirstNames->AppendL(KFirstName1);
       
    63     iContactLastNames->AppendL(KLastName1); 
       
    64     
       
    65     iTelNumbers->AppendL(KNumber2);
       
    66     iContactFirstNames->AppendL(KFirstName2);
       
    67     iContactLastNames->AppendL(KLastName2);       
       
    68     
       
    69     iTelNumbers->AppendL(KNumber3);
       
    70     iContactFirstNames->AppendL(KFirstName3);
       
    71     iContactLastNames->AppendL(KLastName3);       
       
    72     
       
    73     iTelNumbers->AppendL(KNumber4);
       
    74     iContactFirstNames->AppendL(KFirstName4);
       
    75     iContactLastNames->AppendL(KLastName4);       
       
    76     
       
    77     iTelNumbers->AppendL(KNumber5);
       
    78     iContactFirstNames->AppendL(KFirstName5);
       
    79     iContactLastNames->AppendL(KLastName5);       
       
    80     
       
    81     iTelNumbers->AppendL(KNumber6);
       
    82     iContactFirstNames->AppendL(KFirstName6);
       
    83     iContactLastNames->AppendL(KLastName6);       
       
    84     
       
    85     iTelNumbers->AppendL(KNumber7);
       
    86     iContactFirstNames->AppendL(KFirstName7);
       
    87     iContactLastNames->AppendL(KLastName7);       
       
    88     }
       
    89  
       
    90 /** Interface of ECOM. In real phone, it should closes the contacts DB
       
    91 */
       
    92 void CLogTestCntMatch::CloseContacts()
       
    93     {
       
    94     RDebug::Print(_L("OpenContactsL is called"));
       
    95     iContactFirstNames->Reset();
       
    96     iContactLastNames->Reset();
       
    97     iTelNumbers->Reset();
       
    98     }
       
    99     
       
   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.
       
   107 */
       
   108 TLogContactItemId CLogTestCntMatch::MatchPhoneNumberL(const TDesC& aNumber, TInt aMatchLengthFromRight)
       
   109     {
       
   110     RDebug::Print(_L("CLogTestCntMatch::MatchPhoneNumberL()"));
       
   111     __ASSERT_ALWAYS(iTelNumbers->Length() == KNumberOfItems && 
       
   112                 iContactFirstNames->Length()==KNumberOfItems &&
       
   113                 iContactLastNames->Length()==KNumberOfItems, _L("CLogTestCntMatch::MatchPhoneNumberL"));   
       
   114     
       
   115     TLogContactItemId contactId = KLogNullContactId;
       
   116     TInt numHit = 0;
       
   117     const TInt KMinLength = 7;
       
   118     TInt pos = -1;
       
   119     if(aNumber.Length() >= KMinLength)
       
   120         {
       
   121         for (TInt ii = 0; ii < KNumberOfItems && numHit < 2; ++ii)
       
   122              {
       
   123              TPtrC number((*iTelNumbers)[ii]);
       
   124              TInt numDigToMatch = aNumber.Length()<aMatchLengthFromRight?aNumber.Length():aMatchLengthFromRight;
       
   125              if(number.Length() < numDigToMatch)
       
   126                  {//This is not matched
       
   127                  continue;
       
   128                  }
       
   129              if(number.Right(numDigToMatch).CompareF(aNumber.Right(numDigToMatch)) == 0)
       
   130                   {
       
   131                   pos = ii;
       
   132                   ++numHit;
       
   133                   }
       
   134              }
       
   135       
       
   136         // Only set contactId if we have exactly one match
       
   137         if (numHit == 1)
       
   138             {
       
   139             contactId = static_cast<TLogContactItemId>(pos)+1;
       
   140             }
       
   141       }
       
   142     
       
   143     return contactId;
       
   144     }
       
   145 
       
   146 /** Gets the text data for the family and given name fields of a given contact Id for tests.
       
   147     
       
   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
       
   151 */
       
   152 void CLogTestCntMatch::ReadContactNameL(TLogContactItemId aContactId, TDes &aName, TLogContactNameFormat aNameFormat)
       
   153     {
       
   154     RDebug::Print(_L("CLogTestCntMatch::ReadContactNameL()"));
       
   155     __ASSERT_ALWAYS(iTelNumbers->Length() == KNumberOfItems && 
       
   156                  iContactFirstNames->Length()==KNumberOfItems &&
       
   157                  iContactLastNames->Length()==KNumberOfItems, _L("CLogTestCntMatch::ReadContactNameL"));
       
   158     
       
   159     if(aContactId < 1 && aContactId > KNumberOfItems)
       
   160         {
       
   161         User::Leave(KErrNotFound);
       
   162         }
       
   163      if(aNameFormat == ELogWesternFormat)
       
   164         {
       
   165         aName.Append((*iContactFirstNames)[aContactId-1]);
       
   166         aName.Append(' ');
       
   167         aName.Append((*iContactLastNames)[aContactId-1]);
       
   168         }
       
   169     else //ELogChineseFormat
       
   170         {
       
   171         aName.Append((*iContactLastNames)[aContactId-1]); 
       
   172         aName.Append((*iContactFirstNames)[aContactId-1]);
       
   173         aName.Append(' ');
       
   174        }
       
   175     }
       
   176 		
       
   177 const TImplementationProxy ImplementationTable[] = 
       
   178 	{
       
   179 	IMPLEMENTATION_PROXY_ENTRY(0x2000862a, CLogTestCntMatch::NewL)
       
   180 	};
       
   181 
       
   182 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   183     {
       
   184     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   185     return ImplementationTable;
       
   186     }
       
   187