Пример #1
0
HBufC* CScriptFile::ReadFileLC(const TDesC& aScript) const
	{
	HBufC8* file = NULL;

	TRAPD(err, file = ReadFileL(aScript));

	if (err)
		{
		TParse fileOut;
		err = iTestUtils.ResolveFile(*iComponent, aScript, fileOut);

		if (err)
			{
			iTestUtils.Test().Printf(_L("Cannot read file %S. Error=%d"), &aScript, err);
			User::Leave(err);
			}

		file = ReadFileL(fileOut.FullName());
		}

	CleanupStack::PushL(file);

	HBufC* buf = HBufC::NewL(file->Length());
	buf->Des().Copy(*file);
	CleanupStack::PopAndDestroy(file);
	CleanupStack::PushL(buf);
	return buf;
	}
EXPORT_C void CIAUpdateXmlParser::ParseFileL( 
    const TDesC& aFilePath )    
    {
    HBufC8* data( ReadFileL( aFilePath ) );
    CleanupStack::PushL( data );
    
    ParseL( *data );

    CleanupStack::PopAndDestroy( data );
    }
	EXPORT_C void ReadL(TBBBuildInfo& aInfo)
	{	
		CALLSTACKITEMSTATIC_N(_CL("BuildInfo"), _CL("ReadL"));
		TFileName fileName;
		BuildInfoPathL( fileName );

		RFs& fs = GetContext()->Fs();	
		auto_ptr<HBufC8> xml( ReadFileL(fs, fileName) );		
		auto_ptr<CSingleParser> parser( CSingleParser::NewL(&aInfo, 
															EFalse,
															EFalse) );
		parser->ParseL( *xml );
	}
Пример #4
0
/**
 * Verify Buffer integrity
 *
 * @param aReferenceFileName	Reference file against to verify integrity
 * @param aData					Buffer to verify
 *
 * @return						N/A
 *
 * @leave						System wide error
 */
void CT_DataVerify::VerifyBufferL( const TFileName& aReferenceFileName, const TDesC8& aData )
    {
	HBufC8* refdata = 0;
	TPtr8 ptr = refdata->Des();
	// read file into buffer, file must fit into HBufC8
	ReadFileL( aReferenceFileName, ptr );

	// compare read file with given buffer
	if( !CompareBuffers( refdata->Des(), aData ) )
		{
		// Data was corrupted
		User::Leave( KErrCorrupt );
		}
    }
Пример #5
0
// ---------------------------------------------------------------------------
// 
// ---------------------------------------------------------------------------
//    
TInt CNcdProviderUtils::UpdateShutdownFileL( 
    const TDesC& aRootPath )
    {
    DLTRACEIN((""));        
    
    RBuf path;       
    
    AppendPathsLC( 
        path, 
        aRootPath,
        NcdProviderDefines::KNcdProviderShutdownFile );
        
    BaflUtils::EnsurePathExistsL( FileSession(), aRootPath );
    
    // Try to read the value from the file if it exists, otherwise create a
    // new file.
    RFile file;
    CleanupClosePushL( file );
    TInt previousStartups = 0;
    
    TInt err = file.Open( FileSession(), path, EFileWrite );
    if ( err == KErrNone ) 
        {
        HBufC8* data = ReadFileL( file );
        if ( data->Length() ) 
            {            
            previousStartups = Des8ToInt( *data );
            DLTRACE(("Previous startups without good shutdown: %d", 
                previousStartups ));           
            }
        delete data;
        data = NULL;        
        User::LeaveIfError( file.Seek( ESeekStart, err ) );
        }
    else
        {
        DLTRACE(("No shutdown file, creating"));        
        User::LeaveIfError( file.Replace( FileSession(), path, EFileWrite ) );
        }
        
    // Update new count to the file
    previousStartups++;
    HBufC8* newData = IntToDes8LC( previousStartups );
    User::LeaveIfError( file.Write( *newData ) );     

    CleanupStack::PopAndDestroy( 3, &path ); // newData, file, path
    DLTRACEOUT(("Wrote previousStartups as: %d", previousStartups));    
    return previousStartups;
    }
