1 /* |
|
2 * Copyright (c) 2008-2010 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 * Implements the test steps for transaction management APIs in the SCR |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "transactionmanagementsteps.h" |
|
21 |
|
22 using namespace Usif; |
|
23 |
|
24 |
|
25 // -----------CScrApplyTransactionStep----------------- |
|
26 |
|
27 CScrApplyTransactionStep::CScrApplyTransactionStep(CScrTestServer& aParent) : CScrTestStep(aParent) |
|
28 { |
|
29 } |
|
30 |
|
31 void CScrApplyTransactionStep::ImplTestStepPreambleL() |
|
32 { |
|
33 // empty |
|
34 } |
|
35 |
|
36 |
|
37 void CScrApplyTransactionStep::ImplTestStepL() |
|
38 { |
|
39 User::LeaveIfError(iScrSession.Connect()); |
|
40 iScrSession.CreateTransactionL(); |
|
41 |
|
42 // Add a new component into SCR database |
|
43 TComponentId componentId= AddNonLocalisableComponentL(iScrSession); |
|
44 AppendSharedComponentIdL(componentId); |
|
45 |
|
46 // Register a file to the component |
|
47 TPtrC fileName; |
|
48 GetFileNameFromConfigL(fileName); |
|
49 iScrSession.RegisterComponentFileL(componentId, fileName); |
|
50 |
|
51 // Get a property from config file and set it. |
|
52 CPropertyEntry *property = GetPropertyFromConfigLC(ETrue); |
|
53 if(property->PropertyType() != CPropertyEntry::EIntProperty) |
|
54 { |
|
55 ERR_PRINTF1(_L("The property is not an integer property which is expected!")); |
|
56 User::Leave(KErrArgument); |
|
57 } |
|
58 CIntPropertyEntry *propertyInt = dynamic_cast<CIntPropertyEntry*>(property); |
|
59 iScrSession.SetComponentPropertyL(componentId, propertyInt->PropertyName(), propertyInt->IntValue()); |
|
60 CleanupStack::PopAndDestroy(propertyInt); |
|
61 |
|
62 // Commit the transaction if it is marked in the configuration |
|
63 TBool isCommitTransaction(EFalse); |
|
64 GetBoolFromConfig(ConfigSection(), _L("CommitTransaction"), isCommitTransaction); |
|
65 if(isCommitTransaction) |
|
66 { |
|
67 iScrSession.CommitTransactionL(); |
|
68 } |
|
69 |
|
70 // Cancel thetransaction if it is marked in the configuration |
|
71 TBool isCancelTransaction(EFalse); |
|
72 GetBoolFromConfig(ConfigSection(), _L("CancelTransaction"), isCancelTransaction); |
|
73 if(isCancelTransaction) |
|
74 { |
|
75 iScrSession.RollbackTransactionL(); |
|
76 } |
|
77 |
|
78 // Close the session |
|
79 iScrSession.Close(); |
|
80 } |
|
81 |
|
82 void CScrApplyTransactionStep::ImplTestStepPostambleL() |
|
83 { |
|
84 // empty |
|
85 } |
|
86 |
|
87 |
|
88 // -----------CScrCreateTransactionStep----------------- |
|
89 |
|
90 void OpenSessionLC(RSoftwareComponentRegistry& aSession) |
|
91 { |
|
92 User::LeaveIfError(aSession.Connect()); |
|
93 CleanupClosePushL(aSession); |
|
94 } |
|
95 |
|
96 void CreateTransactionL(RSoftwareComponentRegistry& aSession) |
|
97 { |
|
98 aSession.CreateTransactionL(); |
|
99 } |
|
100 |
|
101 void OpenSubsessionL(RSoftwareComponentRegistry aSession, RSoftwareComponentRegistryView& aSubsession) |
|
102 { |
|
103 CComponentFilter *filter = CComponentFilter::NewL(); // NewL is used for the sake of coverage |
|
104 CleanupStack::PushL(filter); |
|
105 aSubsession.OpenViewL(aSession, filter); |
|
106 CleanupStack::PopAndDestroy(filter); |
|
107 } |
|
108 |
|
109 void OpenSubsessionLC(RSoftwareComponentRegistry aSession, RSoftwareComponentRegistryView& aSubsession) |
|
110 { |
|
111 OpenSubsessionL(aSession, aSubsession); |
|
112 CleanupClosePushL(aSubsession); |
|
113 } |
|
114 |
|
115 CScrCreateTransactionStep::CScrCreateTransactionStep(CScrTestServer& aParent) : CScrTestStep(aParent) |
|
116 { |
|
117 } |
|
118 |
|
119 void CScrCreateTransactionStep::ImplTestStepPreambleL() |
|
120 { |
|
121 // empty |
|
122 } |
|
123 |
|
124 |
|
125 void CScrCreateTransactionStep::ImplTestStepL() |
|
126 { |
|
127 RSoftwareComponentRegistry session1; |
|
128 RSoftwareComponentRegistry session2; |
|
129 RSoftwareComponentRegistryView subsession; |
|
130 RSoftwareComponentRegistryView subsession2; |
|
131 |
|
132 TBool isBeginTransactionBeforeSubsession(EFalse); |
|
133 GetBoolFromConfig(ConfigSection(), _L("BeginTransactionBeforeSubsession"), isBeginTransactionBeforeSubsession); |
|
134 if(isBeginTransactionBeforeSubsession) |
|
135 { |
|
136 OpenSessionLC(session1); |
|
137 CreateTransactionL(session1); |
|
138 OpenSessionLC(session2); |
|
139 OpenSubsessionLC(session2, subsession); |
|
140 CleanupStack::PopAndDestroy(3, &session1); |
|
141 } |
|
142 |
|
143 TBool isOpenSubsessionInTheSameSession(EFalse); |
|
144 GetBoolFromConfig(ConfigSection(), _L("OpenSubsessionInTheSameSession"), isOpenSubsessionInTheSameSession); |
|
145 if(isOpenSubsessionInTheSameSession) |
|
146 { |
|
147 OpenSessionLC(session1); |
|
148 CreateTransactionL(session1); |
|
149 OpenSubsessionLC(session1, subsession); |
|
150 CleanupStack::PopAndDestroy(2, &session1); |
|
151 |
|
152 // Now do the same, but in reverse order |
|
153 OpenSessionLC(session1); |
|
154 OpenSubsessionLC(session1, subsession); |
|
155 CreateTransactionL(session1); |
|
156 CleanupStack::PopAndDestroy(2, &session1); |
|
157 } |
|
158 |
|
159 TBool isBeginTransactionAfterSubsession(EFalse); |
|
160 GetBoolFromConfig(ConfigSection(), _L("BeginTransactionAfterSubsession"), isBeginTransactionAfterSubsession); |
|
161 if(isBeginTransactionAfterSubsession) |
|
162 { |
|
163 OpenSessionLC(session1); |
|
164 OpenSessionLC(session2); |
|
165 OpenSubsessionLC(session1, subsession); |
|
166 CreateTransactionL(session2); |
|
167 CleanupStack::PopAndDestroy(3, &session1); |
|
168 } |
|
169 |
|
170 TBool isBeginTransactionInTheSameSession(EFalse); |
|
171 GetBoolFromConfig(ConfigSection(), _L("BeginTransactionInTheSameSession"), isBeginTransactionInTheSameSession); |
|
172 if(isBeginTransactionAfterSubsession) |
|
173 { |
|
174 OpenSessionLC(session1); |
|
175 OpenSubsessionLC(session1, subsession); |
|
176 CreateTransactionL(session1); |
|
177 CleanupStack::PopAndDestroy(2, &session1); |
|
178 } |
|
179 |
|
180 TBool isBeginAfterAnotherBegin(EFalse); |
|
181 GetBoolFromConfig(ConfigSection(), _L("BeginTransactionAfterAnotherBegin"), isBeginAfterAnotherBegin); |
|
182 if(isBeginAfterAnotherBegin) |
|
183 { |
|
184 OpenSessionLC(session1); |
|
185 CreateTransactionL(session1); |
|
186 OpenSessionLC(session2); |
|
187 CreateTransactionL(session2); |
|
188 CleanupStack::PopAndDestroy(2, &session1); |
|
189 } |
|
190 |
|
191 TBool isMultipleSubsessions(EFalse); |
|
192 GetBoolFromConfig(ConfigSection(), _L("MultipleSubsessions"), isMultipleSubsessions); |
|
193 if(isMultipleSubsessions) |
|
194 { |
|
195 OpenSessionLC(session1); |
|
196 OpenSubsessionLC(session1, subsession); |
|
197 OpenSessionLC(session2); |
|
198 OpenSubsessionLC(session2, subsession2); |
|
199 CleanupStack::PopAndDestroy(4, &session1); |
|
200 } |
|
201 |
|
202 TBool isWriteAfterBegin(EFalse); |
|
203 GetBoolFromConfig(ConfigSection(), _L("WriteAfterBeginTransaction"), isWriteAfterBegin); |
|
204 if(isWriteAfterBegin) |
|
205 { |
|
206 OpenSessionLC(session1); |
|
207 CreateTransactionL(session1); |
|
208 OpenSessionLC(session2); |
|
209 session2.AddComponentL(_L("test"),_L("vendor"),_L("plain")); |
|
210 CleanupStack::PopAndDestroy(2, &session1); |
|
211 } |
|
212 |
|
213 TBool isReadAfterBegin(EFalse); |
|
214 GetBoolFromConfig(ConfigSection(), _L("ReadAfterBeginTransaction"), isReadAfterBegin); |
|
215 if(isReadAfterBegin) |
|
216 { |
|
217 OpenSessionLC(session1); |
|
218 CreateTransactionL(session1); |
|
219 OpenSessionLC(session2); |
|
220 CComponentEntry *entry = CComponentEntry::NewLC(); |
|
221 session2.GetComponentL(1, *entry); |
|
222 CleanupStack::PopAndDestroy(3, &session1); |
|
223 } |
|
224 |
|
225 TBool mutatingOperationWithSubsession(EFalse); |
|
226 GetBoolFromConfig(ConfigSection(), _L("MutatingOperationWithSubsession"), mutatingOperationWithSubsession); |
|
227 if(mutatingOperationWithSubsession) |
|
228 { |
|
229 OpenSessionLC(session1); |
|
230 OpenSubsessionLC(session1, subsession); |
|
231 OpenSessionLC(session2); |
|
232 session2.AddComponentL(_L("test"),_L("vendor"),_L("plain")); |
|
233 CleanupStack::PopAndDestroy(3, &session1); // session2, subsession |
|
234 } |
|
235 |
|
236 TBool closeSessionWithoutClosingSubsession(EFalse); |
|
237 GetBoolFromConfig(ConfigSection(), _L("CloseSessionWithoutClosingSubsession"), closeSessionWithoutClosingSubsession); |
|
238 if(closeSessionWithoutClosingSubsession) |
|
239 { |
|
240 OpenSessionLC(session1); |
|
241 CreateTransactionL(session1); |
|
242 OpenSubsessionL(session1, subsession); |
|
243 OpenSubsessionL(session1, subsession2); |
|
244 CComponentEntry *entry = subsession.NextComponentL(); |
|
245 CleanupStack::PushL(entry); |
|
246 CComponentEntry *entry2 = subsession2.NextComponentL(); |
|
247 CleanupStack::PushL(entry2); |
|
248 CleanupStack::PopAndDestroy(3, &session1); // entry, entry2 |
|
249 } |
|
250 |
|
251 |
|
252 TBool isMultipleActiveSubsessions (EFalse); |
|
253 GetBoolFromConfig(ConfigSection(), _L("MultipleActiveSubsessions"), isMultipleActiveSubsessions); |
|
254 if(isMultipleActiveSubsessions) |
|
255 { |
|
256 OpenSessionLC(session1); |
|
257 OpenSubsessionLC(session1, subsession); |
|
258 TInt foundRecords (0); |
|
259 CComponentEntry *entry = subsession.NextComponentL(); |
|
260 if(entry) |
|
261 { |
|
262 ++foundRecords; |
|
263 delete entry; |
|
264 entry = NULL; |
|
265 } |
|
266 |
|
267 OpenSessionLC(session2); |
|
268 CComponentFilter *filter = CComponentFilter::NewL(); // NewL is used for the sake of coverage |
|
269 CleanupStack::PushL(filter); |
|
270 filter->SetNameL(_L("nonexistingcomponentnamefortransactionmanagementtest")); |
|
271 filter->SetVendorL(_L("nonexistingvendornamefortransactionmanagementtest")); |
|
272 subsession2.OpenViewL(session2, filter); |
|
273 CleanupStack::PopAndDestroy(filter); |
|
274 CleanupClosePushL(subsession2); |
|
275 |
|
276 CComponentEntry *entry2 = subsession2.NextComponentL(); |
|
277 if(entry2) |
|
278 { |
|
279 delete entry2; |
|
280 entry2 = NULL; |
|
281 entry2 = subsession2.NextComponentL(); |
|
282 ERR_PRINTF1(_L("Subsession2 has unexpectedly retrieved a component!")); |
|
283 SetTestStepResult(EFail); |
|
284 } |
|
285 CleanupStack::PopAndDestroy(2, &session2); // session2, subsession2 |
|
286 |
|
287 entry = subsession.NextComponentL(); |
|
288 while(entry) |
|
289 { |
|
290 ++foundRecords; |
|
291 delete entry; |
|
292 entry = NULL; |
|
293 entry = subsession.NextComponentL(); |
|
294 } |
|
295 if(foundRecords < 2) |
|
296 { |
|
297 ERR_PRINTF1(_L("Subsession1 has unexpectedly reached the end of the view!")); |
|
298 SetTestStepResult(EFail); |
|
299 } |
|
300 CleanupStack::PopAndDestroy(2, &session1); |
|
301 } |
|
302 } |
|
303 |
|
304 void CScrCreateTransactionStep::ImplTestStepPostambleL() |
|
305 { |
|
306 // empty |
|
307 } |
|
308 |
|
309 // -----------CScrManageAnotherTransactionStep----------------- |
|
310 |
|
311 CScrManageAnotherTransactionStep::CScrManageAnotherTransactionStep(CScrTestServer& aParent) : CScrTestStep(aParent) |
|
312 { |
|
313 } |
|
314 |
|
315 void CScrManageAnotherTransactionStep::ImplTestStepPreambleL() |
|
316 { |
|
317 // empty |
|
318 } |
|
319 |
|
320 |
|
321 void CScrManageAnotherTransactionStep::ImplTestStepL() |
|
322 { |
|
323 User::LeaveIfError(iScrSession.Connect()); |
|
324 iScrSession.CreateTransactionL(); |
|
325 |
|
326 RSoftwareComponentRegistry anotherSession; |
|
327 User::LeaveIfError(anotherSession.Connect()); |
|
328 CleanupClosePushL(anotherSession); |
|
329 |
|
330 // Commit the transaction if it is marked in the configuration |
|
331 TBool isCommitTransaction(EFalse); |
|
332 GetBoolFromConfig(ConfigSection(), _L("CommitTransaction"), isCommitTransaction); |
|
333 if(isCommitTransaction) |
|
334 anotherSession.CommitTransactionL(); |
|
335 |
|
336 TBool isCancelTransaction(EFalse); |
|
337 GetBoolFromConfig(ConfigSection(), _L("CancelTransaction"), isCancelTransaction); |
|
338 if(isCancelTransaction) |
|
339 anotherSession.RollbackTransactionL(); |
|
340 |
|
341 TBool isInvokeMutatingFunction(EFalse); |
|
342 GetBoolFromConfig(ConfigSection(), _L("InvokeMutatingFunction"), isInvokeMutatingFunction); |
|
343 if(isInvokeMutatingFunction) |
|
344 anotherSession.AddComponentL(_L("test"), _L("vendor"),_L("plain")); |
|
345 |
|
346 TBool isInvokeNonMutatingFunction(EFalse); |
|
347 GetBoolFromConfig(ConfigSection(), _L("InvokeNonMutatingFunction"), isInvokeNonMutatingFunction); |
|
348 if(isInvokeNonMutatingFunction) |
|
349 { |
|
350 RArray<TComponentId> componentIdList; |
|
351 anotherSession.GetComponentIdsL(componentIdList); |
|
352 componentIdList.Close(); |
|
353 } |
|
354 |
|
355 CleanupStack::PopAndDestroy(&anotherSession); |
|
356 iScrSession.Close(); |
|
357 } |
|
358 |
|
359 void CScrManageAnotherTransactionStep::ImplTestStepPostambleL() |
|
360 { |
|
361 // empty |
|
362 } |
|