// ----------------------------------------------------------------------------- // CLibxml2Tester::TestSetInputFileL // test setting input file // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt CLibxml2Tester::TestSetInputFileInfosetL(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); 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->SetInputFileL(pDoc); des->UseExternalDataL( list ); des->DeserializeL(); CleanupStack::PopAndDestroy( 8 ); return KErrNone; }
void CTFontSessionCache::ConstructL() { User::LeaveIfError(iChunk.CreateGlobal(KNullDesC,0x10000,0x10000)); iSharedHeap = UserHeap::ChunkHeap(iChunk,0x10000,0x1000,0x10000,0,EFalse,0); if(iSharedHeap == NULL) { RDebug::Print(_L("iSharedHeap = NULL")); User::Leave(KErrNoMemory); } iIFontStore = CTIsolatedFontStore::NewL(iSharedHeap); iIFontStore->LoadRasterizersL(); iIFontStore->iFs->LoadFontsAtStartupL(); _LIT(KTypefaceName, "DejaVu Sans Condensed"); TFontSpec spec(KTypefaceName, KFontHeight); TInt ret = iIFontStore->iFs->GetNearestFontToDesignHeightInPixels(iFont,spec); TEST(ret == KErrNone); }
PassRefPtr<SharedMemory> SharedMemory::create(size_t size) { // On Symbian, global chunks (shared memory segments) have system-unique names, so we pick a random // number from the kernel's random pool and use it as a string. // Using an integer simplifies serialization of the name in Handle::encode() uint32_t random = Math::Random(); TBuf<KMaxKernelName> chunkName; chunkName.Format(_L("%d"), random); RChunk chunk; TInt error = chunk.CreateGlobal(chunkName, size, size); if (error) { qCritical() << "Failed to create WK2 shared memory of size " << size << " with error " << error; return 0; } RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory)); sharedMemory->m_handle = chunk.Handle(); sharedMemory->m_size = chunk.Size(); sharedMemory->m_data = static_cast<void*>(chunk.Base()); return sharedMemory.release(); }
// ----------------------------------------------------------------------------- // CLibxml2Tester::TestUseExternalDataL // test deserialize from file, using external data // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt CLibxml2Tester::TestUseExternalDataInfosetL(CStifItemParser& aItem) { TInt err; TPtrC pDeserializerType; aItem.GetNextString( pDeserializerType ); TPtrC pInputFile; aItem.GetNextString( pInputFile ); TPtrC pBinary; aItem.GetNextString( pBinary ); TPtrC pFile; aItem.GetNextString(pFile); TPtrC pOutputFile; aItem.GetNextString( pOutputFile ); TPtrC pDirtyReturn; aItem.GetNextString( pDirtyReturn ); TLex inputNum (pDirtyReturn); TInt dirtyReturn; inputNum.Val(dirtyReturn); TInt nContainers = 3; RFile fileHandle; RFs aRFs; aRFs.Connect(); CleanupClosePushL( aRFs ); 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); User::LeaveIfError( fileHandle.Replace( aRFs, pOutputFile, EFileStream | EFileWrite | EFileShareExclusive)); CleanupClosePushL( fileHandle ); CTestHandler* testHandle = CTestHandler::NewLC( fileHandle ); RArray<TXmlEngDataContainer> list; CleanupClosePushL(list); //// iDoc.GetDataContainerList(list); CXmlEngDeserializer* des; if( pDeserializerType.FindF( XOP ) != KErrNotFound ) { des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerXOP ); CleanupStack::PushL( des ); des->SetInputFileL( pInputFile ); des->UseExternalDataL( list ); TRAP(err,des->DeserializeL()); } else if( pDeserializerType.FindF( INFOSET ) != KErrNotFound ) { des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerXOPInfoset ); CleanupStack::PushL( des ); des->SetInputFileL( pInputFile ); des->UseExternalDataL( list ); TRAP(err,des->DeserializeL()); } if(list.Count() != nContainers) User::Leave(KErrGeneral); CleanupStack::PopAndDestroy( 8 ); if ( err == dirtyReturn ) return KErrNone; else return err; }
// ----------------------------------------------------------------------------- // 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; }
TInt CLibxml2Tester::TestDOMExternalDataL(CStifItemParser& aItem) { TInt err; TPtrC pDeserializerType; aItem.GetNextString( pDeserializerType ); TPtrC pInputFile; aItem.GetNextString( pInputFile ); TPtrC pBinary; TPtrC pFile; if( (pDeserializerType.FindF( INFOSET ) != KErrNotFound ) || (pDeserializerType.FindF( XOP ) != KErrNotFound ) ) { aItem.GetNextString( pBinary ); aItem.GetNextString(pFile); } TPtrC pOutputFile; aItem.GetNextString( pOutputFile ); TPtrC pDirtyReturn; aItem.GetNextString( pDirtyReturn ); TLex inputNum (pDirtyReturn); TInt dirtyReturn; inputNum.Val(dirtyReturn); TInt nContainers = 3; RFile fileHandle; RFs aRFs; aRFs.Connect(); CleanupClosePushL( aRFs ); RArray<TXmlEngDataContainer> list; if( (pDeserializerType.FindF( INFOSET ) != KErrNotFound ) || (pDeserializerType.FindF( XOP ) != 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( pDeserializerType.FindF( XOP ) != KErrNotFound ) { des->UseExternalDataL( list ); des->SetInputFileL( pInputFile,EDeserializerXOP); TRAP(err,doc=des->DeserializeL()); } else if( pDeserializerType.FindF( INFOSET ) != KErrNotFound ) { des->UseExternalDataL( list ); des->SetInputFileL( pInputFile,EDeserializerXOPInfoset ); TRAP(err,doc=des->DeserializeL()); } if(list.Count() != nContainers) User::Leave(KErrGeneral); RArray<TXmlEngDataContainer>* fromDeserializer = des->ExternalData(); if(fromDeserializer->Count() != nContainers) User::Leave(KErrGeneral); for(TInt i = 0; i < nContainers; i++ ) { if (fromDeserializer->operator[](i).NodeType() != list.operator[](i).NodeType() ) User::Leave( KErrGeneral ); if (fromDeserializer->operator[](i).Size() != list.operator[](i).Size() ) User::Leave( KErrGeneral ); } // fromDeserializer->Close(); SaveDocumentL(doc,pOutputFile); CleanupStack::PopAndDestroy( 6 ); if ( err == dirtyReturn ) return KErrNone; else return err; }
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; }