// -----------------------------------------------------------------------------
// CLibxml2Tester::TestSetInputBufferL
// test setting input buffer
// (other items were commented in a header).
// -----------------------------------------------------------------------------
// 
TInt CLibxml2Tester::TestSetInputBufferInfosetL(CStifItemParser& aItem)
	{
	TPtrC pType;
	aItem.GetNextString(pType);
	
	TPtrC pDoc;
	aItem.GetNextString(pDoc);
	
	TPtrC pOut;
	aItem.GetNextString(pOut);
	
		iDoc = parser.ParseFileL(pDoc);
	TBufC<100> chunkName(_L("ChunkContainer") );
    TInt size = 2000;
    TInt maxSize = 10000;
    TInt offset = 0;
    TInt binarySize = CID_1().Length();
//    TBool isReadOnly = EFalse;
    RChunk chunk;
    chunk.CreateGlobal(chunkName, size, maxSize);
    CleanupClosePushL(chunk);
	TBuf8<32> contbuff = _L8("binary container some data...");
	RFs aRFs;
    aRFs.Connect();
    CleanupClosePushL( aRFs );
	RFile fp;
	User::LeaveIfError( fp.Open(aRFs, _L("c:\\testing\\data\\xmleng\\efute\\input\\containers\\petit.jpg"), EFileRead) );
	CleanupClosePushL(fp); 	
    TXmlEngBinaryContainer bincont = iDoc.CreateBinaryContainerL(CID_1(), contbuff);
    TXmlEngChunkContainer chunkcont = iDoc.CreateChunkContainerL(CID_2(), chunk, offset, binarySize);
	TXmlEngFileContainer filecont = iDoc.CreateFileContainerL(CID_3(), fp);
	iDoc.DocumentElement().AppendChildL(bincont);
	iDoc.DocumentElement().AppendChildL(chunkcont);
	iDoc.DocumentElement().AppendChildL(filecont);										
	RArray<TXmlEngDataContainer> list;
	CleanupClosePushL(list);
	iDoc.GetDataContainerList(list);
	
	
	HBufC8* buf = ReadFileL(pDoc);
    CleanupStack::PushL(buf);
		
	RFile fileHandle;
    RFs aRFs_2;
    aRFs_2.Connect();
    CleanupClosePushL( aRFs_2 );
	
    User::LeaveIfError( fileHandle.Replace( aRFs_2, pOut, EFileStream | EFileWrite | EFileShareExclusive));
    CleanupClosePushL( fileHandle );
	
    CTestHandler* testHandle = CTestHandler::NewLC( fileHandle );
    CXmlEngDeserializer* des = CXmlEngDeserializer::NewL( *testHandle, RetDeserializerType(pType) );
    CleanupStack::PushL( des );
    
   	des->SetInputBuffer(buf->Des());
   	des->UseExternalDataL( list );
   	des->DeserializeL();
	
	CleanupStack::PopAndDestroy( 9 );
	return KErrNone;	
	}
