sl@0: /* sl@0: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include "cafserver.h" sl@0: #include "oomstep.h" sl@0: #include "content.h" sl@0: #include "data.h" sl@0: #include "supplier.h" sl@0: #include "cafmimeheader.h" sl@0: #include "importfile.h" sl@0: #include "supplieroutputfile.h" sl@0: #include "attribute.h" sl@0: #include "bitset.h" sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: const TInt KOomReadContent = 1; sl@0: const TInt KOomSupply = 2; sl@0: sl@0: sl@0: /* sl@0: * This step imports a DCF file into CAF sl@0: * sl@0: */ sl@0: CCafOomStep::~CCafOomStep() sl@0: { sl@0: } sl@0: sl@0: CCafOomStep::CCafOomStep(CCAFServer& aParent) : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFOomStep); sl@0: } sl@0: sl@0: sl@0: TVerdict CCafOomStep::doTestStepL() sl@0: { sl@0: SetTestStepResult(EInconclusive); sl@0: sl@0: TInt failCount=1; sl@0: TInt ret=-1; sl@0: const TInt MaxAllocationFailures=450; sl@0: sl@0: sl@0: TInt OomTest = KErrNotFound; sl@0: GetIntFromConfig(ConfigSection(),_L("OomTest"),OomTest); sl@0: sl@0: sl@0: if(OomTest == 2) sl@0: { sl@0: INFO_PRINTF2(_L("Starting Apparc..."),failCount); sl@0: StartApparcServerL(); sl@0: User::After(500000); // Allow async libraries to unload sl@0: } sl@0: sl@0: sl@0: while(failCount < MaxAllocationFailures && OomTest > 0) sl@0: { sl@0: // Mark heap and set allocation to fail sl@0: __UHEAP_MARK; sl@0: sl@0: switch(OomTest) sl@0: { sl@0: case KOomReadContent: sl@0: INFO_PRINTF2(_L("ReadContent() __UHEAP_FAILNEXT: %d"),failCount); sl@0: __UHEAP_FAILNEXT(failCount); sl@0: TRAP(ret,OomReadContentL()); sl@0: break; sl@0: case KOomSupply: sl@0: INFO_PRINTF2(_L("Supply() __UHEAP_FAILNEXT: %d"),failCount); sl@0: __UHEAP_FAILNEXT(failCount); sl@0: TRAP(ret,OomSupplyL()); sl@0: break; sl@0: default: sl@0: INFO_PRINTF2(_L("Out of Memory test %d does not exist"),OomTest); sl@0: SetTestStepResult(EFail); sl@0: ret = KErrNone; sl@0: break; sl@0: }; sl@0: sl@0: User::After(500000); // Allow async libraries to unload sl@0: sl@0: sl@0: // Check all heap is free'd sl@0: __UHEAP_MARKEND; sl@0: sl@0: // cancel heap failure sl@0: __UHEAP_RESET; sl@0: if(ret == KErrNone) sl@0: { sl@0: // Allocation failure has been moved all the way through the test sl@0: // Succeeded after failCount allocations sl@0: return TestStepResult(); sl@0: } sl@0: else sl@0: { sl@0: // Try failing a little further into the process sl@0: failCount++; sl@0: } sl@0: } sl@0: sl@0: // We must have reached our maximum number of allocation failures sl@0: // There must be some other problem sl@0: SetTestStepResult(EFail); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TVerdict CCafOomStep::OomReadContentL() sl@0: { sl@0: sl@0: TBuf8<2> buffer; sl@0: TRequestStatus status; sl@0: sl@0: TPtrC uri; sl@0: GetStringFromConfig(ConfigSection(),_L("URI"),uri); sl@0: sl@0: CContent* content = CContent::NewLC(uri); sl@0: CData* data = content->OpenContentL(EPeek); sl@0: CleanupStack::PushL(data); sl@0: sl@0: TInt size = 0; sl@0: data->DataSizeL(size); sl@0: sl@0: // Seek and read from start using both CAF and RFile sl@0: TInt pos = size/4; sl@0: data->Seek(ESeekStart, pos); sl@0: data->Read(buffer); sl@0: sl@0: pos=0; sl@0: data->Seek(ESeekCurrent, pos); sl@0: sl@0: data->Read(buffer,1,status); sl@0: User::WaitForRequest(status); sl@0: sl@0: CleanupStack::PopAndDestroy(2, content); sl@0: sl@0: SetTestStepResult(EPass); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CCafOomStep::OomSupplyL() sl@0: { sl@0: SetTestStepResult(EInconclusive); sl@0: sl@0: RFs fs; sl@0: RFile file; sl@0: TBuf8 <128> readBuffer; sl@0: sl@0: TPtrC outputDirectory, sourceFileName, suggestedFileName, mimeType; sl@0: TInt expectedLeave; sl@0: sl@0: // Get parameters from INI file sl@0: GetStringFromConfig(ConfigSection(),_L("OutputPath"),outputDirectory); sl@0: GetStringFromConfig(ConfigSection(),_L("SourceFileName"),sourceFileName); sl@0: GetStringFromConfig(ConfigSection(),_L("SuggestedFileName"),suggestedFileName); sl@0: GetStringFromConfig(ConfigSection(),_L("MimeType"),mimeType); sl@0: GetIntFromConfig(ConfigSection(),_L("LeaveResult"),expectedLeave); sl@0: sl@0: sl@0: // delete any file previously supplied, don't care if this sl@0: // has errors so trap. sl@0: Delete(_L("C:\\supplied.drm")); sl@0: Delete(_L("C:\\receipt.txt")); sl@0: sl@0: sl@0: HBufC8 *mime = ConvertDes16toHBufC8LC(mimeType); sl@0: sl@0: CCafMimeHeader *header = CCafMimeHeader::NewL(mime->Des()); sl@0: CleanupStack::PushL(header); sl@0: sl@0: CSupplier *mySupplier = CSupplier::NewLC(); sl@0: mySupplier->SetOutputDirectoryL(outputDirectory); sl@0: sl@0: // ignore return value, just exercises code for CCover sl@0: mySupplier->IsImportSupported(header->StandardMimeData(EContentType)); sl@0: sl@0: CImportFile *import = NULL; sl@0: import = mySupplier->ImportFileL(*header, suggestedFileName); sl@0: CleanupStack::PushL(import); sl@0: sl@0: // read the input file and pass it to the CAF sl@0: fs.Connect(); sl@0: CleanupClosePushL(fs); sl@0: sl@0: TInt result = file.Open(fs, sourceFileName, EFileRead | EFileStream | EFileShareAny); sl@0: CleanupClosePushL(file); sl@0: while(result == KErrNone) sl@0: { sl@0: result = file.Read(readBuffer); sl@0: if(readBuffer.Length() == 0) sl@0: break; sl@0: User::LeaveIfError(import->WriteData(readBuffer)); sl@0: } sl@0: CleanupStack::PopAndDestroy(&file); sl@0: User::LeaveIfError(import->WriteDataComplete()); sl@0: sl@0: TInt n = import->OutputFileCountL(); sl@0: if(n > 0) sl@0: { sl@0: // get output file type (content or receipt) sl@0: TOutputType outputType = import->OutputFileL(0).OutputType(); sl@0: sl@0: // get output file name, but ignore it because it would cause a warning sl@0: import->OutputFileL(0).FileName(); sl@0: sl@0: // get output file mime type sl@0: TPtrC8 OutputMimeType = import->OutputFileL(0).MimeTypeL(); sl@0: HBufC *outmime = ConvertDes8toHBufC16LC(OutputMimeType ); sl@0: CleanupStack::PopAndDestroy(outmime); sl@0: sl@0: if(outputType != EContent) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: // check an attribute, it's only a reference so no need to delete it sl@0: import->OutputFileL(0).AttributesL(ETrue); sl@0: } sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(&fs); sl@0: CleanupStack::PopAndDestroy(import); sl@0: CleanupStack::PopAndDestroy(mySupplier); sl@0: CleanupStack::PopAndDestroy(header); sl@0: CleanupStack::PopAndDestroy(mime); sl@0: sl@0: if (TestStepResult() != EFail) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: