phonebookengines/contactsmodel/tsrc/T_CntMatch.cpp
changeset 24 0ba2181d7c28
parent 0 e686773b3f54
child 40 b46a585f6909
equal deleted inserted replaced
0:e686773b3f54 24:0ba2181d7c28
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 /*
     2 // All rights reserved.
     2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 // This component and the accompanying materials are made available
     3 * All rights reserved.
     4 // under the terms of "Eclipse Public License v1.0"
     4 * This component and the accompanying materials are made available
     5 // which accompanies this distribution, and is available
     5 * under the terms of "Eclipse Public License v1.0"
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 * which accompanies this distribution, and is available
     7 //
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 // Initial Contributors:
     8 *
     9 // Nokia Corporation - initial contribution.
     9 * Initial Contributors:
    10 //
    10 * Nokia Corporation - initial contribution.
    11 // Contributors:
    11 *
    12 //
    12 * Contributors:
    13 // Description:
    13 *
    14 //
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
    15 
    18 
    16 
    19 
    17 
    20 
    18 #include <e32test.h>
    21 #include <e32test.h>
    19 #include <f32file.h>
    22 #include <f32file.h>
    20 #include "T_UTILS.H"
    23 #include "t_utils.h"
    21 
    24 
    22 _LIT(KTestName,"T_CntMatch");
    25 _LIT(KTestName,"T_CntMatch");
    23 #include "testhelpers.h"
    26 #include "testhelpers.h"
    24 
    27 
    25 RFs fs;
    28 RFs fs;
   169 
   172 
   170 LOCAL_C void DontUnderestimateTheMeaningOfZeroL()
   173 LOCAL_C void DontUnderestimateTheMeaningOfZeroL()
   171 	{
   174 	{
   172 	ResetDatabaseL();
   175 	ResetDatabaseL();
   173 
   176 
   174 	//Database contains only this number 207 946 0321;
   177 	//Database contains only this number 228 876 5324;
   175 	CreateContactL(KCntName,KCntSurname,_L("207 946 0321"),KNullDesC);
   178 	CreateContactL(KCntName,KCntSurname,_L("228 876 5324"),KNullDesC);
   176 	//Trying to search on that exact number by 6 digits...
   179 	//Trying to search on that exact number by 6 digits...
   177 		TESTVALUE(CheckPhoneMatchL(		_L("207 946 0321"), 6),0);
   180 		TESTVALUE(CheckPhoneMatchL(		_L("228 876 5324"), 6),0);
   178 	//No matches, well I kind of expected it... :-(
   181 	//No matches, well I kind of expected it... :-(
   179 
   182 
   180 	//Now we add a number that differs from the first one by one digit..
   183 	//Now we add a number that differs from the first one by one digit..
   181 	CreateContactL(KCntName,KCntSurname,_L("207 046 0321"),KNullDesC);
   184 	CreateContactL(KCntName,KCntSurname,_L("228 076 5324"),KNullDesC);
   182 
   185 
   183 	//Repeat our search
   186 	//Repeat our search
   184 		TESTVALUE(CheckPhoneMatchL(		_L("207 946 0321"), 6),1);
   187 		TESTVALUE(CheckPhoneMatchL(		_L("228 876 5324"), 6),1);
   185 	//It matches!!... Please don't laugh! There is logic in it!
   188 	//It matches!!... Please don't laugh! There is logic in it!
   186 	//If the number doesn't match to itself - then it should match on different one! ;-)
   189 	//If the number doesn't match to itself - then it should match on different one! ;-)
   187 	}
   190 	}
   188 
   191 
   189 
   192 
   190 LOCAL_C void Test2L()
   193 LOCAL_C void Test2L()
   191 	{
   194 	{
   192 	ResetDatabaseL();
   195 	ResetDatabaseL();
   193 
   196 
   194 	//if 5324 doesn't match to  228 100 5324...
   197 	//if 5324 doesn't match to  228 100 5324...
   195 	CreateContactL(KCntName,KCntSurname,_L("207 100 0324"),KNullDesC);
   198 	CreateContactL(KCntName,KCntSurname,_L("228 100 5324"),KNullDesC);
   196 	TESTVALUE(CheckPhoneMatchL(					_L("0324"),11),0);
   199 	TESTVALUE(CheckPhoneMatchL(					_L("5324"),11),0);
   197 	TESTVALUE(CheckPhoneMatchL(					_L("0324"), 4),0);
   200 	TESTVALUE(CheckPhoneMatchL(					_L("5324"), 4),0);
   198 
   201 
   199 	//it shouldn't match to 228 000 5324 as well, but... it does
   202 	//it shouldn't match to 228 000 5324 as well, but... it does
   200 	CreateContactL(KCntName,KCntSurname,_L("207 000 0324"),KNullDesC);
   203 	CreateContactL(KCntName,KCntSurname,_L("228 000 5324"),KNullDesC);
   201 	TESTVALUE(CheckPhoneMatchL(					_L("0324"),11),1);	// AB
   204 	TESTVALUE(CheckPhoneMatchL(					_L("5324"),11),1);	// AB
   202 	TESTVALUE(CheckPhoneMatchL(					_L("0324"), 4),1);
   205 	TESTVALUE(CheckPhoneMatchL(					_L("5324"), 4),1);
   203 	}
   206 	}
   204 
   207 
   205 
   208 
   206 LOCAL_C void TestCallingAmericaL()
   209 LOCAL_C void TestCallingAmericaL()
   207 	{
   210 	{
   208 	ResetDatabaseL();
   211 	ResetDatabaseL();
   209 
   212 
   210 	//here are some additional test numbers for testing the acceptance of the '(+' combination
   213 	//here are some additional test numbers for testing the acceptance of the '(+' combination
   211 	CreateContactL(KCntName,KCntSurname,_L("(+020) 79460123"),KNullDesC);
   214 	CreateContactL(KCntName,KCntSurname,_L("(+358) 1234567"),KNullDesC);
   212 	CreateContactL(KCntName,KCntSurname,_L("(020) 79460123"),KNullDesC);
   215 	CreateContactL(KCntName,KCntSurname,_L("(358) 1234567"),KNullDesC);
   213 	CreateContactL(KCntName,KCntSurname,_L("+020 79460123"),KNullDesC);
   216 	CreateContactL(KCntName,KCntSurname,_L("+358 1234567"),KNullDesC);
   214 
   217 
   215 	//when searching for any of the above numbers 3 instances should be found
   218 	//when searching for any of the above numbers 3 instances should be found
   216 	TESTVALUE(CheckPhoneMatchL(_L("(+020) 79460123"),10),3);
   219 	TESTVALUE(CheckPhoneMatchL(_L("(+358) 1234567"),10),3);
   217 	TESTVALUE(CheckPhoneMatchL(_L("(020) 79460123"),10),3);
   220 	TESTVALUE(CheckPhoneMatchL(_L("(358) 1234567"),10),3);
   218 	TESTVALUE(CheckPhoneMatchL(_L("+020 79460123"),10),3);
   221 	TESTVALUE(CheckPhoneMatchL(_L("+358 1234567"),10),3);
   219 
   222 
   220 	// Note that the phone number parser does generate a hash of 0 for all
   223 	// Note that the phone number parser does generate a hash of 0 for all
   221 	//these now that the '(+'combination is recognised
   224 	//these now that the '(+'combination is recognised
   222 	CreateContactL(KCntName,KCntSurname,_L("(+1) 0755 345 3644 644"),KNullDesC);
   225 	CreateContactL(KCntName,KCntSurname,_L("(+1) 0755 345 3644 644"),KNullDesC);
   223 	CreateContactL(KCntName,KCntSurname,_L("(+1) 0789 37737 39173-1"),KNullDesC);
   226 	CreateContactL(KCntName,KCntSurname,_L("(+1) 0789 37737 39173-1"),KNullDesC);
   327 	// 2. Check that no panic or error occurs when we attempt to match.
   330 	// 2. Check that no panic or error occurs when we attempt to match.
   328 	//
   331 	//
   329 	TRAPD( err, CheckPhoneMatchL(KTestNumber3,1) );
   332 	TRAPD( err, CheckPhoneMatchL(KTestNumber3,1) );
   330 	test( err == KErrNone );
   333 	test( err == KErrNone );
   331 	}
   334 	}
   332 // CCsvReader  class //
   335 /////// CCsvReader  class //////////////////////////
   333 
   336 
   334 class CCsvReader : CBase
   337 class CCsvReader : CBase
   335 	{
   338 	{
   336 public:
   339 public:
   337 	static CCsvReader* NewLC(const TDesC& filename);
   340 	static CCsvReader* NewLC(const TDesC& filename);