xml/libxml2libs/test/xmlengtester/xmlengtester_target/src/xmlengtesterblocksserxop.cpp
changeset 0 e35f40988205
child 20 889504eac4fb
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "TestContentHandler.h"
       
    19 #include "xmlengtester.h"
       
    20 
       
    21 #include <e32svr.h>
       
    22 #include <e32std.h>
       
    23 #include <domain/osextensions/StifParser.h>
       
    24 #include <domain/osextensions/Stiftestinterface.h>
       
    25 #include "XmlEngBinaryContainer.h"
       
    26 #include "XmlEngChunkContainer.h"
       
    27 #include "XmlEngFileContainer.h"
       
    28 #include "xmlengtesterdef.h"
       
    29 
       
    30 #include <XmlEngSerializer.h>
       
    31 #include <XmlEngDeserializer.h>
       
    32 
       
    33 #include <InetProtTextUtils.h>
       
    34 #include <libc\string.h>
       
    35 #include <charconv.h>
       
    36 #include <UTF.H>
       
    37 #include <XmlEngDOMParser.h>
       
    38 
       
    39 /************************************** SerXOP ****************************************/
       
    40 // -----------------------------------------------------------------------------
       
    41 // CLibxml2Tester::SaveXmlWithBinaryDataL
       
    42 // saves xml file with added binary data, returns RDocument
       
    43 // (other items were commented in a header).
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 TInt CLibxml2Tester::SaveXmlWithBinaryDataL(RXmlEngDocument& iDocument, TPtrC serOptions, 
       
    47 											TPtrC pData, TPtrC pXml, TPtrC pOut,TBool multiNode)
       
    48     {
       
    49    	
       
    50     //parse input xml file
       
    51     iDocument = parser.ParseFileL(pXml);	
       
    52 	
       
    53     HBufC8* containerBuffer = ReadFileToBufferL(pData);
       
    54 	CleanupStack::PushL( containerBuffer );
       
    55  		
       
    56     // check if input binary data file is empty or not	
       
    57     if ( containerBuffer->Length()  != 0 )
       
    58         {	
       
    59 	//add binary container node to xml document
       
    60         if (!multiNode)
       
    61             {
       
    62 		   //create binary container  
       
    63 		   TXmlEngBinaryContainer binaryData = iDocument.CreateBinaryContainerL(CID_1(),containerBuffer->Des());
       
    64 		   iDocument.DocumentElement().AppendChildL(binaryData);
       
    65 		   }
       
    66 	        else
       
    67 	            {
       
    68 	            //create binary container 1
       
    69 	            TXmlEngBinaryContainer binaryData1 = iDocument.CreateBinaryContainerL(CID_1(),containerBuffer->Des());
       
    70 	            		
       
    71 			    //create binary container 2
       
    72 	            TXmlEngBinaryContainer binaryData2 = iDocument.CreateBinaryContainerL(CID_2(),containerBuffer->Des());
       
    73 	            		
       
    74 	            //create binary container 3
       
    75 	            TXmlEngBinaryContainer binaryData3 = iDocument.CreateBinaryContainerL(CID_3(),containerBuffer->Des());
       
    76 					
       
    77 	            TPtrC8 nodeName;
       
    78 	            nodeName.Set(Node1);
       
    79 	            TXmlEngNode currentNode = FindNodeL(iDocument,nodeName);
       
    80 	            currentNode.AppendChildL(binaryData1);
       
    81 					
       
    82 	            nodeName.Set(Node2);
       
    83 	            currentNode = FindNodeL(iDocument,nodeName);
       
    84 	            currentNode.AppendChildL(binaryData2);
       
    85 					
       
    86 	            nodeName.Set(Node3);
       
    87 	            currentNode = FindNodeL(iDocument,nodeName);
       
    88 	            currentNode.AppendChildL(binaryData3);						
       
    89 	            }
       
    90 	        }
       
    91 		
       
    92 	        TInt saveResult( KErrNone );
       
    93 	        if ( pOut.Size() )
       
    94 	            {
       
    95 	            saveResult = KErrGeneral;
       
    96 			
       
    97 	            if( serOptions != EMPTY_STRING() )
       
    98 	                {
       
    99 	              			    
       
   100 	                TXmlEngSerializationOptions options ( GetHexFromPointerL( serOptions )); 	
       
   101 	                saveResult = iDocument.SaveL(pOut, iDocument, options);
       
   102 	                }
       
   103 	            else 
       
   104 	                {
       
   105 	                TXmlEngElement root = iDocument.DocumentElement();
       
   106 	                if(root.NotNull())
       
   107 	                	{
       
   108 	              	    saveResult = iDocument.SaveL( pOut );
       
   109 					    }
       
   110 			    	}
       
   111 			 
       
   112 			}
       
   113     
       
   114 	CleanupStack::PopAndDestroy( 1 );
       
   115 	if (saveResult >= 0)
       
   116 		{
       
   117 		return KErrNone;
       
   118 		}
       
   119 		else
       
   120 			{
       
   121 			return saveResult;
       
   122 			}
       
   123 		
       
   124 	}
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CLibxml2Tester::TestSerialize1paraToFileL
       
   128 // test "TInt SerializeL(const TNode aRoot);"
       
   129 // (other items were commented in a header).
       
   130 // -----------------------------------------------------------------------------
       
   131 //	
       
   132 TInt CLibxml2Tester::TestSerialize1paraToFileL( RXmlEngDocument& iDocument, TPtrC pXml, TPtrC pSerOpt,TXmlEngSerializerType serializerType )
       
   133 	{
       
   134 	TInt error(KErrGeneral);
       
   135 	
       
   136 	// create serializer 
       
   137 	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(serializerType);
       
   138 	//CDOMSerializer* serializer = CDOMSerializer::SerializerL();
       
   139 	CleanupStack::PushL(serializer);
       
   140 	
       
   141 	
       
   142 	// check if serialization options are avaliable 
       
   143 	if( !pSerOpt.operator==(EMPTY_STRING) )
       
   144 		{
       
   145 		// set serialization options
       
   146 		TXmlEngSerializationOptions options ( GetHexFromPointerL(pSerOpt ));
       
   147 		
       
   148 		// set output
       
   149 		TFileName srcFileName( pXml );
       
   150 		serializer->SetOutputL( srcFileName );	
       
   151 		// set serialization options 
       
   152 		serializer->SetSerializationOptions(options);
       
   153 		// serialize
       
   154 		error = serializer->SerializeL( iDocument );
       
   155 		}
       
   156 		else	
       
   157 			// serialization without setting serialization options
       
   158 			//
       
   159 			{
       
   160 			// set output
       
   161 			TFileName srcFileName( pXml );
       
   162 			serializer->SetOutputL( srcFileName );	
       
   163 			// serialize
       
   164 			error = serializer->SerializeL( iDocument );
       
   165 			}
       
   166 	
       
   167 	CleanupStack::PopAndDestroy( 1 );
       
   168 	
       
   169 	return error;
       
   170 	}
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CLibxml2Tester::TestSerialize3paraToFileL
       
   174 // test "TInt SerializeL(const TNode aRoot);"
       
   175 // (other items were commented in a header).
       
   176 // -----------------------------------------------------------------------------
       
   177 //	
       
   178 TInt CLibxml2Tester::TestSerialize3paraToFileL( RXmlEngDocument& iDocument, TPtrC pXml, TPtrC pSerOpt, TXmlEngSerializerType serializerType )
       
   179 	{
       
   180 	TInt error(KErrGeneral);
       
   181 	
       
   182 	// create serializer 	
       
   183 	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(serializerType);
       
   184 	CleanupStack::PushL(serializer);
       
   185 	
       
   186 	
       
   187 	// check if serialization options are avaliable 
       
   188 	if( !pSerOpt.operator==(EMPTY_STRING) )
       
   189 		{
       
   190 		// set serialization options
       
   191 		TXmlEngSerializationOptions options ( GetHexFromPointerL(pSerOpt ));
       
   192 		
       
   193 		// serialize
       
   194 		error = serializer->SerializeL(pXml, iDocument, options);
       
   195 		}
       
   196 		else	
       
   197 			// serialization without setting serialization options
       
   198 			//
       
   199 			{
       
   200 			error = KErrArgument;
       
   201 			}
       
   202 
       
   203 	CleanupStack::PopAndDestroy( 1 );
       
   204 	return error;
       
   205 	}
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CLibxml2Tester::TestSerializeRFsL
       
   209 // test "TInt SerializeL(const TNode aRoot);"
       
   210 // (other items were commented in a header).
       
   211 // -----------------------------------------------------------------------------
       
   212 //	
       
   213 TInt CLibxml2Tester::TestSerializeRFsL( RXmlEngDocument& iDocument, TPtrC pXml, TPtrC pSerOpt, TXmlEngSerializerType serializerType )
       
   214 	{
       
   215 	TInt error(KErrGeneral);
       
   216 	
       
   217 	// connecting to RFs
       
   218 	RFs aRFs;
       
   219 	User::LeaveIfError(aRFs.Connect());
       
   220    	CleanupClosePushL(aRFs);
       
   221 	
       
   222 	// create serializer 	
       
   223 	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(serializerType);
       
   224 	CleanupStack::PushL(serializer);
       
   225 	
       
   226 	
       
   227 	// check if serialization options are avaliable 
       
   228 	if( !pSerOpt.operator==(EMPTY_STRING) )
       
   229 		{
       
   230 		// set serialization options
       
   231 		TXmlEngSerializationOptions options ( GetHexFromPointerL(pSerOpt ));
       
   232 		
       
   233 	
       
   234 		// serialize
       
   235 		error = serializer->SerializeL(aRFs, pXml, iDocument, options);
       
   236 		}
       
   237 		else	
       
   238 			// serialization without setting serialization options
       
   239 			//
       
   240 			{
       
   241 			error = KErrArgument;
       
   242 			}
       
   243 	
       
   244 	CleanupStack::PopAndDestroy( 2 );
       
   245 	return error;
       
   246 	}
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CLibxml2Tester::TestSerializeToBufferL
       
   250 // test "TInt SerializeL(const TNode aRoot);"
       
   251 // (other items were commented in a header).
       
   252 // -----------------------------------------------------------------------------
       
   253 //	
       
   254 TInt CLibxml2Tester::TestSerializeToBufferL( RXmlEngDocument& iDocument, TPtrC pXml, TPtrC pSerOpt, TXmlEngSerializerType serializerType )
       
   255 	{
       
   256 	TInt nBytes;
       
   257 	
       
   258 	RBuf8 buffer;
       
   259 	CleanupClosePushL( buffer );
       
   260 	
       
   261 	
       
   262 	// create serializer 	
       
   263 	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(serializerType);
       
   264 	CleanupStack::PushL(serializer);
       
   265 	
       
   266 	
       
   267 	TXmlEngSerializationOptions options ( GetHexFromPointerL(pSerOpt ));
       
   268 	nBytes = serializer->SerializeL(buffer, iDocument, options);
       
   269 	
       
   270 	// serialize
       
   271 	
       
   272 	
       
   273 	if (!nBytes)
       
   274 		{
       
   275 		User::Leave( KErrWrite );
       
   276 		}
       
   277 		
       
   278 	TPtrC8 bufferPtr = buffer.Ptr();
       
   279 	TInt bufferSize = buffer.Size();
       
   280 	
       
   281 	if ( bufferSize != nBytes )
       
   282 		{
       
   283 		User::Leave ( KErrWrite );
       
   284 		}
       
   285 	
       
   286 	WriteFileFromBufferL(pXml,buffer);
       
   287 	
       
   288 	CleanupStack::PopAndDestroy( 2 );
       
   289 	
       
   290 	return nBytes;
       
   291 	}
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CLibxml2Tester::SerializeXopL
       
   295 // test binary container method function.
       
   296 // (other items were commented in a header).
       
   297 // -----------------------------------------------------------------------------
       
   298 //	
       
   299 TInt CLibxml2Tester::SerializeXOPL(CStifItemParser& aItem)
       
   300 	{
       
   301 
       
   302 	TInt error(KErrGeneral);
       
   303 	
       
   304 	//	get test controls, input&output paths
       
   305 	TPtrC p_Control;
       
   306 	aItem.GetNextString( p_Control );
       
   307 	
       
   308 	TPtrC p_BinaryData;
       
   309  	aItem.GetNextString( p_BinaryData );
       
   310  	
       
   311 	TPtrC p_XMLin;
       
   312  	aItem.GetNextString( p_XMLin );
       
   313  	
       
   314  	TPtrC p_XMLbefore;
       
   315  	aItem.GetNextString( p_XMLbefore );
       
   316  	 	
       
   317  	TPtrC p_XMLafter;
       
   318  	aItem.GetNextString( p_XMLafter );
       
   319  	
       
   320  	TPtrC p_SerializationOptions;
       
   321  	aItem.GetNextString( p_SerializationOptions );
       
   322  	
       
   323  
       
   324 	// saves xml file with binary data added ( default serialize )
       
   325 	RXmlEngDocument iDocument;
       
   326 	CleanupClosePushL( iDocument );
       
   327 	if( p_Control.FindF( SINGLE ) != KErrNotFound )
       
   328 		{
       
   329 		error = SaveXmlWithBinaryDataL(iDocument, p_SerializationOptions, p_BinaryData, p_XMLin, p_XMLbefore);
       
   330 		
       
   331 		}
       
   332 		else if ( p_Control.FindF( MULTI ) != KErrNotFound )
       
   333 			{
       
   334 			error = SaveXmlWithBinaryDataL(iDocument, p_SerializationOptions, p_BinaryData, p_XMLin, p_XMLbefore,TRUE);
       
   335 		
       
   336 			}
       
   337 			else
       
   338 				{
       
   339 				User::Leave(KErrArgument);	
       
   340 				}
       
   341 		
       
   342 			
       
   343 	if ( p_Control.FindF( ONE_PARA ) != KErrNotFound )
       
   344 		{
       
   345 		User::LeaveIfError( TestSerialize1paraToFileL( iDocument, p_XMLafter, p_SerializationOptions, ESerializerXOP ) );	
       
   346 		}
       
   347 	
       
   348 	
       
   349 	if ( p_Control.FindF( THREE_PARA ) != KErrNotFound )
       
   350 		{ 						  
       
   351 		User::LeaveIfError ( TestSerialize3paraToFileL( iDocument, p_XMLafter, p_SerializationOptions, ESerializerXOP) );
       
   352 		}
       
   353 	
       
   354 	
       
   355 	if ( p_Control.FindF( TO_RFS ) != KErrNotFound )
       
   356 		{						  
       
   357 		User::LeaveIfError( TestSerializeRFsL( iDocument, p_XMLafter, p_SerializationOptions, ESerializerXOP ) );
       
   358 		}
       
   359 		
       
   360 			
       
   361 	if ( p_Control.FindF( BUFFER ) != KErrNotFound )
       
   362 		{						  				  	 					
       
   363 		User::LeaveIfError( TestSerializeToBufferL( iDocument, p_XMLafter, p_SerializationOptions, ESerializerXOP ) );
       
   364 		}
       
   365 
       
   366 
       
   367 	
       
   368 	// pop and destroy pushed objects
       
   369 	CleanupStack::PopAndDestroy( 1 ); 
       
   370 	
       
   371 	return error;
       
   372 	}
       
   373 // -----------------------------------------------------------------------------
       
   374 // CLibxml2Tester::DirtySerializeXopL
       
   375 // test binary container method function.
       
   376 // (other items were commented in a header).
       
   377 // -----------------------------------------------------------------------------
       
   378 //	
       
   379 TInt CLibxml2Tester::DirtySerializeXOPL(CStifItemParser& aItem)
       
   380 	{
       
   381 
       
   382 	TInt error(KErrGeneral);
       
   383 	 TPtrC p_Control;
       
   384 	aItem.GetNextString( p_Control );
       
   385 	
       
   386 	TPtrC p_binaryData;
       
   387  	aItem.GetNextString( p_binaryData );
       
   388 	 	
       
   389 	TPtrC p_XMLin;
       
   390  	aItem.GetNextString( p_XMLin );
       
   391  	  	TPtrC p_XMLbefore;
       
   392  	aItem.GetNextString( p_XMLbefore );	 	
       
   393  	TPtrC p_XMLafter;
       
   394  	aItem.GetNextString( p_XMLafter );
       
   395  	
       
   396 	// saves xml file with binary data added ( default serialize )
       
   397 /*	TDOMImplementation iDomImpl = DOMImplementationSource::DOMImplementationL(KImplementationID);
       
   398          RDocument iDocument = iDomImpl.CreateDocumentL();
       
   399 	CleanupClosePushL( iDocument );
       
   400 		
       
   401         _LIT8( cid, "123456789@123456789" );
       
   402         _LIT( chunkName, "test chunk" );
       
   403     
       
   404         TInt size1 = 1000;
       
   405         TInt maxSize = 5000;
       
   406         TInt offset = 100;
       
   407         TInt binarySize = 500;
       
   408         TBool isReadOnly = EFalse;
       
   409         RChunk chunk;
       
   410         chunk.CreateGlobal(chunkName(), size1, maxSize);
       
   411         CleanupClosePushL(chunk);
       
   412 	XmlEngine::DOM::TChunkContainer binData = iDocument.CreateChunkContainerL(
       
   413 											cid, chunk,	offset, binarySize);
       
   414 											
       
   415 	XmlEngine::DOM::TElement el = iDocument.CreateDocumentElementL( "doc" );
       
   416 	XmlEngine::DOM::TElement el2 = iDocument.CreateElementL("test1");
       
   417 	el.AppendChildL(el2);										
       
   418          XmlEngine::DOM::TElement el3 = iDocument.CreateElementL("chunkcontainer");
       
   419          iDocument.DocumentElement().AppendChildL(el3); 									
       
   420 	
       
   421         el3.AppendChildL(binData);
       
   422          RFs aRFs;
       
   423    	User::LeaveIfError(aRFs.Connect());
       
   424    	CleanupClosePushL(aRFs);
       
   425  	TInt size;
       
   426  	RFile fileHandle;
       
   427  	User::LeaveIfError(fileHandle.Open(aRFs, p_binaryData, EFileRead | EFileShareReadersOnly));
       
   428 	CleanupClosePushL(fileHandle);
       
   429 	User::LeaveIfError(fileHandle.Size(size));
       
   430 	HBufC8* bufferData = HBufC8::NewLC(size);
       
   431 	TPtr8 dataPtr = bufferData->Des();
       
   432 	User::LeaveIfError(fileHandle.Read(dataPtr, size)); 
       
   433 	
       
   434 	XmlEngine::DOM::TBinaryContainer binaryData1 = iDocument.CreateBinaryContainerL(_L8("123456789@01223444"),dataPtr);
       
   435 	XmlEngine::DOM::TElement el4 = iDocument.CreateElementL("binarycontainer");
       
   436          iDocument.DocumentElement().AppendChildL(el4); 							
       
   437 	el4.AppendChildL(binaryData1);
       
   438 */
       
   439 	RXmlEngDocument iDocument;
       
   440 	CleanupClosePushL( iDocument );
       
   441     error = SaveXmlWithBinaryDataL(iDocument, _L("1"), p_binaryData, p_XMLin, p_XMLbefore);
       
   442 
       
   443 		
       
   444     if ( p_Control.FindF( NONE ) == KErrNotFound )
       
   445         {
       
   446 
       
   447         			
       
   448 	if ( p_Control.FindF( FILE ) != KErrNotFound )
       
   449 		{
       
   450 		//invalid output file
       
   451 		//User::LeaveIfError( TestSerialize1paraToFileL( iDocument, p_XMLafter, p_SerializationOptions, ESerializerXOP ) );	
       
   452 		}
       
   453 			
       
   454 	if ( p_Control.FindF( BUFFER ) != KErrNotFound )
       
   455 		{
       
   456 		//invalid output buffer						  				  	 					
       
   457 		//User::LeaveIfError( TestSerializeToBufferL( iDocument, p_XMLafter, p_SerializationOptions, ESerializerXOP ) );
       
   458 		}
       
   459         }
       
   460     	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(ESerializerXOP);
       
   461 	//CDOMSerializer* serializer = CDOMSerializer::SerializerL();
       
   462 	CleanupStack::PushL(serializer);
       
   463 	
       
   464 	// set output
       
   465 	TFileName srcFileName( p_XMLafter);
       
   466 	serializer->SetOutputL( srcFileName );	
       
   467 	// serialize
       
   468 	error = serializer->SerializeL( iDocument );
       
   469 	iDocument.SaveL(_L("c:\\serxoptest.xml"));
       
   470 	
       
   471 	// pop and destroy pushed objects
       
   472 	CleanupStack::PopAndDestroy( 3 ); 
       
   473 	
       
   474 	return error;
       
   475 	}
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // CLibxml2Tester::SerializeXopSoapL
       
   479 // serialize soap documents
       
   480 // (other items were commented in a header).
       
   481 // -----------------------------------------------------------------------------
       
   482 //	
       
   483 
       
   484 TInt CLibxml2Tester::SerializeXopSoapL(CStifItemParser& aItem)
       
   485 	{
       
   486 	TPtrC pDocument;
       
   487 	aItem.GetNextString(pDocument);
       
   488 	
       
   489 	TPtrC pData;
       
   490 	aItem.GetNextString(pData);
       
   491 		
       
   492 	TPtrC pOut;
       
   493 	aItem.GetNextString(pOut);
       
   494 	
       
   495     iDoc = parser.ParseFileL(pDocument);
       
   496 
       
   497       
       
   498   	TXmlEngNode result = FindNodeL(iDoc, _L8("photo"));
       
   499   	
       
   500   	HBufC8* buffer = ReadFileToBufferL(pData);
       
   501 	CleanupStack::PushL(buffer);
       
   502 	
       
   503 	TXmlEngBinaryContainer bincont = iDoc.CreateBinaryContainerL(CID_1(), buffer->Des());
       
   504 	result.AppendChildL(bincont);
       
   505 	
       
   506 	// procesing
       
   507 	// create serializer 
       
   508 	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(ESerializerXOP);
       
   509 	CleanupStack::PushL(serializer);
       
   510 	
       
   511 	// set output
       
   512 	TFileName srcFileName( pOut );
       
   513 	serializer->SetOutputL( srcFileName );	
       
   514 	
       
   515 	// set serialization options
       
   516 	TXmlEngSerializationOptions options ( TXmlEngSerializationOptions::KOptionDecodeBinaryContainers );
       
   517 	serializer->SetSerializationOptions( options );
       
   518 	TInt serializedBits;
       
   519 	// serialize
       
   520 	serializedBits = serializer->SerializeL( iDoc );
       
   521 		
       
   522 	CleanupStack::PopAndDestroy( 2 );
       
   523 	return KErrNone;
       
   524 	}
       
   525 	
       
   526 // -----------------------------------------------------------------------------
       
   527 // CLibxml2Tester::MultiSerializeXopSoapL
       
   528 // Multi serialiazation soap documents
       
   529 // (other items were commented in a header).
       
   530 // -----------------------------------------------------------------------------
       
   531 //	
       
   532 
       
   533 TInt CLibxml2Tester::MultiSerializeXopSoapL(CStifItemParser& aItem)
       
   534 	{
       
   535 	TPtrC pDocument;
       
   536 	aItem.GetNextString(pDocument);
       
   537 	
       
   538 	TPtrC pData1;
       
   539 	aItem.GetNextString(pData1);
       
   540 	
       
   541 	TPtrC pData2;
       
   542 	aItem.GetNextString(pData2);
       
   543 		
       
   544 	TPtrC pOut;
       
   545 	aItem.GetNextString(pOut);
       
   546 	
       
   547     iDoc = parser.ParseFileL(pDocument);
       
   548 
       
   549       
       
   550   		
       
   551   	HBufC8* buffer1 = ReadFileToBufferL(pData1);
       
   552 	CleanupStack::PushL(buffer1);
       
   553 	
       
   554 	HBufC8* buffer2 = ReadFileToBufferL(pData2);
       
   555 	CleanupStack::PushL(buffer2);
       
   556 	
       
   557 	TXmlEngNode aNode = FindNodeL(iDoc,_L8("photo"));
       
   558 	TXmlEngBinaryContainer bincont1 = iDoc.CreateBinaryContainerL(CID_1(), buffer1->Des());
       
   559 	aNode.AppendChildL(bincont1);
       
   560 	
       
   561 	aNode = FindNodeL(iDoc,_L8("sig"));
       
   562 	TXmlEngBinaryContainer bincont2 = iDoc.CreateBinaryContainerL(CID_2(), buffer2->Des());
       
   563 	aNode.AppendChildL(bincont2);
       
   564 	
       
   565 	// procesing
       
   566 	// create serializer 
       
   567 	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(ESerializerXOP);
       
   568 	CleanupStack::PushL(serializer);
       
   569 	
       
   570 	// set output
       
   571 	TFileName srcFileName( pOut );
       
   572 	serializer->SetOutputL( srcFileName );	
       
   573 	
       
   574 	// set serialization options
       
   575 	TXmlEngSerializationOptions options ( TXmlEngSerializationOptions::KOptionDecodeBinaryContainers );
       
   576 	serializer->SetSerializationOptions( options );
       
   577 	
       
   578 	// serialize
       
   579 	serializer->SerializeL( iDoc );
       
   580 		
       
   581 	CleanupStack::PopAndDestroy( 3 );
       
   582 	return KErrNone;
       
   583 	}
       
   584 // -----------------------------------------------------------------------------
       
   585 // CLibxml2Tester::SerializeXopFileL
       
   586 // serialization to file test function 
       
   587 // specification
       
   588 // (other items were commented in a header).
       
   589 // -----------------------------------------------------------------------------
       
   590 //	
       
   591 
       
   592 TInt CLibxml2Tester::SerializeXopFileL(CStifItemParser& aItem)
       
   593 	{
       
   594 	TPtrC pType;
       
   595 	aItem.GetNextString( pType );
       
   596 		
       
   597 	TPtrC pOption;
       
   598 	aItem.GetNextString( pOption );
       
   599 	
       
   600 	TPtrC pData;
       
   601 	aItem.GetNextString(pData);
       
   602 	
       
   603 	TPtrC pDoc;
       
   604 	aItem.GetNextString(pDoc);
       
   605 	
       
   606 	TPtrC pOut;
       
   607 	aItem.GetNextString(pOut);
       
   608 	
       
   609     iDoc = parser.ParseFileL(pDoc);
       
   610        
       
   611     // set serialization options
       
   612 	TLex inputNum (pOption);
       
   613     TInt nOption;
       
   614     inputNum.Val(nOption);
       
   615     
       
   616     //open binary file
       
   617     HBufC8* buffer = ReadFileToBufferL(pData);
       
   618 	CleanupStack::PushL( buffer );
       
   619  		
       
   620     //create binary container  
       
   621 	TXmlEngBinaryContainer binaryData = iDoc.CreateBinaryContainerL(CID_1(),buffer->Des());
       
   622 	iDoc.DocumentElement().AppendChildL(binaryData);
       
   623 	
       
   624 	// procesing
       
   625 	// create serializer 
       
   626 	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(RetSerializerType(pType));
       
   627 	CleanupStack::PushL(serializer);
       
   628 	
       
   629 	// set output
       
   630 	TFileName srcFileName( pOut );
       
   631 	serializer->SetOutputL( srcFileName );	
       
   632 	
       
   633 	// set serialization options
       
   634 	TXmlEngSerializationOptions options ( nOption );
       
   635 	serializer->SetSerializationOptions( options );
       
   636 	
       
   637 	// serialize
       
   638 	TInt serializedBits = serializer->SerializeL( iDoc );
       
   639 	// end processing
       
   640 	
       
   641 	CleanupStack::PopAndDestroy( 2 );
       
   642 	return KErrNone;
       
   643 	}
       
   644 		
       
   645 // -----------------------------------------------------------------------------
       
   646 // CLibxml2Tester::SerializeXopFileDirtyL
       
   647 // dirty functional serialization test function 
       
   648 // specification
       
   649 // (other items were commented in a header).
       
   650 // -----------------------------------------------------------------------------
       
   651 //	
       
   652 
       
   653 TInt CLibxml2Tester::SerializeXopFileDirtyL(CStifItemParser& aItem)
       
   654 	{
       
   655 	TInt nResult = KErrNone;
       
   656 	
       
   657 	TPtrC pData;
       
   658 	aItem.GetNextString(pData);
       
   659 	
       
   660 	TPtrC pDoc;
       
   661 	aItem.GetNextString(pDoc);
       
   662 	
       
   663 	TPtrC pOut;
       
   664 	aItem.GetNextString(pOut);
       
   665 	
       
   666 	TPtrC pDirtyReturn;
       
   667 	aItem.GetNextString(pDirtyReturn);
       
   668 	
       
   669 	TLex inputNum (pDirtyReturn);
       
   670     TInt dirtyReturn;
       
   671     inputNum.Val(dirtyReturn);
       
   672 	
       
   673 	iDoc = parser.ParseFileL(pDoc);
       
   674        
       
   675     //open binary file
       
   676     HBufC8* buffer = ReadFileToBufferL(pData);
       
   677 	CleanupStack::PushL( buffer );
       
   678  		
       
   679     //create binary container  
       
   680 	TXmlEngBinaryContainer binaryData = iDoc.CreateBinaryContainerL(CID_1(),buffer->Des());
       
   681 	iDoc.DocumentElement().AppendChildL(binaryData);
       
   682 	
       
   683 	// procesing
       
   684 	// create serializer 
       
   685 	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(ESerializerXOP);
       
   686 	CleanupStack::PushL(serializer);
       
   687 	
       
   688 	// set output
       
   689 	TFileName srcFileName( pOut );
       
   690 	serializer->SetOutputL( srcFileName );	
       
   691 	
       
   692 	TInt serializedBits;
       
   693 	// serialize
       
   694 	TRAPD(trapResult, serializedBits = serializer->SerializeL( iDoc ) );
       
   695 	
       
   696 	CleanupStack::PopAndDestroy( 2 );
       
   697 	if (trapResult == dirtyReturn ) nResult = KErrNone;
       
   698 			else if (trapResult != KErrNone) nResult = trapResult;
       
   699 				else nResult = KErrGeneral;
       
   700 	
       
   701 	
       
   702 	return nResult;
       
   703 	}
       
   704 	
       
   705 	// -----------------------------------------------------------------------------
       
   706 // CLibxml2Tester::SerializeXopDirtySoapL
       
   707 // special conditions serialization test function			
       
   708 // (other items were commented in a header).
       
   709 // -----------------------------------------------------------------------------
       
   710 //	
       
   711 
       
   712 TInt CLibxml2Tester::SerializeXopDirtySoapL(CStifItemParser& aItem)
       
   713 	{
       
   714 	TInt nResult = KErrNone;
       
   715 	
       
   716 	TPtrC pDocument;
       
   717 	aItem.GetNextString(pDocument);
       
   718 	
       
   719 	TPtrC pData;
       
   720 	aItem.GetNextString(pData);
       
   721 	
       
   722 	TPtrC pOut;
       
   723 	aItem.GetNextString(pOut);
       
   724 	
       
   725 	TPtrC pDirtyReturn;
       
   726 	aItem.GetNextString(pDirtyReturn);
       
   727 	
       
   728 	TLex inputNum (pDirtyReturn);
       
   729     TInt dirtyReturn;
       
   730     inputNum.Val(dirtyReturn);
       
   731     
       
   732 	iDoc = parser.ParseFileL(pDocument);
       
   733     
       
   734     
       
   735     TXmlEngNode result = FindNodeL(iDoc, _L8("photo"));
       
   736   	
       
   737   	HBufC8* buffer = ReadFileToBufferL(pData);
       
   738 	CleanupStack::PushL(buffer);
       
   739 	
       
   740 	TXmlEngBinaryContainer bincont = iDoc.CreateBinaryContainerL(CID_1(), buffer->Des());
       
   741 	result.AppendChildL(bincont);
       
   742     
       
   743     // procesing
       
   744 	// create serializer 
       
   745 	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(ESerializerXOP);
       
   746 	CleanupStack::PushL(serializer);
       
   747 	
       
   748 	// set output
       
   749 	TFileName srcFileName( pOut );
       
   750 	serializer->SetOutputL( srcFileName );	
       
   751 	
       
   752 		// set serialization options
       
   753 	//TXmlEngSerializationOptions options ( TXmlEngSerializationOptions::KOptionDecodeBinaryContainers );
       
   754 	TXmlEngSerializationOptions options ( TXmlEngSerializationOptions::KOptionStandalone );
       
   755 	serializer->SetSerializationOptions( options );
       
   756 	
       
   757 	// serialize
       
   758 	TRAPD(trapResult, serializer->SerializeL( iDoc ) );
       
   759 	
       
   760 	if (trapResult == dirtyReturn ) nResult = KErrNone;
       
   761 			else if (trapResult != KErrNone) nResult = trapResult;
       
   762 				else nResult = KErrGeneral;
       
   763 				
       
   764 	CleanupStack::PopAndDestroy( 2 );
       
   765 	
       
   766 	return nResult;
       
   767 	}
       
   768 
       
   769 // -----------------------------------------------------------------------------
       
   770 // CLibxml2Tester::SerializeXopBufferL
       
   771 // serialization to buffer
       
   772 // (other items were commented in a header).
       
   773 // -----------------------------------------------------------------------------
       
   774 //	
       
   775 
       
   776 TInt CLibxml2Tester::SerializeXopBufferL(CStifItemParser& aItem)
       
   777 	{
       
   778 	TPtrC pType;
       
   779 	aItem.GetNextString( pType );
       
   780 	
       
   781 	TPtrC pOption;
       
   782 	aItem.GetNextString( pOption );
       
   783 	
       
   784 	TPtrC pData;
       
   785 	aItem.GetNextString(pData);
       
   786 	
       
   787 	TPtrC pDoc;
       
   788 	aItem.GetNextString(pDoc);
       
   789 	
       
   790 	TPtrC pOut;
       
   791 	aItem.GetNextString(pOut);
       
   792 
       
   793 	
       
   794 	iDoc = parser.ParseFileL(pDoc);
       
   795        
       
   796     // set serialization options
       
   797 	TLex inputNum (pOption);
       
   798     TInt nOption;
       
   799     inputNum.Val(nOption);
       
   800     
       
   801     //open binary file
       
   802     HBufC8* containerBuffer = ReadFileToBufferL(pData);
       
   803 	CleanupStack::PushL( containerBuffer );
       
   804  		
       
   805     //create binary container  
       
   806 	TXmlEngBinaryContainer binaryData = iDoc.CreateBinaryContainerL(CID_1(),containerBuffer->Des());
       
   807 	iDoc.DocumentElement().AppendChildL(binaryData);
       
   808 	
       
   809 	
       
   810 	RBuf8 buffer;
       
   811 	CleanupClosePushL( buffer );
       
   812 	
       
   813 	// procesing
       
   814 	
       
   815 	// create serializer 	
       
   816 	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(RetSerializerType(pType));
       
   817 	CleanupStack::PushL(serializer);
       
   818 	
       
   819 	
       
   820 	// set serialization options
       
   821 	TXmlEngSerializationOptions options ( nOption );
       
   822 		
       
   823 	
       
   824 	// serialize
       
   825 	TInt nBytes = serializer->SerializeL(buffer, iDoc, options);
       
   826 	// end processing
       
   827 	
       
   828 	if (!nBytes)
       
   829 		{
       
   830 		User::Leave( KErrWrite );
       
   831 		}
       
   832 		
       
   833 	TPtrC8 bufferPtr = buffer.Ptr();
       
   834 	TInt bufferSize = buffer.Size();
       
   835 	
       
   836 	if ( bufferSize != nBytes )
       
   837 		{
       
   838 		User::Leave ( KErrWrite );
       
   839 		}
       
   840 	
       
   841 	WriteFileFromBufferL(pOut,buffer);
       
   842 	
       
   843 	CleanupStack::PopAndDestroy( 3 );
       
   844 	return KErrNone;
       
   845 	}
       
   846 
       
   847 // -----------------------------------------------------------------------------
       
   848 // CLibxml2Tester::SerializeXopBufferL
       
   849 // serialization to file, XML contains chunk & binary & file containers
       
   850 // (other items were commented in a header).
       
   851 // -----------------------------------------------------------------------------
       
   852 //		
       
   853 TInt CLibxml2Tester::Serxop3diffContL(CStifItemParser& aItem)
       
   854 	{
       
   855 	TPtrC pDoc;
       
   856 	aItem.GetNextString(pDoc);
       
   857 	
       
   858 	
       
   859 	TPtrC pBinary;
       
   860 	aItem.GetNextString(pBinary);
       
   861 	
       
   862 	TPtrC pFile;
       
   863 	aItem.GetNextString(pFile);
       
   864 	
       
   865 	TPtrC pOut;
       
   866 	aItem.GetNextString(pOut);
       
   867 	
       
   868 	iDoc = parser.ParseFileL(pDoc);	
       
   869 	  
       
   870     HBufC8* binbuf = ReadFileToBufferL(pBinary);
       
   871 	CleanupStack::PushL(binbuf);
       
   872     
       
   873 	
       
   874 	TBufC<100> chunkName(_L("ChunkContainer") );
       
   875     TInt size = 2000;
       
   876     TInt maxSize = 10000;
       
   877     TInt offset = 0;
       
   878     TInt binarySize = CID_2().Length();
       
   879 //    TBool isReadOnly = EFalse;
       
   880     RChunk chunk;
       
   881     chunk.CreateGlobal(chunkName, size, maxSize);
       
   882     CleanupClosePushL(chunk);
       
   883     
       
   884     RFs aRFs;
       
   885 	User::LeaveIfError(aRFs.Connect());
       
   886 	CleanupClosePushL(aRFs);
       
   887 	
       
   888 	RFile fp;
       
   889 	User::LeaveIfError( fp.Open(aRFs, pFile, EFileRead) );
       
   890 	CleanupClosePushL(fp); 	
       
   891   
       
   892   
       
   893 	
       
   894     TXmlEngBinaryContainer bincont = iDoc.CreateBinaryContainerL(CID_1(), binbuf->Des());
       
   895     TXmlEngChunkContainer chunkcont = iDoc.CreateChunkContainerL(CID_2(), chunk, offset, binarySize);
       
   896 	TXmlEngFileContainer filecont = iDoc.CreateFileContainerL(CID_3(), fp);
       
   897 		
       
   898 	
       
   899 	TXmlEngNode aNode = FindNodeL(iDoc,_L8("bincont"));
       
   900 	aNode.AppendChildL(bincont);
       
   901 	
       
   902 	aNode = FindNodeL(iDoc,_L8("chunkcont"));
       
   903 	aNode.AppendChildL(chunkcont);
       
   904 		
       
   905 	aNode = FindNodeL(iDoc,_L8("filecont"));
       
   906 	aNode.AppendChildL(filecont);
       
   907 	
       
   908 	// create serializer 
       
   909 	CXmlEngSerializer* serializer = CXmlEngSerializer::NewL(ESerializerXOP);
       
   910 	//CXmlEngSerializer* serializer = CXmlEngSerializer::NewL();
       
   911 	CleanupStack::PushL(serializer);
       
   912 	
       
   913 	// set output
       
   914 	TFileName srcFileName( pOut );
       
   915 	serializer->SetOutputL( srcFileName );	
       
   916 	
       
   917 	// set serialization options
       
   918 	TXmlEngSerializationOptions options ( 	TXmlEngSerializationOptions::KOptionIndent  );
       
   919 	serializer->SetSerializationOptions( options );
       
   920 	
       
   921 	// serialize
       
   922 	serializer->SerializeL( iDoc );
       
   923 		
       
   924 	CleanupStack::PopAndDestroy( 5 );
       
   925 	return KErrNone;
       
   926     
       
   927 	}
       
   928 
       
   929 // End of file