271
|
1 |
// Copyright (c) 2010 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\system\t_console.cpp
|
|
15 |
// Overview:
|
|
16 |
// Test methods of CConsoleBase, CProxyConsole and CColorConsole class.
|
|
17 |
// API Information:
|
|
18 |
// CConsoleBase.
|
|
19 |
// Details:
|
|
20 |
// - Create an object of CTestConsole class which is derived from CColorConsole.
|
|
21 |
// - Call methods of CColorConsole class with this test object.
|
|
22 |
// - Create a full screen console object of CConsoleBase.
|
|
23 |
// - Call methods of CConsoleBase class with this console object.
|
|
24 |
// Platforms/Drives/Compatibility:
|
|
25 |
// All
|
|
26 |
// Assumptions/Requirement/Pre-requisites:
|
|
27 |
// Failures and causes:
|
|
28 |
// Base Port information:
|
|
29 |
//
|
|
30 |
//
|
|
31 |
|
|
32 |
#define __E32TEST_EXTENSION__
|
|
33 |
|
|
34 |
#include <e32test.h>
|
|
35 |
#include <e32event.h>
|
|
36 |
#include <e32svr.h>
|
|
37 |
|
|
38 |
LOCAL_D RTest test(_L("T_CONSOLE"));
|
|
39 |
|
|
40 |
// Literals
|
|
41 |
_LIT(KTxtTitle,"Console App");
|
|
42 |
_LIT(KTxtNewTitle,"New Console Title");
|
|
43 |
_LIT(KTxtWrite,"Write some text ");
|
|
44 |
_LIT(KTxtPressAnyKey,"Press any key or wait 2 seconds");
|
|
45 |
|
|
46 |
// This is test class for testing methods of CColorConsoleBase
|
|
47 |
class CTestConsole : public CColorConsoleBase
|
|
48 |
{
|
|
49 |
public:
|
|
50 |
TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
|
|
51 |
{
|
|
52 |
return CColorConsoleBase::Extension_(aExtensionId, a0, a1);
|
|
53 |
}
|
|
54 |
};
|
|
55 |
|
|
56 |
// Creates an object of CTestConsole.
|
|
57 |
// Calls methods of CColorConsoleBase
|
|
58 |
LOCAL_C void InitTestConsoleL()
|
|
59 |
{
|
|
60 |
// create a full screen test console object
|
|
61 |
CTestConsole* testConsole;
|
|
62 |
testConsole = (CTestConsole*)Console::NewL(KTxtTitle, TSize(KConsFullScreen,KConsFullScreen));
|
|
63 |
|
|
64 |
CleanupStack::PushL(testConsole);
|
|
65 |
|
|
66 |
// Defines the bold text attribute.
|
|
67 |
testConsole->SetTextAttribute(ETextAttributeBold);
|
|
68 |
testConsole->Write(KTxtWrite);
|
|
69 |
// Defines the inverse text attribute.
|
|
70 |
testConsole->SetTextAttribute(ETextAttributeInverse);
|
|
71 |
testConsole->Write(KTxtWrite);
|
|
72 |
// Defines the highlight text attribute.
|
|
73 |
testConsole->SetTextAttribute(ETextAttributeHighlight);
|
|
74 |
testConsole->Write(KTxtWrite);
|
|
75 |
// Defines the normal text attribute.
|
|
76 |
testConsole->SetTextAttribute(ETextAttributeNormal);
|
|
77 |
testConsole->Write(KTxtWrite);
|
|
78 |
|
|
79 |
TInt a1 = 0;
|
|
80 |
TAny* any = 0;
|
|
81 |
testConsole->Extension_((TUint)a1,any,any);
|
|
82 |
|
|
83 |
// cleanup and return
|
|
84 |
CleanupStack::PopAndDestroy(); // close console
|
|
85 |
}
|
|
86 |
|
|
87 |
LOCAL_C void SimulateKeyPress(TStdScanCode aScanCode)
|
|
88 |
{
|
|
89 |
TRawEvent eventDown;
|
|
90 |
eventDown.Set(TRawEvent::EKeyDown, aScanCode);
|
|
91 |
UserSvr::AddEvent(eventDown);
|
|
92 |
TRawEvent eventUp;
|
|
93 |
eventUp.Set(TRawEvent::EKeyUp, aScanCode);
|
|
94 |
UserSvr::AddEvent(eventUp);
|
|
95 |
}
|
|
96 |
|
|
97 |
LOCAL_C void ReadConsole(CConsoleBase* aConsole)
|
|
98 |
{
|
|
99 |
aConsole->Printf(KTxtPressAnyKey);
|
|
100 |
|
|
101 |
TRequestStatus keyStatus;
|
|
102 |
// Gets a keystroke from the console window, asynchronously
|
|
103 |
aConsole->Read(keyStatus);
|
|
104 |
RTimer timer;
|
|
105 |
test_KErrNone(timer.CreateLocal());
|
|
106 |
TRequestStatus timerStatus;
|
|
107 |
timer.After(timerStatus,2*1000000);
|
|
108 |
User::WaitForRequest(timerStatus,keyStatus);
|
|
109 |
if(keyStatus!=KRequestPending)
|
|
110 |
{
|
|
111 |
TKeyCode keyCode = aConsole->KeyCode();
|
|
112 |
aConsole->Printf(_L("Keycode %d\n"),keyCode);
|
|
113 |
}
|
|
114 |
timer.Cancel();
|
|
115 |
// Cancels any outstanding request
|
|
116 |
aConsole->ReadCancel();
|
|
117 |
User::WaitForAnyRequest();
|
|
118 |
}
|
|
119 |
|
|
120 |
LOCAL_C void InitConsoleL()
|
|
121 |
{
|
|
122 |
// create a full screen console object
|
|
123 |
CConsoleBase* console;
|
|
124 |
console = Console::NewL(KTxtTitle, TSize(KConsFullScreen,KConsFullScreen));
|
|
125 |
|
|
126 |
CleanupStack::PushL(console);
|
|
127 |
|
|
128 |
//Gets the size of the console
|
|
129 |
TSize screenSize = console->ScreenSize();
|
|
130 |
test.Printf(_L("Screen size %d %d\r\n"),screenSize.iWidth,screenSize.iHeight);
|
|
131 |
|
|
132 |
// Gets the cursor's x-position
|
|
133 |
TInt x = console->WhereX();
|
|
134 |
// Gets the cursor's y-position
|
|
135 |
TInt y = console->WhereY();
|
|
136 |
test_Equal(x, 0);
|
|
137 |
test_Equal(y, 0);
|
|
138 |
test.Printf(_L("**1** Cursor positions x: %d y: %d\r\n"),x, y);
|
|
139 |
|
|
140 |
// Sets the cursor's x-position
|
|
141 |
for(TInt i=0; i<4; i++)
|
|
142 |
{
|
|
143 |
console->SetPos(screenSize.iWidth + i);
|
|
144 |
x = console->WhereX();
|
|
145 |
test_Equal(x, screenSize.iWidth -3);
|
|
146 |
}
|
|
147 |
|
|
148 |
test.Printf(_L("**2** Cursor positions x: %d y: %d\r\n"),x, y);
|
|
149 |
|
|
150 |
// Clears the console and set cursor to position 0,0
|
|
151 |
console->ClearScreen();
|
|
152 |
test_Equal(console->WhereX(), 0);
|
|
153 |
test_Equal(console->WhereY(), 0);
|
|
154 |
|
|
155 |
// Sets the cursor's x-position and y-position
|
|
156 |
for(TInt j=0; j<4; j++)
|
|
157 |
{
|
|
158 |
console->SetPos(screenSize.iWidth - j, screenSize.iHeight - j);
|
|
159 |
x = console->WhereX();
|
|
160 |
y = console->WhereY();
|
|
161 |
test_Equal(x, screenSize.iWidth -3);
|
|
162 |
test_Equal(y, screenSize.iHeight -3);
|
|
163 |
}
|
|
164 |
test.Printf(_L("**3** Cursor positions x: %d y: %d\r\n"),x, y);
|
|
165 |
|
|
166 |
console->SetPos(0,0);
|
|
167 |
x = console->WhereX();
|
|
168 |
y = console->WhereY();
|
|
169 |
test_Equal(x, 0);
|
|
170 |
test_Equal(y, 0);
|
|
171 |
test.Printf(_L("**4** Cursor positions x: %d y: %d\r\n"),x, y);
|
|
172 |
|
|
173 |
console->SetPos(screenSize.iWidth/2,screenSize.iHeight/2);
|
|
174 |
x = console->WhereX();
|
|
175 |
y = console->WhereY();
|
|
176 |
test.Printf(_L("**5** Cursor positions x: %d y: %d\r\n"),x, y);
|
|
177 |
|
|
178 |
// Sets the percentage height of the cursor
|
|
179 |
console->SetCursorHeight(50);
|
|
180 |
|
|
181 |
// Gets the current cursor position relative to the console window
|
|
182 |
TPoint cursorPos = console->CursorPos();
|
|
183 |
test.Printf(_L("CursorPos iX: %d iY: %d\r\n"),cursorPos.iX, cursorPos.iY);
|
|
184 |
|
|
185 |
// Puts the cursor at the specified position relative
|
|
186 |
// to the current cursor position
|
|
187 |
TPoint relPos;
|
|
188 |
relPos.iX = screenSize.iWidth/4;
|
|
189 |
relPos.iY = screenSize.iHeight/4;
|
|
190 |
console->SetCursorPosRel(relPos);
|
|
191 |
cursorPos = console->CursorPos();
|
|
192 |
test.Printf(_L("CursorPosRel iX: %d iY: %d\r\n"),cursorPos.iX, cursorPos.iY);
|
|
193 |
|
|
194 |
// Puts the cursor at the absolute position in the window
|
|
195 |
cursorPos.iX = screenSize.iWidth/6;
|
|
196 |
cursorPos.iY = screenSize.iHeight/6;
|
|
197 |
console->SetCursorPosAbs(cursorPos);
|
|
198 |
cursorPos = console->CursorPos();
|
|
199 |
test.Printf(_L("CursorPosAbs iX: %d iY: %d\r\n"),cursorPos.iX, cursorPos.iY);
|
|
200 |
|
|
201 |
// Sets a new console title
|
|
202 |
console->SetTitle(KTxtNewTitle);
|
|
203 |
// Writes the content of the specified descriptor to the console window
|
|
204 |
console->Write(KTxtWrite);
|
|
205 |
cursorPos.iX = cursorPos.iX + 6;
|
|
206 |
console->SetCursorPosAbs(cursorPos);
|
|
207 |
// Clears the console from the current cursor position to the end of the line
|
|
208 |
console->ClearToEndOfLine();
|
|
209 |
// Clears the console and set cursor to position 0,0
|
|
210 |
console->ClearScreen();
|
|
211 |
|
|
212 |
TUint keyModifiers = console->KeyModifiers();
|
|
213 |
test.Printf(_L("keyModifiers %d"),keyModifiers);
|
|
214 |
TKeyCode keyCode = console->KeyCode();
|
|
215 |
ReadConsole(console);
|
|
216 |
|
|
217 |
SimulateKeyPress(EStdKeyEnter);
|
|
218 |
keyCode = console->Getch();
|
|
219 |
|
|
220 |
// cleanup and return
|
|
221 |
CleanupStack::PopAndDestroy(); // close console
|
|
222 |
}
|
|
223 |
|
|
224 |
TInt E32Main()
|
|
225 |
//
|
|
226 |
//
|
|
227 |
//
|
|
228 |
{
|
|
229 |
test.Title();
|
|
230 |
__UHEAP_MARK;
|
|
231 |
|
|
232 |
test.Start(_L("Testing Console"));
|
|
233 |
// Get cleanup stack
|
|
234 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
235 |
TInt result = KErrNoMemory;
|
|
236 |
if (cleanup)
|
|
237 |
{
|
|
238 |
TRAP(result, InitTestConsoleL());
|
|
239 |
TRAP(result, InitConsoleL());
|
|
240 |
// Destroy the cleanup stack
|
|
241 |
delete cleanup;
|
|
242 |
}
|
|
243 |
__UHEAP_MARKEND;
|
|
244 |
test.End();
|
|
245 |
return(result);
|
|
246 |
}
|
|
247 |
|