summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/t_remoteview.cpp
blob: 5dfc6499a1ef4a10cb16576963293e9e7d018919 (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
/*
* 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: 
* T_RemoteView creates a database in the main thread. Another thread is created containing
* a remote view to the same database.  A number of contacts are added, then some deleted. 
* Meanwhile whenever the view is updated and available, the second thread prints all the
* contact IDs to the console using an active object, one at a time (a nicely time-consuming
* process intended to cause a backlog of messages between the thread). 
* After the contacts are added, a number of them are deleted at once.
* Before the changes for INC037352 , this would Panic. Now it executes without any errors. 
* Note: This overwrites the default contacts database:  c:\system\data\Contacts.cdb
* This is necessary if this is to be used with phonebook server which requires this file
*
*/

#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"

// Constants

_LIT(KThreadNameOne, "OneThread");

_LIT(KViewNameOne, "T_RemoteView-ViewOne");

const TInt KNumberOfContacts = 300;
const TInt KNumberOfContactsForTest2 = 300;
const TInt KNumberToDeleteAtOneTime = 45;

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

///////////////////////////////////////////////////////////////////////////////
//#pragma mark ==== Class definitions ====
///////////////////////////////////////////////////////////////////////////////

/** 
This class recieves view events, prints them, and then prints all the
contacts in the view. If a view changes while printing, it will stop, 
starting again from the top when the view becomes available again
*/
class CViewObsever : public CActive, public MContactViewObserver
	{
	public: 
		CViewObsever(RTest& aTest);
		void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent);

	protected: 
		void RunL();
		void DoCancel();
		TInt RunError(TInt aError);

	private:
		void StartPrintingAllContacts(const CContactViewBase& aView);
		TBool iReady;
		RTest& iTest;
		TInt iCount;
		TInt iIndex;
		const CContactViewBase* iView;
	};

/** This class is used to create a named remote view  in its own thread, displaying the contents
	 in a console */
class CViewer : public CBase
	{
	public: 
		static TThreadId Create(const TDesC& aName, const TDesC& aViewName);
		static TInt LaunchThread(TAny* aAny);
		static CViewer* NewL(const TDesC& aViewName);
		static TInt CheckFinished(TAny* self);
		~CViewer();

	private: 
		void ConstructL(const TDesC& aViewName);
		TBool IsDone();

	private:
		RTest* iTest;
		CContactDatabase* iDatabase;
		RContactViewSortOrder iViewSortOrder;
		CViewObsever* iEventObserver;
		CContactNamedRemoteView* iView;
		RSemaphore iSemaphore;
		CIdle* iSemaphoreWatcher;
	};


//#pragma mark -

CViewObsever::CViewObsever(RTest& aTest) : CActive(EPriorityStandard+4), iTest(aTest)
	{
	}

/** Tell to print all contacts in the view (using RunL) */
void CViewObsever::StartPrintingAllContacts(const CContactViewBase& aView) 
	{
	ASSERT(iReady);
	
	if(IsActive())
		{
		Cancel();		
		}
	
	iView = &aView;
	TRAPD(err, iCount = aView.CountL() );
	if(err!=KErrNone)
		{
		RunError(err);
		return;
		}
	iIndex=iCount;
	TRequestStatus* stat = &iStatus;
	User::RequestComplete(stat,KErrNone);
	SetActive();
	}


/** Print any error. If it's simply not ready, ignore it (but end the printing cycle) */
/** And, if it's not found ... do the same ... this happens when the test system is slow
either due to other processes running or the speed of the processor itself.  If the test
in question is Test2L, the attempt to gain a count may have indicated the view cannot be
found. */
TInt CViewObsever::RunError(TInt aError)
	{
	iTest.Printf(_L("Error: %i\n"),aError);
	if(aError == KErrNotReady | aError == KErrNotFound)		
	// view is not ready or count returned not found
		{	
		/* Can only get here by a Leave in AtL() (or by being called manually an equvalent Leaver in CountL() in StartPrintingAllContacts() ) 
			This means the object thinks the state is ready, but it really is not .
			This can *only* ever happen if an EUnavailable event got sent,
			but it's not been recieved yet. 
			So, to save the trouble set the readiness to false and just sit and wait
			for the EUnavailable and (eventually) the EReady events
		*/
		iReady=EFalse;
		return KErrNone;
		}
	else if(aError == KErrNotFound)
		{
		return KErrNone;
		}
	return aError;
	}

