|
1 // Copyright (c) 2008-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 // Contains wrapper helper functions for test code to control the test wrappers |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @test |
|
21 @internalComponent - Internal Symbian test code |
|
22 */ |
|
23 |
|
24 #include "startupadaptationwrapper.h" |
|
25 |
|
26 /** |
|
27 * Sets the value for the wrapper for if the startup adaptation is loaded. |
|
28 * |
|
29 * @internalComponent |
|
30 * @test |
|
31 */ |
|
32 void CStartupAdaptationWrapper::SetLoaded(TBool aLoaded) |
|
33 { |
|
34 iIsLoaded = aLoaded; |
|
35 } |
|
36 |
|
37 /** |
|
38 * Returns the value for the wrapper for if the startup adaptation is loaded. |
|
39 * |
|
40 * @internalComponent |
|
41 * @test |
|
42 */ |
|
43 TBool CStartupAdaptationWrapper::IsLoaded() |
|
44 { |
|
45 return iIsLoaded; |
|
46 } |
|
47 |
|
48 /** |
|
49 * Allocates and returns a new startup adaptation |
|
50 * |
|
51 * Returns NULL if a startup adaptation has already been created |
|
52 * |
|
53 * @internalComponent |
|
54 * @test |
|
55 */ |
|
56 CStartupAdaptation* CStartupAdaptationWrapper::NewStartupAdaptation(TAny* aParams) |
|
57 { |
|
58 if (iStartupAdaptation != NULL) |
|
59 { |
|
60 return NULL; |
|
61 } |
|
62 iStartupAdaptation = new CStartupAdaptationWrapper(static_cast<MStartupAdaptationObserver*>(aParams)); |
|
63 SetLoaded(ETrue); |
|
64 return static_cast<CStartupAdaptation*>(iStartupAdaptation); |
|
65 } |
|
66 |
|
67 /** |
|
68 * Deletes the allocated startup adaptation from a previous call to NewStartupAdaptation |
|
69 * |
|
70 * @internalComponent |
|
71 * @test |
|
72 */ |
|
73 void CStartupAdaptationWrapper::DeleteStartupAdaptation() |
|
74 { |
|
75 SetLoaded(EFalse); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Sets the last command id to be returned by the wrapper |
|
80 * |
|
81 * @internalComponent |
|
82 * @test |
|
83 */ |
|
84 void CStartupAdaptationWrapper::SetLastCommandId(StartupAdaptation::TCommand aCommandId) |
|
85 { |
|
86 iLastCommandId = aCommandId; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Returns the last command id to be given to the wrapper |
|
91 * |
|
92 * @internalComponent |
|
93 * @test |
|
94 */ |
|
95 StartupAdaptation::TCommand CStartupAdaptationWrapper::LastCommandId() |
|
96 { |
|
97 return iLastCommandId; |
|
98 } |
|
99 |
|
100 /** |
|
101 * Sets the last command data to be returned |
|
102 * |
|
103 * @internalComponent |
|
104 * @test |
|
105 */ |
|
106 void CStartupAdaptationWrapper::SetLastCommandDataL(TDesC8& aData) |
|
107 { |
|
108 // Make a copy of the data |
|
109 HBufC8* newData = aData.AllocL(); |
|
110 |
|
111 delete iLastCommandData; |
|
112 iLastCommandData = newData; |
|
113 } |
|
114 |
|
115 /** |
|
116 * Returns the last command data to be given to the wrapper |
|
117 * |
|
118 * Ownership of the HBufC* remains with the CStartupAdaptationWrapper |
|
119 * and will be deleted when the next command is issued |
|
120 * |
|
121 * @internalComponent |
|
122 * @test |
|
123 */ |
|
124 HBufC8* CStartupAdaptationWrapper::LastCommandData() |
|
125 { |
|
126 return iLastCommandData; |
|
127 } |
|
128 |
|
129 /** |
|
130 * Frees any data allocated for last command data |
|
131 * |
|
132 * @internalComponent |
|
133 * @test |
|
134 */ |
|
135 void CStartupAdaptationWrapper::DeleteLastCommandData() |
|
136 { |
|
137 delete iLastCommandData; |
|
138 iLastCommandData = NULL; |
|
139 } |
|
140 |
|
141 /** |
|
142 * Triggers an event callback on the startup adaptation observer class |
|
143 * associated with the wrapper |
|
144 * |
|
145 * @internalComponent |
|
146 * @test |
|
147 */ |
|
148 void CStartupAdaptationWrapper::TriggerObserverEventCallbackL(const StartupAdaptation::TEvent aEventId, TDesC8& aData) |
|
149 { |
|
150 iStartupAdaptation->iObserver->EventL(aEventId, aData); |
|
151 } |
|
152 |
|
153 /** |
|
154 * Triggers a response callback on the startup adaptation observer class |
|
155 * associated with the wrapper |
|
156 * |
|
157 * @internalComponent |
|
158 * @test |
|
159 */ |
|
160 void CStartupAdaptationWrapper::TriggerResponseCallbackL(const StartupAdaptation::TCommand aCommandId, TDesC8& aData) |
|
161 { |
|
162 // Use iResponding to ensure that CommandL is not issued from ResponseL() |
|
163 iStartupAdaptation->iResponding = ETrue; |
|
164 TRAPD(err, iStartupAdaptation->iObserver->ResponseL(aCommandId, aData)); |
|
165 iStartupAdaptation->iResponding = EFalse; |
|
166 User::LeaveIfError(err); |
|
167 } |
|
168 |
|
169 /** |
|
170 * Stores the last command data to be issued to the wrapper |
|
171 * |
|
172 * @internalComponent |
|
173 * @test |
|
174 */ |
|
175 StartupAdaptation::TCommand CStartupAdaptationWrapper::iLastCommandId = static_cast<StartupAdaptation::TCommand>(0); |
|
176 |
|
177 /** |
|
178 * Stores the last command data to be stored by the wrapper |
|
179 * |
|
180 * @internalComponent |
|
181 * @test |
|
182 */ |
|
183 HBufC8* CStartupAdaptationWrapper::iLastCommandData = NULL; |
|
184 |
|
185 /** |
|
186 * Stores the created startup adaptation |
|
187 * |
|
188 * @internalComponent |
|
189 * @test |
|
190 */ |
|
191 CStartupAdaptationWrapper* CStartupAdaptationWrapper::iStartupAdaptation = NULL; |
|
192 |
|
193 /** |
|
194 * Stores the value for the wrapper for if the startup adaptation is loaded. |
|
195 * |
|
196 * @internalComponent |
|
197 * @test |
|
198 */ |
|
199 TBool CStartupAdaptationWrapper::iIsLoaded = EFalse; |
|
200 |
|
201 |
|
202 CStartupAdaptationWrapper::CStartupAdaptationWrapper(MStartupAdaptationObserver* aObserver) |
|
203 : iObserver(aObserver) |
|
204 { |
|
205 |
|
206 } |
|
207 |
|
208 void CStartupAdaptationWrapper::CommandL(const StartupAdaptation::TCommand aCommandId, TDesC8& aData) |
|
209 { |
|
210 if(iResponding) |
|
211 { |
|
212 // CommandL has been called from within RespondL, this is not allowed |
|
213 User::Panic(_L("StartupAdaptationWrapper"), 20); |
|
214 } |
|
215 SetLastCommandId(aCommandId); |
|
216 SetLastCommandDataL(aData); |
|
217 } |
|
218 |
|
219 void CStartupAdaptationWrapper::CancelCommandL(const StartupAdaptation::TCommand aCommandId) |
|
220 { |
|
221 _LIT(KWrapperPanic, "SAA Test Wrapper"); |
|
222 if (aCommandId != LastCommandId()) |
|
223 { |
|
224 // If it's not the last command being cancelled then panic |
|
225 User::Panic(KWrapperPanic, 0); |
|
226 } |
|
227 } |
|
228 |
|
229 TVersion CStartupAdaptationWrapper::Version() const |
|
230 { |
|
231 return TVersion(1, 0, 0); |
|
232 } |