phonebookengines_old/contactsmodel/tsrc/t_HintExtension.cpp
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 2003-2009 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 //
       
    15 
       
    16 #include <e32std.h>
       
    17 #include <e32test.h>
       
    18 #include <cntdb.h>
       
    19 
       
    20 #include <f32file.h>
       
    21 #include "t_HintExtension.h"
       
    22 #include <coreappstest/testserver.h>
       
    23 
       
    24 
       
    25 
       
    26 _LIT(KTestName, "T_HintExtension");
       
    27 
       
    28 _LIT(KSrcDatabaseFileName, "Z:\\t_HintExtension_original.cdb");
       
    29 
       
    30 _LIT(KDatabaseSecureName, "C:t_HintExtension_in_use.cdb");
       
    31 _LIT(KDatabaseSecurePhysicalName, "C:\\private\\10003A73\\t_HintExtension_in_use.cdb");
       
    32 
       
    33 _LIT(KDatabaseFileName, "C:\\t_HintExtension_in_use.cdb");
       
    34 
       
    35 _LIT(KCntDbSecureFormat,"secure[100065FF]");
       
    36 
       
    37 _LIT(KViewName,"RemoteView");
       
    38 
       
    39 //from cntstd.h
       
    40 _LIT(KIdentityTableName, "IDENTITYTABLE");
       
    41 _LIT(KContactExtHintField, "CM_ExtHintField");
       
    42 
       
    43 
       
    44 
       
    45 // Logging macros //
       
    46 GLDEF_C RTest test(KTestName);
       
    47 int __ttp_err;
       
    48 
       
    49 _LIT(KTestSmile, "\n{°±°}");
       
    50 _LIT(KTestNoErrMask, "%s(%d) : runtime error: Function '%s' returned %d\n");
       
    51 _LIT(KTestTrapMask,  "%s(%d) : runtime error: Function '%s' left with code %d\n");
       
    52 _LIT(KTestTrueMask,  "%s(%d) : runtime error: Statement '%s' equals %d\n");
       
    53 
       
    54 
       
    55 
       
    56 #define __ttr(x, c, l, f)  \
       
    57 	if (x == EFalse) \
       
    58 	_TestNoErrL(KTestTrueMask, x, _S(c), l,_S(f))
       
    59 
       
    60 #define TestTrue(x) __ttr(x, #x, __LINE__,__FILE__)
       
    61 
       
    62 
       
    63 #define __ttt(x, c, l, f)  \
       
    64 	{ const TInt res = x; if (res != KErrNone)   \
       
    65 	  _TestNoErrL(KTestNoErrMask, res, _S(c), l,_S(f));  }
       
    66 
       
    67 #define TestNoErrL(x) __ttt(x, #x, __LINE__,__FILE__)
       
    68 
       
    69 
       
    70 
       
    71 #define __ttp(x, c, l, f)		\
       
    72 	TRAP(__ttp_err, x);		\
       
    73 	if (__ttp_err != KErrNone)	\
       
    74 	  _TestNoErrL(KTestTrapMask, __ttp_err, _S(c), l,_S(f))
       
    75 
       
    76 #define TestTrap(x) __ttp(x, #x, __LINE__,__FILE__)
       
    77 
       
    78 
       
    79 void _TestNoErrL(const TDesC& aMask, TInt aResult, const TText* aCommand, TInt aLineNum,const TText* aFileName)
       
    80 	{
       
    81 	TBuf<0x400> str;
       
    82 	str.Format(aMask, aFileName, aLineNum, aCommand, aResult);
       
    83 	test.Printf(KTestSmile);
       
    84 	test.Printf(str);
       
    85 	User::Leave(aResult < 0 ? aResult : KErrUnknown);
       
    86 	}
       
    87 //
       
    88 
       
    89 RPIMTestServer serv;
       
    90 
       
    91 
       
    92 CViewTester* CViewTester::NewLC()
       
    93 	{
       
    94 	CViewTester* self=new(ELeave) CViewTester();
       
    95 	CleanupStack::PushL(self);
       
    96 	//self->ConstructL();
       
    97 	return self;
       
    98 	}
       
    99 
       
   100 CViewTester::~CViewTester()
       
   101 	{
       
   102 	iRingToneView->Close(*this);
       
   103 	iVoiceDialView->Close(*this);
       
   104 	iCNRView->Close(*this);
       
   105 
       
   106 	delete iDatabase;
       
   107 	}
       
   108 
       
   109 
       
   110 /**
       
   111 
       
   112 @SYMTestCaseID     PIM-T-HINTEXTENSION-0001
       
   113 
       
   114 */
       
   115 
       
   116 void CViewTester::CreateFilterViewsL()
       
   117 	{
       
   118 	test.Start(_L("@SYMTESTCaseID:PIM-T-HINTEXTENSION-0001 Checking that ERingTone and EVoiceDial views work and empty"));
       
   119 
       
   120 	//Creating Database
       
   121 	TestTrap(iDatabase = CContactDatabase::OpenL(KDatabaseSecureName));
       
   122 
       
   123 	//Creating Sort Order
       
   124 	TAutoClose<RContactViewSortOrder> theSortOrder;
       
   125 	theSortOrder.iObj.AppendL(KUidContactFieldGivenName);
       
   126 
       
   127 	//Creating Views
       
   128 	TestTrap(iCNRView=CContactNamedRemoteView::NewL(*this,KViewName,*iDatabase,theSortOrder.iObj,EContactsOnly));
       
   129 	TestTrap(iRingToneView = CContactFilteredView::NewL( *this, *iDatabase, *iCNRView, CContactDatabase::ERingTone));
       
   130 	TestTrap(iVoiceDialView = CContactFilteredView::NewL( *this, *iDatabase, *iCNRView, CContactDatabase::EVoiceDial));
       
   131 
       
   132 	CActiveScheduler::Start();
       
   133 	test.End();
       
   134 	}
       
   135 
       
   136 
       
   137 
       
   138 void CViewTester::HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent)
       
   139 	{
       
   140 
       
   141 	if (aEvent.iEventType == TContactViewEvent::EReady)
       
   142 		{
       
   143 		TInt err(KErrNone);
       
   144 		++iEventsReceived;
       
   145 		if (&aView == iCNRView)
       
   146 			{//Ignore main view
       
   147 			test.Printf(_L("Main view ready\n"));
       
   148 			}
       
   149 		else if (&aView == iRingToneView)
       
   150 			{
       
   151 			test.Printf(_L("RingTone view ready"));
       
   152 			TRAP(err, TestNoErrL(aView.CountL() ) );
       
   153 			test(err == KErrNone);
       
   154 			test.Printf(_L(" and empty!\n"));
       
   155 			}
       
   156 		else if (&aView == iVoiceDialView)
       
   157 			{
       
   158 			test.Printf(_L("VoiceDial view ready"));
       
   159 			TRAP(err, TestNoErrL(aView.CountL() ) );
       
   160 			test(err == KErrNone);
       
   161 			test.Printf(_L(" and empty!\n"));
       
   162 			}
       
   163 		else
       
   164 			{
       
   165 			test.Printf(_L("Unknown view in CViewTester::HandleContactViewEvent"));
       
   166 			test(EFalse);
       
   167 			}
       
   168 
       
   169 		if (iEventsReceived == 3) //events from, iCNRView, iRingToneView and iVoiceDialView
       
   170 			CActiveScheduler::Stop();
       
   171 		}
       
   172 	}
       
   173 
       
   174 
       
   175 
       
   176 
       
   177 TBool ExtHintFieldExistsL(RFs& theFS)
       
   178 	{
       
   179 	TBool theResult;
       
   180 	RDbNamedDatabase theDatabase;
       
   181 	
       
   182 	TestNoErrL(theDatabase.Open(theFS, KDatabaseFileName,KCntDbSecureFormat));
       
   183 
       
   184 	CDbColSet* theIdentitiTable = theDatabase.ColSetL(KIdentityTableName);
       
   185 	CleanupStack::PushL(theIdentitiTable);
       
   186 	const TDbCol* theExtHint = theIdentitiTable->Col(KContactExtHintField);
       
   187 	theResult = (theExtHint != NULL); //The field shouldn't exits
       
   188 
       
   189 	CleanupStack::PopAndDestroy(); //theIdentitiTable
       
   190 	theDatabase.Close();
       
   191 
       
   192 	return theResult;
       
   193 	}
       
   194 
       
   195 void TestExtHintFieldCreationL(RFs& theFS)
       
   196 	{
       
   197 	test.Start(_L("Ext Hint field creation"));
       
   198 
       
   199 
       
   200     serv.CopyFileL(KSrcDatabaseFileName, KDatabaseFileName);
       
   201 	serv.CopyFileL(KSrcDatabaseFileName, KDatabaseSecurePhysicalName);
       
   202 		
       
   203 	test.Printf(_L("Checking ExtHintField before loading cntmodel\n"));
       
   204 	TestTrue(!ExtHintFieldExistsL(theFS)); //The field shouldn't exist in original table
       
   205 
       
   206 	//Contact model must open and upgrade database
       
   207 	test.Printf(_L("Loading cntmodel\n"));
       
   208 	CContactDatabase* theDatabase = NULL; 
       
   209 	
       
   210 	TestTrap(theDatabase = CContactDatabase::OpenL(KDatabaseSecureName));
       
   211 	delete theDatabase;
       
   212 	theDatabase = NULL;
       
   213 
       
   214 	//Copy the file to the C drive, where it can be checked by the test code through DBMS
       
   215 	serv.CopyFileL(KDatabaseSecurePhysicalName, KDatabaseFileName);
       
   216 
       
   217 	test.Printf(_L("Checking ExtHintField after opening with cntmodel\n"));
       
   218 	TestTrue(ExtHintFieldExistsL(theFS)); //Contacts model must have created the ExtHintField
       
   219 	test.End();
       
   220 	}
       
   221 
       
   222 
       
   223 
       
   224 void DoTestL()
       
   225 	{
       
   226 	TAutoClose<RFs> theFS;
       
   227 	TestNoErrL(theFS.iObj.Connect());
       
   228 
       
   229     User::LeaveIfError(serv.Connect());
       
   230 	CleanupClosePushL(serv);
       
   231 
       
   232 	TestExtHintFieldCreationL(theFS.iObj);
       
   233 
       
   234 	CViewTester* viewTester = CViewTester::NewLC();
       
   235 	viewTester->CreateFilterViewsL();
       
   236 	CleanupStack::PopAndDestroy(viewTester);
       
   237 
       
   238     serv.DeleteFileL(KDatabaseFileName);
       
   239 	serv.DeleteFileL(KDatabaseSecurePhysicalName);
       
   240 
       
   241 	CleanupStack::PopAndDestroy(&serv);
       
   242 	}
       
   243 
       
   244 
       
   245 GLDEF_C TInt E32Main()
       
   246 	{
       
   247 	__UHEAP_MARK;
       
   248 	CActiveScheduler* scheduler=new CActiveScheduler;
       
   249 	if (scheduler)
       
   250 		{
       
   251 		CActiveScheduler::Install(scheduler);
       
   252 		CTrapCleanup* cleanup=CTrapCleanup::New();
       
   253 		if (cleanup)
       
   254 			{
       
   255 			test.Title();
       
   256 			test.Start(_L("T_HintExtension"));
       
   257 
       
   258 			TRAPD(err, DoTestL()); 
       
   259 			test(err == KErrNone);
       
   260 			test.End();
       
   261 
       
   262 			//test.Printf(_L("Exiting in one second...\n"));
       
   263 			User::After(1000000);
       
   264 			test.Close();
       
   265 			delete cleanup;
       
   266 			}
       
   267 		delete scheduler;
       
   268 		}
       
   269 	__UHEAP_MARKEND;
       
   270 	return KErrNone;
       
   271     }
       
   272 
       
   273