// -----------------------------------------------------------------------------
// CLibxml2Tester::DeserializeFromBufferL
// deserialize from buffer, convinience function
// (other items were commented in a header).
// -----------------------------------------------------------------------------
// 
TInt CLibxml2Tester::DeserializeFromBufferInfosetL(CStifItemParser& aItem)
    {    
    TInt err;    
    TPtrC pDeserializerType;
    aItem.GetNextString( pDeserializerType );
	
    TPtrC pInputFile;
    aItem.GetNextString( pInputFile );
	
    TPtrC pOutputFile;
    aItem.GetNextString( pOutputFile );
    
    TPtrC pDirtyReturn;
    aItem.GetNextString( pDirtyReturn );
    
    TLex lexer (pDirtyReturn);
    TInt dirtyReturn;
    lexer.Val(dirtyReturn);
    
    HBufC8* buf = ReadFileL(pInputFile);
    CleanupStack::PushL(buf);
    
	iDoc = parser.ParseFileL(pInputFile);
	TBufC<100> chunkName(_L("ChunkContainer") );
    TInt size = 2000;
    TInt maxSize = 10000;
    TInt offset = 0;
    TInt binarySize = CID_1().Length();
//    TBool isReadOnly = EFalse;
    RChunk chunk;
    chunk.CreateGlobal(chunkName, size, maxSize);
    CleanupClosePushL(chunk);
	TBuf8<32> contbuff = _L8("binary container some data...");
	RFs aRFs;
    aRFs.Connect();
    CleanupClosePushL( aRFs );
	RFile fp;
	User::LeaveIfError( fp.Open(aRFs, _L("c:\\testing\\data\\xmleng\\efute\\input\\containers\\petit.jpg"), EFileRead) );
	CleanupClosePushL(fp); 	
    TXmlEngBinaryContainer bincont = iDoc.CreateBinaryContainerL(CID_1(), contbuff);
    TXmlEngChunkContainer chunkcont = iDoc.CreateChunkContainerL(CID_2(), chunk, offset, binarySize);
	TXmlEngFileContainer filecont = iDoc.CreateFileContainerL(CID_3(), fp);
	iDoc.DocumentElement().AppendChildL(bincont);
	iDoc.DocumentElement().AppendChildL(chunkcont);
	iDoc.DocumentElement().AppendChildL(filecont);										
	RArray<TXmlEngDataContainer> list;
	CleanupClosePushL(list);
	iDoc.GetDataContainerList(list);
	 	
		
    RFile handleOutput;
    RFs rfOutput;
    rfOutput.Connect();
    CleanupClosePushL( rfOutput );
	
    User::LeaveIfError( handleOutput.Replace( rfOutput, pOutputFile, EFileWrite));
    CleanupClosePushL( handleOutput );	
		
    CTestHandler* testHandle = CTestHandler::NewLC( handleOutput );
    if( pDeserializerType.FindF( DEFAULT ) != KErrNotFound )
        {
        CXmlEngDeserializer* des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerDefault );
        CleanupStack::PushL( des );
        TRAP(err,des->DeserializeL(buf->Des()));
        }
    else if( pDeserializerType.FindF( XOP ) != KErrNotFound )     
        {
        CXmlEngDeserializer* des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerXOP );
        CleanupStack::PushL( des );
        TRAP(err,des->DeserializeL(buf->Des()));
        }
    else if( pDeserializerType.FindF( INFOSET ) != KErrNotFound )     
        {
        CXmlEngDeserializer* des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerXOPInfoset );
        CleanupStack::PushL( des );
        des->UseExternalDataL( list );
        TRAP(err,des->DeserializeL(buf->Des()));
        }
    else if( pDeserializerType.FindF( GZIP ) != KErrNotFound )     
        {
        CXmlEngDeserializer* des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerGZip );
        CleanupStack::PushL( des );
        TRAP(err,des->DeserializeL(buf->Des()));
        }

    CleanupStack::PopAndDestroy( 9 );
    
    if ( err == dirtyReturn ) return KErrNone;		
    else return err;	
    }
