xml/wbxmlparser/test/rtest/tsrc/t_wbxmldefects.cpp
changeset 0 e35f40988205
child 20 889504eac4fb
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <ecom/ecom.h>
       
    18 
       
    19 #include <xml/contentprocessor.h>
       
    20 #include <xml/parser.h>
       
    21 #include <xml/wbxmlextensionhandler.h>
       
    22 #include <xml/xmlframeworkerrors.h>
       
    23 
       
    24 LOCAL_D RTest 				test(_L("t_wbxmldefects.exe"));
       
    25 LOCAL_D TBool               OOM_TestingActive = EFalse;
       
    26 LOCAL_D RFs					TheFs;
       
    27 
       
    28 LOCAL_D CTrapCleanup* 		TheTrapCleanup 		= NULL;
       
    29 
       
    30 // Installed via bld.inf test exports
       
    31 _LIT  (KTestDocument1,"z:\\system\\xmltest\\SyncML\\1.2\\Defects\\DEF078987_1.wbxml");
       
    32 _LIT  (KTestDocument2,"z:\\system\\xmlTest\\SyncML\\1.2\\Defects\\DEF078987_2.wbxml");
       
    33 _LIT  (KCorruptWAPEmailPushMsg1,"z:\\system\\xmltest\\defects\\00000036.emnc");
       
    34 _LIT  (KCorruptWAPEmailPushMsg2,"z:\\system\\xmltest\\defects\\00000036b.emnc");
       
    35 _LIT  (KCorruptWAPEmailPushMsg3,"z:\\system\\xmltest\\defects\\00000060.emnc");
       
    36 _LIT  (KCorruptWAPEmailPushMsg4,"z:\\system\\xmltest\\defects\\00000104.emnc");
       
    37 
       
    38 
       
    39 typedef void (*TestFunc) (void);
       
    40 
       
    41 
       
    42 //----------------------------------------------------------------------------
       
    43 // The Content Handler
       
    44 
       
    45 using namespace Xml;
       
    46 
       
    47 class RDefectTests : public MWbxmlExtensionHandler, public MContentHandler
       
    48 	{
       
    49 public:
       
    50 	RDefectTests() {/*do nothing*/};
       
    51 	virtual ~RDefectTests() {/*do nothing*/};
       
    52 
       
    53 	void Open() {/*do nothing*/};
       
    54 	void Close() {/*do nothing*/};
       
    55 
       
    56 	// From MContentHandler
       
    57 	void OnStartDocumentL(const RDocumentParameters& aDocParam, TInt aErrorCode);
       
    58 	void OnEndDocumentL(TInt aErrorCode);
       
    59 	void OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttribute, TInt aErrorCode);
       
    60 	void OnEndElementL(const RTagInfo& aElement, TInt aErrorCode);
       
    61 	void OnContentL(const TDesC8& aBytes, TInt aErrorCode);
       
    62 	void OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aErrorCode);
       
    63 	void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode);
       
    64 	void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode) ;
       
    65 	void OnSkippedEntityL(const RString& aName, TInt aErrorCode);
       
    66 	void OnProcessingInstructionL(const TDesC8& aTarget, const TDesC8& aData, TInt aErrorCode);
       
    67 	TAny* GetExtendedInterface(const TInt32 aUid);
       
    68 
       
    69 	void OnError(TInt aErrorCode);
       
    70 
       
    71 	// From MWbxmlExtensionHandler
       
    72 	void OnExtensionL(const RString& aData, TInt aToken, TInt aErrorCode);
       
    73 	};
       
    74 
       
    75 
       
    76 
       
    77 // From MContentHandler
       
    78 
       
    79 // maps to SAX 2.0 startDocument method.
       
    80 void RDefectTests::OnStartDocumentL(const RDocumentParameters& /*aDocParam*/, TInt aErrorCode)
       
    81 	{
       
    82 	test(aErrorCode == KErrNone);
       
    83 	}
       
    84 
       
    85 
       
    86 	// maps to SAX 2.0 endDocument method.
       
    87 void RDefectTests::OnEndDocumentL(TInt aErrorCode)
       
    88 	{
       
    89 	test(aErrorCode == KErrNone);
       
    90 	}
       
    91 
       
    92 
       
    93 // maps to SAX 2.0 startElement method.
       
    94 void RDefectTests::OnStartElementL(const RTagInfo& /*aElement*/, const RAttributeArray& /*aAttribute*/, TInt aErrorCode)
       
    95 	{
       
    96 	test(aErrorCode == KErrNone);
       
    97 	}
       
    98 
       
    99 
       
   100 // maps to SAX 2.0 endElement method.
       
   101 void RDefectTests::OnEndElementL(const RTagInfo& /*aElement*/, TInt aErrorCode)
       
   102 	{
       
   103 	test(aErrorCode == KErrNone);
       
   104 	}
       
   105 
       
   106 
       
   107 // maps to SAX 2.0 characters method.
       
   108 void RDefectTests::OnContentL(const TDesC8& /*aBytes*/, TInt aErrorCode)
       
   109 	{
       
   110 	test(aErrorCode == KErrNone);
       
   111 	}
       
   112 
       
   113 
       
   114 // maps to SAX 2.0 startPrefixMapping method.
       
   115 void RDefectTests::OnStartPrefixMappingL(const RString& /*aPrefix*/, const RString& /*aUri*/, TInt aErrorCode)
       
   116 	{
       
   117 	test.Next(_L("Entered OnStartPrefixMappingL"));
       
   118 	test(aErrorCode == KErrNone);
       
   119 	}
       
   120 
       
   121 
       
   122 // maps to SAX 2.0 endPrefixMapping method.
       
   123 void RDefectTests::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt aErrorCode)
       
   124 	{
       
   125 	test(aErrorCode == KErrNone);
       
   126 	}
       
   127 
       
   128 
       
   129 // maps to SAX 2.0 ignorableWhitespace method.
       
   130 void RDefectTests::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt aErrorCode)
       
   131 	{
       
   132 	test(aErrorCode == KErrNone);
       
   133 	}
       
   134 
       
   135 
       
   136 // maps to SAX 2.0 skippedEntity method.
       
   137 void RDefectTests::OnSkippedEntityL(const RString& /*aName*/, TInt aErrorCode)
       
   138 	{
       
   139 	test(aErrorCode == KErrNone);
       
   140 	}
       
   141 
       
   142 
       
   143 // maps to SAX 2.0 processingInstruction method.
       
   144 void RDefectTests::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, TInt aErrorCode)
       
   145 	{
       
   146 	test(aErrorCode == KErrNone);
       
   147 	}
       
   148 
       
   149 
       
   150 // NOTE: SAX 2.0 setDocumentLocator method not supported.
       
   151 
       
   152 void RDefectTests::OnExtensionL(const RString& /*aData*/, TInt /*aToken*/, TInt aErrorCode)
       
   153 	{
       
   154 	test(aErrorCode == KErrNone);
       
   155 	}
       
   156 
       
   157 
       
   158 // Note that Oom tests between Xml and Wbxml behave differently.
       
   159 // Xml has a preallocated block of memory allocated upfront that
       
   160 // it uses to obtain internal memory allocations from.
       
   161 // In this manner out of memory allocations happen BEFORE parsing.
       
   162 // Therefore, OnError() is never called due to KErrNoMemory. However,
       
   163 // the parser will leave and fall into the oom TRAP block.
       
   164 // With Wbxml there is no such preallocation so an OnError will occur.
       
   165 void RDefectTests::OnError(TInt aErrorCode)
       
   166 	{
       
   167 	test (aErrorCode == KErrEof || aErrorCode == KErrNoMemory || aErrorCode == KErrXmlDocumentCorrupt);
       
   168 	}
       
   169 
       
   170 
       
   171 TAny* RDefectTests::GetExtendedInterface(const TInt32 aUid)
       
   172 /**
       
   173 This method obtains the interface matching the specified uid.
       
   174 @return				0 if no interface matching the uid is found.
       
   175 					Otherwise, the this pointer cast to that interface.
       
   176 @param				aUid the uid identifying the required interface.
       
   177 */
       
   178 	{
       
   179 	if (aUid == MWbxmlExtensionHandler::EExtInterfaceUid)
       
   180 		{
       
   181 		return static_cast<MWbxmlExtensionHandler*>(this);
       
   182 		}
       
   183 	return 0;
       
   184 	}
       
   185 
       
   186 
       
   187 //----------------------------------------------------------------------------
       
   188 
       
   189 
       
   190 /**
       
   191 @SYMTestCaseID 		 		SYSLIB-XML-CT-3730
       
   192 @SYMTestCaseDesc		    OOM testing.
       
   193 @SYMTestPriority 		    Medium
       
   194 @SYMTestActions  		    Runs the set of tests in OOM conditions.
       
   195 @SYMTestExpectedResults 	parser should be able to deal with OOM conditions.
       
   196 @SYMDEF 		 		 	PDEF083044
       
   197 */
       
   198 LOCAL_C void DoOomTestL(TestFunc testFuncL, const TDesC& /*aDesc*/)
       
   199 	{
       
   200 	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3730 "));
       
   201 	test.Printf(_L("    OOM test"));
       
   202 			
       
   203     OOM_TestingActive = ETrue;
       
   204 	TInt err, tryCount = 0;
       
   205 	do
       
   206 		{
       
   207 		User::__DbgSetAllocFail(RHeap::EUser, RHeap::EFailNext, ++tryCount);
       
   208 		User::__DbgMarkStart(RHeap::EUser);
       
   209 		TRAP(err, (*testFuncL)());
       
   210 		User::__DbgMarkEnd(RHeap::EUser, 0);
       
   211 		} while(err==KErrNoMemory);
       
   212     OOM_TestingActive = EFalse;
       
   213 
       
   214 	if(err==KErrNone)
       
   215 		{
       
   216 		// Reset
       
   217 		User::__DbgSetAllocFail(RHeap::EUser,RHeap::ENone,1);
       
   218 		}
       
   219 	else
       
   220 		{
       
   221 		User::Panic(_L("Unexpected leave reason\n"),err);
       
   222 		}
       
   223 
       
   224 	test.Printf(_L("- succeeded with rate %i\r\n"), tryCount);
       
   225 	}
       
   226 
       
   227 
       
   228 LOCAL_C void DoTestL(TestFunc aTestFuncL, const TDesC& aDesc)
       
   229 	{
       
   230 	test.Next(aDesc);
       
   231 
       
   232 	// Set up for heap leak checking
       
   233 	__UHEAP_MARK;
       
   234 
       
   235 	// and leaking thread handles
       
   236 	TInt startProcessHandleCount;
       
   237 	TInt startThreadHandleCount;
       
   238 	TInt endProcessHandleCount;
       
   239 	TInt endThreadHandleCount;
       
   240 
       
   241 	// Test Starts...
       
   242 
       
   243 	RThread thisThread;
       
   244 	thisThread.HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   245 
       
   246 	(*aTestFuncL)();
       
   247 
       
   248 	REComSession::FinalClose(); // Don't want leaks outside the test
       
   249 
       
   250 	//--------------
       
   251 	// Check for open handles
       
   252 	thisThread.HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   253 
       
   254 	test(startThreadHandleCount == endThreadHandleCount);
       
   255 
       
   256 	__UHEAP_MARKEND;
       
   257 
       
   258 	DoOomTestL(aTestFuncL, aDesc);
       
   259 
       
   260 	}
       
   261 
       
   262 
       
   263 //----------------------------------------------------------------------------
       
   264 // The Defect Tests
       
   265 
       
   266 
       
   267 /**
       
   268 @SYMTestCaseID 		 		SYSLIB-XML-CT-1666
       
   269 @SYMTestCaseDesc		    Testing : Convergence: KErrXmlStringDictionaryPluginNotFound when
       
   270 							syncing with DM server
       
   271 @SYMTestPriority 		    High
       
   272 @SYMTestActions  		    It parse the two files DEF078987_1.wbxml and DEF078987_1.wbxml
       
   273 							(Attached with the defect) which contain the updated
       
   274 							publicID FD3 for DTD SyncML 1.1
       
   275 @SYMTestExpectedResults 	Test should not fail
       
   276 @SYMDEF 		 		 	DEF083044
       
   277 */
       
   278 
       
   279 LOCAL_C void Defect_DEF083044L()
       
   280 	{
       
   281 
       
   282 	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-1666 "));
       
   283 	_LIT8 (KWbxmlParserDataType, "text/wbxml");
       
   284 
       
   285 	RDefectTests handler;
       
   286 	CleanupClosePushL (handler);
       
   287 
       
   288 	CParser* parser = CParser::NewL(KWbxmlParserDataType, handler);
       
   289 	CleanupStack::PushL (parser);
       
   290 	ParseL(*parser,TheFs, KTestDocument1);
       
   291 	CleanupStack::PopAndDestroy (parser);
       
   292 
       
   293 	// Actually we don't need to delete the parser and create it again to parser another file.
       
   294 	//But here with WBXML file, it is failing when parsing wbxml file second time.
       
   295 	//Seems  it is defect in wbxml parser
       
   296 
       
   297 
       
   298 	parser = CParser::NewL(KWbxmlParserDataType, handler);
       
   299 	CleanupStack::PushL (parser);
       
   300 	ParseL(*parser,TheFs, KTestDocument2);
       
   301 
       
   302 
       
   303 	CleanupStack::PopAndDestroy (parser);
       
   304 	CleanupStack::PopAndDestroy (&handler);
       
   305 	}
       
   306 
       
   307 
       
   308 /**
       
   309 @SYMTestCaseID 		 		SYSLIB-XML-CT-3173
       
   310 @SYMTestCaseDesc		    Testing : XML parser USER 130 panic parsing DRM rights object
       
   311 @SYMTestPriority 		    High
       
   312 @SYMTestActions  		    It parse wbxml with extra END tag
       
   313 @SYMTestExpectedResults 	Test should not fail
       
   314 @SYMDEF 		 		 	DEF096973
       
   315 */
       
   316 
       
   317 
       
   318 LOCAL_C void Defect_DEF096973L()
       
   319 	{
       
   320 
       
   321 	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3173 "));
       
   322 	TBuf16<128> ucs4_0041;
       
   323 
       
   324 	ucs4_0041.Append(0x01);
       
   325 	ucs4_0041.Append(0x04);
       
   326 	ucs4_0041.Append(0x6A);
       
   327 	ucs4_0041.Append(0x00);
       
   328 	ucs4_0041.Append(0x7F);
       
   329 	ucs4_0041.Append(0x02);
       
   330 	ucs4_0041.Append(0x80);
       
   331 	ucs4_0041.Append(0x41);
       
   332 	ucs4_0041.Append(0x01);
       
   333 	ucs4_0041.Append(0x01); //Extra END tag
       
   334 
       
   335 	_LIT8 (KWbxmlParserDataType, "text/wbxml");
       
   336 
       
   337 	RDefectTests handler;
       
   338 	CleanupClosePushL (handler);
       
   339 
       
   340 	CParser* parser = CParser::NewL(KWbxmlParserDataType, handler);
       
   341 	CleanupStack::PushL (parser);
       
   342 
       
   343 
       
   344 	// Now switch to a different parser (wbxml)
       
   345 	parser->ParseBeginL (KWbxmlParserDataType);
       
   346 
       
   347 	TBuf8<256> buf8;
       
   348 	// Copy will ignore the upper byte if the byte-pair < 256, otherwise the value 1 is used.
       
   349 	buf8.Copy(ucs4_0041);
       
   350 
       
   351 	TRAPD (err,parser->ParseL(buf8));
       
   352 	test(err == KErrXmlDocumentCorrupt);
       
   353 
       
   354 	parser->ParseEndL();
       
   355 
       
   356 
       
   357 	CleanupStack::PopAndDestroy (parser);
       
   358 	CleanupStack::PopAndDestroy (&handler);
       
   359 	}
       
   360 
       
   361 
       
   362 /*
       
   363 @SYMTestCaseID          SYSLIB-XML-UT-1679
       
   364 @SYMTestCaseDesc	    DEF083625 - WBXML parser crash when it tries to parse second wbxml file
       
   365 @SYMTestPriority 	    High
       
   366 @SYMTestActions  	    Tests that the wbxml parser can handle parsing more than one wbxml file
       
   367 @SYMTestExpectedResults Test must not fail
       
   368 @SYMDEF                 DEF083625
       
   369 */
       
   370 LOCAL_C void DEF083625L()
       
   371 	{
       
   372 	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-UT-1679 "));
       
   373 	_LIT8 (KWbxmlParserDataType, "text/wbxml");
       
   374 	_LIT  (KTestDocument1, "z:\\system\\XmlTest\\SyncML\\1.1\\add-to-client\\FromServer1.wbxml");
       
   375 	_LIT  (KTestDocument2, "z:\\system\\XmlTest\\SyncML\\1.1\\add-to-server\\FromServer1.wbxml");
       
   376 
       
   377 	RDefectTests handler;
       
   378 	CleanupClosePushL (handler);
       
   379 
       
   380 	CParser* parser = CParser::NewLC(KWbxmlParserDataType, handler);
       
   381 
       
   382 	// Parse the first wbxml doc.
       
   383 	ParseL(*parser,TheFs, KTestDocument1);
       
   384 
       
   385 	// Parse the second wbxml doc. This will panic if DEF083625 is still present.
       
   386 	ParseL(*parser,TheFs, KTestDocument2);
       
   387 
       
   388 	CleanupStack::PopAndDestroy (parser);
       
   389 	CleanupStack::PopAndDestroy (&handler);
       
   390 	}
       
   391 
       
   392 /*
       
   393 @SYMTestCaseID          BASESRVCS-XML-UT-4011
       
   394 @SYMTestCaseDesc	    INC127127-Test WAP push email message which contain a corrupt string table length encoding and a negative string table length.
       
   395 @SYMTestPriority 	    High
       
   396 @SYMTestActions  	    Tests that the wbxml parser can handle parsing of corrupted emnc file.
       
   397 @SYMTestExpectedResults WBXML Parser should detect corruption or negative length and  leave with KErrXmlDocumentCorrupt
       
   398 @SYMDEF                 INC127127	
       
   399 */
       
   400 LOCAL_C void Incident_INC127127L()
       
   401 	{
       
   402 	test.Next(_L(" @SYMTestCaseID:BASESRVCS-XML-UT-4011 "));
       
   403 
       
   404 	_LIT8( KWbxmlParserDataType, "text/wbxml");
       
   405 	
       
   406 	RBuf8 aBuf,aBuf1;
       
   407 	RFs aRfs;
       
   408 	RFile aRFile,aRFile1;
       
   409 
       
   410 	
       
   411 	RDefectTests handler;
       
   412 	CleanupClosePushL(handler);
       
   413 	
       
   414 	CParser* parser = CParser::NewLC( KWbxmlParserDataType, handler );
       
   415 	parser->ParseBeginL();
       
   416 
       
   417 
       
   418 	User::LeaveIfError(aRfs.Connect());
       
   419 	CleanupClosePushL(aRfs);
       
   420 	
       
   421 	
       
   422 	User::LeaveIfError(aRFile.Open(aRfs,KCorruptWAPEmailPushMsg1,EFileRead));
       
   423 	CleanupClosePushL(aRFile);
       
   424 	TInt size1;
       
   425 	User::LeaveIfError(aRFile.Size(size1));
       
   426 	aBuf.CreateL(size1);
       
   427 	CleanupClosePushL(aBuf);
       
   428 	aRFile.Read(aBuf);
       
   429 
       
   430 	TRAPD(err1,parser->ParseL(aBuf));
       
   431 	// If inside an OOM test loop and alloc failure then report it back to the caller.
       
   432 	if (OOM_TestingActive && (err1 == KErrNoMemory))
       
   433         User::Leave(err1);
       
   434     test(err1 == KErrXmlDocumentCorrupt);
       
   435 	
       
   436 	
       
   437 	User::LeaveIfError(aRFile1.Open(aRfs,KCorruptWAPEmailPushMsg2,EFileRead));
       
   438 	CleanupClosePushL(aRFile1);
       
   439 	TInt size2;
       
   440 	User::LeaveIfError(aRFile1.Size(size2));
       
   441 	aBuf1.CreateL(size2);
       
   442 	CleanupClosePushL(aBuf1);
       
   443 	aRFile1.Read(aBuf1);
       
   444 		
       
   445 	TRAPD(err2,parser->ParseL(aBuf1));
       
   446 	// If inside an OOM test loop and alloc failure then report it back to the caller.
       
   447 	if (OOM_TestingActive && (err2 == KErrNoMemory))
       
   448         User::Leave(err2);
       
   449 	test(err2 == KErrXmlDocumentCorrupt);
       
   450 
       
   451 
       
   452 	CleanupStack::PopAndDestroy(5, &aRfs); 
       
   453 
       
   454 	CleanupStack::PopAndDestroy (parser);
       
   455 	CleanupStack::PopAndDestroy (&handler);
       
   456 	}
       
   457 
       
   458 /*
       
   459 @SYMTestCaseID          BASESRVCS-XML-UT-4012
       
   460 @SYMTestCaseDesc	    INC133484-Watchermainthread crashes when receiving corrupted email notification.
       
   461 @SYMTestPriority 	    High
       
   462 @SYMTestActions  	    Tests that the wbxml parser can handle parsing of corrupted emnc file.
       
   463 @SYMTestExpectedResults WBXML Parser should detect corruption or negative length and  leave with KErrXmlDocumentCorrupt
       
   464 @SYMDEF                 INC133484	
       
   465 */
       
   466 LOCAL_C void Incident_INC133484L()
       
   467 	{
       
   468 	_LIT8( KWbxmlParserDataType, "text/wbxml");
       
   469 	
       
   470 	RBuf8 aBuf;
       
   471 	RFs aRfs;
       
   472 	RFile aRFile;
       
   473 
       
   474 	
       
   475 	RDefectTests handler;
       
   476 	CleanupClosePushL(handler);
       
   477 	
       
   478 	CParser* parser = CParser::NewLC( KWbxmlParserDataType, handler );
       
   479 	parser->ParseBeginL();
       
   480 
       
   481 
       
   482 	User::LeaveIfError(aRfs.Connect());
       
   483 	CleanupClosePushL(aRfs);
       
   484 	
       
   485 	
       
   486 	User::LeaveIfError(aRFile.Open(aRfs,KCorruptWAPEmailPushMsg3,EFileRead));
       
   487 	CleanupClosePushL(aRFile);
       
   488 	TInt size;
       
   489 	User::LeaveIfError(aRFile.Size(size));
       
   490 	aBuf.CreateL(size);
       
   491 	CleanupClosePushL(aBuf);
       
   492 	aRFile.Read(aBuf);
       
   493 
       
   494 	TRAPD(err,parser->ParseL(aBuf));
       
   495 	// If inside an OOM test loop and alloc failure then report it back to the caller.
       
   496 	if (OOM_TestingActive && (err == KErrNoMemory))
       
   497         User::Leave(err);
       
   498     test(err == KErrXmlDocumentCorrupt);
       
   499 	
       
   500 	
       
   501 	CleanupStack::PopAndDestroy(3, &aRfs); 
       
   502 
       
   503 	CleanupStack::PopAndDestroy (parser);
       
   504 	CleanupStack::PopAndDestroy (&handler);
       
   505 	}
       
   506 
       
   507 
       
   508 /*
       
   509 
       
   510 PDEF142385-Tests that the wbxml parser can handle parsing of corrupted emnc file.
       
   511 	
       
   512 */
       
   513 LOCAL_C void Defect_PDEF142385L()
       
   514  	{
       
   515  	_LIT8( KWbxmlParserDataType, "text/wbxml");
       
   516  	
       
   517 	RBuf8 aBuf;
       
   518  	RFs aRfs;
       
   519  	RFile aRFile;
       
   520  
       
   521  	RDefectTests handler;
       
   522  	CleanupClosePushL(handler);
       
   523  	
       
   524  	CParser* parser = CParser::NewLC( KWbxmlParserDataType, handler );
       
   525  	parser->ParseBeginL();
       
   526  
       
   527  
       
   528  	User::LeaveIfError(aRfs.Connect());
       
   529  	CleanupClosePushL(aRfs);
       
   530  	
       
   531 
       
   532  	User::LeaveIfError(aRFile.Open(aRfs,KCorruptWAPEmailPushMsg4,EFileRead));
       
   533  	CleanupClosePushL(aRFile);
       
   534  	TInt size;
       
   535  	User::LeaveIfError(aRFile.Size(size));
       
   536  	aBuf.CreateL(size);
       
   537  	CleanupClosePushL(aBuf);
       
   538  	aRFile.Read(aBuf);
       
   539  
       
   540  	TRAPD(err,parser->ParseL(aBuf));
       
   541  	// If inside an OOM test loop and alloc failure then report it back to the caller.
       
   542  	if (OOM_TestingActive && (err == KErrNoMemory))
       
   543          User::Leave(err);
       
   544      // Since the input file is a well formed WBXML, the code should not crash nor should it raise a "KErrXmlDocumentCorrupt" exception
       
   545  	test(err == KErrNone);
       
   546  	
       
   547  	CleanupStack::PopAndDestroy(5); 
       
   548  	}
       
   549 	
       
   550 		
       
   551 	
       
   552 LOCAL_C void DoTestsL()
       
   553 	{
       
   554 	//DEF096973: XML parser USER 130 panic parsing DRM rights object
       
   555 	Defect_DEF096973L();
       
   556 	
       
   557     DoTestL(Incident_INC127127L, _L("INC127127: Test WBXML Parser robustness with corrupt string table length files..."));
       
   558     DoTestL(Defect_DEF083044L, _L("DEF083044: P:Convergence: KErrXmlStringDictionaryPluginNotFound when syncing with DM server..."));
       
   559 	DoTestL(DEF083625L, _L("DEF083625 - WBXML parser crash when it tries to parse second wbxml file..."));
       
   560 	DoTestL(Incident_INC133484L, _L("INC133484:Watchermainthread crashes when receiving corrupted email notification..."));
       
   561 	DoTestL(Defect_PDEF142385L, _L("PDEF142385:Watchermainthread crashes when receiving corrupted email ntfcn   ..."));
       
   562 	}
       
   563 
       
   564 
       
   565 TInt E32Main()
       
   566     {
       
   567 	__UHEAP_MARK;
       
   568 
       
   569 	test.Printf(_L("\n"));
       
   570 	test.Title();
       
   571 	test.Start(_L("Wbxml XML Defect tests\n"));
       
   572 
       
   573 	// Connect the file server instance
       
   574 	User::LeaveIfError(TheFs.Connect());
       
   575 
       
   576 	TheTrapCleanup = CTrapCleanup::New();
       
   577 
       
   578 	TInt err;
       
   579 
       
   580 	TRAP(err, DoTestsL());
       
   581 	test(err == KErrNone);
       
   582 
       
   583 	delete TheTrapCleanup;
       
   584 
       
   585 	TheFs.Close();
       
   586 
       
   587 	test.End();
       
   588 	test.Close();
       
   589 
       
   590 	__UHEAP_MARKEND;
       
   591 	return (KErrNone);
       
   592     }
       
   593