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