|
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 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include "t_backupsrvdefects.h" |
|
18 |
|
19 |
|
20 RTest TheTest (_L("t_backupsrvdefects")); |
|
21 #define TEST(arg) TheTest((arg), __LINE__) |
|
22 |
|
23 _LIT(KFileName1, "FileName1"); |
|
24 |
|
25 |
|
26 CBUDefectTestMachine* CBUDefectTestMachine::NewL() |
|
27 { |
|
28 CBUDefectTestMachine* self = new (ELeave) CBUDefectTestMachine(); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 CleanupStack::Pop(); |
|
32 return self; |
|
33 } |
|
34 |
|
35 CBUDefectTestMachine::CBUDefectTestMachine() |
|
36 :CActive(0) |
|
37 {} |
|
38 |
|
39 CBUDefectTestMachine::~CBUDefectTestMachine() |
|
40 { |
|
41 delete iWrapper; |
|
42 |
|
43 // Cancel this if it's active |
|
44 if (IsActive()) |
|
45 { |
|
46 Cancel(); |
|
47 } |
|
48 } |
|
49 |
|
50 void CBUDefectTestMachine::ConstructL() |
|
51 { |
|
52 iWrapper = CBaBackupSessionWrapper::NewL(); |
|
53 |
|
54 iNextState = EMachineStart; |
|
55 |
|
56 // Add this to the Active Scheduler and set us active |
|
57 CActiveScheduler::Add(this); |
|
58 SetActive(); |
|
59 } |
|
60 |
|
61 // Called when CloseAll request is completed or the active object is scheduled. |
|
62 void CBUDefectTestMachine::RunL() |
|
63 { |
|
64 switch(iNextState) |
|
65 { |
|
66 case EMachineStart: |
|
67 // Send 2 requests of CloseAll with different file lock states. |
|
68 // The second request will be ignored. The first one will be completed. |
|
69 iWrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, iStatus); |
|
70 iWrapper->CloseAll(MBackupObserver::EReleaseLockNoAccess, iStatus); |
|
71 |
|
72 iNextState = EMachineCloseAllsEndSameClient; |
|
73 SetActive(); |
|
74 break; |
|
75 case EMachineCloseAllsEndSameClient: |
|
76 // The first CloseAll request is completed. |
|
77 TEST(iStatus == KErrNone); |
|
78 |
|
79 // Send 2 requests of CloseAll from different client. |
|
80 // The second client should be completed with KErrServerBusy before |
|
81 // the first client is completed with KErrNone |
|
82 iWrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, iStatus); |
|
83 iBackupFileObserver->CloseAll(MBackupObserver::EReleaseLockReadOnly); |
|
84 |
|
85 iNextState = EMachineCloseAllsEndOtherClient; |
|
86 SetActive(); |
|
87 break; |
|
88 case EMachineCloseAllsEndOtherClient: |
|
89 // The first CloseAll client is completed successfully |
|
90 TEST(iStatus == KErrNone); |
|
91 |
|
92 // Tests under CloseAll operation, CloseFileL requested by the other client will leave; |
|
93 // CloseFileL requested by the same client will be successful and not affect the CloseAll |
|
94 // process. |
|
95 iWrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, iStatus); |
|
96 |
|
97 TRAPD(err, iBackupFileObserver->CloseFileL(KFileName1,MBackupObserver::EReleaseLockNoAccess)); |
|
98 TEST(err == KErrServerBusy); |
|
99 |
|
100 iWrapper->CloseFileL(KFileName1,MBackupObserver::EReleaseLockReadOnly); |
|
101 |
|
102 iNextState = EMachineCloseAllsEndCloseFile; |
|
103 SetActive(); |
|
104 |
|
105 break; |
|
106 |
|
107 case EMachineCloseAllsEndCloseFile: |
|
108 // The CloseAll is completed successfully |
|
109 TEST(iStatus == KErrNone); |
|
110 |
|
111 CActiveScheduler::Stop(); |
|
112 break; |
|
113 |
|
114 default: |
|
115 break; |
|
116 } |
|
117 } |
|
118 |
|
119 void CBUDefectTestMachine::DoCancel() |
|
120 { |
|
121 Complete(); |
|
122 } |
|
123 |
|
124 void CBUDefectTestMachine::Complete() |
|
125 { |
|
126 TRequestStatus* tempStatus=&iStatus; |
|
127 User::RequestComplete(tempStatus, KErrNone); |
|
128 } |
|
129 |
|
130 /* |
|
131 Sets the other client of the backup server |
|
132 */ |
|
133 void CBUDefectTestMachine::SetFileObserver(CBackupFileObserver* aBackupFileObserver) |
|
134 { |
|
135 iBackupFileObserver = aBackupFileObserver; |
|
136 } |
|
137 |
|
138 |
|
139 |
|
140 //CBackupFileObserver |
|
141 CBackupFileObserver* CBackupFileObserver::NewL(CBUDefectTestMachine& aDefectMachine, const TDesC& aLockedFileName) |
|
142 { |
|
143 CBackupFileObserver* self = new (ELeave) CBackupFileObserver(aDefectMachine, aLockedFileName); |
|
144 CleanupStack::PushL(self); |
|
145 self->ConstructL(); |
|
146 CleanupStack::Pop(); |
|
147 return self; |
|
148 } |
|
149 |
|
150 CBackupFileObserver::CBackupFileObserver(CBUDefectTestMachine& aTestMachine, const TDesC& aLockedFileName) |
|
151 :CActive(0), iTestMachine(aTestMachine), iLockedFileName(aLockedFileName) |
|
152 {} |
|
153 |
|
154 void CBackupFileObserver::ConstructL() |
|
155 { |
|
156 iWrapper = CBaBackupSessionWrapper::NewL(); |
|
157 |
|
158 iWrapper->RegisterFileL(iLockedFileName, *this); |
|
159 iTestMachine.SetFileObserver(this); |
|
160 |
|
161 // Add this to the Active Scheduler and set us active |
|
162 CActiveScheduler::Add(this); |
|
163 } |
|
164 |
|
165 CBackupFileObserver::~CBackupFileObserver() |
|
166 { |
|
167 delete iWrapper; |
|
168 |
|
169 // Cancel this if it's active |
|
170 if (IsActive()) |
|
171 { |
|
172 Cancel(); |
|
173 } |
|
174 } |
|
175 |
|
176 void CBackupFileObserver::CloseAll(MBackupObserver::TFileLockFlags aFlags) |
|
177 { |
|
178 iWrapper->CloseAll(aFlags, iStatus); |
|
179 if(! IsActive()) |
|
180 { |
|
181 SetActive(); |
|
182 } |
|
183 } |
|
184 |
|
185 void CBackupFileObserver::CloseFileL(const TDesC& aFileName,MBackupObserver::TFileLockFlags aFlags) |
|
186 { |
|
187 iWrapper->CloseFileL(aFileName,aFlags); |
|
188 } |
|
189 |
|
190 |
|
191 void CBackupFileObserver::ChangeFileLockL(const TDesC& aFileName,TFileLockFlags aFlags) |
|
192 { |
|
193 TEST(aFileName == KFileName1); |
|
194 TEST(aFlags == MBackupObserver::EReleaseLockReadOnly); |
|
195 } |
|
196 |
|
197 /** |
|
198 Called when CloseAll request is completed. |
|
199 */ |
|
200 void CBackupFileObserver::RunL() |
|
201 { |
|
202 if(iTestMachine.iNextState == EMachineCloseAllsEndOtherClient) |
|
203 { |
|
204 // As the second CloseAll client, Tests the CloseAll request is completed with KErrServerBusy |
|
205 // while the first one is still pending |
|
206 TEST(iStatus == KErrServerBusy); |
|
207 TEST(iTestMachine.iStatus == KRequestPending); |
|
208 } |
|
209 } |
|
210 |
|
211 void CBackupFileObserver::DoCancel() |
|
212 { |
|
213 TRequestStatus* tempStatus=&iStatus; |
|
214 User::RequestComplete(tempStatus, KErrNone); |
|
215 } |
|
216 |
|
217 /** |
|
218 Tests CBaBackupSessionWrapper::RegisterFileL leaves with KErrServerBusy while the sever is under |
|
219 CloseAll operation. And the CloseAll request is complete successfully. |
|
220 */ |
|
221 void TestRegisterFileL() |
|
222 { |
|
223 class TSimpleObserver : public MBackupObserver |
|
224 { |
|
225 void ChangeFileLockL(const TDesC& /*aFileName*/,TFileLockFlags /*aFlags*/) {;} |
|
226 } simpleObserver; |
|
227 |
|
228 CBaBackupSessionWrapper* wrapper = CBaBackupSessionWrapper::NewL(); |
|
229 CleanupStack::PushL(wrapper); |
|
230 TRequestStatus status; |
|
231 wrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, status); |
|
232 TRAPD(err,wrapper->RegisterFileL(KFileName1, simpleObserver)); |
|
233 TEST(err == KErrServerBusy); |
|
234 User::WaitForRequest(status); |
|
235 TEST(status == KErrNone); |
|
236 CleanupStack::PopAndDestroy(wrapper); |
|
237 } |
|
238 |
|
239 /** |
|
240 @SYMTestCaseID SYSLIB-BAFL-CT-4053 |
|
241 @SYMTestCaseDesc Tests the updated functions work as expectation |
|
242 @SYMTestPriority High |
|
243 @SYMTestActions Calls the updated functions under the specified circumstance (sever under |
|
244 CloseAll operation). They run as expectation: |
|
245 1. Call CBaBackupSessionWrapper::RegisterFileL while the sever is under |
|
246 CloseAll operation. It leaves with KErrServerBusy. The CloseAll |
|
247 request is complete successfully. |
|
248 2. Call CBaBackupSessionWrapper::CloseAll() 2 times from the same client. |
|
249 The second request will be ignored. The first one will be completed |
|
250 successfully. |
|
251 3. Call CBaBackupSessionWrapper::CloseAll() 2 times from the different clients. |
|
252 The second request will be completed immediately with KErrServerBusy. The |
|
253 first one will be completed successfully. |
|
254 4. Call CBaBackupSessionWrapper::CloseFileL() while the sever is under CloseAll |
|
255 operation requested by the other client. It leaves with KErrServerBusy. The |
|
256 CloseAll request is complete successfully. |
|
257 5. Call CBaBackupSessionWrapper::CloseFileL() while the sever is |
|
258 under CloseAll operation requested by the same client. It is ignored and |
|
259 the CloseAll request is complete successfully. |
|
260 |
|
261 @SYMTestExpectedResults Test must not fail |
|
262 @SYMDEF PDEF121575 |
|
263 */ |
|
264 void PDEF121575L() |
|
265 { |
|
266 |
|
267 TestRegisterFileL(); |
|
268 CBUDefectTestMachine* bUSrvDefectMachine = CBUDefectTestMachine::NewL(); |
|
269 CleanupStack::PushL(bUSrvDefectMachine); |
|
270 |
|
271 CBackupFileObserver* fileObserver = CBackupFileObserver::NewL(*bUSrvDefectMachine, KFileName1); |
|
272 |
|
273 CleanupStack::Pop(bUSrvDefectMachine); |
|
274 |
|
275 // start the machine |
|
276 bUSrvDefectMachine->Complete(); |
|
277 |
|
278 CActiveScheduler::Start(); |
|
279 |
|
280 delete bUSrvDefectMachine ; |
|
281 delete fileObserver ; |
|
282 |
|
283 return; |
|
284 |
|
285 } |
|
286 |
|
287 void StartTestsL() |
|
288 { |
|
289 TheTest.Start (_L("PDEF121575: BAFL Backup System Multiple Simultaneous Call Problema\n")); |
|
290 PDEF121575L(); |
|
291 } |
|
292 |
|
293 TInt E32Main() |
|
294 { |
|
295 TheTest.Title (); |
|
296 |
|
297 __UHEAP_MARK; |
|
298 |
|
299 |
|
300 CTrapCleanup* theTrapCleanup=CTrapCleanup::New(); |
|
301 CActiveScheduler *activeScheduler=new CActiveScheduler; |
|
302 CActiveScheduler::Install(activeScheduler); |
|
303 |
|
304 TRAPD(error, StartTestsL()); |
|
305 TEST(error == KErrNone); |
|
306 |
|
307 delete activeScheduler; |
|
308 delete theTrapCleanup; |
|
309 |
|
310 __UHEAP_MARKEND; |
|
311 |
|
312 TheTest.End(); |
|
313 |
|
314 return(KErrNone); |
|
315 } |
|
316 |