summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/t_owncard.cpp
blob: 34bf13d1d51772c29ab285042230915b303e8fe7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/

#include <cntdb.h>
#include <cntdef.h>
#include <cntitem.h>
#include <cntfield.h>
#include <cntfldst.h>

// System includes
#include <e32std.h>
#include <e32twin.h>
#include <e32test.h>
#include <cntdbobs.h>

// User includes
#include "t_utils2.h"

// Constant
_LIT(KDatabaseFileName, "c:t_owncard.cdb");
_LIT(KSemaphoreNameOne,		"One");
_LIT(KSemaphoreNameTwo,		"Two");

_LIT(KThreadNameOne,		"OneThread");
_LIT(KThreadNameTwo,		"TwoThread");


const TInt KDelay = 1000000;

static RTest					TheTest(_L("t_owncard"));


///////////////////////////////////////////////////////////////////////////////
/* CTestActiveScheduler                                                      */
//  This class has been nicked from the t_currentdb.h / .cpp files
class CTestActiveScheduler : public CActiveScheduler
	{
	public:
		void Error (TInt aError) const;
	};
void CTestActiveScheduler::Error(TInt aError) const
	{
	User::Panic(_L("AScheduler"),aError);
	}



///////////////////////////////////////////////////////////////////////////////
/* CConcurrentDatabaseAccessBase - Specification                             */
// Forms the base class for both threads.
class CConcurrentDatabaseAccessBase : public CActive
	{
	public: // Data Types
		enum TStage
			{
			EOne_Startup,
			ETwo_FirstCheck,
			EThree_ChangeOwner,
			ENOP_One,
			ENOP_Two,
			EFour_SecondCheck,
			EFive_Cleanup,
			EFinished
			} ;
	public:
		CConcurrentDatabaseAccessBase();
		virtual ~CConcurrentDatabaseAccessBase();

		virtual void ConstructL(const TDesC& aFilename);

		void RunTestL();


	public: // data
		RThread					iThread;

	protected:
		void OpenSemaphore();
		void CloseSemaphore();
		void SyncronizeSignal();
		void SyncronizeWait();
		void OpenDatabaseL();
		void CloseDatabase();
		void CloseTest();

		virtual TBool RunTestImplementationL() = 0;

	protected: // from CActive
		void DoCancel() {};
		void RunL();
		TInt RunError(TInt aError);
		void CallRunLAgain();
		TBool NextStage();


	protected:
		CContactDatabase*		iDb;
		TStage					iStage;
		TInt					iTestError;

	private:
		RSemaphore				iSemaphoreSignal;
		RSemaphore				iSemaphoreWait;
		TBool					iSemaphoreOpen;
		HBufC*					iDatabaseName;
	};

///////////////////////////////////////////////////////////////////////////////
/* CConcurrentDatabaseAccessBase - Implementation                            */
CConcurrentDatabaseAccessBase::CConcurrentDatabaseAccessBase()
	: CActive( /*EPriorityStandard*/ EPriorityIdle )
	{
	iStage = EOne_Startup;
	}

CConcurrentDatabaseAccessBase::~CConcurrentDatabaseAccessBase()
	{
	iThread.Close();
	CloseSemaphore();
	delete iDatabaseName;
	}

void CConcurrentDatabaseAccessBase::ConstructL(const TDesC& aFilename)
	{
	iDatabaseName = aFilename.AllocL();
	}

void CConcurrentDatabaseAccessBase::OpenDatabaseL()
	{
	iDb = CContactDatabase::OpenL(*iDatabaseName, CContactDatabase::EMultiThread);
	}

void CConcurrentDatabaseAccessBase::CloseDatabase()
	{
	delete iDb;
	iDb = NULL;
	}

void CConcurrentDatabaseAccessBase::CloseTest()
	{
	}

void CConcurrentDatabaseAccessBase::CallRunLAgain()
	{
	iStatus = KRequestPending;

	TRequestStatus* ptrStatus = &iStatus;
	User::RequestComplete( ptrStatus, KErrNone );
	SetActive();
	}

TBool CConcurrentDatabaseAccessBase::NextStage()
	{
	TInt stage = static_cast<TInt>( iStage );
	stage++;
	iStage = static_cast<TStage>( stage );
	return ( iStage == EFinished );
	}

void CConcurrentDatabaseAccessBase::RunL()
	{
	TBool stopProcessing = EFalse;

	stopProcessing = RunTestImplementationL();

	if (stopProcessing)
		{
		CActiveScheduler::Stop();
		}
	}

