sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Started by DWW, April 1997
|
sl@0
|
15 |
// Tests active scheduler
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32test.h>
|
sl@0
|
20 |
#include <basched.h>
|
sl@0
|
21 |
#include <baerror.h>
|
sl@0
|
22 |
#include <baerrhan.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
#define KUidTestValue 0x43
|
sl@0
|
25 |
const TUid KUidTest={KUidTestValue};
|
sl@0
|
26 |
|
sl@0
|
27 |
LOCAL_D RTest test(_L("T_SCHED"));
|
sl@0
|
28 |
|
sl@0
|
29 |
class CSimpleErrorHandler : public CBaErrorHandler
|
sl@0
|
30 |
{
|
sl@0
|
31 |
private:
|
sl@0
|
32 |
TErrorHandlerResponse HandleError(TDes& aErrorText,TDes& aContextText);
|
sl@0
|
33 |
};
|
sl@0
|
34 |
|
sl@0
|
35 |
class CErrorHandlerWithState : public CBaErrorHandler
|
sl@0
|
36 |
{
|
sl@0
|
37 |
public:
|
sl@0
|
38 |
void SetState(TInt aState) { iState=aState; }
|
sl@0
|
39 |
private:
|
sl@0
|
40 |
TErrorHandlerResponse HandleError(TDes& aErrorText,TDes& aContextText);
|
sl@0
|
41 |
private:
|
sl@0
|
42 |
TInt iState;
|
sl@0
|
43 |
};
|
sl@0
|
44 |
|
sl@0
|
45 |
TErrorHandlerResponse CSimpleErrorHandler::HandleError(TDes& aErrorText,TDes& aContextText)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
aErrorText=_L("ERROR");
|
sl@0
|
48 |
aContextText=_L("CONTEXT");
|
sl@0
|
49 |
return(EAlertDisplay);
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
TErrorHandlerResponse CErrorHandlerWithState::HandleError(TDes& aErrorText,TDes& aContextText)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
aErrorText.Num(iState);
|
sl@0
|
55 |
aContextText.Zero();
|
sl@0
|
56 |
return(iState? EInfoDisplay: ENoDisplay);
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
class CTestScheduler : public CBaActiveScheduler
|
sl@0
|
60 |
{
|
sl@0
|
61 |
private: // from CBaActiveScheduler
|
sl@0
|
62 |
void DisplayError(TInt aError);
|
sl@0
|
63 |
private:
|
sl@0
|
64 |
TInt iState;
|
sl@0
|
65 |
};
|
sl@0
|
66 |
|
sl@0
|
67 |
class CTestActive : public CActive
|
sl@0
|
68 |
{
|
sl@0
|
69 |
public:
|
sl@0
|
70 |
static CTestActive* NewL();
|
sl@0
|
71 |
private:
|
sl@0
|
72 |
CTestActive();
|
sl@0
|
73 |
~CTestActive();
|
sl@0
|
74 |
void DoCancel();
|
sl@0
|
75 |
void RunL();
|
sl@0
|
76 |
void Queue();
|
sl@0
|
77 |
private:
|
sl@0
|
78 |
TInt iState;
|
sl@0
|
79 |
CSimpleErrorHandler iSimpleErrorHandler;
|
sl@0
|
80 |
CErrorHandlerWithState iComplexErrorHandler;
|
sl@0
|
81 |
};
|
sl@0
|
82 |
|
sl@0
|
83 |
CTestActive::CTestActive()
|
sl@0
|
84 |
: CActive(0)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
CTestActive::~CTestActive()
|
sl@0
|
89 |
{
|
sl@0
|
90 |
Cancel();
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
CTestActive* CTestActive::NewL()
|
sl@0
|
94 |
{ // static
|
sl@0
|
95 |
CTestActive* self=new(ELeave) CTestActive;
|
sl@0
|
96 |
CActiveScheduler::Add(self);
|
sl@0
|
97 |
self->Queue();
|
sl@0
|
98 |
return(self);
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
void CTestActive::Queue()
|
sl@0
|
102 |
{
|
sl@0
|
103 |
TRequestStatus* pS=(&iStatus);
|
sl@0
|
104 |
User::RequestComplete(pS,0);
|
sl@0
|
105 |
SetActive();
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
void CTestActive::DoCancel()
|
sl@0
|
109 |
{
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
void CTestActive::RunL()
|
sl@0
|
113 |
{
|
sl@0
|
114 |
Queue();
|
sl@0
|
115 |
switch (iState++)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
case 0:
|
sl@0
|
118 |
test.Next(_L("Extended error"));
|
sl@0
|
119 |
CBaActiveScheduler::DisplayExtendedError(KUidTest,66);
|
sl@0
|
120 |
test.Next(_L("Leave for alert"));
|
sl@0
|
121 |
CBaActiveScheduler::LeaveForAlert(KUidBaflDll,77);
|
sl@0
|
122 |
CBaActiveScheduler::DisplayExtendedError(KUidTest,88); // won't reach here
|
sl@0
|
123 |
break;
|
sl@0
|
124 |
case 1:
|
sl@0
|
125 |
test.Next(_L("Leave"));
|
sl@0
|
126 |
User::Leave(-22);
|
sl@0
|
127 |
CBaActiveScheduler::DisplayExtendedError(KUidBaflDll,9); // won't reach here
|
sl@0
|
128 |
break;
|
sl@0
|
129 |
case 2:
|
sl@0
|
130 |
test.Next(_L("Leave no alert"));
|
sl@0
|
131 |
CBaActiveScheduler::LeaveNoAlert();
|
sl@0
|
132 |
CBaActiveScheduler::DisplayExtendedError(KUidTest,55); // won't reach here
|
sl@0
|
133 |
break;
|
sl@0
|
134 |
case 3:
|
sl@0
|
135 |
test.Next(_L("Extended error again"));
|
sl@0
|
136 |
CBaActiveScheduler::DisplayExtendedError(KUidBaflDll,33);
|
sl@0
|
137 |
test.Next(_L("Leave for info print"));
|
sl@0
|
138 |
CBaActiveScheduler::LeaveForInfoPrint(KUidTest,11);
|
sl@0
|
139 |
CBaActiveScheduler::DisplayExtendedError(KUidBaflDll,88); // won't reach here
|
sl@0
|
140 |
break;
|
sl@0
|
141 |
case 4:
|
sl@0
|
142 |
test.Next(_L("Simple error handler"));
|
sl@0
|
143 |
CBaActiveScheduler::LeaveForErrorHandler(&iSimpleErrorHandler);
|
sl@0
|
144 |
CBaActiveScheduler::DisplayExtendedError(KUidBaflDll,87); // won't reach here
|
sl@0
|
145 |
break;
|
sl@0
|
146 |
case 5:
|
sl@0
|
147 |
test.Next(_L("Complex error handler - 1"));
|
sl@0
|
148 |
CBaActiveScheduler::LeaveForErrorHandler(&iComplexErrorHandler);
|
sl@0
|
149 |
CBaActiveScheduler::DisplayExtendedError(KUidBaflDll,86); // won't reach here
|
sl@0
|
150 |
break;
|
sl@0
|
151 |
case 6:
|
sl@0
|
152 |
test.Next(_L("Complex error handler - 2"));
|
sl@0
|
153 |
iComplexErrorHandler.SetState(6);
|
sl@0
|
154 |
CBaActiveScheduler::LeaveForErrorHandler(&iComplexErrorHandler);
|
sl@0
|
155 |
CBaActiveScheduler::DisplayExtendedError(KUidBaflDll,85); // won't reach here
|
sl@0
|
156 |
break;
|
sl@0
|
157 |
case 7:
|
sl@0
|
158 |
test.Next(_L("Exit"));
|
sl@0
|
159 |
CBaActiveScheduler::Exit();
|
sl@0
|
160 |
CBaActiveScheduler::DisplayExtendedError(KUidBaflDll,99); // won't reach here
|
sl@0
|
161 |
break;
|
sl@0
|
162 |
case 8:
|
sl@0
|
163 |
CBaActiveScheduler::DisplayExtendedError(KUidBaflDll,999); // won't reach here
|
sl@0
|
164 |
break;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
void CTestScheduler::DisplayError(TInt aError)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
TBuf<80> errorText;
|
sl@0
|
171 |
TBuf<80> contextText;
|
sl@0
|
172 |
TErrorHandlerResponse resp;
|
sl@0
|
173 |
switch (iState++)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
case 0:
|
sl@0
|
176 |
test(aError==KErrExtended);
|
sl@0
|
177 |
test(iExtendedError.iComponent==KUidTest);
|
sl@0
|
178 |
test(iExtendedError.iErrorNumber==66);
|
sl@0
|
179 |
test(iExtendedError.iInformation==EFalse);
|
sl@0
|
180 |
break;
|
sl@0
|
181 |
case 1:
|
sl@0
|
182 |
test(aError==KErrExtended);
|
sl@0
|
183 |
test(iExtendedError.iComponent==KUidBaflDll);
|
sl@0
|
184 |
test(iExtendedError.iErrorNumber==77);
|
sl@0
|
185 |
test(iExtendedError.iInformation==EFalse);
|
sl@0
|
186 |
break;
|
sl@0
|
187 |
case 2:
|
sl@0
|
188 |
test(aError==-22);
|
sl@0
|
189 |
break;
|
sl@0
|
190 |
case 3:
|
sl@0
|
191 |
test(aError==KErrExtended);
|
sl@0
|
192 |
test(iExtendedError.iComponent==KUidBaflDll);
|
sl@0
|
193 |
test(iExtendedError.iErrorNumber==33);
|
sl@0
|
194 |
test(iExtendedError.iInformation==EFalse);
|
sl@0
|
195 |
break;
|
sl@0
|
196 |
case 4:
|
sl@0
|
197 |
test(aError==KErrExtended);
|
sl@0
|
198 |
test(iExtendedError.iComponent==KUidTest);
|
sl@0
|
199 |
test(iExtendedError.iErrorNumber==11);
|
sl@0
|
200 |
test(iExtendedError.iInformation);
|
sl@0
|
201 |
break;
|
sl@0
|
202 |
case 5:
|
sl@0
|
203 |
test(aError==KErrExtended);
|
sl@0
|
204 |
test(iExtendedError.iComponent==KUidBaflErrorHandler);
|
sl@0
|
205 |
resp=CBaErrorHandler::CallBack(iExtendedError.iErrorNumber,errorText,contextText);
|
sl@0
|
206 |
test(resp==EAlertDisplay);
|
sl@0
|
207 |
test(errorText==_L("ERROR"));
|
sl@0
|
208 |
test(contextText==_L("CONTEXT"));
|
sl@0
|
209 |
break;
|
sl@0
|
210 |
case 6:
|
sl@0
|
211 |
test(aError==KErrExtended);
|
sl@0
|
212 |
test(iExtendedError.iComponent==KUidBaflErrorHandler);
|
sl@0
|
213 |
resp=CBaErrorHandler::CallBack(iExtendedError.iErrorNumber,errorText,contextText);
|
sl@0
|
214 |
test(resp==ENoDisplay);
|
sl@0
|
215 |
test(errorText==_L("0"));
|
sl@0
|
216 |
test(!contextText.Length());
|
sl@0
|
217 |
break;
|
sl@0
|
218 |
case 7:
|
sl@0
|
219 |
test(aError==KErrExtended);
|
sl@0
|
220 |
test(iExtendedError.iComponent==KUidBaflErrorHandler);
|
sl@0
|
221 |
resp=CBaErrorHandler::CallBack(iExtendedError.iErrorNumber,errorText,contextText);
|
sl@0
|
222 |
test(resp==EInfoDisplay);
|
sl@0
|
223 |
test(errorText==_L("6"));
|
sl@0
|
224 |
test(!contextText.Length());
|
sl@0
|
225 |
break;
|
sl@0
|
226 |
case 8:
|
sl@0
|
227 |
test(EFalse); // should never reach here
|
sl@0
|
228 |
}
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
/**
|
sl@0
|
232 |
@SYMTestCaseID SYSLIB-BAFL-CT-0442
|
sl@0
|
233 |
@SYMTestCaseDesc Tests for the Active Scheduler
|
sl@0
|
234 |
@SYMTestPriority High
|
sl@0
|
235 |
@SYMTestActions Tests for the functionality of ActiveScheduler
|
sl@0
|
236 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
237 |
@SYMREQ REQ0000
|
sl@0
|
238 |
*/
|
sl@0
|
239 |
void DoTests()
|
sl@0
|
240 |
{
|
sl@0
|
241 |
test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0442 "));
|
sl@0
|
242 |
CActiveScheduler* as=new(ELeave) CTestScheduler;
|
sl@0
|
243 |
CActiveScheduler::Install(as);
|
sl@0
|
244 |
CActive* ac=CTestActive::NewL();
|
sl@0
|
245 |
TRAPD(ret,as->Start());
|
sl@0
|
246 |
test(ret==KLeaveExit);
|
sl@0
|
247 |
delete(as);
|
sl@0
|
248 |
delete(ac);
|
sl@0
|
249 |
}
|
sl@0
|
250 |
|
sl@0
|
251 |
GLDEF_C TInt E32Main()
|
sl@0
|
252 |
{
|
sl@0
|
253 |
__UHEAP_MARK;
|
sl@0
|
254 |
CTrapCleanup *cleanup=CTrapCleanup::New();
|
sl@0
|
255 |
test.Title();
|
sl@0
|
256 |
test.Start(_L("Testing CBaActiveScheduler"));
|
sl@0
|
257 |
TRAPD(err,DoTests());
|
sl@0
|
258 |
test(err==KErrNone);
|
sl@0
|
259 |
test.End();
|
sl@0
|
260 |
test.Close();
|
sl@0
|
261 |
delete cleanup;
|
sl@0
|
262 |
__UHEAP_MARKEND;
|
sl@0
|
263 |
return(0);
|
sl@0
|
264 |
}
|