void CFileOperator::DoWriteL()
	{
	RFile file;
	TInt count = iFirstFile;
	_LIT8(KData, "Some text for writing test of enhanced notification performance test.");
	
	while (count < iFirstFile + iNumFiles)
		{
		TFileName nextFile;
		FileNameGen(nextFile, count);
		file.Open(iFs, nextFile, EFileWrite);
		file.Write(KData);
		// Flush file to ensure notification is received
		file.Flush();
		file.Close();	
		count++;
		}
	}
void CFileOperator::DoManyChangesOnSingleFileL()
	{
	TFileName fileName;
	FileNameGen(fileName, 9999);
	
	RFile file;
	_LIT8(KData, "a");
	
	for(TInt i = 0; i < iNumFiles; i++)
		{
		TInt offset = 0;
		file.Open(iFs, fileName, EFileWrite);
		file.Seek(ESeekEnd, offset);
		file.Write(KData);
		file.Flush();
		file.Close();
		}
	}
Exemplo n.º 3
0
void CIoReadTest::ReadFileL()
	{
	RFile file;
	LeaveIfErr(file.Open(Fs(), iFile, EFileRead | EFileShareExclusive), _L("Cannot open file '%S'"), &iFile);
	CleanupClosePushL(file);
	TInt fileSize;
	User::LeaveIfError(file.Size(fileSize));
	
	RBuf8 contents;
	contents.CreateL(fileSize);
	CleanupClosePushL(contents);
	User::LeaveIfError(file.Read(contents));
	
	// convert data to 16-bit which is how it'll come out of the io server
	iFileContents.CreateL(fileSize);
	iFileContents.Copy(contents); // copy & expand
	CleanupStack::PopAndDestroy(2, &file); // contents, file
	}
void FileDependencyUtil::CheckFileDependencyL()
	{	
	RFs fsSession;
  	RFile file;

    CleanupClosePushL(fsSession);
  	User::LeaveIfError(fsSession.Connect());

    TInt err = file.Open(fsSession, KSoundDevBtFileName, EFileRead);

  	file.Close();

  	if(err != KErrNone)
  		{
	    User::LeaveIfError(KErrNotSupported);
  		}
  	CleanupStack::PopAndDestroy(); //fsSession 
	}
HBufC* TestUniDataModelVCalPlugin::ReadFromFileL(const TDesC& aFile)
{
		RFile file;
		TBuf8<1024> lineBuffer;
		TInt err = KErrNone;

		err = file.Open(iFs, aFile, EFileStreamText | EFileRead | EFileShareAny);

		if (err != KErrNone) // Didn't find the file, so leave - should only get valid filenames!
			{
				User::Leave(KErrNotFound);
			}

		HBufC* bioBuf = HBufC::NewLC(65535); // Create a new descriptor on the heap.
		HBufC* copyBuffer = HBufC::NewLC(1024);

		do // Read in the text from file, and also check if there is a name field:
			{
				err = file.Read(lineBuffer);// Read upto 256 chars, '\n' and all...
				//err = ReadLineL(file,lineBuffer);
				if (err == KErrNone) // Made a valid read,
					if (lineBuffer.Length() == 0) // but read 0 chars
                err = KErrEof; // so set err value to end processing

				if (err == KErrNone)
					{	
						copyBuffer->Des().Copy(lineBuffer);// Copy, and overwrite existing text
						if ( (bioBuf->Length() + copyBuffer->Length())
								> bioBuf->Des().MaxLength())
							{
								bioBuf = bioBuf->ReAllocL(bioBuf->Length()
										+ copyBuffer->Length());
							}
						bioBuf->Des().Append(*copyBuffer);
						//bioBuf->Des().Append(_L("\n"));
					}
    }while (err != KErrEof);

    CleanupStack::PopAndDestroy(); // Destroy the copyBuffer.
    CleanupStack::Pop();// Remove the bioBuf.

    file.Close();
    return bioBuf;
}
/**
 * Creates a file and copies the data in the source file to the destination file. 
 */