/** Print the next item in the view*/
void CViewObsever::RunL()
	{
	if(iReady && --iIndex > (iCount-10))
		{
		iView->AtL(iIndex);
		
		TRequestStatus* stat = &iStatus;
		User::RequestComplete(stat,KErrNone);
		SetActive();
		}
	iTest.Printf(_L("\n"));
	}

/** Stop printing */
void CViewObsever::DoCancel()
	{
	iIndex = iCount;
	iTest.Printf(_L("Cancelling view observer\n"));
	}

/** Print the current readiness state and the incoming event.  If the view is ready, start printing the list of contacts*/
void CViewObsever::HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent)
	{
	TPtrC name(RThread().Name());
	if(iReady) 
		{
		iTest.Printf(_L("%S Ready: "), &name);
		}
	else 
		{
		iTest.Printf(_L("%S Not ready: "), &name);
		}
	switch(aEvent.iEventType)
		{
		case TContactViewEvent::EUnavailable: 
			iReady = EFalse;
			iTest.Printf(_L("EUnavailable\n"));
			break;
		case TContactViewEvent::EReady:
			iReady = ETrue;
			iTest.Printf(_L("EReady\n"));
			break;
		case TContactViewEvent::ESortOrderChanged:
			iTest.Printf(_L("ESortOrderChanged\n"));
			break;
		case TContactViewEvent::ESortError:
		case TContactViewEvent::EServerError:
		case TContactViewEvent::EIndexingError:
			iTest.Printf(_L("Error: %x %i\n"),aEvent.iEventType, aEvent.iInt);
			iReady = EFalse;
			break;
		case TContactViewEvent::EItemAdded:
			iTest.Printf(_L("EItemAdded %i (%i)\n"), aEvent.iContactId, aEvent.iInt);
			break;
		case TContactViewEvent::EItemRemoved:
			iTest.Printf(_L("EItemRemoved\n"));
			break;
		case TContactViewEvent::EGroupChanged:
			iTest.Printf(_L("EGroupChanged\n"));
			break;
		default:
			return;	
		}
	
	if(iReady)
		{
		StartPrintingAllContacts(aView);
		}
	}
	
//#pragma mark -

CViewer* CViewer::NewL(const TDesC& aViewName)
	{
	CViewer* self = new(ELeave) CViewer;
	CleanupStack::PushL(self);
	self->ConstructL(aViewName);
	CleanupStack::Pop(self);
	return(self);
	}

CViewer::~CViewer()
	{
	TPtrC name(RThread().Name());
	iTest->Printf(_L("Deleting viewer: %S\n"), &name);
	iView->Close(*iEventObserver);
	delete iEventObserver;
	iViewSortOrder.Close();
	
	delete iDatabase;
	iSemaphore.Close();
	iTest->End();
	iTest->Close();
	delete iTest;
	delete iSemaphoreWatcher;
	CActiveScheduler::Stop();
	}

void CViewer::ConstructL( const TDesC& aViewName)
	{

	TPtrC name(RThread().Name());

	// Create and name an RTest
	iTest = new(ELeave) RTest(name);
	CConsoleBase* console = iTest->Console();
	// Position our console window
	if(console) 
		{
		TSize size = console->ScreenSize();
		size.iWidth = size.iWidth /2 -3;
		console = Console::NewL(name, size);
		}
	else
		{
		TSize size(40,10);
		console = Console::NewL(name, size);
		}
	delete const_cast<RTest*>(iTest)->Console();
	iTest->SetConsole(console);
	console->SetTitle(name);
	iTest->Start(_L("Thread: Starting Viewer"));
	
	iTest->Next(_L("Thread: Creating view sort order"));
	iViewSortOrder.AppendL(KUidContactFieldFamilyName);
   	iViewSortOrder.AppendL(KUidContactFieldGivenName);
    iViewSortOrder.AppendL(KUidContactFieldCompanyName);

	iTest->Next(_L("Thread: Creating view observer"));
	iEventObserver = new(ELeave) CViewObsever(*iTest);
	
	User::LeaveIfError(iSemaphore.OpenGlobal(aViewName));

	User::After(2000000);		// give the other thread a chance to do stuff
	TInt err=KErrNotFound;
	TInt count=0;
	while(err!=KErrNone)
		{
		if(count) 
			{
			iTest->Printf(_L("  retry %i\n"),count);
			}
		else
			{
			iTest->Next(_L("Thread: Starting Database"));
			}
		TRAP(err, iDatabase = CContactDatabase::OpenL());
		count++;
		if(count>30)
			{
			User::Leave(err);
			}
		}

	CActiveScheduler::Add(iEventObserver);
	
	iTest->Next(_L("Thread: Starting View"));
	iView = CContactNamedRemoteView::NewL(*iEventObserver, aViewName, *iDatabase, iViewSortOrder, EContactsOnly);

	iSemaphore.Signal(); // main thread can start doing things
	iSemaphoreWatcher = CIdle::NewL(CActive::EPriorityIdle-100);			// really very idle
	TCallBack callback(CViewer::CheckFinished,this); 
	iSemaphoreWatcher->Start(callback);
	}

