|
1 // Copyright (c) 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 <e32test.h> |
|
17 #include <featmgr.h> |
|
18 #include <featureuids.h> |
|
19 #include "featurepanics.h" |
|
20 #include <featurecontrol.h> |
|
21 #include <featurenotifier.h> |
|
22 |
|
23 using namespace NFeature; |
|
24 |
|
25 static RTest TheTest(_L("t_fmgrpanic")); |
|
26 |
|
27 _LIT(KPanicCategory, "RFeatureControl"); |
|
28 |
|
29 /////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
31 //Deletes all created test files. |
|
32 void DestroyTestEnv() |
|
33 { |
|
34 } |
|
35 |
|
36 /////////////////////////////////////////////////////////////////////////////////////// |
|
37 /////////////////////////////////////////////////////////////////////////////////////// |
|
38 //Test macros and functions |
|
39 void Check1(TInt aValue, TInt aLine) |
|
40 { |
|
41 if(!aValue) |
|
42 { |
|
43 DestroyTestEnv(); |
|
44 RDebug::Print(_L("*** Expression evaluated to false. Line %d\r\n"), aLine); |
|
45 TheTest(EFalse, aLine); |
|
46 } |
|
47 } |
|
48 void Check2(TInt aValue, TInt aExpected, TInt aLine) |
|
49 { |
|
50 if(aValue != aExpected) |
|
51 { |
|
52 DestroyTestEnv(); |
|
53 RDebug::Print(_L("*** Expected: %d, got: %d. Line %d\r\n"), aExpected, aValue, aLine); |
|
54 TheTest(EFalse, aLine); |
|
55 } |
|
56 } |
|
57 #define TEST(arg) ::Check1((arg), __LINE__) |
|
58 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
|
59 |
|
60 /////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
|
62 //Panic thread function. |
|
63 //It will cast aData parameter to a TFunctor pointer and call it. |
|
64 //The expectation is that the called function will panic and kill the panic thread. |
|
65 TInt ThreadFunc(void* aData) |
|
66 { |
|
67 CTrapCleanup* tc = CTrapCleanup::New(); |
|
68 TEST(tc != NULL); |
|
69 |
|
70 User::SetJustInTime(EFalse); // disable debugger panic handling |
|
71 |
|
72 TFunctor* obj = reinterpret_cast<TFunctor*> (aData); |
|
73 TEST(obj != NULL); |
|
74 (*obj)();//call the panic function |
|
75 |
|
76 delete tc; |
|
77 |
|
78 return KErrNone; |
|
79 } |
|
80 |
|
81 //Panic test. |
|
82 //PanicTest function will create a new thread - panic thread, giving it a pointer to the function which has to |
|
83 //be executed and the expectation is that the function will panic and kill the panic thread. |
|
84 //PanicTest function will check the panic thread exit code, exit category and the panic code. |
|
85 |
|
86 /** |
|
87 @SYMTestCaseID PDS-EFM-CT-4094 |
|
88 @SYMTestCaseDesc Include test case 4105 too |
|
89 @SYMTestPriority High |
|
90 @SYMTestActions PanicTest function will create a new thread - panic |
|
91 thread, giving it a pointer to the function which has to |
|
92 be executed and the expectation is that the function |
|
93 will panic and kill the panic thread. |
|
94 PanicTest function will check the panic thread exit code, |
|
95 exit category and the panic code. |
|
96 @SYMTestExpectedResults Test must not fail |
|
97 @SYMDEF DEF144262 |
|
98 */ |
|
99 void PanicTest(TFunctor& aFunctor, TExitType aExpectedExitType, const TDesC& aExpectedCategory, TInt aExpectedPanicCode) |
|
100 { |
|
101 RThread thread; |
|
102 _LIT(KThreadName,"FeatMgrPanicThread"); |
|
103 TEST2(thread.Create(KThreadName, &ThreadFunc, 0x2000, 0x1000, 0x10000, (void*)&aFunctor, EOwnerThread), KErrNone); |
|
104 |
|
105 TRequestStatus status; |
|
106 thread.Logon(status); |
|
107 TEST2(status.Int(), KRequestPending); |
|
108 thread.Resume(); |
|
109 User::WaitForRequest(status); |
|
110 User::SetJustInTime(ETrue); // enable debugger panic handling |
|
111 |
|
112 TEST2(thread.ExitType(), aExpectedExitType); |
|
113 TEST(thread.ExitCategory() == aExpectedCategory); |
|
114 TEST2(thread.ExitReason(), aExpectedPanicCode); |
|
115 |
|
116 CLOSE_AND_WAIT(thread); |
|
117 } |
|
118 |
|
119 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
120 ////////////////////////////// Panic test functions ///////////////////////////////////////////////// |
|
121 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
122 |
|
123 //1 Panic when calling RFeatureControl::FeatureSupported() on an invalid RFeatureControl object. |
|
124 class TFeatureControl_NotCreated_FeatureSupported1 : public TFunctor |
|
125 { |
|
126 private: |
|
127 virtual void operator()() |
|
128 { |
|
129 RFeatureControl ctrl; |
|
130 (void)ctrl.FeatureSupported(KConnectivity); |
|
131 } |
|
132 }; |
|
133 static TFeatureControl_NotCreated_FeatureSupported1 TheFeatureControl_NotCreated_FeatureSupported1; |
|
134 |
|
135 //2 Panic when calling RFeatureControl::FeatureSupported() on an invalid RFeatureControl object. |
|
136 class TFeatureControl_NotCreated_FeatureSupported2 : public TFunctor |
|
137 { |
|
138 private: |
|
139 virtual void operator()() |
|
140 { |
|
141 RFeatureControl ctrl; |
|
142 TFeatureEntry fentry; |
|
143 (void)ctrl.FeatureSupported(fentry); |
|
144 } |
|
145 }; |
|
146 static TFeatureControl_NotCreated_FeatureSupported2 TheFeatureControl_NotCreated_FeatureSupported2; |
|
147 |
|
148 //Panic when calling RFeatureControl::FeaturesSupported() on an invalid RFeatureControl object. |
|
149 class TFeatureControl_NotCreated_FeaturesSupported : public TFunctor |
|
150 { |
|
151 private: |
|
152 virtual void operator()() |
|
153 { |
|
154 RFeatureControl ctrl; |
|
155 RFeatureArray farray; |
|
156 TFeatureEntry fentry; |
|
157 TInt err = farray.Append(fentry); |
|
158 TEST2(err, KErrNone); |
|
159 (void)ctrl.FeaturesSupported(farray); |
|
160 } |
|
161 }; |
|
162 static TFeatureControl_NotCreated_FeaturesSupported TheFeatureControl_NotCreated_FeaturesSupported; |
|
163 |
|
164 //Panic when calling RFeatureControl::EnableFeature() on an invalid RFeatureControl object. |
|
165 class TFeatureControl_NotCreated_EnableFeature : public TFunctor |
|
166 { |
|
167 private: |
|
168 virtual void operator()() |
|
169 { |
|
170 RFeatureControl ctrl; |
|
171 (void)ctrl.EnableFeature(KConnectivity); |
|
172 } |
|
173 }; |
|
174 static TFeatureControl_NotCreated_EnableFeature TheFeatureControl_NotCreated_EnableFeature; |
|
175 |
|
176 //Panic when calling RFeatureControl::DisableFeature() on an invalid RFeatureControl object. |
|
177 class TFeatureControl_NotCreated_DisableFeature : public TFunctor |
|
178 { |
|
179 private: |
|
180 virtual void operator()() |
|
181 { |
|
182 RFeatureControl ctrl; |
|
183 (void)ctrl.DisableFeature(KConnectivity); |
|
184 } |
|
185 }; |
|
186 static TFeatureControl_NotCreated_DisableFeature TheFeatureControl_NotCreated_DisableFeature; |
|
187 |
|
188 //1 Panic when calling RFeatureControl::SetFeature() on an invalid RFeatureControl object. |
|
189 class TFeatureControl_NotCreated_SetFeature1 : public TFunctor |
|
190 { |
|
191 private: |
|
192 virtual void operator()() |
|
193 { |
|
194 RFeatureControl ctrl; |
|
195 (void)ctrl.SetFeature(KConnectivity, EFalse, 0); |
|
196 } |
|
197 }; |
|
198 static TFeatureControl_NotCreated_SetFeature1 TheFeatureControl_NotCreated_SetFeature1; |
|
199 |
|
200 //2 Panic when calling RFeatureControl::SetFeature() on an invalid RFeatureControl object. |
|
201 class TFeatureControl_NotCreated_SetFeature2 : public TFunctor |
|
202 { |
|
203 private: |
|
204 virtual void operator()() |
|
205 { |
|
206 RFeatureControl ctrl; |
|
207 (void)ctrl.SetFeature(KConnectivity, 0); |
|
208 } |
|
209 }; |
|
210 static TFeatureControl_NotCreated_SetFeature2 TheFeatureControl_NotCreated_SetFeature2; |
|
211 |
|
212 //Panic when calling RFeatureControl::AddFeature() on an invalid RFeatureControl object. |
|
213 class TFeatureControl_NotCreated_AddFeature : public TFunctor |
|
214 { |
|
215 private: |
|
216 virtual void operator()() |
|
217 { |
|
218 RFeatureControl ctrl; |
|
219 TFeatureEntry fentry; |
|
220 (void)ctrl.AddFeature(fentry); |
|
221 } |
|
222 }; |
|
223 static TFeatureControl_NotCreated_AddFeature TheFeatureControl_NotCreated_AddFeature; |
|
224 |
|
225 //Panic when calling RFeatureControl::DeleteFeature() on an invalid RFeatureControl object. |
|
226 class TFeatureControl_NotCreated_DeleteFeature : public TFunctor |
|
227 { |
|
228 private: |
|
229 virtual void operator()() |
|
230 { |
|
231 RFeatureControl ctrl; |
|
232 (void)ctrl.DeleteFeature(KConnectivity); |
|
233 } |
|
234 }; |
|
235 static TFeatureControl_NotCreated_DeleteFeature TheFeatureControl_NotCreated_DeleteFeature; |
|
236 |
|
237 //Panic when calling RFeatureControl::ListSupportedFeatures() on an invalid RFeatureControl object. |
|
238 class TFeatureControl_NotCreated_ListSupportedFeatures : public TFunctor |
|
239 { |
|
240 private: |
|
241 virtual void operator()() |
|
242 { |
|
243 RFeatureControl ctrl; |
|
244 RFeatureUidArray farray; |
|
245 (void)ctrl.ListSupportedFeatures(farray); |
|
246 } |
|
247 }; |
|
248 static TFeatureControl_NotCreated_ListSupportedFeatures TheFeatureControl_NotCreated_ListSupportedFeatures; |
|
249 |
|
250 //Panic when calling RFeatureControl::SWIStart() on an invalid RFeatureControl object. |
|
251 class TFeatureControl_NotCreated_SWIStart : public TFunctor |
|
252 { |
|
253 private: |
|
254 virtual void operator()() |
|
255 { |
|
256 RFeatureControl ctrl; |
|
257 (void)ctrl.SWIStart(); |
|
258 } |
|
259 }; |
|
260 static TFeatureControl_NotCreated_SWIStart TheFeatureControl_NotCreated_SWIStart; |
|
261 |
|
262 //Panic when calling RFeatureControl::SWIEnd() on an invalid RFeatureControl object. |
|
263 class TFeatureControl_NotCreated_SWIEnd : public TFunctor |
|
264 { |
|
265 private: |
|
266 virtual void operator()() |
|
267 { |
|
268 RFeatureControl ctrl; |
|
269 (void)ctrl.SWIEnd(); |
|
270 } |
|
271 }; |
|
272 static TFeatureControl_NotCreated_SWIEnd TheFeatureControl_NotCreated_SWIEnd; |
|
273 |
|
274 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
275 |
|
276 void DoTestsL() |
|
277 { |
|
278 TheTest.Start(_L("@SYMTestCaseID:PDS-EFM-CT-4094 RFeatureControl::FeatureSupported() panic test 1")); |
|
279 PanicTest(TheFeatureControl_NotCreated_FeatureSupported1, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
280 |
|
281 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4095 RFeatureControl::FeatureSupported() panic test 2")); |
|
282 PanicTest(TheFeatureControl_NotCreated_FeatureSupported2, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
283 |
|
284 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4096 RFeatureControl::FeaturesSupported() panic test")); |
|
285 PanicTest(TheFeatureControl_NotCreated_FeaturesSupported, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
286 |
|
287 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4097 RFeatureControl::EnableFeature() panic test")); |
|
288 PanicTest(TheFeatureControl_NotCreated_EnableFeature, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
289 |
|
290 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4098 RFeatureControl::DisableFeature() panic test")); |
|
291 PanicTest(TheFeatureControl_NotCreated_DisableFeature, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
292 |
|
293 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4099 RFeatureControl::SetFeature() panic test 1")); |
|
294 PanicTest(TheFeatureControl_NotCreated_SetFeature1, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
295 |
|
296 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4100 RFeatureControl::SetFeature() panic test 2")); |
|
297 PanicTest(TheFeatureControl_NotCreated_SetFeature2, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
298 |
|
299 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4101 RFeatureControl::AddFeature() panic test")); |
|
300 PanicTest(TheFeatureControl_NotCreated_AddFeature, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
301 |
|
302 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4102 RFeatureControl::DeleteFeature() panic test")); |
|
303 PanicTest(TheFeatureControl_NotCreated_DeleteFeature, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
304 |
|
305 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4103 RFeatureControl::ListSupportedFeatures() panic test")); |
|
306 PanicTest(TheFeatureControl_NotCreated_ListSupportedFeatures, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
307 |
|
308 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4104 RFeatureControl::SWIStart() panic test")); |
|
309 PanicTest(TheFeatureControl_NotCreated_SWIStart, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
310 |
|
311 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4105 RFeatureControl::SWIEnd() panic test")); |
|
312 PanicTest(TheFeatureControl_NotCreated_SWIEnd, EExitPanic, KPanicCategory, EPanicBadHandle); |
|
313 } |
|
314 |
|
315 TInt E32Main() |
|
316 { |
|
317 TheTest.Title(); |
|
318 |
|
319 CTrapCleanup* tc = CTrapCleanup::New(); |
|
320 TheTest(tc != NULL); |
|
321 |
|
322 __UHEAP_MARK; |
|
323 |
|
324 TRAPD(err, DoTestsL()); |
|
325 DestroyTestEnv(); |
|
326 TEST2(err, KErrNone); |
|
327 |
|
328 __UHEAP_MARKEND; |
|
329 |
|
330 TheTest.End(); |
|
331 TheTest.Close(); |
|
332 |
|
333 delete tc; |
|
334 |
|
335 User::Heap().Check(); |
|
336 return KErrNone; |
|
337 } |