TInt RTestStepOggCtrlBase::CopyFile(TPtrC aFileNameSrc, TPtrC aFileNameDst)
	{
	TInt theErr = KErrNone;
	RFs		fs;
	fs.Connect();
	RFile	theFileNew;
	RFile	theFile;

	fs.MkDirAll(aFileNameDst);
	theFile.Open(fs, aFileNameSrc, EFileShareReadersOnly);
	TInt	theSize;
	theFile.Size(theSize);
	
	TBuf8<KSizeBuf>	theBuf;
	TInt	theStep = KSizeBuf;
	if(theStep > theSize)
		{
		theStep = theSize;
		}
	TInt theRes = theFileNew.Create(fs, aFileNameDst, EFileShareAny);
	if(theRes == KErrAlreadyExists)
		{
		theRes = theFileNew.Replace(fs, aFileNameDst, EFileShareAny);	
		}
	if(theRes != KErrNone)
		{
		return theRes;	
		}
	TInt	theCurLength = 0;
	while(theCurLength < theSize)
		{
		theFile.Read(theBuf, theStep);
		theFileNew.Write(theBuf, theStep);
		theCurLength += theStep;
		if(theCurLength + theStep > theSize )
			{
			theStep = theSize - theCurLength;
			}
		}
	theFileNew.Close();
	theFile.Close();
	fs.Close();
	return theErr;
	}
// ---------------------------------------------------------
// CBrCtlSampleAppLinkResolver::ReadFile
// ---------------------------------------------------------
//
HBufC8* 
CBrCtlSampleAppLinkResolver::ReadFileLC(const TDesC& aFileName)
    {
    RFs rfs;
    RFile file;
    User::LeaveIfError(rfs.Connect());
    CleanupClosePushL(rfs);
    User::LeaveIfError(file.Open(rfs, aFileName, EFileRead));
    CleanupClosePushL(file);
    TInt size;
    User::LeaveIfError(file.Size(size));
    HBufC8* buf = HBufC8::NewLC(size);
    TPtr8 bufPtr(buf->Des());
    User::LeaveIfError(file.Read(bufPtr));
    CleanupStack::Pop(); // buf
    CleanupStack::PopAndDestroy(2); // file, rfs
    CleanupStack::PushL(buf);
    return buf;
    }
Exemplo n.º 8
0
void CLinePaginatorTest::OpenTestFileL()
	{
	TBuf8<128> text;
	TInt err=ifsClient.Connect();
	err=iTestFile.Open(ifsClient,TEST_FILE,EFileStream|EFileRead|EFileShareReadersOnly);


	iTestFile.Read(0,text,128);
	TInt startNum=text.Locate('<')+1;
	text.Delete(0,startNum);
	TLex8 lex=text;
	TInt pageHeight;
	lex.Val(pageHeight);
	iPaginator.SetPageHeight(pageHeight);

	TBuf<254> buf;
	buf.AppendFormat(_L("DocPos\tHeight\tKeep\tStart\tHeight of Pages = <%d>\n"), pageHeight);
	TESTPRINT(buf);
	}
Exemplo n.º 9
0
// -----------------------------------------------------------------------------
// AddDomainRoL()
// The function will add a file info into database
// -----------------------------------------------------------------------------
//
void CDcfRepSrv::AddDomainRoL( const TDesC& aFile )
{
#ifdef _DRM_TESTING
    WriteL(_L8("AddDomainRoL"));
#endif

    __UHEAP_MARK;
    RFile file;
    TPtr8 ptr(NULL,0,0);
    CContent* content =NULL;
    User::LeaveIfError(file.Open(iFs, aFile, EFileShareReadersOrWriters | EFileWrite ) );
    CleanupClosePushL(file);
    content = CContent::NewL(file);
    CleanupStack::PushL(content);
    User::LeaveIfError(content->AgentSpecificCommand(EEmbedDomainRo,
                       KNullDesC8, ptr ));
    CleanupStack::PopAndDestroy(2); // content, file
    __UHEAP_MARKEND;
}
Exemplo n.º 10
0
void CTFXConfigParser::ParseL(const TDesC& aFilename)
    {
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);
    RFile file;
    User::LeaveIfError(file.Open(fs, aFilename, EFileRead | EFileShareReadersOnly));
    CleanupClosePushL(file);
    TInt filesize = 0;
    User::LeaveIfError(file.Size(filesize));
    HBufC8* buffer = HBufC8::NewLC(filesize);
    TPtr8 ptr( buffer->Des() );
    User::LeaveIfError(file.Read(ptr, filesize));

    iParser->ParseBeginL();
    iParser->ParseL(*buffer);
    iParser->ParseEndL();
    CleanupStack::PopAndDestroy(3); // fs, file, buffer
    }
