First public contribution.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include <test/testexecutelog.h>
21 #include "cafserver.h"
26 #include "cafmimeheader.h"
27 #include "importfile.h"
28 #include "supplieroutputfile.h"
29 #include "attribute.h"
32 using namespace ContentAccess;
34 const TInt KOomReadContent = 1;
35 const TInt KOomSupply = 2;
39 * This step imports a DCF file into CAF
42 CCafOomStep::~CCafOomStep()
46 CCafOomStep::CCafOomStep(CCAFServer& aParent) : iParent(aParent)
48 SetTestStepName(KCAFOomStep);
52 TVerdict CCafOomStep::doTestStepL()
54 SetTestStepResult(EInconclusive);
58 const TInt MaxAllocationFailures=450;
61 TInt OomTest = KErrNotFound;
62 GetIntFromConfig(ConfigSection(),_L("OomTest"),OomTest);
67 INFO_PRINTF2(_L("Starting Apparc..."),failCount);
69 User::After(500000); // Allow async libraries to unload
73 while(failCount < MaxAllocationFailures && OomTest > 0)
75 // Mark heap and set allocation to fail
81 INFO_PRINTF2(_L("ReadContent() __UHEAP_FAILNEXT: %d"),failCount);
82 __UHEAP_FAILNEXT(failCount);
83 TRAP(ret,OomReadContentL());
86 INFO_PRINTF2(_L("Supply() __UHEAP_FAILNEXT: %d"),failCount);
87 __UHEAP_FAILNEXT(failCount);
88 TRAP(ret,OomSupplyL());
91 INFO_PRINTF2(_L("Out of Memory test %d does not exist"),OomTest);
92 SetTestStepResult(EFail);
97 User::After(500000); // Allow async libraries to unload
100 // Check all heap is free'd
103 // cancel heap failure
107 // Allocation failure has been moved all the way through the test
108 // Succeeded after failCount allocations
109 return TestStepResult();
113 // Try failing a little further into the process
118 // We must have reached our maximum number of allocation failures
119 // There must be some other problem
120 SetTestStepResult(EFail);
122 return TestStepResult();
125 TVerdict CCafOomStep::OomReadContentL()
129 TRequestStatus status;
132 GetStringFromConfig(ConfigSection(),_L("URI"),uri);
134 CContent* content = CContent::NewLC(uri);
135 CData* data = content->OpenContentL(EPeek);
136 CleanupStack::PushL(data);
139 data->DataSizeL(size);
141 // Seek and read from start using both CAF and RFile
143 data->Seek(ESeekStart, pos);
147 data->Seek(ESeekCurrent, pos);
149 data->Read(buffer,1,status);
150 User::WaitForRequest(status);
152 CleanupStack::PopAndDestroy(2, content);
154 SetTestStepResult(EPass);
156 return TestStepResult();
160 TVerdict CCafOomStep::OomSupplyL()
162 SetTestStepResult(EInconclusive);
166 TBuf8 <128> readBuffer;
168 TPtrC outputDirectory, sourceFileName, suggestedFileName, mimeType;
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);
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"));
185 HBufC8 *mime = ConvertDes16toHBufC8LC(mimeType);
187 CCafMimeHeader *header = CCafMimeHeader::NewL(mime->Des());
188 CleanupStack::PushL(header);
190 CSupplier *mySupplier = CSupplier::NewLC();
191 mySupplier->SetOutputDirectoryL(outputDirectory);
193 // ignore return value, just exercises code for CCover
194 mySupplier->IsImportSupported(header->StandardMimeData(EContentType));
196 CImportFile *import = NULL;
197 import = mySupplier->ImportFileL(*header, suggestedFileName);
198 CleanupStack::PushL(import);
200 // read the input file and pass it to the CAF
202 CleanupClosePushL(fs);
204 TInt result = file.Open(fs, sourceFileName, EFileRead | EFileStream | EFileShareAny);
205 CleanupClosePushL(file);
206 while(result == KErrNone)
208 result = file.Read(readBuffer);
209 if(readBuffer.Length() == 0)
211 User::LeaveIfError(import->WriteData(readBuffer));
213 CleanupStack::PopAndDestroy(&file);
214 User::LeaveIfError(import->WriteDataComplete());
216 TInt n = import->OutputFileCountL();
219 // get output file type (content or receipt)
220 TOutputType outputType = import->OutputFileL(0).OutputType();
222 // get output file name, but ignore it because it would cause a warning
223 import->OutputFileL(0).FileName();
225 // get output file mime type
226 TPtrC8 OutputMimeType = import->OutputFileL(0).MimeTypeL();
227 HBufC *outmime = ConvertDes8toHBufC16LC(OutputMimeType );
228 CleanupStack::PopAndDestroy(outmime);
230 if(outputType != EContent)
232 SetTestStepResult(EFail);
236 // check an attribute, it's only a reference so no need to delete it
237 import->OutputFileL(0).AttributesL(ETrue);
241 CleanupStack::PopAndDestroy(&fs);
242 CleanupStack::PopAndDestroy(import);
243 CleanupStack::PopAndDestroy(mySupplier);
244 CleanupStack::PopAndDestroy(header);
245 CleanupStack::PopAndDestroy(mime);
247 if (TestStepResult() != EFail)
249 SetTestStepResult(EPass);
252 return TestStepResult();