1 // Copyright (c) 2007-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 "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 // |
|
15 |
|
16 #include "tavsrcConsole.h" |
|
17 #include "tavsrc.h" |
|
18 |
|
19 #include <e32test.h> |
|
20 |
|
21 #if defined (__WINS__) |
|
22 #define PDD_NAME _L("ECDRV") |
|
23 #define LDD_NAME _L("ECOMM") |
|
24 #else // __GCC32__ |
|
25 #define PDD_NAME _L("EUART1") |
|
26 #define LDD_NAME _L("ECOMM") |
|
27 #endif |
|
28 |
|
29 static RTest testOutcome(_L("Test results")); |
|
30 |
|
31 CActiveConsole::CActiveConsole(MActiveConsoleNotify& aNotify) |
|
32 : CActive(EPriorityStandard), iNotify(aNotify) |
|
33 { |
|
34 CActiveScheduler::Add(this); |
|
35 } |
|
36 |
|
37 |
|
38 CActiveConsole::~CActiveConsole() |
|
39 { |
|
40 Cancel(); |
|
41 delete iConsole; |
|
42 } |
|
43 |
|
44 CActiveConsole* CActiveConsole::NewL(MActiveConsoleNotify& aNotify,const TDesC& aTitle,const TSize& aSize) |
|
45 { |
|
46 CActiveConsole* console = new (ELeave) CActiveConsole(aNotify); |
|
47 CleanupStack::PushL(console); |
|
48 console->ConstructL(aTitle,aSize); |
|
49 CleanupStack::Pop(); |
|
50 return console; |
|
51 } |
|
52 |
|
53 void CActiveConsole::ConstructL(const TDesC& aTitle,const TSize& aSize) |
|
54 { |
|
55 iConsole = Console::NewL(aTitle,aSize); |
|
56 } |
|
57 |
|
58 void CActiveConsole::DoCancel() |
|
59 { |
|
60 iConsole->ReadCancel(); |
|
61 } |
|
62 |
|
63 void CActiveConsole::RequestKey() |
|
64 { |
|
65 DrawCursor(); |
|
66 iConsole->Read(iStatus); |
|
67 SetActive(); |
|
68 } |
|
69 |
|
70 void CActiveConsole::DrawCursor() |
|
71 { |
|
72 iConsole->Printf(_L(">>")); |
|
73 } |
|
74 |
|
75 void CActiveConsole::RunL() |
|
76 { |
|
77 // key has been pressed |
|
78 TChar ch = iConsole->KeyCode(); |
|
79 iNotify.KeyPressed(ch); |
|
80 } |
|
81 |
|
82 TInt CActiveConsole::RunError(TInt aError) |
|
83 { |
|
84 iConsole->Printf(_L("Console error %d\nTrying again...\n"), aError); |
|
85 RequestKey(); |
|
86 return KErrNone; |
|
87 } |
|
88 |
|
89 TInt CActiveConsole::GetIntFromUser() |
|
90 { |
|
91 TBool requeRead = EFalse; |
|
92 if(IsActive()) |
|
93 { |
|
94 Cancel(); |
|
95 requeRead = ETrue; |
|
96 } |
|
97 |
|
98 TKeyCode key; |
|
99 |
|
100 TBuf<10> intBuf; |
|
101 |
|
102 while((key = iConsole->Getch())!=EKeyEnter) |
|
103 { |
|
104 if(key == EKeyBackspace&&intBuf.Length()!=0) |
|
105 { |
|
106 intBuf.SetLength(intBuf.Length()-1); |
|
107 iConsole->Printf(_L("%c"), key); |
|
108 } |
|
109 else if ( intBuf.Length() < intBuf.MaxLength()) |
|
110 { |
|
111 intBuf.Append(key); |
|
112 iConsole->Printf(_L("%c"), key); |
|
113 } |
|
114 } |
|
115 |
|
116 iConsole->Printf(_L("\n")); |
|
117 |
|
118 TLex lex(intBuf); |
|
119 TInt value = 0; |
|
120 |
|
121 TInt err = lex.Val(value); |
|
122 if(err) |
|
123 { |
|
124 iConsole->Printf(_L("Error %d reading value from console\n"), err); |
|
125 } |
|
126 |
|
127 if(requeRead) |
|
128 { |
|
129 RequestKey(); |
|
130 } |
|
131 return value; |
|
132 } |
|
133 |
|
134 void LoadLDD_PDDL() |
|
135 { |
|
136 TInt err = KErrNone; |
|
137 testOutcome.Printf(_L("Loading PDD... ")); |
|
138 err = User::LoadPhysicalDevice(PDD_NAME); |
|
139 if(err != KErrNone && err != KErrAlreadyExists) |
|
140 { |
|
141 User::Leave(err); |
|
142 } |
|
143 testOutcome.Printf(_L("Loading LDD... ")); |
|
144 err = User::LoadLogicalDevice(LDD_NAME); |
|
145 if(err != KErrNone && err != KErrAlreadyExists) |
|
146 { |
|
147 User::Leave(err); |
|
148 } |
|
149 } |
|
150 |
|
151 void StartL() |
|
152 { |
|
153 LoadLDD_PDDL(); |
|
154 |
|
155 CAVTestApp* app = CAVTestApp::NewL(); |
|
156 app->StartL(); |
|
157 |
|
158 delete app; |
|
159 } |
|
160 |
|
161 |
|
162 TInt E32Main() |
|
163 { |
|
164 __UHEAP_MARK; |
|
165 |
|
166 CTrapCleanup* cleanupStack=CTrapCleanup::New(); // Get CleanupStack |
|
167 |
|
168 CActiveScheduler* activescheduler=new CActiveScheduler; |
|
169 CActiveScheduler::Install(activescheduler); |
|
170 |
|
171 testOutcome.Printf(_L("Starting tests... ")); |
|
172 |
|
173 TRAPD(err, StartL()); |
|
174 |
|
175 delete activescheduler; |
|
176 delete cleanupStack; |
|
177 |
|
178 testOutcome.Printf(_L("Test completed result %d"), err); |
|
179 if(err != KErrNone) |
|
180 { |
|
181 testOutcome.Getch(); |
|
182 } |
|
183 testOutcome.Close(); |
|
184 |
|
185 |
|
186 __UHEAP_MARKEND; |
|
187 |
|
188 return err ; |
|
189 } |
|
190 |
|
191 |
|