Exemplo n.º 11
0
TInt CFloggerTest025_BuildTestUrel3::DoTestCheckWriteL()
	{
	RFile theFile;
	HBufC8 * hBuffer;
	TInt listfilesize;
	TInt returnCode;
	RFs fileSystem; //For file operation create a file system	
	TInt numSuccessful = 0;

	User::After(KTimeToLog);
	
	User::LeaveIfError(fileSystem.Connect());
	
	//Open the file in the read mode
	User::LeaveIfError(theFile.Open(fileSystem,KFloggerOutputFile,EFileRead)); 

	CleanupClosePushL(theFile);	
	
	User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
	CleanupStack::PushL(hBuffer);
	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer

	// Read from position 0: start of file
	returnCode = theFile.Read(ptrString);
	
	// we should not find any log string
	if (returnCode == KErrNone)
		{
		returnCode = ptrString.Find(KTestMessage8);
		if (returnCode == KErrNotFound)
			{
			numSuccessful++;
			}
		}

	CleanupStack::PopAndDestroy(hBuffer);
	CleanupStack::PopAndDestroy(); // For theFile object
	if (numSuccessful > 0)
		return KErrNone;
	else 
		return KErrGeneral;
	}
Exemplo n.º 12
0
void CCntPBAPSupport::CompareExportsL(const TDesC8& aExpected)
    {
    
	RFile exportedFile;	
	TInt err = exportedFile.Open(iFsSession, KTempExportFile(), EFileRead);
	if (err != KErrNone)
		{
		ReportFileErrorL(err, KTempExportFile());	
		}
	CleanupClosePushL(exportedFile);
	RFileReadStream stream1(exportedFile);
	CleanupClosePushL(stream1);

	TBuf8<0x80> bufO;
	
	TInt line = 1;
	do {
		TRAP(err, stream1.ReadL(bufO, TChar(0xa)));
		if (err != KErrNone && err != KErrEof)
			{
			User::Leave(err);	
			}
        			
    	_LIT8(KPropREV,"REV:");
    	_LIT8(KPropUID,"UID:");
		TBufC8<4> first4char(bufO.Left(4));
		if(!first4char.Compare(KPropREV()) || !first4char.Compare(KPropUID()))
		    {
		    continue;
		    }
		
        if (KErrNotFound == aExpected.Find(bufO))
        	{
        	TBuf<256> info;
            info.Copy(bufO);
            TRefByValue<const TDesC> format(info);
            test.Printf(format);
            test (EFalse);
        	}
		++line;
		} while (err != KErrEof);
	CleanupStack::PopAndDestroy(2,&exportedFile);
    }
Exemplo n.º 13
0
/**
@SYMTestCaseID 		 		SYSLIB-XML-CT-3748
@SYMTestCaseDesc		    Processing namespaces.
@SYMTestPriority 		    Medium
@SYMTestActions  		    Creating an xml parser and enabling namespace mapping reporting, before parsing a document.
@SYMTestExpectedResults 	The document is parsed with the namespace mapping reporting enabled.
@SYMDEF 		 		 	INC059062
*/
LOCAL_C void INC059062L()
	{
	RDefectTests handler;
	CleanupClosePushL (handler);

	CParser* parser = CParser::NewLC(KXmlParserDataType, handler);

	User::LeaveIfError(parser->EnableFeature(EReportNamespaceMapping));

	RFile handle;
	handle.Open(TheFs, KNsAndBindingFile, EFileShareReadersOnly);
	CleanupClosePushL (handle);

	ParseL(*parser, handle);

	CleanupStack::PopAndDestroy (&handle);
	CleanupStack::PopAndDestroy (parser);
	CleanupStack::PopAndDestroy (&handler);
	}
