|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 */ |
|
22 |
|
23 #include "tdaemonstep.h" |
|
24 |
|
25 |
|
26 namespace Swi |
|
27 { |
|
28 namespace Test |
|
29 { |
|
30 |
|
31 /** |
|
32 * Checked version of GetIntFromConfigL. Leaves with KErrConfigRead, and logs a message if an error occurs. |
|
33 * |
|
34 * @see CTestStep::GetIntFromConfig |
|
35 */ |
|
36 TBool CDaemonTestStep::CheckedGetIntFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult) |
|
37 { |
|
38 TBool result=GetIntFromConfig(aSectName,aKeyName,aResult); |
|
39 |
|
40 if (EFalse==result) |
|
41 { |
|
42 _LIT(KLogFormat,"Error reading int %S, from config section %S"); |
|
43 ERR_PRINTF3(KLogFormat, &aKeyName, &aSectName); |
|
44 |
|
45 User::Leave(KErrConfigRead); |
|
46 } |
|
47 |
|
48 return result; |
|
49 } |
|
50 |
|
51 /** |
|
52 * Checked version of GetStringFromConfigL. Leaves with KErrConfigRead, and logs a message if an error occurs. |
|
53 * |
|
54 * @see CTestStep::GetStringFromConfig |
|
55 */ |
|
56 TBool CDaemonTestStep::CheckedGetStringFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult) |
|
57 { |
|
58 TBool result=GetStringFromConfig(aSectName,aKeyName,aResult); |
|
59 |
|
60 if (EFalse==result) |
|
61 { |
|
62 _LIT(KLogFormat,"Error reading string %S, from config section %S"); |
|
63 ERR_PRINTF3(KLogFormat, &aKeyName, &aSectName); |
|
64 |
|
65 User::Leave(KErrConfigRead); |
|
66 } |
|
67 |
|
68 return result; |
|
69 } |
|
70 |
|
71 /** |
|
72 * Checked version of GetBoolFromConfigL. Leaves with KErrConfigRead, and logs a message if an error occurs. |
|
73 * |
|
74 * @see CTestStep::GetBoolFromConfig |
|
75 */ |
|
76 TBool CDaemonTestStep::CheckedGetBoolFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, TBool& aResult) |
|
77 { |
|
78 TBool result=GetBoolFromConfig(aSectName,aKeyName,aResult); |
|
79 |
|
80 if (EFalse==result) |
|
81 { |
|
82 _LIT(KLogFormat,"Error reading boolean %S, from config section %S"); |
|
83 ERR_PRINTF3(KLogFormat, &aKeyName, &aSectName); |
|
84 |
|
85 User::Leave(KErrConfigRead); |
|
86 } |
|
87 |
|
88 return result; |
|
89 } |
|
90 |
|
91 /** |
|
92 * Checked version of GetIntFromConfigL. Leaves with KErrConfigRead, and logs a message if an error occurs. |
|
93 * |
|
94 * @see CTestStep::GetIntFromConfig |
|
95 */ |
|
96 TBool CDaemonTestStep::CheckedGetIntFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult, const TDesC& aObjectName) |
|
97 { |
|
98 HBufC* nameBuf=HBufC::NewLC(aObjectName.Length()+aKeyName.Length()+5); |
|
99 TPtr nameBufDes=nameBuf->Des(); |
|
100 nameBufDes.AppendFormat(_L("%S.%S"), &aObjectName, &aKeyName); |
|
101 |
|
102 TBool result=GetIntFromConfig(aSectName,nameBufDes,aResult); |
|
103 |
|
104 if (EFalse==result) |
|
105 { |
|
106 _LIT(KLogFormat,"Error reading int %S, from config section %S"); |
|
107 ERR_PRINTF3(KLogFormat, &nameBufDes, &aSectName); |
|
108 |
|
109 User::Leave(KErrConfigRead); |
|
110 } |
|
111 CleanupStack::PopAndDestroy(nameBuf); |
|
112 return result; |
|
113 } |
|
114 |
|
115 /** |
|
116 * Checked version of GetStringFromConfigL. Leaves with KErrConfigRead, and logs a message if an error occurs. |
|
117 * |
|
118 * @see CTestStep::GetStringFromConfig |
|
119 */ |
|
120 TBool CDaemonTestStep::CheckedGetStringFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult, const TDesC& aObjectName) |
|
121 { |
|
122 HBufC* nameBuf=HBufC::NewLC(aObjectName.Length()+aKeyName.Length()+5); |
|
123 TPtr nameBufDes=nameBuf->Des(); |
|
124 _LIT(KAppendFormat,"%S.%S"); |
|
125 nameBufDes.AppendFormat(KAppendFormat, &aObjectName, &aKeyName); |
|
126 |
|
127 TBool result=GetStringFromConfig(aSectName,nameBufDes,aResult); |
|
128 |
|
129 if (EFalse==result) |
|
130 { |
|
131 _LIT(KLogFormat,"Error reading string %S, from config section %S"); |
|
132 ERR_PRINTF3(KLogFormat, &nameBufDes, &aSectName); |
|
133 |
|
134 User::Leave(KErrConfigRead); |
|
135 } |
|
136 CleanupStack::PopAndDestroy(nameBuf); |
|
137 return result; |
|
138 } |
|
139 |
|
140 /** |
|
141 * Checked version of GetBoolFromConfigL. Leaves with KErrConfigRead, and logs a message if an error occurs. |
|
142 * |
|
143 * @see CTestStep::GetBoolFromConfig |
|
144 */ |
|
145 TBool CDaemonTestStep::CheckedGetBoolFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, TBool& aResult, const TDesC& aObjectName) |
|
146 { |
|
147 HBufC* nameBuf=HBufC::NewLC(aObjectName.Length()+aKeyName.Length()+5); |
|
148 TPtr nameBufDes=nameBuf->Des(); |
|
149 _LIT(KAppendFormat,"%S.%S"); |
|
150 nameBufDes.AppendFormat(KAppendFormat, &aObjectName, &aKeyName); |
|
151 |
|
152 TBool result=GetBoolFromConfig(aSectName,nameBufDes,aResult); |
|
153 |
|
154 if (EFalse==result) |
|
155 { |
|
156 _LIT(KLogFormat,"Error reading bool %S, from config section %S"); |
|
157 ERR_PRINTF3(KLogFormat, &nameBufDes, &aSectName); |
|
158 |
|
159 User::Leave(KErrConfigRead); |
|
160 } |
|
161 CleanupStack::PopAndDestroy(nameBuf); |
|
162 return result; |
|
163 } |
|
164 |
|
165 void CDaemonTestStep::ReadIntReturnValueL(TInt& aValue) |
|
166 { |
|
167 _LIT(KReturnValueKeyName,"ReturnValue"); |
|
168 CheckedGetIntFromConfigL(ConfigSection(),KReturnValueKeyName,aValue); |
|
169 } |
|
170 |
|
171 void CDaemonTestStep::ReadBoolReturnValueL(TBool& aValue) |
|
172 { |
|
173 _LIT(KReturnValueKeyName,"ReturnValue"); |
|
174 CheckedGetBoolFromConfigL(ConfigSection(),KReturnValueKeyName,aValue); |
|
175 } |
|
176 |
|
177 TVerdict CDaemonTestStep::doTestStepL() |
|
178 { |
|
179 // Check for OOM tests |
|
180 TBool oomTest=EFalse; |
|
181 GetBoolFromConfig(ConfigSection(), _L("OOM"),oomTest); |
|
182 |
|
183 CActiveScheduler* sched=new (ELeave) CActiveScheduler(); |
|
184 CActiveScheduler::Install(sched); |
|
185 |
|
186 if (oomTest) |
|
187 { |
|
188 INFO_PRINTF1(_L("Running OOM Test")); |
|
189 |
|
190 TInt err=KErrNoMemory; |
|
191 TInt nextFailure=1; |
|
192 TVerdict verdict=EFail; |
|
193 |
|
194 while (err!=KErrNone) |
|
195 { |
|
196 __UHEAP_MARK; |
|
197 __UHEAP_FAILNEXT(nextFailure); |
|
198 TRAP(err, verdict=runTestStepL(ETrue)); |
|
199 FreeMemory(); |
|
200 __UHEAP_MARKEND; |
|
201 ++nextFailure; |
|
202 |
|
203 if (err==KErrNone) |
|
204 { |
|
205 return verdict; |
|
206 } |
|
207 } |
|
208 } |
|
209 else |
|
210 { |
|
211 __UHEAP_MARK; |
|
212 TVerdict v=runTestStepL(EFalse); |
|
213 FreeMemory(); |
|
214 __UHEAP_MARKEND; |
|
215 return v; |
|
216 } |
|
217 |
|
218 CActiveScheduler::Install(NULL); |
|
219 delete sched; |
|
220 sched=0; |
|
221 |
|
222 return EFail; |
|
223 } |
|
224 |
|
225 |
|
226 void CDaemonTestStep::FreeMemory() |
|
227 { |
|
228 // no memory to free |
|
229 } |
|
230 |
|
231 } // namespace Swi::Test |
|
232 |
|
233 } //namespace Swi |