// T_WGNAM.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//


#include <e32test.h>
#include <apgwgnam.h>
#include <w32std.h>

const TInt KTestCleanupStack=0x40;

LOCAL_D RTest test(_L("T_WGNAM"));
LOCAL_D CTrapCleanup* TheTrapCleanup;
LOCAL_D RWsSession wsSession;



LOCAL_C void testWgNamesL()
	{ 
	// RDebug::Print(_L("Starting testWgNamesL()"));
	//
	// Instantiate a blank name
	CApaWindowGroupName* name1=NULL;
	TRAPD(ret,
		name1=CApaWindowGroupName::NewLC(wsSession);
		CleanupStack::Pop() );
		test(ret==KErrNone);
		test(name1!=NULL);

	// test setting system
	// RDebug::Print(_L("Block 1"));
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(!name1->IsSystem());
	test.Printf(_L("Setting system\n"));
	name1->SetSystem(ETrue);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(name1->IsSystem());
	test.Printf(_L("Setting not system\n"));
	name1->SetSystem(EFalse);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(!name1->IsSystem());
	test.Printf(_L("\n"));
	// User::After(2000000);

	// test setting busy
	// RDebug::Print(_L("Block 2"));
	test.Next(_L("Test setting busy"));
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(!name1->IsBusy());
	test.Printf(_L("Setting busy\n"));
	name1->SetBusy(ETrue);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(name1->IsBusy());
	test.Printf(_L("Setting not busy\n"));
	name1->SetBusy(EFalse);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(!name1->IsBusy());
	test.Printf(_L("\n"));
	// User::After(2000000);

	// test setting docname not a file
	// RDebug::Print(_L("Block 3"));
	test.Next(_L("Test setting doc name is not a file"));
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(name1->DocNameIsAFile());
	test.Printf(_L("Setting doc name not a file\n"));
	name1->SetDocNameIsAFile(EFalse);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(!name1->DocNameIsAFile());
	test.Printf(_L("Setting doc name is a file\n"));
	name1->SetDocNameIsAFile(ETrue);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(name1->DocNameIsAFile());
	test.Printf(_L("\n"));
	// User::After(2000000);

	// test setting does not respond to shutdown event
	// RDebug::Print(_L("Block 3"));
	test.Next(_L("Test setting does not respond to shutdown event"));
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(name1->RespondsToShutdownEvent());
	test.Printf(_L("Setting does not respond to shutdown event\n"));
	name1->SetRespondsToShutdownEvent(EFalse);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(!name1->RespondsToShutdownEvent());
	test.Printf(_L("Setting does respond to shutdown event\n"));
	name1->SetRespondsToShutdownEvent(ETrue);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(name1->RespondsToShutdownEvent());
	test.Printf(_L("\n"));
	// User::After(2000000);

	// test setting does not respond to switch files event
	// RDebug::Print(_L("Block 3"));
	test.Next(_L("Test setting does not respond to switch files event"));
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(name1->RespondsToSwitchFilesEvent());
	test.Printf(_L("Setting does not respond to switch files event\n"));
	name1->SetRespondsToSwitchFilesEvent(EFalse);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(!name1->RespondsToSwitchFilesEvent());
	test.Printf(_L("Setting does respond to switch files event\n"));
	name1->SetRespondsToSwitchFilesEvent(ETrue);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(name1->RespondsToSwitchFilesEvent());
	test.Printf(_L("\n"));
	// User::After(2000000);

	// test setting app uid
	// RDebug::Print(_L("Block 5"));
	test.Next(_L("Test setting appUid"));
	const TUid uid={ 0x10000111 };
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test.Printf(_L("Setting app uid to %x\n"), uid.iUid);
	name1->SetAppUid(uid);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(name1->AppUid()==uid);
	test.Printf(_L("\n"));
	// User::After(2000000);

	// test setting caption
	// RDebug::Print(_L("Block 6"));
	test.Next(_L("Test setting caption"));
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	TPtrC caption=_L("App caption");
	test.Printf(_L("Setting app caption to %S\n"), &caption);
	name1->SetCaptionL(caption);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(!(name1->Caption().Compare(caption)));
	test.Printf(_L("\n"));
	// User::After(2000000);

	// test setting document name
	// RDebug::Print(_L("Block 7"));
	test.Next(_L("Test setting document name"));
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	TPtrC docName=_L("Doc name");
	test.Printf(_L("Setting doc name to %S\n"), &docName);
	name1->SetDocNameL(docName);
	test.Printf(_L("Current name=\"%S\"\n"), &(name1->WindowGroupName()));
	test(!(name1->DocName().Compare(docName)));
	test.Printf(_L("\n"));
	// User::After(2000000);
	//
	// cleanup
	// RDebug::Print(_L("Cleaning up"));
	delete name1; // name1

	// RDebug::Print(_L("Finished testWgNamesL()"));
	}


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);\
		});
	}


GLDEF_C TInt E32Main()
	{
	setupCleanup();
	test.Title();
	test.Start(_L("Testing window group names"));
	// RDebug::Print(_L("Testing window group names"));
	//
	// run the testcode (inside an alloc heaven harness)

	__UHEAP_MARK;
	TRAPD(r,testWgNamesL());
		test(r==KErrNone);
	__UHEAP_MARKEND;

//	wsSession.Disconnect();
 	test.End();
	test.Close();
	
	delete TheTrapCleanup;
	return KErrNone;
	}

