|
1 // Copyright (c) 2005-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 <f32file.h> |
|
17 #include <bautils.h> |
|
18 #include <startup.hrh> |
|
19 #include "TestHarnessDomainMember.h" |
|
20 |
|
21 const TInt KInitialTestState = EStartupStateUndefined + 1; |
|
22 _LIT(KIniEcomTestBehaviourFileName, "c:\\EComTestBehaviour.ini"); |
|
23 |
|
24 /** |
|
25 Constructor. |
|
26 Adds this active object to the active scheduler. The priority of the active object |
|
27 is the standard value, i.e. CActive::EPriorityStandard. |
|
28 @param aHierarchyId The Id of the domain hierarchy to connect to. |
|
29 @param aDomainId The Id of the domain to connect to. |
|
30 @see CActive |
|
31 @see CActive::TPriority |
|
32 */ |
|
33 CDmDomainTestHarness::CDmDomainTestHarness(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId): |
|
34 CDmDomain(aHierarchyId, aDomainId), |
|
35 iIsRequestSent(EFalse), |
|
36 iIsLastStateAcknowledged(ETrue), |
|
37 iState(KInitialTestState), |
|
38 iIsTestBehaviour(EFalse), |
|
39 iIsBehaviourSet(EFalse), |
|
40 iIsRequestCancelled(EFalse) |
|
41 { |
|
42 } |
|
43 |
|
44 /** |
|
45 Destructor. |
|
46 Closes the session to the domain manager. |
|
47 */ |
|
48 CDmDomainTestHarness::~CDmDomainTestHarness() |
|
49 { |
|
50 |
|
51 } |
|
52 |
|
53 /** |
|
54 Requests notification when the domain's state changes. |
|
55 RunL() will be called when this happens. |
|
56 */ |
|
57 void CDmDomainTestHarness::RequestTransitionNotificationL() |
|
58 { |
|
59 if(!IsTestBehaviour()) |
|
60 { |
|
61 CDmDomain::RequestTransitionNotification(); |
|
62 } |
|
63 else |
|
64 { |
|
65 if((iIsRequestSent)&& (!iIsRequestCancelled)) |
|
66 { |
|
67 //If the request has already been sent and there is |
|
68 //another request there's a serious problem in the |
|
69 //production code. |
|
70 User::Leave(KErrGeneral); |
|
71 } |
|
72 |
|
73 iIsRequestSent = ETrue; |
|
74 } |
|
75 } |
|
76 |
|
77 /** |
|
78 Acknowledges the last state change. |
|
79 An application must acknowledge that it has performed all actions required |
|
80 by the last known state of the domain. |
|
81 @param aError The error to return to the domain manager. The client should |
|
82 set this to KErrNone if it successfully transitioned to the |
|
83 new state or to one of the system-wide error codes. |
|
84 */ |
|
85 void CDmDomainTestHarness::AcknowledgeLastStateL(TInt aError) |
|
86 { |
|
87 if(!IsTestBehaviour()) |
|
88 { |
|
89 CDmDomain::AcknowledgeLastState(aError); |
|
90 } |
|
91 else |
|
92 { |
|
93 if(!iIsLastStateAcknowledged) |
|
94 { |
|
95 //If the last state is acknowledged when it wasn't expected |
|
96 //in the first place there's a serious problem in the |
|
97 //production code. |
|
98 User::Leave(KErrGeneral); |
|
99 } |
|
100 iIsLastStateAcknowledged = ETrue; |
|
101 } |
|
102 } |
|
103 |
|
104 /** |
|
105 Gets the domain's state. |
|
106 For this test implementation it only returns the member value |
|
107 @return The connected domain's state. |
|
108 */ |
|
109 TDmDomainState CDmDomainTestHarness::GetState() |
|
110 { |
|
111 if(!IsTestBehaviour()) |
|
112 { |
|
113 return CDmDomain::GetState(); |
|
114 } |
|
115 else |
|
116 { |
|
117 return iState; |
|
118 } |
|
119 } |
|
120 /** |
|
121 it has to use Cancel() to invoke DoCancel() since the Active object |
|
122 is not activated in Test Mode. |
|
123 */ |
|
124 void CDmDomainTestHarness::Cancel() |
|
125 { |
|
126 if(!IsTestBehaviour()) |
|
127 { |
|
128 CActive::Cancel(); |
|
129 } |
|
130 else |
|
131 { |
|
132 DoCancel(); |
|
133 } |
|
134 } |
|
135 |
|
136 |
|
137 /** |
|
138 If not test behaviour passes the call to CDmDomain. Otherwise |
|
139 disables the call. |
|
140 */ |
|
141 void CDmDomainTestHarness::DoCancel() |
|
142 { |
|
143 if(!IsTestBehaviour()) |
|
144 { |
|
145 CDmDomain::DoCancel(); |
|
146 } |
|
147 else |
|
148 { |
|
149 iIsRequestCancelled = ETrue; |
|
150 } |
|
151 } |
|
152 |
|
153 /** |
|
154 If not test behaviour passes the call to CDmDomain. Otherwise |
|
155 disables the call. |
|
156 */ |
|
157 void CDmDomainTestHarness::ConstructL() |
|
158 { |
|
159 if(!IsTestBehaviour()) |
|
160 { |
|
161 CDmDomain::ConstructL(); |
|
162 } |
|
163 } |
|
164 |
|
165 /** |
|
166 Sets the domain's state |
|
167 @param aState the new state |
|
168 */ |
|
169 void CDmDomainTestHarness::ChangeStartupStateL(TInt aState) |
|
170 { |
|
171 if(!IsTestBehaviour()) |
|
172 { |
|
173 User::Leave(KErrNotSupported); |
|
174 } |
|
175 else |
|
176 { |
|
177 iState = aState; |
|
178 } |
|
179 } |
|
180 |
|
181 /** |
|
182 Resets the iIsRequestSent member. The member is used as a flag |
|
183 to check if RequestTransitionNotificationL() has been called. |
|
184 */ |
|
185 void CDmDomainTestHarness::ResetRequestTransitionNotificationL() |
|
186 { |
|
187 if(!IsTestBehaviour()) |
|
188 { |
|
189 User::Leave(KErrNotSupported); |
|
190 } |
|
191 else |
|
192 { |
|
193 iIsRequestSent = EFalse; |
|
194 iIsRequestCancelled = EFalse; |
|
195 } |
|
196 } |
|
197 |
|
198 /** |
|
199 Checks if RequestTransitionNotificationL() has been called since |
|
200 iIsRequestSent member is last reset. |
|
201 */ |
|
202 TBool CDmDomainTestHarness::IsTransitionNotificationRequestedL() |
|
203 { |
|
204 if(!IsTestBehaviour()) |
|
205 { |
|
206 User::Leave(KErrNotSupported); |
|
207 } |
|
208 return iIsRequestSent; |
|
209 } |
|
210 |
|
211 /** |
|
212 Resets the iIsLastStateAcknowledged member. The member is used as a flag |
|
213 to check if AcknowledgeLastStateL() has been called. |
|
214 */ |
|
215 void CDmDomainTestHarness::ResetLastStateAcknowledgedL() |
|
216 { |
|
217 if(!IsTestBehaviour()) |
|
218 { |
|
219 User::Leave(KErrNotSupported); |
|
220 } |
|
221 else |
|
222 { |
|
223 iIsLastStateAcknowledged = ETrue; |
|
224 } |
|
225 } |
|
226 |
|
227 /** |
|
228 Checks if AcknowledgeLastStateL() has been called since |
|
229 iIsLastStateAcknowledged member is last reset. |
|
230 */ |
|
231 TBool CDmDomainTestHarness::IsLastStateAcknowledgedL() |
|
232 { |
|
233 if(!IsTestBehaviour()) |
|
234 { |
|
235 User::Leave(KErrNotSupported); |
|
236 } |
|
237 return iIsLastStateAcknowledged; |
|
238 } |
|
239 |
|
240 /** |
|
241 Checks to see if the class should follow test behaviour |
|
242 or just act as a dummy intermediate class which passes |
|
243 all the calls directly to the base class CDmDomain. |
|
244 The nature of the behaviour is defined by the existence |
|
245 of KIniEcomTestBehaviourFileName. |
|
246 */ |
|
247 TBool CDmDomainTestHarness::IsTestBehaviour() |
|
248 { |
|
249 if(!iIsBehaviourSet) |
|
250 { |
|
251 RFs fsSession; |
|
252 TInt err = fsSession.Connect(); |
|
253 //error in file sever connection. |
|
254 if(err) |
|
255 { |
|
256 iIsTestBehaviour = EFalse; |
|
257 } |
|
258 else |
|
259 { |
|
260 iIsTestBehaviour = BaflUtils::FileExists(fsSession, KIniEcomTestBehaviourFileName); |
|
261 fsSession.Close(); |
|
262 } |
|
263 iIsBehaviourSet = ETrue; |
|
264 } |
|
265 |
|
266 return iIsTestBehaviour; |
|
267 } |
|
268 |
|
269 /** |
|
270 Checks if RequestTransitionNotificationL() has been cancelled since |
|
271 iIsRequestCancel member is last reset. |
|
272 */ |
|
273 TBool CDmDomainTestHarness::IsRequestNotificationCancelledL() |
|
274 { |
|
275 if(!IsTestBehaviour()) |
|
276 { |
|
277 User::Leave(KErrNotSupported); |
|
278 } |
|
279 return iIsRequestCancelled; |
|
280 } |