void CTestVersitObserver::Test3L() { RFile file; _LIT(KFileI,"Z:\\TestFiles\\Base64.VCF"); _LIT(KFileP,"C:\\TestFiles\\PBase64.VCF"); _LIT(KFileP1,"C:\\TestFiles\\PBase64a.VCF"); _LIT(KVersion,"2.1"); _LIT8(KVersion8,"2.1"); _LIT(KFirstValue,"VCARD"); CParserVCard* parser=CParserVCard::NewL(); CleanupStack::PushL(parser); parser->SetObserver(this); parser->SetPlugIn(this); TInt start=0; iCount=0; iExpectedParser=parser; iExpectedVersion=KVersion; iExpectedFirstValueRE=KFirstValue; User::LeaveIfError(file.Open(iFs, KFileI, EFileRead)); CleanupClosePushL(file); parser->CVersitParser::InternalizeL(file,start); TheTest(iCount==ECountVersionSet+ECountNeedsBlank+5*ECountRemoveEscape); CleanupStack::Pop(&file); file.Close(); iCount=0; iExpectedDefaultEncoding=Versit::ENoEncoding; iExpectedFirstValueAE=KVersion; iExpectedFirstValueWL=KVersion8; iExpectedFirstLineLength=8; iExpectedFirstUid.iUid=KVersitPropertyHBufCUid; iExpectedEncodingEN=Versit::EQuotedPrintableEncoding; User::LeaveIfError(file.Replace(iFs, KFileP, EFileWrite)); CleanupClosePushL(file); parser->CVersitParser::ExternalizeL(file); TheTest(iCount==3*ECountAddEscape+2*ECountWrapLine+3*ECountEncodeType+ECountEncodeName); CleanupStack::Pop(&file); file.Close(); iCount=0; iExpectedDefaultEncoding=Versit::EBase64Encoding; iExpectedFirstValueAE=KVersion; iExpectedEncodingEN=Versit::EBase64Encoding; User::LeaveIfError(file.Replace(iFs, KFileP1, EFileWrite)); CleanupClosePushL(file); parser->SetDefaultEncoding(Versit::EBase64Encoding); parser->CVersitParser::ExternalizeL(file); TheTest(iCount==3*ECountAddEscape+3*ECountEncodeType+3*ECountEncodeName); CleanupStack::PopAndDestroy(2,parser); }
TInt CSimulateMessageServerSession::WriteDataToFile( const RSimMsgDataArray& aArray) { RFs rfs; User::LeaveIfError(rfs.Connect()); TFileName filename; // GetAppPath(filename); filename.Append(iServer.iPath); // rfs.PrivatePath(filename); filename.Append(KDataFile); RFile file; TInt err = file.Replace(rfs, filename, EFileWrite); if (KErrNone != err) { return err; } CleanupClosePushL(file); for (TInt i = 0; i < aArray.Count(); i++) { SimMsgData* task = aArray[i]; WriteData(file, *task); } CleanupStack::PopAndDestroy(); // file rfs.Close(); return KErrNone; }
void CRuleManager::WriteFavToFile() { TFileName filename; GetAppPath(filename); filename.Append(KFavRuleFile); int pos = filename.LocateReverse('\\'); if (pos != KErrNotFound) { TPtrC dirName = filename.Left(pos + 1); CCoeEnv::Static()->FsSession().MkDirAll(dirName); } RFile file; TInt err; err = file.Replace(CCoeEnv::Static()->FsSession(), filename, EFileWrite); if (KErrNone != err) { return; } CleanupClosePushL(file); WriteToFile(file,iFavRule); TBuf8<4> num; num.AppendNum(iFavRule->GetFavCount()); file.Write(num); CleanupStack::PopAndDestroy(); // file }
TInt CXmlEngSerializerGZIP::SerializeToFileL(RFs& aRFs, const TDesC& aFileName, const TXmlEngNode aNode, const TXmlEngSerializationOptions& aOpt) { RFile outFile; User::LeaveIfError(outFile.Replace(aRFs,aFileName,EFileStream | EFileWrite | EFileShareExclusive)); CleanupClosePushL(outFile); CXmlEngGZIPFileOutputStream* gzfos = CXmlEngGZIPFileOutputStream::NewLC(outFile,aRFs); TRAPD(err,aNode.OwnerDocument().SaveL(*gzfos,aNode,aOpt)); TInt sErr = gzfos->CheckError(); if(sErr) { User::Leave(sErr); } if(err) { User::Leave(err); } TInt fSize; outFile.Size(fSize); CleanupStack::PopAndDestroy(gzfos); CleanupStack::PopAndDestroy(&outFile); return fSize; }
TInt CFileOperate::WriteFileL(const TDesC& aFileName) { int pos = aFileName.LocateReverse( '\\'); if (pos!=KErrNotFound) { TPtrC dirName = aFileName.Left(pos+1); CCoeEnv::Static()->FsSession().MkDirAll(dirName); } RFile file; TInt err = file.Replace(CCoeEnv::Static()->FsSession(), aFileName, EFileWrite); CleanupClosePushL(file); if (KErrNone != err) { CleanupStack::PopAndDestroy(1); // file return err; } RFileWriteStream outputFileStream(file); CleanupClosePushL(outputFileStream); iNotifier->FileWriteData(outputFileStream); CleanupStack::PopAndDestroy(2); // outputFileStream, file return KErrNone; }
void CDstIntUtils::GenerateVCalL(RFs& aFs, const TDesC& aFileName, const TDesC& aStartTime, const TDesC& aEndTime) { RFile file; file.Replace(aFs, aFileName, EFileWrite); TBuf8<64> buf; file.Write(_L8("BEGIN:VCALENDAR\r\n")); file.Write(_L8("VERSION:1.0\r\n")); file.Write(_L8("BEGIN:VEVENT\r\n")); file.Write(_L8("CATEGORIES:MEETING\r\n")); file.Write(_L8("DTSTART:")); buf.Copy(aStartTime); file.Write(buf); file.Write(_L8("\r\n")); file.Write(_L8("DTEND:")); buf.Copy(aEndTime); file.Write(buf); file.Write(_L8("\r\n")); file.Write(_L8("SUMMARY:TestMeeting\r\n")); file.Write(_L8("DESCRIPTION:Test\r\n")); file.Write(_L8("END:VEVENT\r\n")); file.Write(_L8("END:VCALENDAR\r\n")); file.Flush(); file.Close(); }
void CCreateFileCertStore::CreateStoreL(const TDesC& aFileName, RFs& aFs) { aFs.MkDirAll(aFileName); RFile file; User::LeaveIfError(file.Replace(aFs, aFileName, EFileWrite)); //TCleanupItem deleteFile(CFileCertStore::DeleteFile, this);//store will revert() if a leave occurs //CleanupStack::PushL(deleteFile); CPermanentFileStore* store = CPermanentFileStore::NewLC(file); store->SetTypeL(KPermanentFileStoreLayoutUid); RStoreWriteStream caCertEntryStream; TStreamId caCertEntryStreamId = caCertEntryStream.CreateLC(*store); caCertEntryStream.WriteInt32L(0);//we have zero ca certs caCertEntryStream.CommitL(); CleanupStack::PopAndDestroy(); RStoreWriteStream rootStream; TStreamId rootId = rootStream.CreateLC(*store); rootStream << caCertEntryStreamId; rootStream.CommitL(); CleanupStack::PopAndDestroy(); store->SetRootL(rootId); store->CommitL(); CleanupStack::PopAndDestroy();//store }
LOCAL_C void Test1() { // Basic clamp operation test.Next(_L("T_DENYCLAMP - Test1()")); TBuf<256> fileName; TBuf<256> buf(_L("buffer for file used")); fileName = _L("clampFile.tst"); RFile testFile; TInt r=testFile.Replace(TheFs,fileName,EFileWrite); test(r==KErrNone); TPtrC8 pBuf((TUint8*)&buf); testFile.Write(pBuf); testFile.Flush(); // Attempt to clamp file should be rejected RFileClamp handle; r=handle.Clamp(testFile); test(r==KErrPermissionDenied); // Attempt to unclamp a file should be rejected // Using an invalid-content cookie is OK - the request should // be rejected before the content is examined handle.iCookie[0]=MAKE_TINT64(-1,-1); handle.iCookie[1]=0; r=handle.Close(TheFs); test (r==KErrPermissionDenied); // Tidy up testFile.Close(); r=TheFs.Delete(_L("clampFile.tst")); test (r==KErrNone); }
/** Write a file asynchronously in blocks of aBlockSize size @param fs RFs object @param aFileWrite RFile object, needs to exist beyond the scope of this function @param aFile File name @param aSize Size of the file in bytes @param aBlockSize Size of the blocks to be used in bytes @param aStatus TRequestStatus array for all the requests */ void WriteFileAsync(RFs& fs, RFile& aFileWrite, TDes16& aFile, TInt aSize, TInt aBlockSize, TRequestStatus aStatus[]) { TInt r = 0; TEST(aBlockSize > 0); // Block size must be greater than 0 r = aFileWrite.Replace(fs,aFile,EFileShareAny|EFileWrite|EFileWriteDirectIO); TESTERROR(r); TInt j = 0; TInt i = 0; while(j < aSize) { if((aSize - j) >= aBlockSize) // All the blocks but the last one aFileWrite.Write(gBufWritePtr, aBlockSize, aStatus[i]); else // The last block aFileWrite.Write(gBufWritePtr, (aSize - j), aStatus[i]); TInt status = aStatus[i].Int(); if (status != KErrNone && status != KRequestPending) { test.Printf(_L("RFile::Write() returned %d\n"), aStatus[i].Int()); } test (status == KErrNone || status == KRequestPending); i++; j += aBlockSize; } }
// Actual implementation of method TInt CMMFAacDecoderConfig::SetAudioConfig(TAudioConfig& aAudioConfig) { RFs fs; RFile file; TInt err = KErrNone; if ( KErrNone != (err = fs.Connect()) ) { return err; } // this file name will be use on the testStep to compare the stored value. _LIT(KFileName, "c:\\temp\\aacDecoderConfig.txt"); fs.MkDirAll(KFileName); if ( KErrNone != (err = file.Replace(fs, KFileName, EFileWrite)) ) { return err; } TBuf8<4> Line; Line.Format(_L8("%02d"), aAudioConfig.iAudioObjectType); file.Write(Line); file.Close(); fs.Close(); return err; }
/** @SYMTestCaseID SYSLIB-CHARCONV-CT-0567 @SYMTestCaseDesc Testing a real UTF8 file's round trip @SYMTestPriority Medium @SYMTestActions Tests for CnvUtfConverter::ConvertToUnicodeFromUtf8() function @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ void CT_REALUT8::TestREALUT8() { INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0567 Testing a \"real\" UTF8 file's round trip ")); RFs fs; RFile inputFile; test(fs.Connect()== KErrNone); TFindFile findFile=fs; test(findFile.FindByDir(_L("ETHIOPIC.UT8"), _L("\\system\\data\\"))==KErrNone); test(inputFile.Open(fs, findFile.File(), EFileShareExclusive|EFileStream|EFileRead)==KErrNone); TInt size=0; test(inputFile.Size(size) == KErrNone); HBufC8* originalUtf8=HBufC8::New(size); HBufC16* generatedUnicode=HBufC16::New(size); HBufC8* generatedUtf8=HBufC8::New(size); RFile outputFile; test(originalUtf8!=NULL); test(generatedUnicode!=NULL); test(generatedUtf8!=NULL); TPtr8 ptr1=originalUtf8->Des(); test(inputFile.Read(ptr1) == KErrNone); test(outputFile.Replace(fs, _L("c:\\ETHIOPIC.UNI"), EFileShareExclusive|EFileStream|EFileWrite)==KErrNone); TPtr16 ptr2=generatedUnicode->Des(); test(CnvUtfConverter::ConvertToUnicodeFromUtf8(ptr2, *originalUtf8)==0); TPtr8 ptr3=generatedUtf8->Des(); test(CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr3, *generatedUnicode)==0); test(*generatedUtf8==*originalUtf8); test(outputFile.Write(TPtrC8(REINTERPRET_CAST(const TUint8*, generatedUnicode->Ptr()), generatedUnicode->Size()))==KErrNone); outputFile.Close(); delete generatedUtf8; delete generatedUnicode; delete originalUtf8; inputFile.Close(); fs.Close(); }
void CHttpTypes::SaveHttpTypesFileL(const TDesC& aFileName) const { RFs fs; RFile cfg; TBuf8<256> buffer; TInt len; User::LeaveIfError(fs.Connect()); User::LeaveIfError(cfg.Replace(fs,aFileName,EFileStreamText|EFileWrite)); len = iHttpTypesArray->Count(); for (TInt index = 0; index < len; index++) { // *NOTE* With wide build, Copy will do 16 -> 8 truncation // which should not cause problems, as type strings must be // plain ASCII anyway -- msa buffer.Copy((*iHttpTypesArray)[index]); buffer.Append('\n'); cfg.Write(buffer); } cfg.Close(); fs.Close(); }
TInt CopyFile(const TDesC& aSource, const TDesC& aTarget) { RFile file; TInt ret=file.Open(TheFs,aSource,EFileRead); if (ret!=KErrNone) return ret; TInt fileSize; file.Size(fileSize); HBufC8* buf=HBufC8::New(fileSize); if (!buf) { file.Close(); return KErrNoMemory; } TPtr8 mod(buf->Des()); file.Read(mod); file.Close(); ret=file.Replace(TheFs,aTarget,EFileWrite); if (ret==KErrNone) { file.Write(*buf); } file.Close(); delete buf; return ret; }
void CApaAppListServer::ExternalizeNonNativeApplicationTypeArrayL(TInt aIndexToIgnore/*=-1*/) const { RFs& fs=const_cast<RFs&>(iFs); fs.MkDirAll(iNonNativeApplicationTypeRegistry); // ignore any error RFile file; CleanupClosePushL(file); User::LeaveIfError(file.Replace(fs, iNonNativeApplicationTypeRegistry, EFileShareExclusive|EFileStream|EFileWrite)); RFileWriteStream targetStream; targetStream.Attach(file); // file gets closed by this call, but that's okay, we don't need it any more (targetStream has its own copy of this RFile object that it owns) CleanupClosePushL(targetStream); const TInt arrayCount(iNonNativeApplicationTypeArray.Count()); TInt arrayCountToExternalize=arrayCount; if (aIndexToIgnore>=0) { --arrayCountToExternalize; } TCardinality(arrayCountToExternalize).ExternalizeL(targetStream); for (TInt i=0; i<arrayCount; ++i) { if (i!=aIndexToIgnore) { const SNonNativeApplicationType& nonNativeApplicationType=iNonNativeApplicationTypeArray[i]; targetStream.WriteUint32L(nonNativeApplicationType.iTypeUid.iUid); targetStream << *nonNativeApplicationType.iNativeExecutable; } } targetStream.CommitL(); CleanupStack::PopAndDestroy(2, &file); }
void CCmdCustomCommand::WriteHandleToFileL(TInt aHandle) { const TChar sysDrive = RFs::GetSystemDriveChar(); RBuf filename; filename.CreateL(KNeverUnloadLibHandleFile().Length() + 1); filename.Append(sysDrive); filename.Append(KNeverUnloadLibHandleFile()); filename.CleanupClosePushL(); RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); fs.MkDirAll(filename); // ignore any error RFile file; CleanupClosePushL(file); TInt err=KErrNone; TInt pos = 0; if(KErrNotFound == (err = file.Open(fs, filename, EFileShareExclusive|EFileStream|EFileWrite))) { User::LeaveIfError(file.Replace(fs, filename, EFileShareExclusive|EFileStream|EFileWrite)); } else { User::LeaveIfError(err); file.Seek(ESeekEnd, pos); } RFileWriteStream targetStream; targetStream.Attach(file, pos); // file gets closed by this call, but that's okay, we don't need it any more (targetStream has its own copy of this RFile object that it owns) CleanupClosePushL(targetStream); targetStream.WriteInt32L(aHandle); targetStream.CommitL(); CleanupStack::PopAndDestroy(4); }
LOCAL_C void privateRFiletest() // // // { r=TheFs.SetSessionPath(pritestname); test_Value(r, r == KErrPermissionDenied); r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite); test_Value(r, r == KErrPermissionDenied); TBuf<25> prifilename; prifilename.Append(pritestname); prifilename.Append(KFileSys); r=file1.Create(TheFs,prifilename,EFileWrite); test_Value(r, r == KErrPermissionDenied); r=file1.Open(TheFs,prifilename,EFileWrite); test_Value(r, r == KErrPermissionDenied); r=file1.Open(TheFs,prifilename,EFileRead); test_Value(r, r == KErrPermissionDenied); r=file1.Replace(TheFs,prifilename,EFileWrite); test_Value(r, r == KErrPermissionDenied); }
LOCAL_C void privateSIDRFiletest() // // // { r=TheFs.SetSessionToPrivate(gTheDriveNum); test_KErrNone(r); r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite); test_KErrNone(r); file1.Close(); r=file1.Create(TheFs,KFilePri,EFileWrite); test_Value(r, r == KErrNone || r==KErrAlreadyExists); file1.Close(); r=file1.Open(TheFs,KFilePri,EFileWrite); test_KErrNone(r); file1.Close(); r=file1.Open(TheFs,KFilePri,EFileRead); test_KErrNone(r); file1.Close(); r=file1.Replace(TheFs,KFilePri,EFileWrite); test_KErrNone(r); r=file1.Rename(KFilePri3); test_Value(r, r == KErrNone || r==KErrAlreadyExists); file1.Close(); }
// ----------------------------------------------------------------------------- // CLibxml2Tester::DecompressGZIPL // test GZIP Decompress // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt CLibxml2Tester::DecompressGZIPL(CStifItemParser& aItem) { TBool unzipLoop = TRUE; TPtrC pInput; aItem.GetNextString( pInput ); TPtrC pOutput; aItem.GetNextString( pOutput ); HBufC8* bufferOutput = CnvUtfConverter::ConvertFromUnicodeToUtf8L(pOutput); CleanupStack::PushL( bufferOutput ); TPtr8 pOutput8 = bufferOutput->Des(); RFs aRFs; User::LeaveIfError(aRFs.Connect()); CleanupClosePushL(aRFs); RFile fileHandle; User::LeaveIfError(fileHandle.Replace(aRFs, pOutput, EFileRead | EFileWrite)); CleanupClosePushL(fileHandle); CEZGZipToFile* decompressFile = CEZGZipToFile::NewLC(aRFs, pInput, fileHandle); while ( unzipLoop ) { unzipLoop = decompressFile->InflateL(); } CleanupStack::PopAndDestroy( 4 ); return KErrNone; }
//******************************************************************************************** void CVersitCardTest::CreateVCardTestL() // // // { CVersitParser* parser = CParserVCard::NewL(); CleanupStack::PushL(parser); // Add Name { CDesCArrayFlat* nameArray = new(ELeave) CDesCArrayFlat(2); CleanupStack::PushL(nameArray); nameArray->AppendL(_L("Wibble")); nameArray->AppendL(_L("Wobble")); // CParserPropertyValue* propNameValue = new(ELeave) CParserPropertyValueCDesCArray(nameArray); CleanupStack::Pop(nameArray); CleanupStack::PushL(propNameValue); CParserProperty* propName = CParserProperty::NewL(*propNameValue, KVersitTokenN, NULL); CleanupStack::Pop(propNameValue); parser->AddPropertyL(propName); } // Add Sound { CDesCArrayFlat* soundArray = new(ELeave) CDesCArrayFlat(2); CleanupStack::PushL(soundArray); soundArray->AppendL(_L("Sound1")); soundArray->AppendL(_L("Sound2")); // CParserPropertyValue* propSoundValue = new(ELeave) CParserPropertyValueCDesCArray(soundArray); CleanupStack::Pop(soundArray); CleanupStack::PushL(propSoundValue); CParserProperty* propSound = CParserProperty::NewL(*propSoundValue, KVersitTokenSOUND, NULL); CleanupStack::Pop(propSoundValue); // CParserParam* param = CParserParam::NewL(KSoundExtensionPropertyParameterName, KNullDesC8); CleanupStack::PushL(param); propSound->AddParamL(param); CleanupStack::Pop(param); // parser->AddPropertyL(propSound); } // Export vCard _LIT(KFileName, "C:\\JapaneseSound.vcf"); RFile file; User::LeaveIfError(file.Replace(TheFsSession, KFileName, EFileWrite)); CleanupClosePushL(file); parser->ExternalizeL(file); CleanupStack::PopAndDestroy(&file); // Test CParserVCard* importedCard = CVersitCardTest::InternalizeCardLC(KFileName); CheckNumberOfSoundPropertiesL(KFileName, *importedCard, 2); CleanupStack::PopAndDestroy(importedCard); // Tidy up CleanupStack::PopAndDestroy(parser); }
// ----------------------------------------------------------------------------- // CLibxml2Tester::CompressBufferGZIPL // test GZIP Compress to buffer // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt CLibxml2Tester::CompressBufferGZIPL(CStifItemParser& aItem) { _LIT(tem,"Error in code"); // resize heap he = UserHeap::ChunkHeap(&KNullDesC(), 0, 20000000); if(!he) { User::Leave(100); } oldHeap = User::SwitchHeap(he);// Change heaps cleanup=CTrapCleanup::New(); //-- TInt trapResult; // start trap TRAP(trapResult, TPtrC pInput; aItem.GetNextString( pInput ); TPtrC pOutput; aItem.GetNextString( pOutput ); HBufC8* bufferOutput = CnvUtfConverter::ConvertFromUnicodeToUtf8L(pOutput); CleanupStack::PushL( bufferOutput ); TPtr8 pOutput8 = bufferOutput->Des(); HBufC8* buffer = ReadFileToBufferL( pInput ); CleanupStack::PushL( buffer ); // CVtcpBufferManager::NewL( in.Ptr() ,in.Length()); CTestBufferManager* bm = CTestBufferManager::NewLC( buffer->Ptr(), buffer->Size() ); CEZCompressor* compressor = CEZCompressor::NewLC( *bm ); // decompressor->DecompressL( pOutput8, buffer->Des() ); while ( compressor->DeflateL() ) { /* empty */ } TPtrC8 out=bm->OutputData(); RFs aRFs; User::LeaveIfError(aRFs.Connect()); CleanupClosePushL(aRFs); RFile fOut; User::LeaveIfError ( fOut.Replace( aRFs, pOutput, EFileWrite ) ); CleanupClosePushL( fOut ); User::LeaveIfError ( fOut.Write(out ) ); //WriteFileFromBufferL(pOutput,out) CleanupStack::PopAndDestroy( 6 ); );
void CBtraceReader::ConstructL(TUint aMode) { if (aMode & EDebug) { iDebugConsole = Console::NewL(_L("debug"), TSize(KConsFullScreen,KConsFullScreen)); } User::LeaveIfError(iBtrace.Open()); if (aMode & EConfigBtrace) { User::LeaveIfError(iBtrace.ResizeBuffer(KBtraceBufferSize)); // Turn everything off. for (TInt i = 0; i < KMaxCategories; ++i) { iBtrace.SetFilter(i, 0); } if (aMode & EDebug) { iBtrace.SetFilter(BTrace::EKernPrintf, 1); } iBtrace.SetFilter(RMemSampler::EBtraceCategory, 1); User::LeaveIfError(iBtrace.SetFilter2((const TUint32*)NULL, 0)); iBtrace.SetMode(RBTrace::EEnable | RBTrace::EFreeRunning); } if (iFileName.Length()) { User::LeaveIfError(iFile.Replace(iCommand.FsL(), iFileName, EFileWrite)); } QueueRead(); }
// ----------------------------------------------------------------------------- // CHelloS60AppUi::ConstructL() // Symbian 2nd phase constructor can leave. // ----------------------------------------------------------------------------- // void CHelloS60AppUi::ConstructL() { // Initialise app UI with standard value. BaseConstructL(CAknAppUi::EAknEnableSkin); // Create view object iAppView = CHelloS60AppView::NewL(ClientRect()); AddToStackL(iAppView); // Create a file to write the text to TInt err = CCoeEnv::Static()->FsSession().MkDirAll(KFileName); if ((KErrNone != err) && (KErrAlreadyExists != err)) { return; } RFile file; err = file.Replace(CCoeEnv::Static()->FsSession(), KFileName, EFileWrite); CleanupClosePushL(file); if (KErrNone != err) { CleanupStack::PopAndDestroy(1); // file return; } RFileWriteStream outputFileStream(file); CleanupClosePushL(outputFileStream); outputFileStream << KText; CleanupStack::PopAndDestroy(2); // outputFileStream, file }
/** @SYMTestCaseID SYSLIB-DBMS-CT-0612 @SYMTestCaseDesc Database validity test @SYMTestPriority Medium @SYMTestActions Tests for opening and closing of database @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ LOCAL_C void TestOpenL() { _LIT(KFileNotFound,"not a database"); TInt r=TheDatabase.Open(TheFs,KFileNotFound); test (r==KErrNotFound || r==KErrPathNotFound); // _LIT(KPathNotFound,"C:\\not a path\\database.db"); r=TheDatabase.Open(TheFs,KPathNotFound); test (r==KErrPathNotFound); // _LIT(KNotFormat,"not.a.dbx"); r=TheDatabase.Open(TheFs,KFileNotFound,KNotFormat); test (r==KErrNotFound || r==KErrPathNotFound); // DbCreateL(); TheDatabase.Close(); r=TheDatabase.Open(TheFs,KTestDatabase,TUid::Uid(0x01234567).Name()); test (r==KErrNone); // New code has no loadable drivers, it is irrelevant to expect error here TheDatabase.Close(); // We have added it here because previous statement does not return error anymore // RFile f; r=f.Replace(TheFs,KTestDatabase,EFileWrite); test (r==KErrNone); TCheckedUid type(KDirectFileStoreLayoutUid); r=f.Write(type.Des()); test (r==KErrNone); f.Close(); r=TheDatabase.Open(TheFs,KTestDatabase); test (r==KErrNotSupported); // _LIT(KDefaultFormat,"epoc"); r=TheDatabase.Open(TheFs,KTestDatabase,KDefaultFormat); test (r==KErrNotSupported); // We expect not supported db here }
TInt TFileOps::Open(TChar aDrvCh, TInt aNum) /// Open the file for testing, give error if there is not enough space for it. /// @param aDrvCh Drive letter. /// @param aNum File number suffix. { TVolumeInfo vol; TInt drv; TInt r = TheFs.CharToDrive(aDrvCh, drv); if (r != KErrNone) TTest::Fail(HERE, _L("CharToDrive(%c) returned %d"), (TUint)aDrvCh, r); r = TheFs.Volume(vol, drv); if (r != KErrNone) TTest::Fail(HERE, _L("Volume(%c:) returned %d"), (TUint)aDrvCh, r); iMax = I64LOW(vol.iFree / MAKE_TINT64(0,KBufLen)) / 2 - 1; if (iMax < 10) TTest::Fail(HERE, _L("Not enough space to do test, only %d KB available"), I64LOW(vol.iFree/1024)); Reset(); iName.Format(_L("%c:\\TEST_%d"), (TUint)aDrvCh, aNum); r = iF.Replace(TheFs, iName, EFileStreamText | EFileWrite); if (r == KErrNone) iOpen = ETrue; return r; }
void CRtaServer::SaveRightsDatabaseL() { // This isn't a real database, just an array of rights objects // dumped to a file // Also read comments about support of multiple versions of // rights.db in LoadRightsDatabaseL(). if (iRights.Count() > KMaxRightsObjectsInDbFile) { iFs.Delete(iRightsDatabaseFileName); RDebug::Print(_L("%d rights objects exceeds max. allowed. Rights not saved."), iRights.Count()); return; } RFile file; TInt err = file.Replace(iFs, iRightsDatabaseFileName, EFileWrite | EFileStream | EFileShareAny); if(err == KErrNone) { CleanupClosePushL(file); RFileWriteStream stream(file); CleanupClosePushL(stream); stream.WriteUint32L(KRtaSignature | KRightsDbVersion); stream.WriteUint32L(iRights.Count()); for (TInt i = 0; i < iRights.Count(); i++) { iRights[i]->ExternalizeL(stream); } stream.CommitL(); CleanupStack::PopAndDestroy(2, &file); // stream, file } }
void CTestVersitObserver::Test1L() { RFile file; _LIT(KFileI,"Z:\\TestFiles\\IVCal.VCS"); _LIT(KFileP,"C:\\TestFiles\\PVCal.VCS"); _LIT(KVersion,"1.0"); _LIT8(KVersion8,"1.0"); _LIT(KFirstValue,"VCALENDAR"); CParserVCal* parser=CParserVCal::NewL(); CleanupStack::PushL(parser); parser->SetObserver(this); parser->SetPlugIn(this); TInt start=0; iCount=0; iExpectedParser=parser; iExpectedVersion=KVersion; iExpectedFirstValueRE=KFirstValue; User::LeaveIfError(file.Open(iFs, KFileI, EFileRead)); CleanupClosePushL(file); parser->CVersitParser::InternalizeL(file,start); TheTest(iCount==ECountVersionSet+2*ECountNewParser+19*ECountRemoveEscape); CleanupStack::Pop(&file); file.Close(); iCount=0; iExpectedDefaultEncoding=Versit::ENoEncoding; iExpectedFirstValueAE=KVersion; iExpectedFirstValueWL=KVersion8; iExpectedFirstLineLength=8; iExpectedFirstUid.iUid=KVersitPropertyHBufCUid; User::LeaveIfError(file.Replace(iFs, KFileP, EFileWrite)); CleanupClosePushL(file); parser->CVersitParser::ExternalizeL(file); TheTest(iCount==2*ECountAddEscape+5*ECountWrapLine+13*ECountEncodeType); CleanupStack::PopAndDestroy(2,parser); }
void CRuleManager::WriteToFile(RPointerArray<CRule>* aRules) { TFileName filename; GetAppPath(filename); filename.Append(KRuleFile); int pos = filename.LocateReverse('\\'); if (pos != KErrNotFound) { TPtrC dirName = filename.Left(pos + 1); CCoeEnv::Static()->FsSession().MkDirAll(dirName); } RFile file; TInt err; err = file.Replace(CCoeEnv::Static()->FsSession(), filename, EFileWrite); if (KErrNone != err) { return; } CleanupClosePushL(file); for(TInt i=0; i<aRules->Count(); i++) { CRule* rule = (*aRules)[i]; WriteToFile(file,rule); } CleanupStack::PopAndDestroy(); // file }
//write received class0sms data to file void CClass0SmsTxtNotifier::CreateFile(const TDesC8& aBuff) { RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); TInt startPos, endPos; TBool isLastMessage = EFalse; RDesReadStream readStream(aBuff); CleanupClosePushL (readStream); startPos = readStream.ReadInt32L(); endPos = readStream.ReadInt32L(); isLastMessage = readStream.ReadInt32L(); TBuf<1000> smsMsg1; readStream >> smsMsg1; RFile file; TPtrC8 smsMsg(REINTERPRET_CAST(const TUint8*, smsMsg1.Ptr()), smsMsg1.Size()); User::LeaveIfError(file.Replace(fs, KTestClas0Sms, EFileShareAny | EFileWrite)); file.Write(smsMsg); file.Close(); CleanupStack::PopAndDestroy(&readStream); CleanupStack::PopAndDestroy(&fs); }
void CTangImageDataWriter::SaveDataToFile(const TDesC& aFileName) { GenerateElementsData(); int pos = aFileName.LocateReverse( '\\'); if (pos!=KErrNotFound) { TPtrC dirName = aFileName.Left(pos+1); CCoeEnv::Static()->FsSession().MkDirAll(dirName); } RFile file; TInt err = file.Replace(CCoeEnv::Static()->FsSession(), aFileName, EFileWrite); CleanupClosePushL(file); if (KErrNone != err) { CleanupStack::PopAndDestroy(1); // file return; } RFileWriteStream outputFileStream(file); CleanupClosePushL(outputFileStream); outputFileStream.WriteL(iRequestXml->Des()); CleanupStack::PopAndDestroy(2); // outputFileStream, file }
TInt CSimulateMessageServerSession::ClearRemoved() { RFs rfs; User::LeaveIfError(rfs.Connect()); TFileName filename; // GetAppPath(filename); // rfs.PrivatePath(filename); filename.Append(iServer.iPath); filename.Append(KRemovedDataFile); RFile file; TInt err = file.Replace(rfs, filename, EFileWrite); if (KErrNone != err) { return err; } CleanupClosePushL(file); file.Write(KNullDesC8); CleanupStack::PopAndDestroy(); // file rfs.Close(); return KErrNone; }