TBool CViewer::IsDone()
	{
		return ETrue;
	}

TInt CViewer::CheckFinished(TAny* self)
	{
	if( ((CViewer*) self)->IsDone() )
		{
		delete  ((CViewer*) self);
		return false;
		}
	return true;
	}

static CViewer* InitL(TDesC& aViewName)
	{
	CActiveScheduler *scheduler=new(ELeave) CActiveScheduler;
	CActiveScheduler::Install(scheduler);
	return CViewer::NewL(aViewName);
	}

TInt CViewer::LaunchThread(TAny* aAny) 
	{
	__UHEAP_MARK;
	CTrapCleanup* cleanUpStack=CTrapCleanup::New();
	if (!cleanUpStack)
		{
		return KErrNoMemory;
		}
	TRAPD(r,InitL(*((TDesC*) aAny)));
	if (r==KErrNone)
		{
		User::After(2000000);		// give the other thread a chance to do stuff
		CActiveScheduler::Start();
		User::After(2000000);		// give the other thread a chance to do stuff
		}
	delete CActiveScheduler::Current();
	delete cleanUpStack;
	
	__UHEAP_MARKEND;
	return r;
	}

/* This is the only thing one needs to call in order to set the view in motion. */
/** Creates a remote view in its own thread. 
@param aName			the name of the thread
@param aViewName	the name of the view*/
TThreadId CViewer::Create(const TDesC& aName, const TDesC& aViewName)
	{
	RThread thread;
	TInt err = thread.Create( aName, CViewer::LaunchThread, KDefaultStackSize, 0x2000, 0x20000, (void*) &aViewName, EOwnerThread );
	if(err!=KErrNone)
		{
		return KNullUidValue;
		}
	thread.Resume();
	thread.SetPriority(EPriorityNormal);
	TThreadId id = thread.Id();
	thread.Close();
	return id;
	}



///////////////////////////////////////////////////////////////////////////////
//#pragma mark -
///////////////////////////////////////////////////////////////////////////////

/** This object creates and closes a thread containing a view to the contacts database. 
	The view will output all changes and the current state of the database using an RDebug object. 
	This thread acts completely independently until it is told to close. 
	@see CViewObsever

	Call Open() to create initailise the other thread. WaitUntilDbIsReady() or Close() must be called eventually. 
	if CheckIfDbIsReady() returns true, WaitUntilDbIsReady() will return immediately. 
	Close() is synchronous and will not return until the other thread dies. 
*/
class RRemoteViewThread
	{
	public:
		TInt Open(const TDesC& aViewName, const TDesC& aThreadName);
		void WaitUntilDbIsReady(); 
		TBool CheckIfDbIsReady();
		TInt Close();

	private:
		RSemaphore iSemaphore;
		TBool iDbReady;
		TRequestStatus iStatus;
	};

/** Create and initalise the view thread. 
	There is no reason why the view name and thread name cannot be the same.
	This call is more or less asynchronous, and the thread will not be immediately ready.
	Call CheckIfDbIsReady() or WaitUntilDbIsReady() to find out if the thread is ready.
	This can be closed at any time, even if the thread is not ready.
@param	aViewName	The name of the view
@param aThreadName	The name of the thread. 
@return the error state
*/

TInt RRemoteViewThread::Open(const TDesC& aViewName, const TDesC& aThreadName)
	{
	// Thread1: create semaphone for communicating w/Thread 2
	iDbReady = EFalse;
	
	//create semphore for communicating between threads:
	TInt err = iSemaphore.CreateGlobal(aViewName, 0);	
	if(err != KErrNone)
		{
		return err;
		}
		
	// this thread: Start Other thread
	TheTest.Printf(_L("Starting view thread %S"), &aThreadName);
	TThreadId id = CViewer::Create(aThreadName, aViewName);
		
	RThread thread;
	err = thread.Open(id);
	if(err==KErrNone)
		{	// tell kernel that this thread wants to know when the other thread dies
		TRequestStatus* stat = &iStatus;
		User::RequestComplete(stat,KRequestPending);
		thread.Logon(iStatus);
		thread.Close();
		}
	
	return err;
	}