TInt CConcurrentDatabaseAccessBase::RunError(TInt aError)
	{
	// propagate the error
	iTestError = aError;

	RDebug::Print(_L("Thread failed at test stage %i, with error %i"), iStage, aError);

	CActiveScheduler::Stop();
	return KErrNone;
	}

void CConcurrentDatabaseAccessBase::RunTestL()
	{
	// set's up an active scheduler for the thread
	// and calls the RunTesImplementation function to actually
	// preform the tests. This function should be implemented in the
	// child class.
	CTestActiveScheduler*  scheduler = NULL;

	scheduler = new (ELeave) CTestActiveScheduler;
	CleanupStack::PushL(scheduler);
	CActiveScheduler::Install(scheduler);

	CActiveScheduler::Add( this );

	OpenDatabaseL();

	CallRunLAgain();
	CActiveScheduler::Start();

	CloseDatabase();

	CleanupStack::PopAndDestroy( scheduler );

	// propagate error
	User::LeaveIfError(iTestError);
	}

void CConcurrentDatabaseAccessBase::OpenSemaphore()
	{
	TInt success = KErrNone;

	success = iSemaphoreSignal.OpenGlobal( KSemaphoreNameOne );
	if ( success == KErrNotFound )
		{
		iSemaphoreSignal.CreateGlobal( KSemaphoreNameOne, 0 );
		success = KErrNone;
		}


	success = iSemaphoreWait.OpenGlobal( KSemaphoreNameTwo );
	if ( success == KErrNotFound )
		{
		iSemaphoreWait.CreateGlobal( KSemaphoreNameTwo, 0 );
		}

	iSemaphoreOpen = ETrue;
	}

void CConcurrentDatabaseAccessBase::CloseSemaphore()
	{
	if (iSemaphoreOpen)
		{
		iSemaphoreSignal.Close();
		iSemaphoreWait.Close();
		}

	iSemaphoreOpen = EFalse;
	}

void CConcurrentDatabaseAccessBase::SyncronizeSignal()
	{
	CallRunLAgain();
	iSemaphoreSignal.Signal();
	iSemaphoreWait.Wait();
	}

void CConcurrentDatabaseAccessBase::SyncronizeWait()
	{
	CallRunLAgain();
	iSemaphoreSignal.Wait();
	iSemaphoreWait.Signal();
	}

///////////////////////////////////////////////////////////////////////////////
/* CConcurrentOwnerCardModifier - Specification                               */
// This class should allow the two threads to compare the owner ID's of there db.
class TOwnerCardCompare
	{
	public:
	enum EThreadName
		{
			EModifier,
			EChecker
		};
	public:
	TOwnerCardCompare();
	~TOwnerCardCompare();
	void			AssignValuesAndCheckL(TContactItemId aValue, EThreadName aThreadName);

	private:
	void			CheckValuesL();
	void			ClearValues();

	private: // data
	TBool			iModifierDataPresent;
	TBool			iCheckerDataPresent;
	TContactItemId	iModifierValue;
	TContactItemId	iCheckerValue;
	};

///////////////////////////////////////////////////////////////////////////////
/* CConcurrentOwnerCardModifier - Implementatio                              */
// This class should allow the two threads to compare the owner ID's of there db.
TOwnerCardCompare::TOwnerCardCompare()
	{
	ClearValues();
	}
TOwnerCardCompare::~TOwnerCardCompare()
	{
	ClearValues();
	}

void TOwnerCardCompare::AssignValuesAndCheckL(TContactItemId aValue, EThreadName aThreadName)
	{
	switch ( aThreadName )
		{
		case EModifier:
			iModifierDataPresent = ETrue;
			iModifierValue = aValue;
		break;

		case EChecker:
			iCheckerDataPresent = ETrue;
			iCheckerValue = aValue;
		break;
		}
	CheckValuesL();
	}

void TOwnerCardCompare::CheckValuesL()
	{
	if ( iModifierDataPresent && iCheckerDataPresent )
		{
		TheTest( (iCheckerValue == iModifierValue) );
		ClearValues();
		}
	}

void TOwnerCardCompare::ClearValues()
	{
	iCheckerDataPresent = EFalse;
	iModifierDataPresent = EFalse;
	iCheckerValue = 0;
	iModifierValue = 0xFFFFFFFF;
	}

