xml/legacyminidomparser/XMLParser/test/t_GmxmlFailure.CPP
changeset 34 c7e9f1c97567
parent 25 417699dc19c9
child 36 172b09aa4eb6
equal deleted inserted replaced
25:417699dc19c9 34:c7e9f1c97567
     1 // Copyright (c) 2004-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 <e32std.h>
       
    17 #include <e32test.h> 
       
    18 #include "t_GmxmlFailure.h"
       
    19 #include "t_XMLParserLOG.H"
       
    20 
       
    21 LOCAL_D CActiveScheduler* scheduler;
       
    22 LOCAL_D CImLog* log; 
       
    23 _LIT(KTestTitle, "T_GmxmlFailure");
       
    24 _LIT(KExistingFilePath, "c:\\GmxmlTest.txt");
       
    25 _LIT(KNonExistingFilePath, "c:\\msg\\NotExist.txt");
       
    26 LOCAL_D CGmxmlFailure* myTester;
       
    27 // Global variables
       
    28 RTest gTest(_L("t_GmxmlFailure Test Harness"));
       
    29 
       
    30 CGmxmlFailure :: CGmxmlFailure() : CActive(EPriorityStandard)
       
    31 	{
       
    32 	}
       
    33 
       
    34 /**
       
    35  * Second stage constructor:
       
    36  * Creates the XML parser and calls the ParseFile() with 
       
    37  * a non-exixtent file
       
    38  */
       
    39 
       
    40 void CGmxmlFailure :: ConstructL()
       
    41 	{
       
    42 	iSession.Connect();
       
    43 	iCMDXMLParser = CMDXMLParser::NewL(this);
       
    44 	log->AppendComment(_L8("Performing tests on opening non-existing file"));
       
    45 	LoadXmlFile(KNonExistingFilePath);
       
    46 	log->AppendComment(_L8("Completed checking of opening non-existing file"));
       
    47 		
       
    48 	CActiveScheduler::Add(this);
       
    49 
       
    50 	iState = ENonExistFileState;
       
    51 	TRequestStatus *s = &iStatus;
       
    52 	User::RequestComplete(s, KErrNone);
       
    53 	SetActive();
       
    54 	}
       
    55 
       
    56 void CGmxmlFailure::LoadXmlFile(const TDesC &aFilePath)
       
    57 	{	
       
    58 	TInt err=iCMDXMLParser->ParseFile(iSession, aFilePath);	
       
    59 	if(err!=KErrNone)
       
    60 		{
       
    61 		log->AppendError(_L8("Parse File returned an error "),err);
       
    62 		}
       
    63 	}
       
    64 	
       
    65 void CGmxmlFailure::LockXmlFile()
       
    66 	{	
       
    67 	RFile file;
       
    68 	//Open the file before calling ParseFile function.
       
    69 	file.Open(iSession, KExistingFilePath,EFileShareExclusive);
       
    70 	//Call the ParseFile() on the locked file
       
    71 	TInt err=iCMDXMLParser->ParseFile(iSession, KExistingFilePath);	
       
    72 	if(err!=KErrNone)
       
    73 		{
       
    74 		log->AppendError(_L8("Parse File returned an error "),err);
       
    75 		}
       
    76 	file.Close();	
       
    77 	}
       
    78 	
       
    79 CGmxmlFailure :: ~CGmxmlFailure()
       
    80 /**
       
    81  * Destructor
       
    82  */
       
    83 	{	
       
    84 	iSession.Close();	
       
    85 	delete iCMDXMLParser;
       
    86 	}
       
    87 
       
    88 CGmxmlFailure* CGmxmlFailure :: NewLC()
       
    89 /** 
       
    90 * Allocates a new CGmxmlFailure test object and pushes 
       
    91 * it on clean up stack.
       
    92 * @return New CGmxmlFailure 
       
    93 */
       
    94 	{
       
    95 	CGmxmlFailure* self = new (ELeave) CGmxmlFailure();
       
    96 	CleanupStack::PushL(self);
       
    97 	self->ConstructL();
       
    98 	return self;
       
    99 	}
       
   100 
       
   101 void CGmxmlFailure :: ParseFileCompleteL()
       
   102 /**
       
   103 * Function from MMDXMLParserObserver class
       
   104 */
       
   105 	{
       
   106 	}
       
   107 
       
   108 	
       
   109 void CGmxmlFailure :: DoCancel()
       
   110 /**
       
   111 * Functions from CActive class
       
   112 */
       
   113 	{
       
   114 	}
       
   115 
       
   116 void CGmxmlFailure :: RunL()	
       
   117 	{
       
   118 	switch(iState)
       
   119 		{
       
   120 	case ENonExistFileState:
       
   121 		{				
       
   122 		CActiveScheduler::Stop();
       
   123 		iState = ELockFileState;
       
   124 		TRequestStatus *s = &iStatus;
       
   125 		User::RequestComplete(s, KErrNone);		
       
   126 		SetActive();		
       
   127 		}
       
   128 		break;
       
   129 	case ELockFileState:
       
   130 		{
       
   131 		CActiveScheduler::Stop();
       
   132 		iState = EEndState;
       
   133 		TRequestStatus *s = &iStatus;
       
   134 		User::RequestComplete(s, KErrNone);
       
   135 		SetActive();				
       
   136 		}
       
   137 		break;				
       
   138 	case EEndState:
       
   139 		{
       
   140 		CActiveScheduler::Stop();
       
   141 		}
       
   142 		break;
       
   143 	default:
       
   144 		break;
       
   145 		}
       
   146 
       
   147 	}
       
   148 
       
   149 LOCAL_C void InitL()
       
   150 	{
       
   151 	TBuf<80> logFile(KLogFileName);
       
   152 
       
   153 #if defined(__WINS__) && defined(__WINSCW__)
       
   154 	logFile.Append(_L(".WINSCW"));
       
   155 #elif(__WINS__)
       
   156 	logFile.Append(_L(".WINS"));
       
   157 #else
       
   158 	logFile.Append(_L(".MARM"));
       
   159 #endif
       
   160 
       
   161 #if defined(_DEBUG)
       
   162 	logFile.Append(_L(".DEB"));
       
   163 #else
       
   164 	logFile.Append(_L(".REL"));
       
   165 #endif
       
   166 	logFile.Append(_L(".LOG"));
       
   167 
       
   168 	gTest.Printf(_L("\nLog File "));
       
   169 	gTest.Printf(logFile);
       
   170 	gTest.Printf(_L("\n"));
       
   171 	log = CImLog::NewL(logFile, EAppend);
       
   172 	CleanupStack::PushL(log);
       
   173 	log->AppendComment(_L8("Test Results"));
       
   174 	log->AppendComment(_L8("T_GMXMLFAILURE memory leak test in XMLParser"));
       
   175 	log->AppendComment(_L8("Test 1 Starting"));
       
   176 	}
       
   177 
       
   178 /**
       
   179  * setup test environment, create CGmxmlFailure object and run test.
       
   180  * 
       
   181  * This is an memory leak test. 
       
   182  * Test case: 
       
   183  * Passes the file name and session to CMDXMLParser::ParseFile() 
       
   184  * as arguments and run the memory leak test.
       
   185  * Running Instructions:
       
   186  * 1. Build this test harness:	cd \GMXML\XMLParser\GROUP
       
   187  *								bldmake bldfiles
       
   188  *								abld test build wins udeb t_GmxmlFailure
       
   189  * 2. Run t_GmxmlFailure.exe:	cd \epoc32\release\wins\udeb
       
   190  *								t_GmxmlFailure -dtextshell -- 
       
   191  *
       
   192  *  Output files produced by running test harness:
       
   193  *	        <DRIVE>:\msglogs\T_GMXMLFAILURE.<PLATFORM>.<VARIANT>.txt
       
   194  */
       
   195 	
       
   196 LOCAL_C void doMainL()
       
   197 	{
       
   198 	gTest.Start(KTestTitle);
       
   199 	InitL();
       
   200 	scheduler = new (ELeave) CActiveScheduler;
       
   201 	CleanupStack::PushL(scheduler);
       
   202 	CActiveScheduler::Install( scheduler );
       
   203 	__UHEAP_MARK;	
       
   204 	myTester = CGmxmlFailure::NewLC();		
       
   205 	CActiveScheduler::Start();	
       
   206 	log->AppendComment(_L8("Completed tests. No panic"));
       
   207 	log->AppendComment(_L8("Test PASSED"));
       
   208 	log->AppendComment(_L8("Test 1 OK"));
       
   209 	
       
   210 	log->AppendComment(_L8("Test 2 Starting"));	
       
   211 	log->AppendComment(_L8("Performing tests on opening existing file"));
       
   212 	myTester->LoadXmlFile(KExistingFilePath);
       
   213 	log->AppendComment(_L8("Completed checking of opening existing file"));	
       
   214 	CActiveScheduler::Start();		
       
   215 	log->AppendComment(_L8("Completed tests. No panic"));
       
   216 	log->AppendComment(_L8("Test PASSED"));	
       
   217 	log->AppendComment(_L8("Test 2 OK"));
       
   218 	
       
   219 	log->AppendComment(_L8("Test 3 Starting"));
       
   220 	log->AppendComment(_L8("Performing tests on locked file"));
       
   221 	myTester->LockXmlFile();
       
   222 	log->AppendComment(_L8("Completed checking of opening a locked file"));		
       
   223 	CActiveScheduler::Start();
       
   224 	log->AppendComment(_L8("Completed tests. No panic"));
       
   225 	log->AppendComment(_L8("Test PASSED"));	
       
   226 	log->AppendComment(_L8("Test 3 OK"));
       
   227 	
       
   228 	CleanupStack::PopAndDestroy(myTester);		// myTester
       
   229 	__UHEAP_MARKEND;	
       
   230 	
       
   231 	log->AppendComment(_L8("No memory leak in XMLParser"));	
       
   232 	log->AppendComment(_L8("T_GMXMLFAILURE Tests Complete"));
       
   233 	log->AppendComment(_L8("Tests Completed"));
       
   234 
       
   235 	CleanupStack::PopAndDestroy(2);		// scheduler, log	
       
   236 	gTest.End();
       
   237 	gTest.Close();
       
   238 	}
       
   239 
       
   240 /** entry point for test executable */
       
   241 GLDEF_C TInt E32Main()
       
   242 	{
       
   243 	CTrapCleanup* theCleanup = CTrapCleanup::New();
       
   244 	TRAPD(ret,doMainL());		
       
   245 	gTest(ret==KErrNone);
       
   246 	delete theCleanup;	
       
   247 
       
   248 	return(KErrNone);
       
   249 	}