xml/libxml2libs/test/tef/xml2/src/texml2teststep.cpp
changeset 0 e35f40988205
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 // Copyright (c) 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 /**
       
    17  @file texml2teststep.cpp
       
    18  @internalTechnology
       
    19 */
       
    20 #include "texml2teststep.h"
       
    21 #include "libxml2_globals_private.h"
       
    22 #include <xml/utils/xmlengmem.h>
       
    23 #include <xml/utils/xmlengutils.h>
       
    24 
       
    25 /**
       
    26  * Class CXmlEngMemStep Implementation
       
    27  */
       
    28 
       
    29 /**
       
    30  * Constructor. Sets the test step name so that it can be 
       
    31  * differentiated from within doTestStepL()
       
    32  */
       
    33 CXmlEngMemStep::CXmlEngMemStep(const TDesC& aStepName)
       
    34 	{
       
    35 	SetTestStepName(aStepName);
       
    36 	}
       
    37 
       
    38 /**
       
    39  * TEF invokes doTestStepL interface along with the step name
       
    40  * to let appropriate action to be taken for the test step.
       
    41  */
       
    42 TVerdict CXmlEngMemStep::doTestStepL(void)
       
    43 	{
       
    44 	if (TestStepName() == KXmlEngLeaveOOMStep1)
       
    45 		{
       
    46 		INFO_PRINTF1(KXmlEngLeaveOOMStep1);
       
    47 		SetTestStepResult(TestKXmlEngLeaveOOMStep1());
       
    48 		}
       
    49 	else if (TestStepName() == KXmlEngLeaveOOMStep2)
       
    50 		{
       
    51 		INFO_PRINTF1(KXmlEngLeaveOOMStep2);
       
    52 		SetTestStepResult(TestKXmlEngLeaveOOMStep2());
       
    53 		}
       
    54 	return TestStepResult();
       
    55 	}
       
    56 /**
       
    57  * Tests the API XmlEngOOMTestL without any OOM condition.
       
    58  */
       
    59 TVerdict CXmlEngMemStep::TestKXmlEngLeaveOOMStep1()
       
    60 	{
       
    61 	TInt err = KErrNone;
       
    62 	//Clean the global state pointer before calling XmlEngLeaveOOML()
       
    63 	xmlGlobalStatePtr gsPtr = xmlCreateAndInitializeGlobalState();
       
    64 	if (!gsPtr)
       
    65 		{
       
    66 		INFO_PRINTF1(_L("Warning: Global state pointer is NULL\n"));
       
    67 		}
       
    68 	//reset the OOM flag
       
    69 	xmlResetOOM();
       
    70 	//invoke the API and check for the error status returned
       
    71 	TRAP(err, XmlEngOOMTestL());
       
    72 	//should pass without any errors
       
    73 	if (err != KErrNone)
       
    74 		{
       
    75 		return EFail;
       
    76 		}
       
    77 	return EPass;
       
    78 	}
       
    79 /**
       
    80  * Tests the API XmlEngOOMTestL without OOM condition.
       
    81  */
       
    82 TVerdict CXmlEngMemStep::TestKXmlEngLeaveOOMStep2()
       
    83 	{
       
    84 	TInt err = KErrNone;
       
    85 	//Set the OOM Flag so that the alternate path in XmlEngOOMTestL()
       
    86 	//is taken
       
    87 	xmlGlobalStatePtr gsPtr = xmlCreateAndInitializeGlobalState();
       
    88 	if (!gsPtr)
       
    89 		{
       
    90 		INFO_PRINTF1(_L("Warning: Global state pointer is NULL\n"));
       
    91 		}
       
    92 	//set the OOM Flag
       
    93 	xmlSetOOM();
       
    94 	//invoke the API
       
    95 	TRAP(err, XmlEngOOMTestL());
       
    96 	//Test case done, reset the flag.
       
    97 	xmlResetOOM();
       
    98 	//check for the error status returned; should have failed with 
       
    99 	//KErrNoMemory
       
   100 	if (err != KErrNoMemory)
       
   101 		{
       
   102 		return EFail;
       
   103 		}
       
   104 	return EPass;
       
   105 	}
       
   106