Exemplo n.º 14
0
EXPORT_C TInt TEFparser::ReadFileLC(RFs& aFs, 
										const TDesC& aScriptFilepath,
										TPtrC& aScriptFileContents )
	{
	
	RFile scriptFile;
	TInt err = scriptFile.Open(aFs, aScriptFilepath, EFileStream | EFileRead | EFileShareAny);
	if (err != KErrNone)
		{	
		return KErrNotFound;
		}
	// gets size of ini file
	TInt size;
	scriptFile.Size(size);
	scriptFile.Close();
			
	// reads ini into iTestInput
	HBufC* scriptFileH16 = HBufC::NewLC(size);
	HBufC8* scriptFileH = HBufC8::NewLC(size);
	
	//RBuf scriptFileR;
	TPtr8 pInput = scriptFileH->Des(); 
	TPtr pInput16 = scriptFileH16->Des(); 
	
	pInput.SetLength(size); 
	
	RFileReadStream stream;
	User::LeaveIfError(stream.Open(aFs, aScriptFilepath, EFileStream | EFileRead | EFileShareReadersOnly));
	CleanupClosePushL(stream);
	stream.ReadL(pInput,size);
	
//	stream.ReadL(pInput, size);
	
	pInput16.Copy(pInput);
	//scriptFileR.Assign(scriptFileH16);
	
	aScriptFileContents.Set(*scriptFileH16);
	
	CleanupStack::PopAndDestroy(2); // stream, testInput
	
	return KErrNone;
	}
Exemplo n.º 15
0
TBool TestExportedFile(const TDesC& aFilename)
    {
	//Check for DTSTART and DTEND
	//Check it is in DATE-TIME format
	TBool DTSTART_patternFound = EFalse;
	TBool DTEND_patternFound = EFalse;    
    
	
	RFile fileHandle;
	CleanupClosePushL(fileHandle);
	fileHandle.Open(calTestLibrary->FileSession(),aFilename, 0);
	
	
	TBuf8<256> line;
	TInt KDateLength = 8;
	TInt KColon = 1;
	while (fileHandle.Read(line) == KErrNone && line.Length() != 0)
	{
	    TInt pos = line.Find(KDTSTART());
		if (pos != KErrNotFound)
		    {
		    DTSTART_patternFound = ETrue;
		    TText time;
		    time = line[pos + KDTSTART().Length() + KColon + KDateLength ];
		    test (time == 'T');	
	  	    }
	  	pos = line.Find(KDTEND());
	    if ( pos != KErrNotFound)
		    {
			DTEND_patternFound = ETrue;
			TText time;
		    time = line[pos + KDTEND().Length() + KColon + KDateLength ];
			test (time == 'T');
			
			if (DTSTART_patternFound && DTEND_patternFound)
			break;
		    }
	} 
	CleanupStack::PopAndDestroy(&fileHandle);
	return (DTSTART_patternFound && DTEND_patternFound);
	
    }
Exemplo n.º 16
0
void CRuleManager::ReadFavFromFile()
	{
	TFileName filename;
	GetAppPath(filename);
	filename.Append(KFavRuleFile);

	RFile file;
	TInt err;
	
	err = file.Open(CCoeEnv::Static()->FsSession(), filename, EFileRead);
	CleanupClosePushL(file);
	
	if (KErrNone != err)
		{
		CleanupStack::PopAndDestroy(); // file
		return;
		}
	
	TInt size;
	file.Size(size);
	
	if (size > 0)
		{
		HBufC8* text = HBufC8::NewL(size);
		TPtr8 ptr = text->Des();
		file.Read(ptr);
	
		TInt pos = ptr.Locate(KCharRuleSymbolEnd);
		if (pos != KErrNotFound)
			{
			ReadFromFile(ptr,pos,iFavRule);		
			ptr.Delete(0,pos+1);
			
			TInt num = CCommonUtils::StrToInt(ptr);
			iFavRule->SetFavCount(num);
			}
	
		delete text;
		}
	
	CleanupStack::PopAndDestroy(); // file
	}
//********************************************************************************************
CParserVCard* CVersitCardTest::InternalizeCardLC(const TDesC& aFile)
//
//	Internalize the specified file
//
	{
    CParserVCard* parser = CParserVCard::NewL();
	CleanupStack::PushL(parser);
    //
    TInt pos = 0;
	RFile file;
	User::LeaveIfError(file.Open(TheFsSession, aFile, EFileRead));
	CleanupClosePushL(file);

	// Read from the file
	static_cast<CVersitParser*>(parser)->InternalizeL(file, pos);

	CleanupStack::PopAndDestroy(); // file
    //
    return parser;
    }
