// T_SERV2.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

//
// ER5 AppArc server bootstrap code
// test code is #included at the bottom of the bootstrap code
// and is common between the ER1 and ER5 style servers
//

#include <f32file.h>
#include <fbs.h>
#include <apaid.h>
#include <apffndr.h>
#include <apgaplst.h>
#include <apaflrec.h>
#include <apgcli.h>
#include <apacmdln.h>
#include <apsserv.h>
#include <apfrec.h>
#include <datastor.h>
#include <apgicnfl.h>
#include <apasvst.h>
#include "tstapp.h"
//
#include <e32test.h>

LOCAL_D RTest test(_L("T_Serv"));
LOCAL_D CTrapCleanup* TheTrapCleanup;
LOCAL_D CActiveScheduler* TheScheduler;
LOCAL_D CApaProcess* TheProcess;
LOCAL_D CIdle* TheIdler;
LOCAL_D RFs TheFs;
LOCAL_D TInt DoTestL();

const TInt KTestCleanupStack=0x40;

LOCAL_C void setupCleanup()
//
// Initialise the cleanup stack.
//
    {
	TheTrapCleanup=CTrapCleanup::New();
	TRAPD(r,\
		{\
		for (TInt i=KTestCleanupStack;i>0;i--)\
			CleanupStack::PushL((TAny*)1);\
		test(r==KErrNone);\
		CleanupStack::Pop(KTestCleanupStack);\
		});
	}

////////////

class CDummyShell : public CBase, public MApaAppStarter
	{
public:
	TThreadId StartAppL(const CApaCommandLine&) { return *(TThreadId*)this; }
	void ConstructL();
public:
	RFs iFs;
	RFbsSession iFbs;
	};

void CDummyShell::ConstructL()
	{
	User::LeaveIfError(iFs.Connect());
	User::LeaveIfError(iFbs.Connect());
	}

GLDEF_C TInt E32Main()
	{
	setupCleanup();

	FbsStartup();
	TInt ret=RFbsSession::Connect();
		test(!ret);
	//
	test.Title();
	test.Start(_L("Testing App list server...ER 5 style interface"));
	//
	// set up the directory structure
	ret = TheFs.Connect();
		test(ret==KErrNone);
	//
	// set up an fbs
	ret = FbsStartup();
		test(ret==KErrNone);
	//
	// set up an app starter
	CDummyShell* dummy=new(ELeave) CDummyShell();
	dummy->ConstructL();
	//
	// set up an app list server
	ret = StartupApaServer(*dummy);
		test(ret==KErrNone);
	// give the server a reasonable time to do some scanning
	User::After(10000);
	//
	// run the testcode (inside an alloc heaven harness)

	// RDebug::Print(_L("About to test server"));
	__UHEAP_MARK;
	TRAP(ret,DoTestL());
		test(ret==KErrNone);
	__UHEAP_MARKEND;

	test.End();
	test.Close();
	
	delete TheTrapCleanup;
	return KErrNone;
	}

#include "tservcom.cpp"