// -----------------------------------------------------------------------------
// CWidgetUiObserver::ResolveEmbeddedLinkL
// -----------------------------------------------------------------------------
//
TBool CWidgetUiObserver::ResolveEmbeddedLinkL(const TDesC& aEmbeddedUrl,
                                              const TDesC& aCurrentUrl,
                                              TBrCtlLoadContentType aLoadContentType,
                                              MBrCtlLinkContent& aEmbeddedLinkContent)
    {
    (void)aCurrentUrl;
    (void)aLoadContentType;
#ifdef _DEBUG
    _LIT(KResolveEmbeddedLink, "Resolve embedded link  aEmbeddedUrl = :%s:, aCurrentUrl = :%s:, aLoadContentType = %d");

    if ( iCanLog )
        {
        iFileLogger.WriteFormat( KResolveEmbeddedLink, aEmbeddedUrl, aCurrentUrl, aLoadContentType );
        }
#endif
    if ( IsFileScheme( aEmbeddedUrl ) )
        {

        // DENY if accessing anything inside WidgetUI's private dir AND that file is not inside 
        // the widget's own "sandbox". We define an installed widget's "sandbox" to be anything
        // under e:/private/10282822/<widget ID>/

        // Convert URL form to a more friendly path form, with locale-specific subdirectory
        TFileName lprojName;
        iWindow->WindowManager().WidgetUIClientSession().GetLprojName( lprojName );
        TranslateURLToFilenameL( aEmbeddedUrl, lprojName ); 
        
		iFs.PrivatePath(iAppPrivatePath);        
        // TRUE if e:/private/10282822/*/* was requested. It may or may not be inside a widget's sandbox.
        TBool isInsidePrivateDir = ( iFileName && ( (*iFileName).FindF(iAppPrivatePath) == KMaxDriveName ) ) ? ETrue : EFalse; 

        HBufC* widgetPath = iWindow->WidgetPath();          // The widget's sandbox. Object not ours.
        // TRUE if e:/private/10282822/<widgetID>/foo.js was requested. This is INSIDE widget's sandbox
        TBool isSandboxed = ( iFileName && widgetPath && (*iFileName).FindF( *widgetPath ) == 0 ) ? ETrue : EFalse;
        
        if ( isInsidePrivateDir && !isSandboxed )
            {   //Acess denied!
            User::Leave(KErrAccessDenied);
            }
        
        if ( !isSandboxed )
            { // For files in Public areas, don't use localized subdirectory
            TranslateURLToFilenameL( aEmbeddedUrl, KNullDesC); 
            } 
        
        HBufC8* buf = ReadFileL( *iFileName);
        
        if ( !buf && isSandboxed )
            { // In case of failure, fall-back to generic/non-localized content
            TranslateURLToFilenameL( aEmbeddedUrl, KNullDesC );
            buf = ReadFileL( *iFileName);
            }
        
        if ( !buf )
            {
            User::Leave(KErrGeneral);  
            }
        
        CleanupStack::PushL( buf );
        HBufC* contentType = NULL;
        TPtrC p( NULL, 0 );
        contentType = RecognizeLC( *iFileName, *buf );
        aEmbeddedLinkContent.HandleResolveComplete( *contentType, p, buf );
        CleanupStack::PopAndDestroy( 2, buf ); // contentType, buf
        return ETrue;
        }

    return EFalse;
    }