Exemplo n.º 18
0
//test for Reccurrence rule in VCal (VCS)
void CTestVersitObserver::TestReccurrenceRulesL()
	{
	RFile file;
	_LIT(KFileI,"Z:\\TestFiles\\IRDailyVCal.VCS");
	CParserVCal* parser=CParserVCal::NewL();
	CleanupStack::PushL(parser);
	User::LeaveIfError(file.Open(iFs, KFileI, EFileRead));
	CleanupClosePushL(file);
	TInt start=0;
	parser->CVersitParser::InternalizeL(file,start);
	CleanupStack::Pop(&file);
	file.Close();
	CArrayPtr<CVersitParser>* entities= parser->ArrayOfEntities(EFalse);
	CArrayPtr<CParserProperty>* properties = (*entities)[0]->PropertyL(KVersitTokenRRULE, TUid::Uid(KVCalPropertyRecurrenceUid), EFalse); // don't take ownership
	CleanupStack::PushL(properties);
	CParserPropertyValueRecurrence* propertyrecurval = (CParserPropertyValueRecurrence*)((*properties)[0]->Value());	
	TheTest(2 == (propertyrecurval->Value())->iDuration);
	CleanupStack::PopAndDestroy(properties);
	CleanupStack::PopAndDestroy(parser);
	}
Exemplo n.º 19
0
HBufC8* CValidateTest::ReadFileLC(const TDesC& aFilename)
	{
	RFile file;
	User::LeaveIfError(file.Open(iFs, aFilename, EFileRead));
	CleanupClosePushL(file);
	TInt size;
	file.Size(size);
	CleanupStack::PopAndDestroy(1);//fileClose

	HBufC8* res = HBufC8::NewLC(size);
	TPtr8 p(res->Des());
	p.SetLength(size);

	RFileReadStream stream;
	User::LeaveIfError(stream.Open(iFs, aFilename, EFileStream));
	CleanupClosePushL(stream);
	stream.ReadL(p, size);
	CleanupStack::PopAndDestroy();//streamClose...bleurgh
	return res;
	}
// -----------------------------------------------------------------------------
// CWidgetUiObserver::ReadFile
// -----------------------------------------------------------------------------
//
HBufC8* CWidgetUiObserver::ReadFileL( const TDesC& aFileName )
    {
    RFile file;

    if (KErrNone != file.Open( CCoeEnv::Static()->FsSession(), aFileName, EFileRead ) )
        {
        return NULL;
        }

    CleanupClosePushL( file );

    TInt size;
    User::LeaveIfError( file.Size( size ) );
    HBufC8* buf = HBufC8::NewLC( size );
    TPtr8 bufPtr( buf->Des() );
    User::LeaveIfError( file.Read( bufPtr ) );
    CleanupStack::Pop( buf );
    CleanupStack::PopAndDestroy( &file );
    return buf;
    }
Exemplo n.º 21
0
/**
 * Read File
 *
 * @param aFileName			File name to read
 * @param aBuf				Buffer to read file content
 *
 * @return					N/A
 *
 * @leave					System wide error
 */
void CT_DataVerify::ReadFileL(const TFileName& aFileName, TDes8& aBuf)
    {
    RFile file;
    User::LeaveIfError( file.Open( iFs, aFileName, EFileRead ) );
    CleanupClosePushL( file );

    // Get the file size
    TInt size;
    User::LeaveIfError( file.Size( size ) );

    // allocate memory from heap for file content
    HBufC8* buf = HBufC8::NewLC( size );
    aBuf = buf->Des();

    // read file content into buffer, file may be too big for HBufC8
    User::LeaveIfError( file.Read( aBuf ) );

    CleanupStack::Pop( buf );
    CleanupStack::PopAndDestroy( &file ); // file.Close
    }
Exemplo n.º 22
0
TInt CFileOperate::ReadFileL(const TDesC& aFileName)
	{
	RFile file;
	TInt err = file.Open(CCoeEnv::Static()->FsSession(), aFileName, EFileRead);
	CleanupClosePushL(file);
	if (KErrNone != err)
		{
		CleanupStack::PopAndDestroy(1); // file
		return err;
		}

	//²Ù×÷
	RFileReadStream stream(file);
	CleanupClosePushL(stream);

	iNotifier->FileReadData(stream);

	CleanupStack::PopAndDestroy(2);
	return KErrNone;
	}