///////////////////////////////////////////////////////////////////////////////
/* CConcurrentOwnerCardModifier - Specification                               */
// This class should create the db, and set the owner card.
class CConcurrentOwnerCardModifier : public CConcurrentDatabaseAccessBase
	{
	public:
		CConcurrentOwnerCardModifier(TOwnerCardCompare& aOwnerCardCompare);
		~CConcurrentOwnerCardModifier();

		static CConcurrentOwnerCardModifier* NewLC(const TDesC& aFilename, TOwnerCardCompare& aOwnerCardCompare);
		virtual void ConstructL(const TDesC& aFilename);

		static TInt ThreadFunction(TAny* aSelf);


	protected:
		TBool	RunTestImplementationL();

	private:
		void					AssignAndCompareOwnerCardIdL(TContactItemId aOwner);

	private:
		TOwnerCardCompare&		iOwnerCardCompare;
	};

///////////////////////////////////////////////////////////////////////////////
/* CConcurrentOwnerCardModifier - Implementation                              */

CConcurrentOwnerCardModifier* CConcurrentOwnerCardModifier::NewLC(const TDesC& aFilename, TOwnerCardCompare& aOwnerCardCompare)
	{
	CConcurrentOwnerCardModifier* self = NULL;
	self = new (ELeave) CConcurrentOwnerCardModifier(aOwnerCardCompare);
	CleanupStack::PushL( self );
	self->ConstructL(aFilename);
	return self;
	}

CConcurrentOwnerCardModifier::CConcurrentOwnerCardModifier(TOwnerCardCompare& aOwnerCardCompare)
	: iOwnerCardCompare( aOwnerCardCompare )
	{
	}

CConcurrentOwnerCardModifier::~CConcurrentOwnerCardModifier()
	{
	}

TInt CConcurrentOwnerCardModifier::ThreadFunction(TAny* aSelf)
	{
	CConcurrentOwnerCardModifier* self = STATIC_CAST(CConcurrentOwnerCardModifier*, aSelf);

	// Prepare the stuff required before we start the
	// active scheduler.
	TInt error = KErrNone;
    CTrapCleanup* cleanup = CTrapCleanup::New();
	if	(!cleanup)
		return KErrNoMemory;

	// Call virtual handler which does anything that needs doing as
	// a result of the thread function from being created.
	TRAP(error, self->RunTestL());


    delete cleanup;
	return error;
	}

void CConcurrentOwnerCardModifier::ConstructL(const TDesC& aFilename)
	{
	CConcurrentDatabaseAccessBase::ConstructL(aFilename);

	iThread.Create( KThreadNameOne, CConcurrentOwnerCardModifier::ThreadFunction, KDefaultStackSize, 0x2000, 0x20000, this, EOwnerThread );
	iThread.Resume();
	iThread.SetPriority(/*EPriorityNormal*/EPriorityAbsoluteBackground);
	}

// 1. Set up
// 2. Check current owner card.
// 3. Sync
// 4. modify owner card
// 5. Sync
// 6. Check owner card
// 7. Sync
// 8. Finished.
TBool CConcurrentOwnerCardModifier::RunTestImplementationL()
	{
	TInt bit = 0;
	TContactItemId id;
	CRandomContactGenerator* generator = NULL;
	CContactItem* item = NULL;
	TBool retval = EFalse;

	switch( iStage )
		{
		case EOne_Startup:
			OpenSemaphore();
			retval = NextStage();
			SyncronizeWait(); // pause until corresponding Searcher thread is ready.
		break;

		case ETwo_FirstCheck:
			id = iDb->OwnCardId();
			AssignAndCompareOwnerCardIdL( id );
			retval = NextStage();
			SyncronizeWait();
		break;

		case EThree_ChangeOwner:
			generator = CRandomContactGenerator::NewL();
			CleanupStack::PushL( generator );
			generator->SetDbL(*iDb);

			bit |= CContactDatabase::ESmsable;
			id = generator->AddTypicalContactForFilterL(bit);
			item = iDb->ReadContactL( id );
			CleanupStack::PushL( item );
			iDb->SetOwnCardL( *item );
			CleanupStack::PopAndDestroy( item );
			item = NULL;
			CleanupStack::PopAndDestroy( generator );
			generator = NULL;
			retval = NextStage();
			SyncronizeWait(); // wait here.
		break;

		case ENOP_One:
			CallRunLAgain();
			retval = NextStage();
		break;

		case ENOP_Two:
			CallRunLAgain();
			retval = NextStage();
		break;

		case EFour_SecondCheck:
			iDb->CountL();
			id = iDb->OwnCardId();
			AssignAndCompareOwnerCardIdL( id );
			retval = NextStage();
			SyncronizeWait();
		break;

		case EFive_Cleanup:
			CloseSemaphore();
			CloseTest();
			retval = ETrue;
		break;

		default:
		break;
		}

	return retval;
	}