Пример #9
0
/*
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
*/
void CZipCompressor::RunL()
{
	if(iDebugFile.SubSessionHandle())
	{	
		iDebugFile.Write(_L8("me run, "));
	}
	
	if(iCancel || iDone || iStatus.Int() == KErrCancel)
	{// We are done or concelled, so lets finalize our zip
		EndL();
	}
	else if(iFilesArray->MdcaCount() > iCurrentFile)
	{
		if(iStatus.Int() != KErrNone )
		{// this would be an error on file read.
			iObserver.GetFileHandler().GetFileUtils().ShowFileErrorNoteL(iFilesArray->MdcaPoint(iCurrentFile), iStatus.Int());
		}
		
		if(iReadFile.SubSessionHandle() && iReadFileBuffer)
		{// we just finished reading a file to the buffer, 
		 // so first lets close the file
			iReadFile.Close();
			
			TInt AddErr(KErrNone);
			TRAP(AddErr,AddFileL(*iReadFileBuffer,iFilesArray->MdcaPoint(iCurrentFile)));	
			if(AddErr!= KErrNone)
			{
				iObserver.GetFileHandler().GetFileUtils().ShowFileErrorNoteL(iFilesArray->MdcaPoint(iCurrentFile), AddErr);
			}
			// lets clear some memory already in here
			delete iReadFileBuffer;
			iReadFileBuffer = NULL;
		}
		else
		{	// we are starting a new file
			// this will call SetActive in succesfull cases
			ReadFileL(iFilesArray->MdcaPoint(iCurrentFile));
			iObserver.CompressProcessL(iCurrentFile,iFilesArray->MdcaPoint(iCurrentFile));
		}
			
		if(iError != KErrNone)
		{	// errors cathed in Add/Read FileL functions
			iObserver.GetFileHandler().GetFileUtils().ShowFileErrorNoteL(iFilesArray->MdcaPoint(iCurrentFile), iError);
			// it has been repoted so we can now clear the error
			iError = KErrNone;
		}
					
		if(!IsActive())// No Read operation issued
		{
			// either we just added a file
			// or we had error while opening new one
			// anyway, lets move to next one
			iCurrentFile++;
			
			TRequestStatus* status=&iStatus;
			User::RequestComplete(status, KErrNone);
			SetActive();
		}
	}
	else
	{// All done so lets finalize our zip
		EndL();
	}
	
	if(iDebugFile.SubSessionHandle())
	{	
		iDebugFile.Write(_L8("rn done, "));
	}
}
Пример #10
0
EXPORT_C void CTestConfig::ReadScriptL(const TDesC& aScript)
	{
	iSections.ResetAndDestroy();

	CTestConfigSection* section = NULL;
	CTestConfigItem* currentItem = NULL;
	TInt currentItemStart = 0;
	CTestConfigSection* sectionDefaults = NULL;

	HBufC8* scriptContents = ReadFileL(aScript);
	CleanupStack::PushL(scriptContents);

	TLex8 input(*scriptContents);

	while (!input.Eos())
		{
		input.SkipSpaceAndMark();
		input.SkipCharacters();

		if ( input.TokenLength() == 0)    // if valid potential token
			{
			//end of the script file found
			break;
			}

		const TPtrC8 token(input.MarkedToken());

		if (token.CompareF(_L8("endscript")) == 0)
			{
			//end of the script file found
			break;
			}
		else if (IsNewSection(*scriptContents, input))
			{
			ParseAndSetItemValueL(*scriptContents, input, currentItemStart, currentItem);

			TInt mid = 1;
			TInt len = token.Length() - 2;

			const TPtrC8 sectionName(token.Mid(mid, len));

			if (sectionDefaults != NULL)
				section = CTestConfigSection::NewLC(sectionName, *sectionDefaults);
			else
				section = CTestConfigSection::NewLC(sectionName);

			if (sectionDefaults == NULL && IsDefaultSection(section->SectionName()))
				sectionDefaults = section;

			User::LeaveIfError(iSections.Append(section));
			CleanupStack::Pop(section);
			}
		else if (section != NULL)
			{
			TInt valueOffset;
			TPtrC8 newItem;

			if (IsNewComment(*scriptContents, input))
				{
				ParseAndSetItemValueL(*scriptContents, input, currentItemStart, currentItem);
				__ASSERT_DEBUG(currentItem == NULL, User::Invariant());
				SkipToNextLine(input);
				}
			else if (IsNewItem(*scriptContents, input, newItem, valueOffset))
				{
				ParseAndSetItemValueL(*scriptContents, input, currentItemStart, currentItem);
				currentItemStart = input.MarkedOffset() + valueOffset;
				currentItem = &section->AddItemL(newItem, KNullDesC8);
				}
			}
		}

	ParseAndSetItemValueL(*scriptContents, input, currentItemStart, currentItem);
	CleanupStack::PopAndDestroy(scriptContents);
	}
