kerneltest/e32test/window/t_wjpwin.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\window\t_wjpwin.cpp
       
    15 // (this test program is formerly known as T_GUI.H)
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <e32test.h>
       
    20 #include <e32twin.h>
       
    21 
       
    22 enum TFault
       
    23 	{
       
    24 	EConnect,
       
    25 	EConsole
       
    26 	};
       
    27 
       
    28 LOCAL_C void Fault(TFault aFault)
       
    29 //
       
    30 // Panic the program.
       
    31 //
       
    32 	{
       
    33 
       
    34 	User::Panic(_L("T_WWINS fault"),aFault);
       
    35 	}
       
    36 
       
    37 class TestGui
       
    38 	{
       
    39 public:
       
    40 	void Test1();
       
    41 	void Test2();
       
    42 private:
       
    43     };
       
    44 
       
    45 void TestGui::Test1()
       
    46 	{
       
    47 	RConsole w;
       
    48 	RTest test(_L("T_WWINS"));
       
    49 	test.Title();
       
    50  	test.Start(_L("GUI Test 1\n"));
       
    51 	TInt r=w.Init(_L("T_WWINS"),TSize(50,15));
       
    52 	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
       
    53 	for(TInt x=0;x<200;x++)
       
    54 		{
       
    55 		TBuf<0x40> b;
       
    56 #if defined(_UNICODE)	// K.K
       
    57 		unsigned char unicode_chars[] = {0x25,0x30,0x33,0x64,0x20,0x90,0xa2,0x8a,0x45,0x82,0xe6,0x20,0x82,0xb1,0x82,0xf1,0x82,0xc9,0x82,0xbf,0x82,0xcd,13,10,0,0};
       
    58 		//b.Format(_L("%03d 世界よ こんにちは\r\n"),x);
       
    59 		b.Format(TPtrC16((unsigned short*)unicode_chars),x);
       
    60 #else	// K.K
       
    61 		b.Format(_L("%03d hello world\r\n"),x);
       
    62 #endif	// K.K
       
    63 		w.Write(b);
       
    64 		}
       
    65 	w.Destroy();
       
    66 	w.Close();
       
    67 	test.Close();
       
    68 	}
       
    69 
       
    70 TInt Test2Window2(TAny* /*aDirective*/)
       
    71 	{
       
    72 	RConsole w;
       
    73 	TInt r=w.Create();
       
    74 	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
       
    75 	r=w.Control(_L("+Scrollbars +Lock"));
       
    76 	r=w.Init(_L("T_WWINS Window 2"),TSize(50,15));
       
    77 	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
       
    78 	TConsoleKey k;
       
    79 	TRequestStatus s;
       
    80 	TInt x;
       
    81 	FOREVER
       
    82 		{
       
    83 		w.Read(k,s);
       
    84 		FOREVER
       
    85 			{
       
    86 			for(x=0;x<10000000 && s==KRequestPending;x++) {};
       
    87 			if (s!=KRequestPending)
       
    88 				break;
       
    89 			w.Control(_L("-Scrollbars"));
       
    90 			for(x=0;x<10000000 && s==KRequestPending;x++) {};
       
    91 			if (s!=KRequestPending)
       
    92 				break;
       
    93 			w.Control(_L("+Scrollbars"));
       
    94 			}
       
    95 		User::WaitForRequest(s);
       
    96 		if (s==KErrNone)
       
    97 			{
       
    98 			TChar a=(TUint)k.Code();
       
    99 			if (a.IsPrint())
       
   100 				{
       
   101 				TBuf<1> b(1);
       
   102 				b[0]=(TText)a;
       
   103 				w.Write(b);
       
   104 				}
       
   105 			}
       
   106 		else
       
   107 			User::Panic(_L("Read-Key"),0);
       
   108 		}
       
   109 //	return(KErrNone);
       
   110 	}
       
   111 
       
   112 TInt Test2Window1(TAny* /*aDirective*/)
       
   113 	{
       
   114 	RConsole w;
       
   115 	TInt r=w.Create();
       
   116 	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
       
   117 	r=w.Control(_L("-Visibilty +Lock"));
       
   118 	r=w.Init(_L("T_WWINS Window 1"),TSize(50,15));
       
   119 	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
       
   120 	FOREVER
       
   121 		{
       
   122 		TInt x;
       
   123 		for(x=0;x<200;x++)
       
   124 			{
       
   125 			w.Write(_L("Hello world\r\n"));
       
   126 			}
       
   127 		w.Control(_L("+Visibilty"));
       
   128 		for(x=0;x<200;x++)
       
   129 			{
       
   130 			w.Write(_L("Hello world\r\n"));
       
   131 			}
       
   132 		w.Control(_L("-Visibility"));
       
   133 		}
       
   134 //	return(0);
       
   135 	}
       
   136 
       
   137 void TestGui::Test2()
       
   138 	{
       
   139 	TInt x;
       
   140 	RThread t1, t2;
       
   141 	RTest test(_L("T_WWINS"));
       
   142 	test.Title();
       
   143  	test.Start(_L("GUI Test 2\n"));
       
   144 	x=t1.Create(_L("Thread1"),Test2Window1,KDefaultStackSize,0x2000,0x2000,(TAny*)1);
       
   145 	if(x==0) t1.Resume();
       
   146 	x=t2.Create(_L("Thread2"),Test2Window2,KDefaultStackSize,0x2000,0x2000,(TAny*)2);
       
   147 	if(x==0) t2.Resume();
       
   148 	RConsole w;
       
   149 	TInt r=w.Init(_L("T_WWINS Window 3"),TSize(50,15));
       
   150 	__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
       
   151 	TConsoleKey k;
       
   152 	TKeyCode c;
       
   153 	do
       
   154 		{
       
   155 		w.Read(k);
       
   156 		c=k.Code();
       
   157 		if(c<256)
       
   158 			{
       
   159 			TText a=(TText)c;
       
   160 #if defined(_UNICODE)	// K.K
       
   161 			if (a >= 0x0061 && a <= 0x006a) a -= 0x0020;
       
   162 			else {
       
   163 				if (a >= 0x0041 && a <= 0x005a) a+= 0xff00;
       
   164 			}
       
   165 #endif	// K.K
       
   166 			TPtrC s(&a,1);
       
   167 			w.Write(s);
       
   168 			}
       
   169 		else
       
   170 			{
       
   171 			if(c==EKeyLeftArrow) w.SetCursorPosRel(TPoint(-1,0));
       
   172 			if(c==EKeyRightArrow) w.SetCursorPosRel(TPoint(1,0));
       
   173 			if(c==EKeyUpArrow) w.SetCursorPosRel(TPoint(0,-1));
       
   174 			if(c==EKeyDownArrow) w.SetCursorPosRel(TPoint(0,1));
       
   175 			if(c==EKeyF1) w.Control(_L("+Cursor"));
       
   176 			if(c==EKeyF2) w.Control(_L("-Cursor"));
       
   177 			if(c==EKeyF3) w.Control(_L("+Scroll"));
       
   178 			if(c==EKeyF4) w.Control(_L("-Scroll"));
       
   179 			if(c==EKeyF5) w.Control(_L("+Lock"));
       
   180 			if(c==EKeyF6) w.Control(_L("-Lock"));
       
   181 			if(c==EKeyF7) w.Control(_L("+Wrap"));
       
   182 			if(c==EKeyF8) w.Control(_L("-Wrap"));
       
   183 			if(c==EKeyF9) w.ClearToEndOfLine();
       
   184 			}
       
   185 		} while(k.Code()!=EKeyEscape);
       
   186 	w.Close();
       
   187 	t1.Terminate(0);
       
   188 	t1.Close();
       
   189 	t2.Terminate(0);
       
   190 	t2.Close();
       
   191 	test.End();
       
   192 	}
       
   193 
       
   194 // To get some data or bss into ths program
       
   195 TInt dataMaker=0;
       
   196 
       
   197 GLDEF_C TInt E32Main()
       
   198 //
       
   199 // Test the various kernel types.
       
   200 //
       
   201     {
       
   202 	TestGui t;
       
   203 	t.Test1();
       
   204 	t.Test2();
       
   205 	return(0);
       
   206     }
       
   207 
       
   208 
       
   209