void CConcurrentOwnerCardModifier::AssignAndCompareOwnerCardIdL(TContactItemId aOwner)
	{
	//SyncronizeWait();
	iOwnerCardCompare.AssignValuesAndCheckL( aOwner, TOwnerCardCompare::EModifier );
	//SyncronizeWait();
	//SyncronizeWait();
	}

///////////////////////////////////////////////////////////////////////////////
/* CConcurrentOwnerCardChecker                                               */
class CConcurrentOwnerCardChecker : public CConcurrentDatabaseAccessBase
	{
	public:
		CConcurrentOwnerCardChecker(TOwnerCardCompare& aOwnerCardCompare);
		~CConcurrentOwnerCardChecker();

		static CConcurrentOwnerCardChecker* NewLC(const TDesC& aFilename, TOwnerCardCompare& aOwnerCardCompare);
		virtual void ConstructL(const TDesC& aFilename);
		static TInt ThreadFunction(TAny* aSelf);
		static TInt FakeFunction(TAny *aParams);



	protected:
		TBool	RunTestImplementationL();

	private:
		void	AssignAndCompareOwnerCardIdL(TContactItemId aOwner);

	private:
		TOwnerCardCompare& iOwnerCardCompare;
	};

CConcurrentOwnerCardChecker* CConcurrentOwnerCardChecker::NewLC(const TDesC& aFilename, TOwnerCardCompare& aOwnerCardCompare)
	{
	CConcurrentOwnerCardChecker* self = NULL;
	self = new (ELeave) CConcurrentOwnerCardChecker(aOwnerCardCompare);
	CleanupStack::PushL( self );
	self->ConstructL(aFilename);
	return self;
	}

CConcurrentOwnerCardChecker::CConcurrentOwnerCardChecker(TOwnerCardCompare& aOwnerCardCompare)
	: iOwnerCardCompare( aOwnerCardCompare )
	{
	}

CConcurrentOwnerCardChecker::~CConcurrentOwnerCardChecker()
	{
	}

TInt CConcurrentOwnerCardChecker::ThreadFunction(TAny* aSelf)
	{
	CConcurrentOwnerCardChecker* self = static_cast<CConcurrentOwnerCardChecker*>(aSelf);

	// Prepare the stuff required before we start the
	// active scheduler.
	TInt error = KErrNone;

    CTrapCleanup* cleanup = CTrapCleanup::New();
	if	(!cleanup)
		return KErrNoMemory;

	// Call virtual handler which does anything that needs doing as
	// a result of the thread function from being created.
	TRAP(error, self->RunTestL());


    delete cleanup;
	return error;
	}

void CConcurrentOwnerCardChecker::ConstructL(const TDesC& aFilename)
	{
	CConcurrentDatabaseAccessBase::ConstructL(aFilename);

	iThread.Create( KThreadNameTwo, CConcurrentOwnerCardChecker::ThreadFunction, KDefaultStackSize, 0x2000, 0x20000, this, EOwnerThread );
	iThread.Resume();
	iThread.SetPriority(/*EPriorityNormal*/EPriorityAbsoluteBackground);

	}


TInt CConcurrentOwnerCardChecker::FakeFunction(TAny* /*aParams*/)
	{
	return(KErrNone);
	}

TBool CConcurrentOwnerCardChecker::RunTestImplementationL()
	{
	// Prep, and get ready to run. Then before starting the search loop
	// wait for the other thread.
	TContactItemId id;
	TBool retval = EFalse;

	switch( iStage )
		{
		case EOne_Startup:
			//TCallBack callBack(FakeFunction);
			OpenSemaphore();
			retval = NextStage();
			SyncronizeSignal(); // wait for the other thread.
		break;

		case ETwo_FirstCheck:
			id = iDb->OwnCardId();
			AssignAndCompareOwnerCardIdL( id );
			retval = NextStage();
			SyncronizeSignal();
		break;

		case EThree_ChangeOwner:
			retval = NextStage();
			SyncronizeSignal();
		break;

		case ENOP_One:
			CallRunLAgain();
			retval = NextStage();
		break;

		case ENOP_Two:
			CallRunLAgain();
			retval = NextStage();
		break;

		case EFour_SecondCheck:
			iDb->CountL();
			id = iDb->OwnCardId();
			AssignAndCompareOwnerCardIdL( id );
			retval = NextStage();
			SyncronizeSignal();
		break;

		case EFive_Cleanup:
			CloseSemaphore();
			CloseTest();
			retval = NextStage();
		break;

		default:
		break;
		}

	return retval;
	}