Exemplo n.º 23
0
	void CStorageManager::WriteToDiskL(TFileName& aFile, const TDesC8& aData)
		/**
		Writes data to disk

		@param aFile - file to write to
		@param aData - data to write

		*/
		{
		RFile file;
		// Place on the cleanup stack:
		CleanupClosePushL(file);
		TInt error = iTestStep->Fs().MkDirAll(aFile);

		if (error == KErrAlreadyExists || error == KErrNone) // directory exists
			{
			if (iLastFile == aFile) // more data needs appended to already open file
				{
				error = file.Open(iTestStep->Fs(), aFile, EFileWrite);
				}
			else
				{
				error = file.Replace(iTestStep->Fs(), aFile, EFileWrite);
				}
			}
		if (error != KErrNone)
			{
			CleanupStack::PopAndDestroy(&file); // file
			User::Leave(error)	;
			}

		TInt size = NULL;
		file.Size(size);
		error = file.Write(size, aData);
		file.Flush();

		iLastFile = aFile;

		CleanupStack::PopAndDestroy(&file); // file
		User::LeaveIfError(error);
		}
/**
Checks if message is logged in the log file.
@param	aMsg The message to be checked.
@return ETrue if the message is found in the log file, otherwise EFalse.
*/
TInt CT_WServGenericpluginStepLoad::CheckLogL(TDesC8& aMsg)
	{
	RFs fs;
	CleanupClosePushL(fs);
	User::LeaveIfError(fs.Connect());
	
	RFile logFile;
	CleanupClosePushL(logFile);

	TInt ret = logFile.Open(fs, KLogFileName, EFileShareAny|EFileRead);
	if (ret == KErrNone)
		{
		TInt fileSize;
    	User::LeaveIfError(logFile.Size(fileSize));

		HBufC8* buf = HBufC8::NewLC(fileSize);
		TPtr8 ptr(buf->Des());
		ret = logFile.Read(ptr);
		if (ret == KErrNone)
			{
			ret = ptr.Find(aMsg);
			if (ret != KErrNotFound)
				{
				ret = EMsgFound;
				}
			else
				{
				ret = EMsgNotFound;
				}		
			}
		CleanupStack::PopAndDestroy(buf);	
		}
	else if (ret == KErrNotFound)
		{
		ret = EFileNotExist;
		ERR_PRINTF1(_L("The log file of test plug-ins was not found."));
		}
	CleanupStack::PopAndDestroy(&logFile);
	CleanupStack::PopAndDestroy(&fs);
	return ret;
	}
Exemplo n.º 25
0
void CLogCompressor::WriteBufL(const TDesC8& /*aBuf*/)
	{
	TDes& filename = iServer.GetFilenameToRotate();

	HBufC* compressedFile = HBufC::NewLC(filename.Length()+3);
	_LIT(KFmt, "%S.gz");
	compressedFile->Des().Format(KFmt, &filename);

	RFile input;

	//_LIT(KInfo,"Compressing file %S to %S\n");
	//console->Printf(KInfo,&inputFile,compressedFile);

	User::LeaveIfError(input.Open(iFs, filename, EFileStream | EFileRead | EFileShareAny));
	CleanupClosePushL(input);

	TRAPD(err, DoGzipL(input, *compressedFile));

	if (err)
		{
		// If the compress failed, delete any fragment (don't care if this fails)
		iFs.Delete(*compressedFile);
		}

	//_LIT(KHoorah,"Hoorah");
	//console->Printf(KHoorah);

	CleanupStack::PopAndDestroy(&input);
	if (err == KErrNone)
		{
		// Don't delete the original unless the compress succeeded!
		err = iFs.Delete(filename);
		}
	if (err == KErrNone)
		{
		// We've sucessfully compressed our file, so update filename to reflect that
		filename = *compressedFile;
		}
	// Don't do anything if the delete fails - the file(s) will be cleaned up when the max number of rotated logs is exceeded
	CleanupStack::PopAndDestroy(compressedFile);
	}
Exemplo n.º 26
0
TInt CFloggerTest012_02::DoTestCheckWriteL()
	{

	
	User::After(KTimeToLog);

	RFile theFile;
	HBufC8 * hBuffer;
	TInt listfilesize;
	TInt returnCode;
	RFs fileSystem; //For file operation create a file system
	TBuf8<256> testData; //To hold the test descriptor
	_LIT(KLogFile, "c:\\logs\\log.txt"); // log file name and path

	_LIT8(KTestMessageTwo,"TEST 12.02: The value of first test integer variable :%d The value of second test integer variable : %d");
	testData.Format(KTestMessageTwo,100, 200);

	User::LeaveIfError(fileSystem.Connect());
	
	//Open the file in the read mode
	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 

	
	returnCode = theFile.Size(listfilesize); //Size of the file
	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
	CleanupStack::PushL(hBuffer);
	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer

	// Read from position 0: start of file
	returnCode = theFile.Read(ptrString);
	
	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
									//from the file
	theFile.Close();
	fileSystem.Close();
	CleanupStack::PopAndDestroy(hBuffer);
	if (returnCode > 0)
		return KErrNone;
	else 
		return KErrGeneral;
	}
