os/kernelhwsrv/kerneltest/e32test/window/t_wwins.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/window/t_wwins.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,226 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\window\t_wwins.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32test.h>
    1.22 +#include <e32twin.h>
    1.23 +
    1.24 +enum TFault
    1.25 +	{
    1.26 +	EConnect,
    1.27 +	EConsole
    1.28 +	};
    1.29 +
    1.30 +LOCAL_C void Fault(TFault aFault)
    1.31 +//
    1.32 +// Panic the program.
    1.33 +//
    1.34 +	{
    1.35 +
    1.36 +	User::Panic(_L("T_WWINS fault"),aFault);
    1.37 +	}
    1.38 +
    1.39 +class TestGui
    1.40 +	{
    1.41 +public:
    1.42 +	void Test1();
    1.43 +	void Test2();
    1.44 +private:
    1.45 +    };
    1.46 +
    1.47 +void TestGui::Test1()
    1.48 +	{
    1.49 +	RConsole w;
    1.50 +
    1.51 +	RTest test(_L("T_WWINS"));
    1.52 +	test.Title();
    1.53 + 	test.Start(_L("GUI Test 1\n"));
    1.54 +	test.Next(_L("User::InfoPrint"));
    1.55 +	TInt r=User::InfoPrint(_L("A short infoprint"));
    1.56 +	test(r==KErrNone);
    1.57 +	r=User::InfoPrint(_L("This infoprint is much longer.   ( 50  characters)"));
    1.58 +	test(r==KErrNone);
    1.59 +	User::After(10000);
    1.60 +	r=w.Create();
    1.61 +	TSize scsz;
    1.62 +	w.ScreenSize(scsz);
    1.63 +	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
    1.64 +	r=w.Init(_L("T_WWINS"),TSize(Min(50,scsz.iWidth-4),Min(15,scsz.iHeight-4)));
    1.65 +	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
    1.66 +	for(TInt x=0;x<600;x++)
    1.67 +		{
    1.68 +		TBuf<0x40> b;
    1.69 +		b.Format(_L("%05d hello world\r\n"),x);
    1.70 +		w.Write(b);
    1.71 +		}
    1.72 +	w.Destroy();
    1.73 +	w.Close();
    1.74 +//
    1.75 +	RNotifier textWS;
    1.76 +	test.Next(_L("RNotify::Connect"));
    1.77 +	r=textWS.Connect();
    1.78 +	test(r==KErrNone);
    1.79 +	test.Next(_L("RNotify::Notify"));
    1.80 +	TRequestStatus stat;
    1.81 +	TPtrC line1(_L("This is a notifier."));
    1.82 +	TPtrC line2(_L("They stay on top."));
    1.83 +	TPtrC line3(_L(" A  longer  notifier  with  just  one  button. "));
    1.84 +	TPtrC null(KNullDesC);
    1.85 +	TPtrC butt1(_L("Esc"));
    1.86 +	TPtrC butt2(_L("Enter"));
    1.87 +	TInt val=-1;
    1.88 +	textWS.Notify(line1,line2,butt1,butt2,val,stat);
    1.89 +	User::WaitForRequest(stat);
    1.90 +	test(val==0||val==1);
    1.91 +	textWS.Notify(line3,null,butt2,null,val,stat);
    1.92 +	User::WaitForRequest(stat);
    1.93 +	test(val==1);
    1.94 +	test.Next(_L("User::InfoPrint again"));
    1.95 +	r=User::InfoPrint(_L("Infoprints stay on top..."));
    1.96 +	test(r==KErrNone);
    1.97 +	textWS.Close();
    1.98 +	test.Close();
    1.99 +	}
   1.100 +
   1.101 +TInt Test2Window2(TAny* /*aDirective*/)
   1.102 +	{
   1.103 +	RConsole w;
   1.104 +	TInt r=w.Create();
   1.105 +	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
   1.106 +	TSize scsz;
   1.107 +	w.ScreenSize(scsz);
   1.108 +	r=w.Control(_L("+Scrollbars +Lock"));
   1.109 +	r=w.Init(_L("T_WWINS Window 2"),TSize(Min(50,scsz.iWidth-4),Min(15,scsz.iHeight-4)));
   1.110 +	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
   1.111 +	TConsoleKey k;
   1.112 +	TRequestStatus s;
   1.113 +	FOREVER
   1.114 +		{
   1.115 +		w.Read(k,s);
   1.116 +		FOREVER
   1.117 +			{
   1.118 +			if (s!=KRequestPending)
   1.119 +				break;
   1.120 +			else
   1.121 +				User::After(1000000);
   1.122 +			w.Control(_L("-Scrollbars"));
   1.123 +			if (s!=KRequestPending)
   1.124 +				break;
   1.125 +			else
   1.126 +				User::After(1000000);
   1.127 +			w.Control(_L("+Scrollbars"));
   1.128 +			}
   1.129 +		User::WaitForRequest(s);
   1.130 +		if (s==KErrNone)
   1.131 +			{
   1.132 +			TChar a=(TUint)k.Code();
   1.133 +			if (a.IsPrint())
   1.134 +				{
   1.135 +				TBuf<1> b(1);
   1.136 +				b[0]=(TText)a;
   1.137 +				w.Write(b);
   1.138 +				}
   1.139 +			}
   1.140 +		else
   1.141 +			User::Panic(_L("Read-Key"),0);
   1.142 +		}
   1.143 +	}
   1.144 +
   1.145 +TInt Test2Window1(TAny* /*aDirective*/)
   1.146 +	{
   1.147 +	RConsole w;
   1.148 +	User::After(200000);
   1.149 +	TInt r=w.Create();
   1.150 +	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
   1.151 +	TSize scsz;
   1.152 +	w.ScreenSize(scsz);
   1.153 +	r=w.Init(_L("T_WWINS Window 1"),TSize(Min(50,scsz.iWidth-4),Min(15,scsz.iHeight-4)));
   1.154 +	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
   1.155 +	w.Control(_L("+Maximised"));
   1.156 +	FOREVER
   1.157 +		User::After(10000000);
   1.158 +	}
   1.159 +
   1.160 +void TestGui::Test2()
   1.161 +	{
   1.162 +	TInt x;
   1.163 +	RThread t1, t2;
   1.164 +	RTest test(_L("T_WWINS"));
   1.165 +	test.Title();
   1.166 + 	test.Start(_L("GUI Test 2\n"));
   1.167 +	x=t1.Create(_L("Thread1"),Test2Window1,KDefaultStackSize,0x2000,0x2000,(TAny*)1);
   1.168 +	if(x==0) t1.Resume();
   1.169 +	x=t2.Create(_L("Thread2"),Test2Window2,KDefaultStackSize,0x2000,0x2000,(TAny*)2);
   1.170 +	if(x==0) t2.Resume();
   1.171 +	RConsole w;
   1.172 +	TInt r=w.Create();
   1.173 +	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
   1.174 +	TSize scsz;
   1.175 +	w.ScreenSize(scsz);
   1.176 +	r=w.Init(_L("T_WWINS Window 3"),TSize(Min(50,scsz.iWidth-4),Min(15,scsz.iHeight-4)));
   1.177 +	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
   1.178 +	w.Control(_L("+Scrollbars"));
   1.179 +	TConsoleKey k;
   1.180 +	TKeyCode c;
   1.181 +	do
   1.182 +		{
   1.183 +		w.Read(k);
   1.184 +		c=k.Code();
   1.185 +		if(c<256)
   1.186 +			{
   1.187 +			TText a=(TText)c;
   1.188 +			TPtrC s(&a,1);
   1.189 +			w.Write(s);
   1.190 +			}
   1.191 +		else
   1.192 +			{
   1.193 +			if(c==EKeyLeftArrow) w.SetCursorPosRel(TPoint(-1,0));
   1.194 +			if(c==EKeyRightArrow) w.SetCursorPosRel(TPoint(1,0));
   1.195 +			if(c==EKeyUpArrow) w.SetCursorPosRel(TPoint(0,-1));
   1.196 +			if(c==EKeyDownArrow) w.SetCursorPosRel(TPoint(0,1));
   1.197 +			if(c==EKeyF1) w.Control(_L("+Cursor"));
   1.198 +			if(c==EKeyF2) w.Control(_L("-Cursor"));
   1.199 +			if(c==EKeyF5) w.Control(_L("+Lock"));
   1.200 +			if(c==EKeyF6) w.Control(_L("-Lock"));
   1.201 +			if(c==EKeyF7) w.Control(_L("+Wrap"));
   1.202 +			if(c==EKeyF8) w.Control(_L("-Wrap"));
   1.203 +			if(c==EKeyF9) w.ClearToEndOfLine();
   1.204 +			}
   1.205 +		} while(k.Code()!=EKeyEscape);
   1.206 +	w.Close();
   1.207 +	t1.Terminate(0);
   1.208 +	t1.Close();
   1.209 +	t2.Terminate(0);
   1.210 +	t2.Close();
   1.211 +	test.End();
   1.212 +	}
   1.213 +
   1.214 +// To get some data or bss into ths program
   1.215 +TInt dataMaker=0;
   1.216 +
   1.217 +GLDEF_C TInt E32Main()
   1.218 +//
   1.219 +// Test the various kernel types.
   1.220 +//
   1.221 +    {
   1.222 +	TestGui t;
   1.223 +	t.Test1();
   1.224 +	t.Test2();
   1.225 +	return(0);
   1.226 +    }
   1.227 +
   1.228 +
   1.229 +