void CConcurrentOwnerCardChecker::AssignAndCompareOwnerCardIdL(TContactItemId aOwner)
	{
	//SyncronizeSignal();
	//SyncronizeSignal();
	iOwnerCardCompare.AssignValuesAndCheckL( aOwner, TOwnerCardCompare::EChecker );
	//SyncronizeSignal();
	}

///////////////////////////////////////////////////////////////////////////////
/* Test Function Prototypes                                                  */
///////////////////////////////////////////////////////////////////////////////
void CreateTestDatabaseL(const TDesC& aFilename);
void TestL();
void doMainL();

///////////////////////////////////////////////////////////////////////////////
/* Test Function Implementations                                             */
///////////////////////////////////////////////////////////////////////////////
void CreateTestDatabaseL(const TDesC& aFilename )
	{
	TInt counter = 0;
	TInt bit = 0;
	CContactDatabase* database = NULL;
	CRandomContactGenerator* generator = NULL;
	CContactItem* ownerCardItem = NULL;
	TContactItemId ownerCard = 0;

	database = CContactDatabase::ReplaceL(aFilename);
	CleanupStack::PushL( database );

	generator = CRandomContactGenerator::NewL();
	CleanupStack::PushL( generator );

	generator->SetDbL(*database);


	bit |= CContactDatabase::ESmsable;
	ownerCard = generator->AddTypicalContactForFilterL(bit);
	TheTest.Printf(_L("Adding SMS contacts %d\n"), counter);


	ownerCardItem = database->ReadContactL( ownerCard );
	CleanupStack::PushL( ownerCardItem );
	database->SetOwnCardL( *ownerCardItem );
	CleanupStack::PopAndDestroy( ownerCardItem ); ownerCardItem = NULL;

	CleanupStack::PopAndDestroy( generator );
	CleanupStack::PopAndDestroy( database );
	}


void TestL()
	{
	TRequestStatus thread1;
	TRequestStatus thread2;
	TOwnerCardCompare compareTool;
	CConcurrentOwnerCardChecker* searcher = NULL;
	CConcurrentOwnerCardModifier* inserter = NULL;

	CreateTestDatabaseL( KDatabaseFileName );

	searcher = CConcurrentOwnerCardChecker::NewLC( KDatabaseFileName, compareTool );
	User::After(KDelay); // so that checker thread created first
	inserter = CConcurrentOwnerCardModifier::NewLC( KDatabaseFileName, compareTool );

	searcher->iThread.Logon(thread1);
	inserter->iThread.Logon(thread2);

	User::WaitForRequest(thread2);
	User::WaitForRequest(thread1);

	CleanupStack::PopAndDestroy( inserter );
	CleanupStack::PopAndDestroy( searcher );

	// fail if either thread failed
	User::LeaveIfError(thread1.Int());
	User::LeaveIfError(thread2.Int());
	}


////////////////////////////////////////////////////////////////////////////////////
// -------> Static global functions (source)
////////////////////////////////////////////////////////////////////////////////////
void doMainL()
	{
	RFs fs;
	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);
	CTestRegister * TempFiles = CTestRegister::NewLC();
	TempFiles->RegisterL(KDatabaseFileName, EFileTypeCnt);

	CTestActiveScheduler*  scheduler = new (ELeave) CTestActiveScheduler;
	CleanupStack::PushL(scheduler);
	CActiveScheduler::Install(scheduler);



	// Delete any existing ini file so that we can be sure this test is ok
	TestL();

	CleanupStack::PopAndDestroy( 3 ); // scheduler, tempfiles, fs

	}


/**

@SYMTestCaseID     PIM-T-OWNCARD-0001

*/

GLDEF_C TInt E32Main()
	{
	CTrapCleanup* cleanupStack = NULL;
	__UHEAP_MARK;
	TheTest.Start(_L("@SYMTESTCaseID:PIM-T-OWNCARD-0001 Multi session testcode"));

	TheTest.Title();
	cleanupStack = CTrapCleanup::New();
	TRAPD(ret, doMainL());
	TheTest(ret == KErrNone);
	delete cleanupStack;

	TheTest.End();
	TheTest.Close();
	__UHEAP_MARKEND;
	return(KErrNone);
	}