Exemplo n.º 27
0
/**  Read File in blocks of size aBlockSize

	@param fs			RFs object
	@param aFile		File name
	@param aBlockSize	Size of the blocks to be used in bytes
	@param aState		Determines if the operation is being done in the main process
						or in a thread
						
	@return Returns KErrNone if everything ok, otherwise it panics 
*/
TInt ReadFile(RFs& fs, TDes16& aFile, TInt aBlockSize, TTestState aState) 
	{
	RTest test(_L("T_FSCHED"));
	TInt r = 0, size = 0;
	RFile fileRead;
	
	TEST(aBlockSize > 0);		

	r = fileRead.Open(fs, aFile, EFileShareAny|EFileRead|EFileReadDirectIO);
	TESTERROR(r);
	
	r = fileRead.Size(size);
	TESTERROR(r);
	
	if(aState == EThreadWait)
	{
		gSync.Wait();
		User::After(gTimeTakenBigBlock);
	}

	TInt j = 0;
	while(j < size) 
		{
			if((j == 0)&&(aState == EThreadSignal))
			{
				gSync.Signal();
			}			
			r = fileRead.Read(gBufReadPtr, aBlockSize);
			TESTERROR(r);
			r = VerifyBuffer(gBufReadPtr, 'B');	
			TESTERROR(r);
			
			j += aBlockSize;
			r = fileRead.Size(size);
			TESTERROR(r);
		}					

	fileRead.Close();

	return KErrNone;	
	}
TInt CDataConsumerMemory::SaveData( const TDesC &filePath )
	{
	TInt	err = KErrNone;
	RFs		FsSession;

	err = FsSession.Connect( );

	if( err == KErrNone )
		{
		iLock.Wait( );
			{
			RFile	file;
			TInt	shareMode = EFileWrite | EFileStream | EFileShareExclusive;

			err = file.Open( FsSession, filePath, shareMode );

			if( err == KErrNotFound )
    			{
    			err = file.Create( FsSession, filePath, shareMode );
    			}

			if( err == KErrNone )
				{
				
				if( NULL != iDataBuffer )
					{
					err = file.Write( iDataBuffer->Des( ) );
					}

				file.Flush( );
				file.Close( );
				}

			iLock.Signal( );
			}

		FsSession.Close( );
		}

	return ( err );
	}
Exemplo n.º 29
0
// -----------------------------------------------------------------------------
// CDRMHelperServer::RestoreL().
// This function restore internal list from data file
// -----------------------------------------------------------------------------
//
void CDRMHelperServer::RestoreL()
    {
#ifdef _DRM_TESTING
    WriteL(_L8("RestoreL"));
#endif

    TInt err = 0;
    RFileReadStream file;

    RFile test;
    err = test.Open( iFs , DataFileL(iFs).FullName() , EFileRead );
    if ( !err )
        {
        CleanupClosePushL(test);
        TInt size = 0;
        err = test.Size(size);
        User::LeaveIfError(err);
        CleanupStack::PopAndDestroy(&test); //test
        if (size == 0)
            {
            StoreL();
            }
        }
    else if ( err == KErrNotFound )
        {
        StoreL();
        }
    else
        {
        User::Leave(err);
        }

    User::LeaveIfError(file.Open( iFs , DataFileL(iFs).FullName() , EFileRead ));
    file.PushL();
    InternalizeL(file);
    CleanupStack::PopAndDestroy(&file); //file

#ifdef _DRM_TESTING
    WriteL(_L8("RestoreL->End"));
#endif
    }
Exemplo n.º 30
0
// ---------------------------------------------------------
// CPosTp148::TraceL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp148::TraceL(const TDesC& msg)
    {
    _LIT8( KEnd, "\r\n" );

    RFile file;
    TInt err = file.Open(iFileSession, KFileTrace, EFileWrite);
    if (err == KErrNotFound)
        {
        file.Create(iFileSession, KFileTrace, EFileWrite);
        }

    HBufC8* line8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( msg );
    
    TInt pos( 0 );
    file.Seek( ESeekEnd, pos );
    file.Write( *line8 );
    file.Write( KEnd );
    file.Close();

    delete line8;
    }