/** Sit and wait until the thread is ready*/
void RRemoteViewThread::WaitUntilDbIsReady()
	{
	if(iDbReady)
		{
		return;
		}
	iSemaphore.Wait();
	iDbReady = ETrue;
	}

/** Always call WaitUntilDbIsReady after this returns a true result
@return true if the thread is ready, false otherwise*/
TBool RRemoteViewThread::CheckIfDbIsReady()
	{
	if(iDbReady)
		{
		return ETrue;
		}
	iDbReady = ETrue;
	return iDbReady;
	}

/** Signal to the other thread that it should shut down and then wait for it to signal that is has closed 
*/
TInt RRemoteViewThread::Close()
	{
	if(!iDbReady)
		{
		WaitUntilDbIsReady();
		}
	iSemaphore.Signal();		// tell thread one it can die now
	TheTest.Printf(_L("Waiting for other thread to die"));
	// iStatus is set when the other thread dies
	User::WaitForRequest(iStatus);
	iSemaphore.Close();
	return iStatus.Int();
	}

///////////////////////////////////////////////////////////////////////////////
//#pragma mark ==== Test Function Prototypes ====
///////////////////////////////////////////////////////////////////////////////
void PopulateTestDatabaseL(CContactDatabase& aDatabase);
void TestL();
void doMainL();

///////////////////////////////////////////////////////////////////////////////
//#pragma mark ==== Test Function Implementations ====
///////////////////////////////////////////////////////////////////////////////
const TInt KPrintFreq=10;

/** add aCount random contacts to the open database. The 1st item will always be the own card */
CContactIdArray* PopulateTestDatabaseLC(CContactDatabase& aDatabase, TInt aCount )
	{
	__ASSERT_ALWAYS(aCount>0, User::Invariant());
	CContactIdArray* contacts = CContactIdArray::NewLC();
	CRandomContactGenerator* generator = CRandomContactGenerator::NewL();
	CleanupStack::PushL( generator );
	generator->SetDbL(aDatabase);

	TInt bit = CContactDatabase::ESmsable;
	
	TContactItemId itemId = generator->AddTypicalContactForFilterL(bit);
	TInt counter = 0;
	TheTest.Printf(_L("Adding own card %d\n"), counter++);
	CContactItem* ownerCardItem = aDatabase.ReadContactL( itemId );
	CleanupStack::PushL( ownerCardItem );
	aDatabase.SetOwnCardL( *ownerCardItem );
	contacts->AddL(itemId);
	for(;counter<aCount;counter++)
		{
		itemId = generator->AddTypicalContactForFilterL(bit);
		if(counter%KPrintFreq==0)
			{
			TheTest.Printf(_L("Added contact %d: %i\n"), counter, itemId);
			}
		contacts->AddL(itemId);
		}
	CleanupStack::PopAndDestroy( ownerCardItem ); 
	CleanupStack::PopAndDestroy( generator );
	return contacts;
	}


/** Test that the view thread always correctly knows weather or not the view is ready for use*/
void Test1L()
	{
	// Thread 1: Create db
	CContactDatabase* database = CContactDatabase::ReplaceL();
	CleanupStack::PushL( database );
 
	// Thread1: create and start a thread with a remote view
	RRemoteViewThread viewer;
	User::LeaveIfError(viewer.Open(KViewNameOne, KThreadNameOne));
	CleanupClosePushL(viewer);

	// Thread 2: Open database
	// Thread 2: Create named view

	viewer.WaitUntilDbIsReady(); // wait until we've at least got the Db open (can cause file sharing trouble otherwise)

	// Thread 1: add a whole lot of contacts
	CContactIdArray& contacts = *PopulateTestDatabaseLC(*database, KNumberOfContacts );
	// Thread 2: print all the contacts in the view

	TInt64 seed=85204;
	CContactIdArray* toDelete = CContactIdArray::NewLC();
	TInt i;
	TInt end = contacts.Count();
	TInt start = Math::Rand(seed)%end;
	if(start+KNumberToDeleteAtOneTime<end)
		{
		end = start+KNumberToDeleteAtOneTime;
		}
	TheTest.Printf(_L("Deleting contatcs %i -- %i\n"), contacts[start],contacts[end-1]);
	for(i=start;i<end;i++)
		{
		toDelete->AddL(contacts[i]);
		}
	contacts.Remove(start,end-start);
	database->DeleteContactsL(*toDelete);
	toDelete->Reset();
	
	CleanupStack::PopAndDestroy(toDelete );	
	CleanupStack::PopAndDestroy(&contacts );
	CleanupStack::Pop( );	
	TheTest( viewer.Close()  == KErrNone );
	
	CleanupStack::PopAndDestroy(database );

	}