TInt CLibxml2Tester::TestDOMSetInputBufferL(CStifItemParser& aItem)
        {
        TPtrC pType;
        aItem.GetNextString(pType);
	
        TPtrC pDoc;
        aItem.GetNextString(pDoc);
        
        TPtrC pBinary;
        TPtrC pFile;
        if( pType.FindF( INFOSET ) != KErrNotFound )   
            {
        aItem.GetNextString( pBinary );
        aItem.GetNextString(pFile);	
            }
        	
        TPtrC pOut;
        aItem.GetNextString(pOut);
	
        HBufC8* buf = ReadFileL(pDoc);
        CleanupStack::PushL(buf);
		
//             TInt nContainers = 3;
        RFile fileHandle;
        RFs aRFs;
        aRFs.Connect();
        CleanupClosePushL( aRFs );
	
        RArray<TXmlEngDataContainer> list;
        if( pType.FindF( INFOSET ) != KErrNotFound )   
        {
        SetupDocumentL();	  
        HBufC8* binbuf = ReadFileToBufferL(pBinary);
        CleanupStack::PushL(binbuf);
        TBufC<100> chunkName(_L("ChunkContainer") );
        TInt size = 2000;
        TInt maxSize = 10000;
        TInt offset = 0;
        TInt binarySize = CID_2().Length();
//        TBool isReadOnly = EFalse;
        RChunk chunk;
        chunk.CreateGlobal(chunkName, size, maxSize);
        CleanupClosePushL(chunk);	
	RFile fp;
	User::LeaveIfError( fp.Open(aRFs, pFile, EFileRead) );
	CleanupClosePushL(fp); 	
        TXmlEngBinaryContainer bincont = iDoc.CreateBinaryContainerL(CID_1(), binbuf->Des());
        TXmlEngChunkContainer chunkcont = iDoc.CreateChunkContainerL(CID_2(), chunk, offset, binarySize);
        TXmlEngFileContainer filecont = iDoc.CreateFileContainerL(CID_3(), fp);
        iDoc.DocumentElement().AppendChildL(bincont);   
        iDoc.DocumentElement().AppendChildL(chunkcont);
        iDoc.DocumentElement().AppendChildL(filecont);
        CleanupClosePushL(list);	////
        iDoc.GetDataContainerList(list); 
        }	
	

        RXmlEngDocument doc;
	
       CXmlEngDeserializerDOM* des = CXmlEngDeserializerDOM::NewL();
       CleanupStack::PushL( des );
       des->UseDOMImplementationL( DOM_impl);
               if( pType.FindF( INFOSET ) != KErrNotFound )   
            {
            des->UseExternalDataL( list );
            }
       des->SetInputBuffer(buf->Des(), RetDeserializerType(pType));
       doc=des->DeserializeL();
       SaveDocumentL(doc,pOut);
          if( pType.FindF( INFOSET ) != KErrNotFound )   
            {
            CleanupStack::PopAndDestroy( 7 );
            }
            else
            {
            CleanupStack::PopAndDestroy( 3 );    
            }
       return KErrNone;	
       }
TVerdict CTestStepCIG711EncoderConfig::DoTestStep0046L()
{
    iTestStepResult = EFail;
    TInt result = KErrGeneral;

    INFO_PRINTF1(_L("G711EncoderIntfc - SetEncoderMode"));

    //Initialize - with the UID of our test HwDevice
#ifndef SYMBIAN_MULTIMEDIA_A3FDEVSOUND
    TUid testUID = {KUidG711EncoderConfigTestDevice};
#else
    TFourCC testUID('T','0','1','6');
#endif

    iTestStepResult = TestInitialize(testUID, EMMFStatePlaying);

    if (iTestStepResult != EPass)
    {
        INFO_PRINTF1(_L("DevSound failed to instantiate the test device"));
        return EInconclusive;
    }

    // reset the value as previous test is pass
    iTestStepResult = EFail;

    // KUidG711EncoderIntfc
    MG711EncoderIntfc* ptr = static_cast <MG711EncoderIntfc*> (iMMFDevSound->CustomInterface(KUidG711EncoderIntfc));

    if (ptr)
    {
        MG711EncoderIntfc::TEncodeMode encodeMode = MG711EncoderIntfc::EEncULaw;
        TInt setEncodeMode = MG711EncoderIntfc::EEncALaw;

        result = ptr->SetEncoderMode(encodeMode) ; // call method

        if (result == KErrNone)
        {
            // This file is created by the test stub, the plugin device
            _LIT(KFileName, "c:\\temp\\g711EncoderConfig.txt");

            ReadFileL(KFileName, setEncodeMode);

            if (static_cast<MG711EncoderIntfc::TEncodeMode>(setEncodeMode) == encodeMode)
            {
                INFO_PRINTF1(_L("MG711EncoderIntfc::SetEncoderMode finished successfully"));

                iTestStepResult = EPass;
            }
            else
            {
                ERR_PRINTF2(_L("MIlbcEncoderIntfc::SetEncoderMode failed with encodeMode %d"), encodeMode);
            }
        }
        else
        {
            ERR_PRINTF2(_L("MG711DecoderIntfc::SetEncoderMode failed with error %d"), result);
        }
    }
    else
    {
        INFO_PRINTF1(_L("MG711DecoderIntfc failed to retrieve the interface"));
        iTestStepResult = EInconclusive;
    }

    return iTestStepResult;
}