|
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 // Test MRU list\n |
|
15 // Tests MRU list by calling CApaProcess::SetMainDocFileName().\n |
|
16 // |
|
17 // t_mrustep.cpp |
|
18 // |
|
19 |
|
20 /** |
|
21 @file t_mrustep.cpp |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 #include <f32file.h> |
|
26 #include <apaid.h> |
|
27 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
28 #include <apaidpartner.h> |
|
29 #include <apgicnflpartner.h> |
|
30 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
31 #include <apgaplst.h> |
|
32 #include <apgicnfl.h> |
|
33 #include <apgdoor.h> |
|
34 #include <apparc.h> |
|
35 #include "tstapp.h" |
|
36 #include <fbs.h> |
|
37 #include <s32std.h> |
|
38 #include <s32stor.h> |
|
39 #include <s32file.h> |
|
40 #include <s32mem.h> |
|
41 #include "T_MruStep.h" |
|
42 |
|
43 #if !defined(__E32TEST_H__) |
|
44 #include <e32test.h> |
|
45 #endif |
|
46 |
|
47 |
|
48 void CT_MruStep::setup() |
|
49 { |
|
50 #if defined(__EPOC32__) |
|
51 // if we're on the rack create the directories we need |
|
52 TFullName filePath=_L("c:\\docs\\tstapp.doc"); |
|
53 TFullName tempPath=_L("c:\\system\\temp\\"); |
|
54 TParse parser; |
|
55 parser.Set(filePath,NULL,NULL); |
|
56 iFs.MkDirAll(parser.DriveAndPath()); |
|
57 parser.Set(tempPath,NULL,NULL); |
|
58 iFs.MkDirAll(parser.DriveAndPath()); |
|
59 #endif |
|
60 } |
|
61 |
|
62 |
|
63 /** |
|
64 @SYMTestCaseID T-MruStep-TestMRUL |
|
65 |
|
66 @SYMPREQ |
|
67 |
|
68 @SYMTestCaseDesc Test MRU list by calling CApaProcess::SetMainDocFileName() multiple times. |
|
69 |
|
70 @SYMTestPriority High |
|
71 |
|
72 @SYMTestStatus Implemented |
|
73 |
|
74 @SYMTestActions Test MRU list by calling CApaProcess::SetMainDocFileName() |
|
75 in the following cases:\n |
|
76 (1) Call CApaProcess::SetMainDocFileName() with no document created.\n |
|
77 (2) Call CApaProcess::SetMainDocFileName() after document creation. \n |
|
78 (3) Create a document for tstapp. Call CApaProcess::SetMainDocFileName() |
|
79 multiple times using the same filename to be set in the |
|
80 Most Recently Used (MRU) list. Ensure that only once the list is updated |
|
81 with the filename.\n |
|
82 (4) Create a document for tstapp. Call CApaProcess::SetMainDocFileName() |
|
83 multiple times using different filename to be set in the |
|
84 Most Recently Used (MRU) list on each attempt. Ensure that only a |
|
85 maximum of 50 filenames are present.\n |
|
86 (5) Open MRU.DAT and then call CApaProcess::SetMainDocFileName(). |
|
87 The filename set should not appear in MRU list since MRU.DAT is open.\n |
|
88 (6) Create a document for tstapp. Call CApaProcess::SetMainDocFileName() |
|
89 multiple times when there is no memory available on the device. |
|
90 The MRU list should not reflect the newly set file name.\n |
|
91 (7) Test CApaRecentFile::GetRecentFileL() by passing KNullUid. |
|
92 Ensure that all entries for those last used documents are retrieved |
|
93 when KNullUid is passed.\n |
|
94 (8) Test CApaRecentFile::GetRecentFileListL() to ensure that it returns NULL.\n |
|
95 In the above mentioned situations tests ensure that |
|
96 there are no memory leaks.\n\n |
|
97 API Calls:\n |
|
98 CApaProcess::SetMainDocFileName(const TDesC& aMainDocFileName)\n |
|
99 CApaRecentFile::GetRecentFileL(RFs& aFs, TUid aAppUid, TInt aIndex)\n |
|
100 CApaRecentFile::GetRecentFileListL(RFs& aFs, TUid aAppUid)\n |
|
101 |
|
102 @SYMTestExpectedResults Each of the tests should complete with the desired |
|
103 output and without any memory leaks. |
|
104 |
|
105 */ |
|
106 void CT_MruStep::TestMRUL() |
|
107 { |
|
108 CApaProcess* process=NULL; |
|
109 CApaDocument* doc=NULL; |
|
110 |
|
111 // Test 1 |
|
112 INFO_PRINTF1(_L("SetMainDocFileName with no document")); |
|
113 __UHEAP_RESET; |
|
114 __UHEAP_MARK; |
|
115 process = CApaProcess::NewL(iFs); |
|
116 process->SetMainDocFileName(_L("FileName 01")); |
|
117 delete process; |
|
118 __UHEAP_MARKEND; |
|
119 |
|
120 // test 2 |
|
121 INFO_PRINTF1(_L("SetMainDocFileName after document construction")); |
|
122 |
|
123 __UHEAP_RESET; |
|
124 __UHEAP_MARK; |
|
125 |
|
126 // Create document |
|
127 process = CApaProcess::NewL(iFs); |
|
128 TApaApplicationFactory appFact(KUidTestApp); |
|
129 doc = process->AddNewDocumentL(appFact); |
|
130 |
|
131 // Set file name into MRU list |
|
132 process->SetMainDocFileName(_L("FileName 02")); |
|
133 process->DestroyDocument(doc); |
|
134 delete process; |
|
135 REComSession::FinalClose(); |
|
136 __UHEAP_MARKEND; |
|
137 |
|
138 // test 3 |
|
139 INFO_PRINTF1(_L("SetMainDocFileName x100 with same filename")); |
|
140 TInt count; |
|
141 |
|
142 __UHEAP_RESET; |
|
143 __UHEAP_MARK; |
|
144 |
|
145 process = CApaProcess::NewL(iFs); |
|
146 doc = process->AddNewDocumentL(appFact); |
|
147 |
|
148 // Set file name into MRU list - this name should only appear once |
|
149 for (count=0; count<100; count++) |
|
150 process->SetMainDocFileName(_L("FileName 03")); |
|
151 |
|
152 process->DestroyDocument(doc); |
|
153 delete process; |
|
154 |
|
155 REComSession::FinalClose(); |
|
156 __UHEAP_MARKEND; |
|
157 |
|
158 // test 4 |
|
159 INFO_PRINTF1(_L("SetMainDocFileName x100 with different filenames")); |
|
160 |
|
161 __UHEAP_RESET; |
|
162 __UHEAP_MARK; |
|
163 |
|
164 process = CApaProcess::NewL(iFs); |
|
165 doc = process->AddNewDocumentL(appFact); |
|
166 |
|
167 /** Set file name into MRU list - there should only be a maximum of 50 names in the list */ |
|
168 TBuf<20> fileName; |
|
169 |
|
170 for (count=0; count < 100; count++) |
|
171 { |
|
172 fileName.Zero(); |
|
173 fileName.AppendFormat(_L("FileName %d"),count); |
|
174 |
|
175 process->SetMainDocFileName(fileName); |
|
176 } |
|
177 |
|
178 process->DestroyDocument(doc); |
|
179 delete process; |
|
180 |
|
181 REComSession::FinalClose(); |
|
182 __UHEAP_MARKEND; |
|
183 |
|
184 |
|
185 // test 7 |
|
186 INFO_PRINTF1(_L("Testing GetRecentFileL with KNullUid")); |
|
187 |
|
188 __UHEAP_RESET; |
|
189 __UHEAP_MARK; |
|
190 |
|
191 process = CApaProcess::NewL(iFs); |
|
192 doc = process->AddNewDocumentL(appFact); |
|
193 |
|
194 process->DestroyDocument(doc); |
|
195 delete process; |
|
196 |
|
197 REComSession::FinalClose(); |
|
198 __UHEAP_MARKEND; |
|
199 |
|
200 // MRU functionality has been removed in 7.0s test that GetRecentFile returns NULL |
|
201 // test 8 |
|
202 INFO_PRINTF1(_L("Testing GetRecentFileListL returns NULL")); |
|
203 |
|
204 __UHEAP_RESET; |
|
205 __UHEAP_MARK; |
|
206 |
|
207 process = CApaProcess::NewL(iFs); |
|
208 doc = process->AddNewDocumentL(appFact); |
|
209 |
|
210 process->DestroyDocument(doc); |
|
211 delete process; |
|
212 |
|
213 REComSession::FinalClose(); |
|
214 __UHEAP_MARKEND; |
|
215 } |
|
216 |
|
217 |
|
218 /** |
|
219 Auxiliary Fn for all Test Cases. |
|
220 |
|
221 This method creates and installs an active scheduler and puts the |
|
222 test code onto the scheduler as a CIdle object. The method initiates |
|
223 all tests by calling the static method CT-MruTestCallBackWrapper::CallBack(). |
|
224 |
|
225 */ |
|
226 void CT_MruStep::DoTestsInScheldulerLoopL() |
|
227 { |
|
228 // create an active scheduler |
|
229 CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; |
|
230 CActiveScheduler::Install(scheduler); |
|
231 CleanupStack::PushL(scheduler); |
|
232 |
|
233 // put the test code onto the scheduler as an idle object |
|
234 CIdle* idle=CIdle::NewL(-20); |
|
235 CleanupStack::PushL(idle); |
|
236 |
|
237 CT_MruTestCallBackWrapper* callBack = new(ELeave) CT_MruTestCallBackWrapper(this); |
|
238 CleanupStack::PushL(callBack); |
|
239 |
|
240 idle->Start(TCallBack(CT_MruTestCallBackWrapper::CallBack,callBack)); |
|
241 // start the test code |
|
242 CActiveScheduler::Start(); |
|
243 |
|
244 // all outstanding requests complete - kill the scheduler |
|
245 CleanupStack::PopAndDestroy(3); //scheduler, callBack, idle |
|
246 } |
|
247 |
|
248 |
|
249 CT_MruTestCallBackWrapper::CT_MruTestCallBackWrapper(CT_MruStep* aTestStep) |
|
250 /** |
|
251 Constructor |
|
252 */ |
|
253 { |
|
254 iTestStep=aTestStep; |
|
255 } |
|
256 |
|
257 CT_MruTestCallBackWrapper::~CT_MruTestCallBackWrapper() |
|
258 /** |
|
259 Destructor |
|
260 */ |
|
261 { |
|
262 } |
|
263 |
|
264 TInt CT_MruTestCallBackWrapper::CallBack(TAny* aPtr) |
|
265 /** |
|
266 This static method is the callback function of CIdle object.The method |
|
267 calls the non-static method TestMRUL() which initiates all the tests. |
|
268 */ |
|
269 { |
|
270 __UHEAP_MARK; |
|
271 |
|
272 TRAPD(r,((CT_MruTestCallBackWrapper *)aPtr)->iTestStep->TestMRUL()); |
|
273 __ASSERT_ALWAYS(!r,User::Panic(_L("TestMRUL"),r)); |
|
274 __UHEAP_MARKEND; |
|
275 |
|
276 CActiveScheduler::Stop(); |
|
277 return EFalse; // don't call back again |
|
278 } |
|
279 |
|
280 CT_MruStep::~CT_MruStep() |
|
281 /** |
|
282 Destructor |
|
283 */ |
|
284 { |
|
285 } |
|
286 |
|
287 CT_MruStep::CT_MruStep() |
|
288 /** |
|
289 Constructor |
|
290 */ |
|
291 { |
|
292 // Call base class method to set up the human readable name for logging |
|
293 SetTestStepName(KT_MruStep); |
|
294 } |
|
295 |
|
296 TVerdict CT_MruStep::doTestStepPreambleL() |
|
297 /** |
|
298 @return - TVerdict code |
|
299 Override of base class virtual |
|
300 */ |
|
301 { |
|
302 SetTestStepResult(EPass); |
|
303 return TestStepResult(); |
|
304 } |
|
305 |
|
306 TVerdict CT_MruStep::doTestStepPostambleL() |
|
307 /** |
|
308 @return - TVerdict code |
|
309 Override of base class virtual |
|
310 */ |
|
311 { |
|
312 return TestStepResult(); |
|
313 } |
|
314 |
|
315 |
|
316 TVerdict CT_MruStep::doTestStepL() |
|
317 /** |
|
318 @return - TVerdict code |
|
319 Override of base class virtual |
|
320 */ |
|
321 { |
|
322 INFO_PRINTF1(_L("Testing Apparch...T_Mru")); |
|
323 |
|
324 // set up an fbs |
|
325 FbsStartup(); |
|
326 TInt ret=RFbsSession::Connect(); |
|
327 TEST(!ret); |
|
328 |
|
329 // set up the directory structure |
|
330 iFs.Connect(); |
|
331 setup(); |
|
332 |
|
333 // run the testcode |
|
334 TRAP(ret,DoTestsInScheldulerLoopL()) |
|
335 TEST(ret==KErrNone); |
|
336 |
|
337 iFs.Close(); |
|
338 |
|
339 INFO_PRINTF1(_L("Testing T_Mru Completed!")); |
|
340 return TestStepResult(); |
|
341 } |
|
342 |