|
1 /* |
|
2 * Copyright (c) 2003-2009 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <test/testexecutelog.h> |
|
20 #include <s32mem.h> |
|
21 #include "cafserver.h" |
|
22 #include "oomstep.h" |
|
23 #include "content.h" |
|
24 #include "data.h" |
|
25 #include "supplier.h" |
|
26 #include "cafmimeheader.h" |
|
27 #include "importfile.h" |
|
28 #include "supplieroutputfile.h" |
|
29 #include "attribute.h" |
|
30 #include "bitset.h" |
|
31 |
|
32 using namespace ContentAccess; |
|
33 |
|
34 const TInt KOomReadContent = 1; |
|
35 const TInt KOomSupply = 2; |
|
36 |
|
37 |
|
38 /* |
|
39 * This step imports a DCF file into CAF |
|
40 * |
|
41 */ |
|
42 CCafOomStep::~CCafOomStep() |
|
43 { |
|
44 } |
|
45 |
|
46 CCafOomStep::CCafOomStep(CCAFServer& aParent) : iParent(aParent) |
|
47 { |
|
48 SetTestStepName(KCAFOomStep); |
|
49 } |
|
50 |
|
51 |
|
52 TVerdict CCafOomStep::doTestStepL() |
|
53 { |
|
54 SetTestStepResult(EInconclusive); |
|
55 |
|
56 TInt failCount=1; |
|
57 TInt ret=-1; |
|
58 const TInt MaxAllocationFailures=450; |
|
59 |
|
60 |
|
61 TInt OomTest = KErrNotFound; |
|
62 GetIntFromConfig(ConfigSection(),_L("OomTest"),OomTest); |
|
63 |
|
64 |
|
65 if(OomTest == 2) |
|
66 { |
|
67 INFO_PRINTF2(_L("Starting Apparc..."),failCount); |
|
68 StartApparcServerL(); |
|
69 User::After(500000); // Allow async libraries to unload |
|
70 } |
|
71 |
|
72 |
|
73 while(failCount < MaxAllocationFailures && OomTest > 0) |
|
74 { |
|
75 // Mark heap and set allocation to fail |
|
76 __UHEAP_MARK; |
|
77 |
|
78 switch(OomTest) |
|
79 { |
|
80 case KOomReadContent: |
|
81 INFO_PRINTF2(_L("ReadContent() __UHEAP_FAILNEXT: %d"),failCount); |
|
82 __UHEAP_FAILNEXT(failCount); |
|
83 TRAP(ret,OomReadContentL()); |
|
84 break; |
|
85 case KOomSupply: |
|
86 INFO_PRINTF2(_L("Supply() __UHEAP_FAILNEXT: %d"),failCount); |
|
87 __UHEAP_FAILNEXT(failCount); |
|
88 TRAP(ret,OomSupplyL()); |
|
89 break; |
|
90 default: |
|
91 INFO_PRINTF2(_L("Out of Memory test %d does not exist"),OomTest); |
|
92 SetTestStepResult(EFail); |
|
93 ret = KErrNone; |
|
94 break; |
|
95 }; |
|
96 |
|
97 User::After(500000); // Allow async libraries to unload |
|
98 |
|
99 |
|
100 // Check all heap is free'd |
|
101 __UHEAP_MARKEND; |
|
102 |
|
103 // cancel heap failure |
|
104 __UHEAP_RESET; |
|
105 if(ret == KErrNone) |
|
106 { |
|
107 // Allocation failure has been moved all the way through the test |
|
108 // Succeeded after failCount allocations |
|
109 return TestStepResult(); |
|
110 } |
|
111 else |
|
112 { |
|
113 // Try failing a little further into the process |
|
114 failCount++; |
|
115 } |
|
116 } |
|
117 |
|
118 // We must have reached our maximum number of allocation failures |
|
119 // There must be some other problem |
|
120 SetTestStepResult(EFail); |
|
121 |
|
122 return TestStepResult(); |
|
123 } |
|
124 |
|
125 TVerdict CCafOomStep::OomReadContentL() |
|
126 { |
|
127 |
|
128 TBuf8<2> buffer; |
|
129 TRequestStatus status; |
|
130 |
|
131 TPtrC uri; |
|
132 GetStringFromConfig(ConfigSection(),_L("URI"),uri); |
|
133 |
|
134 CContent* content = CContent::NewLC(uri); |
|
135 CData* data = content->OpenContentL(EPeek); |
|
136 CleanupStack::PushL(data); |
|
137 |
|
138 TInt size = 0; |
|
139 data->DataSizeL(size); |
|
140 |
|
141 // Seek and read from start using both CAF and RFile |
|
142 TInt pos = size/4; |
|
143 data->Seek(ESeekStart, pos); |
|
144 data->Read(buffer); |
|
145 |
|
146 pos=0; |
|
147 data->Seek(ESeekCurrent, pos); |
|
148 |
|
149 data->Read(buffer,1,status); |
|
150 User::WaitForRequest(status); |
|
151 |
|
152 CleanupStack::PopAndDestroy(2, content); |
|
153 |
|
154 SetTestStepResult(EPass); |
|
155 |
|
156 return TestStepResult(); |
|
157 } |
|
158 |
|
159 |
|
160 TVerdict CCafOomStep::OomSupplyL() |
|
161 { |
|
162 SetTestStepResult(EInconclusive); |
|
163 |
|
164 RFs fs; |
|
165 RFile file; |
|
166 TBuf8 <128> readBuffer; |
|
167 |
|
168 TPtrC outputDirectory, sourceFileName, suggestedFileName, mimeType; |
|
169 TInt expectedLeave; |
|
170 |
|
171 // Get parameters from INI file |
|
172 GetStringFromConfig(ConfigSection(),_L("OutputPath"),outputDirectory); |
|
173 GetStringFromConfig(ConfigSection(),_L("SourceFileName"),sourceFileName); |
|
174 GetStringFromConfig(ConfigSection(),_L("SuggestedFileName"),suggestedFileName); |
|
175 GetStringFromConfig(ConfigSection(),_L("MimeType"),mimeType); |
|
176 GetIntFromConfig(ConfigSection(),_L("LeaveResult"),expectedLeave); |
|
177 |
|
178 |
|
179 // delete any file previously supplied, don't care if this |
|
180 // has errors so trap. |
|
181 Delete(_L("C:\\supplied.drm")); |
|
182 Delete(_L("C:\\receipt.txt")); |
|
183 |
|
184 |
|
185 HBufC8 *mime = ConvertDes16toHBufC8LC(mimeType); |
|
186 |
|
187 CCafMimeHeader *header = CCafMimeHeader::NewL(mime->Des()); |
|
188 CleanupStack::PushL(header); |
|
189 |
|
190 CSupplier *mySupplier = CSupplier::NewLC(); |
|
191 mySupplier->SetOutputDirectoryL(outputDirectory); |
|
192 |
|
193 // ignore return value, just exercises code for CCover |
|
194 mySupplier->IsImportSupported(header->StandardMimeData(EContentType)); |
|
195 |
|
196 CImportFile *import = NULL; |
|
197 import = mySupplier->ImportFileL(*header, suggestedFileName); |
|
198 CleanupStack::PushL(import); |
|
199 |
|
200 // read the input file and pass it to the CAF |
|
201 fs.Connect(); |
|
202 CleanupClosePushL(fs); |
|
203 |
|
204 TInt result = file.Open(fs, sourceFileName, EFileRead | EFileStream | EFileShareAny); |
|
205 CleanupClosePushL(file); |
|
206 while(result == KErrNone) |
|
207 { |
|
208 result = file.Read(readBuffer); |
|
209 if(readBuffer.Length() == 0) |
|
210 break; |
|
211 User::LeaveIfError(import->WriteData(readBuffer)); |
|
212 } |
|
213 CleanupStack::PopAndDestroy(&file); |
|
214 User::LeaveIfError(import->WriteDataComplete()); |
|
215 |
|
216 TInt n = import->OutputFileCountL(); |
|
217 if(n > 0) |
|
218 { |
|
219 // get output file type (content or receipt) |
|
220 TOutputType outputType = import->OutputFileL(0).OutputType(); |
|
221 |
|
222 // get output file name, but ignore it because it would cause a warning |
|
223 import->OutputFileL(0).FileName(); |
|
224 |
|
225 // get output file mime type |
|
226 TPtrC8 OutputMimeType = import->OutputFileL(0).MimeTypeL(); |
|
227 HBufC *outmime = ConvertDes8toHBufC16LC(OutputMimeType ); |
|
228 CleanupStack::PopAndDestroy(outmime); |
|
229 |
|
230 if(outputType != EContent) |
|
231 { |
|
232 SetTestStepResult(EFail); |
|
233 } |
|
234 else |
|
235 { |
|
236 // check an attribute, it's only a reference so no need to delete it |
|
237 import->OutputFileL(0).AttributesL(ETrue); |
|
238 } |
|
239 } |
|
240 |
|
241 CleanupStack::PopAndDestroy(&fs); |
|
242 CleanupStack::PopAndDestroy(import); |
|
243 CleanupStack::PopAndDestroy(mySupplier); |
|
244 CleanupStack::PopAndDestroy(header); |
|
245 CleanupStack::PopAndDestroy(mime); |
|
246 |
|
247 if (TestStepResult() != EFail) |
|
248 { |
|
249 SetTestStepResult(EPass); |
|
250 } |
|
251 |
|
252 return TestStepResult(); |
|
253 } |
|
254 |