/** Test to make sure another thread can open the db when this one is performing many operations on it */
void Test2L()
	{
	// Thread 1: Create db
	CContactDatabase* database = CContactDatabase::ReplaceL();
	CleanupStack::PushL( database );

 	// Thread 1: add a whole lot of contacts
	CContactIdArray& contacts = *PopulateTestDatabaseLC(*database, KNumberOfContactsForTest2 );


 	// Thread 1: create a group
	CContactItem* group = database->CreateContactGroupL(_L("My Group"));
	CleanupStack::PushL(group);
	TContactItemId groupId = group->Id();

	// Thread1: create and start a thread with a remote view
	RRemoteViewThread viewer;
	User::LeaveIfError(viewer.Open(KViewNameOne, KThreadNameOne));
	CleanupClosePushL(viewer);

	// Thread 1: start hammering the database
	TInt i;
	TInt err;
	for(i=-1/*contacts.Count()-1*/;i>=0;i--) 
		{
		TRAP(err,database->AddContactToGroupL(contacts[i],groupId));
		if(err==KErrNotReady || err==KErrLocked)
			{
			i++;		// try again
			}
		else 
			{
			User::LeaveIfError(err);
			if(i%KPrintFreq==0)
				{
				TheTest.Printf(_L("Added contact %d to group\n"),contacts[i]);
				viewer.CheckIfDbIsReady(); // acknowledge db-is-ready signal
				}
			}
		}

	// Thread 2: Open database
	// Thread 2: Create named view

	viewer.WaitUntilDbIsReady(); // just in case is not ready yet -- acknowledge db-is-ready signal
	
	// Thread 2: print all the contacts in the view

	CContactIdArray* toDelete = CContactIdArray::NewLC();
	TInt64 seed=85204;
	TInt end   = contacts.Count();
	TInt start = Math::Rand(seed)%end;
	if(start+KNumberToDeleteAtOneTime<end)
		{
		end = start+KNumberToDeleteAtOneTime;
		}
	TheTest.Printf(_L("\nDeleting contacts %i -- %i\n"), contacts[start],contacts[end-1]);
	for(i=start;i<end;i++)
		{
		toDelete->AddL(contacts[i]);
		}
	contacts.Remove(start,end-start);
	database->DeleteContactsL(*toDelete);
	toDelete->Reset();
	
	CleanupStack::PopAndDestroy(toDelete );	
	CleanupStack::Pop( );	
	TheTest( viewer.Close()  == KErrNone );
	
	CleanupStack::PopAndDestroy(group );
	CleanupStack::PopAndDestroy(&contacts );
	CleanupStack::PopAndDestroy(database );
	}


////////////////////////////////////////////////////////////////////////////////////
// -------> Static global functions (source)
////////////////////////////////////////////////////////////////////////////////////
void doMainL()
	{
	CActiveScheduler*  scheduler = new (ELeave) CActiveScheduler;
	CleanupStack::PushL(scheduler);
	CActiveScheduler::Install(scheduler);

	// This call is just included to get rid of a linker warning LNK4089
	// Probably the reason for the warning is that the MVC++ environment 
	// sometimes does not realise when a library is actually used.
	// We do not care about if the server is hung or not, we just want to 
	// make the call.

	// Delete any existing ini file so that we can be sure this test is ok
	Test1L();			// Test read-when-not-ready Panic defect

	Test2L();
	CleanupStack::PopAndDestroy( scheduler );
	// delete db file here
	}


/**

@SYMTestCaseID     PIM-T-REMOTEVIEW-0001

*/

GLDEF_C TInt E32Main()
	{
	RDebug::Print(_L("t_bench started"));

	CTrapCleanup* cleanupStack = NULL;
	__UHEAP_MARK;
	TheTest.Start(_L("@SYMTESTCaseID:PIM-T-REMOTEVIEW-0001 Remote View testing"));

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

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