xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pauld...@apache.org
Subject cvs commit: xml-xalan/c/Tests/Extensions extensions.cpp
Date Thu, 30 Aug 2001 17:45:39 GMT
pauldick    01/08/30 10:45:39

  Modified:    c/Tests/Extensions extensions.cpp
  Log:
  XalanTransformer now automaticly defines the external functions.
  Test now accomodates this behavior,  plus better comments.
  
  Revision  Changes    Path
  1.6       +113 -123  xml-xalan/c/Tests/Extensions/extensions.cpp
  
  Index: extensions.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/Tests/Extensions/extensions.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- extensions.cpp	2001/08/02 21:09:23	1.5
  +++ extensions.cpp	2001/08/30 17:45:39	1.6
  @@ -98,6 +98,7 @@
   XalanDOMString			baseDir, outputRoot, goldRoot;  // These are set by the getParams routine.
   const XalanDOMString	testDir("extensions");
   const XalanDOMString	theNamespace("http://xml.apache.org/xalan");
  +const char *resultString = "The specified function is not available: http://xml.apache.org/xalan:nodeset";
   
   
   void
  @@ -209,121 +210,80 @@
   	return fSuccess;
   }
   
  +// Generate the various filenames needed for testing.
   void generateFiles(const XalanDOMString &fileName, 
   				   XalanDOMString &xml, 
  -				   XalanDOMString &xsl, 
  +				   XalanDOMString &xsl,
   				   XalanDOMString &out,
  -				   XalanDOMString &gold)
  +				   XalanDOMString &gold,
  +				   const char* test)
   {
   	// Set up the input/output files.
  +	const XalanDOMString testName(test + XalanDOMString(".out"));
   
   	xsl = baseDir + testDir + pathSep + fileName;
  +	
   	xml = futil.GenerateFileName(xsl,"xml");
  -	out =  outputRoot + testDir + pathSep + fileName; 
  -	out = futil.GenerateFileName(out, "out");
  +
  +	out =  outputRoot + testDir + pathSep + testName; 
   
   	gold = goldRoot +testDir + pathSep + fileName;
   	gold = futil.GenerateFileName(gold, "out");
   
   }
  -
  -void installUninstallExtensions(XalanTransformer &transformer, bool install)
  -{
  -	// The namespace for our functions is "http://xml.apache.org/xalan".
  -
  -	// Install the functions in the local space.  They will only be installed in this instance,
so no other instances
  -	// will know about them...
  -	if (install)
  -	{
  -		transformer.installExternalFunction(theNamespace, XalanDOMString("difference"), FunctionDifference());
  -		transformer.installExternalFunction(theNamespace, XalanDOMString("distinct"), FunctionDistinct());
  -		transformer.installExternalFunction(theNamespace, XalanDOMString("evaluate"), FunctionEvaluate());
  -		transformer.installExternalFunction(theNamespace, XalanDOMString("hasSameNodes"), FunctionHasSameNodes());
  -		transformer.installExternalFunction(theNamespace, XalanDOMString("intersection"), FunctionIntersection());
  -	}
  -	else
  -	{
  -		transformer.uninstallExternalFunction(theNamespace, XalanDOMString("difference"));
  -		transformer.uninstallExternalFunction(theNamespace, XalanDOMString("distinct"));
  -		transformer.uninstallExternalFunction(theNamespace, XalanDOMString("evaluate"));
  -		transformer.uninstallExternalFunction(theNamespace, XalanDOMString("hasSameNodes"));
  -		transformer.uninstallExternalFunction(theNamespace, XalanDOMString("intersection"));
  -
  -	}
  -	return;
  -}
   
  -//TestCase1:
  -//	This tests uses transformer method installExternalFunction to install the nodeset function.

  -//	Then if checks that the nodeset function works. 
  +//	TestCase1
  +//  API Call: 
  +//		None. Verfies default behavior of XalanTransformer.
  +//	Comments:
  +//		This test verifies that the Nodeset function was properly installed with the transformer.
 All 
  +//		functions are preinstalled globally.  Output file should contain data. 
  +//		 
   void TestCase1(XalanTransformer &transformEngine, const XalanDOMString &fileName)
   {
   	
   	XalanDOMString	xml, xsl, result, gold;
  -	char *resultString = "The specified function is not available: http://xml.apache.org/xalan:nodeset";
	
  -	generateFiles(fileName, xml, xsl, result, gold);
  +		
  +	generateFiles(fileName, xml, xsl, result, gold, "TestCase1");
   
   	// Create the InputSources and ResultTraget.
   	const XSLTInputSource	xmlInputSource(c_wstr(xml));
   	const XSLTInputSource	xslInputSource(c_wstr(xsl));
   	const XSLTResultTarget	theResultTarget(result);
   
  -	// Install the external function "nodeset"
  -	transformEngine.installExternalFunction(
  -		theNamespace,
  -		XalanDOMString("nodeset"),
  -		FunctionNodeSet());
  -
   	// Perform the transform and check the results.
   	int	theResult = transformEngine.transform(xmlInputSource, xslInputSource, theResultTarget);
   	if (!theResult)
   	{
   		const XSLTInputSource resultInputSource(c_wstr(result));
   		const XSLTInputSource goldInputSource(c_wstr(gold));
  -		futil.compareSerializedResults(resultInputSource, goldInputSource, fileName, "TestCase1a");

  -	}
  -	else
  -	{
  -		cout << endl << "Failed: TestCase1a" ;
  -	}
  -
  -	XalanTransformer newEngine;
  -	int secondResult = newEngine.transform(xmlInputSource, xslInputSource, theResultTarget);
  -	if (secondResult == -1)
  -	{
  -		if (!strcmp(resultString, newEngine.getLastError()))
  -		{
  -			cout << endl << "Passed: TestCase1b" ;
  -		}
  -		else 
  -		{
  -			cout << endl << "Failed: TestCase1b" ;
  -		}
  +		futil.compareSerializedResults(resultInputSource, goldInputSource, fileName, "TestCase1");

   	}
   	else
   	{
  -		cout << endl << "Failed: TestCase1b" ;
  +		cout << endl << "Failed: TestCase1" ;
   	}
  -
   }
   
  -//TestCase2 
  -//	This tests uses transformer method installExternalFunction to install the following
functions:
  -//		difference, distinct, evaluate, hasSameNodes, intersection
  -//	They are then tested with a stylesheet.
  +//	TestCase2
  +//  API Call: 
  +//		None. Verfies default behavior of XalanTransformer.
  +//	Comments:
  +//		This test verifies that the following functions: difference, distinct, evaluate, hasSameNodes,

  +//		and intersection are defined and working.  Output file should contain data.
  +//
   void TestCase2(XalanTransformer &transformEngine, const XalanDOMString &fileName)
   {
   	
   	XalanDOMString	xml, xsl, result, gold;
  -		
  -	generateFiles(fileName, xml, xsl, result, gold);
   
  +	generateFiles(fileName, xml, xsl, result, gold, "TestCase2");
  +
   	// Create the InputSources and ResultTraget.
   	const XSLTInputSource	xmlInputSource(c_wstr(xml));
   	const XSLTInputSource	xslInputSource(c_wstr(xsl));
   	const XSLTResultTarget	theResultTarget(result);
   
  -	installUninstallExtensions(transformEngine, true);
   
   	// Perform the transform and check the results.
   	int	theResult = transformEngine.transform(xmlInputSource, xslInputSource, theResultTarget);
  @@ -340,30 +300,31 @@
   
   }
   
  -//TestCase3:
  -//	This tests uses transformer method uninstallExternalFunction to remove the nodeset function.

  -//	It then attempts to execute the function.  The test passes if the proper error message
is 
  -//	returned.  The remaining installed functions from the previous test are uninstalled.
  +//	TestCase3
  +//  API Call:
  +//		XalanTransformer::uninstallExternalFunctionGlobal
  +//	Comments:
  +//		This test verifies that the 'nodeset' function is properly uninstalled via the api.
  +//		Output file should NOT contain data. 
  +//
   void TestCase3(XalanTransformer &transformEngine, const XalanDOMString &fileName)
  -{
  -	
  -	XalanDOMString	xml, xsl, result, gold;
  -	char *resultString = "The specified function is not available: http://xml.apache.org/xalan:nodeset";
  +{	
   
  -	generateFiles(fileName, xml, xsl, result, gold);
  +	XalanDOMString	xml, xsl, result, gold;
  +	
  +	generateFiles(fileName, xml, xsl, result, gold, "TestCase3");
   
   	// Create the InputSources and ResultTraget.
   	const XSLTInputSource	xmlInputSource(c_wstr(xml));
   	const XSLTInputSource	xslInputSource(c_wstr(xsl));
   	const XSLTResultTarget	theResultTarget(result);
   
  -	// Install the external function "nodeset"
  -	transformEngine.uninstallExternalFunction(
  -		theNamespace,
  -		XalanDOMString("nodeset"));
  +	// UnInstall the external Global function "nodeset"
  +	transformEngine.uninstallExternalFunctionGlobal(
  +					theNamespace,
  +					XalanDOMString("nodeset"));
   
  -	// Perform the transform and check the results.
  -	int	theResult = transformEngine.transform(xmlInputSource, xslInputSource, theResultTarget);
  +	int theResult = transformEngine.transform(xmlInputSource, xslInputSource, theResultTarget);
   	if (theResult == -1)
   	{
   		if (!strcmp(resultString, transformEngine.getLastError()))
  @@ -379,18 +340,25 @@
   	{
   		cout << endl << "Failed: TestCase3" ;
   	}
  -	installUninstallExtensions(transformEngine, false);
  +
   }
   
  -//TestCase4:
  -//	This tests the nodeset function as well as the 
  -//	installExternalFunction method of XalanTransformer
  +
  +//	TestCase4:
  +//  API Call:	
  +//		XalanTransformer::installExternalFunction
  +//		XalanTransformer::uninstallExternalFunction
  +//  Comments:
  +//		This tests the installExternalFunction method of XalanTransformer using the nodeset
function.
  +//		Output file should NOT contain data.
  +//
   void TestCase4(XalanTransformer &transformEngine, const XalanDOMString &fileName)
   {
   	
   	XalanDOMString	xml, xsl, result, gold;
  +
   
  -	generateFiles(fileName, xml, xsl, result, gold);
  +	generateFiles(fileName, xml, xsl, result, gold, "TestCase4");
   
   	// Create the InputSources and ResultTraget.
   	const XSLTInputSource	xmlInputSource(c_wstr(xml));
  @@ -398,7 +366,7 @@
   	const XSLTResultTarget	theResultTarget(result);
   
   	// Install the external function "nodeset"
  -	transformEngine.installExternalFunctionGlobal(
  +	transformEngine.installExternalFunction(
   		theNamespace,
   		XalanDOMString("nodeset"),
   		FunctionNodeSet());
  @@ -416,79 +384,101 @@
   		cout << endl << "Failed: TestCase4a" ;
   	}
   
  +	// Because we install the function locally, this second instance of the transformer should
not run the
  +	// test successfully.
   	XalanTransformer newEngine;
  -	int secondResult = newEngine.transform(xmlInputSource, xslInputSource, theResultTarget);
  -	if (!secondResult)
  +	theResult = newEngine.transform(xmlInputSource, xslInputSource, theResultTarget);
  +	if (theResult == -1)
   	{
  -		const XSLTInputSource resultInputSource(c_wstr(result));
  -		const XSLTInputSource goldInputSource(c_wstr(gold));
  -		futil.compareSerializedResults(resultInputSource, goldInputSource, fileName, "TestCase4b");

  +		if (!strcmp(resultString, newEngine.getLastError()))
  +		{
  +			cout << endl << "Passed: TestCase4b" ;
  +		}
  +		else 
  +		{
  +			cout << endl << "Failed: TestCase4b" ;
  +		}
   	}
   	else
   	{
   		cout << endl << "Failed: TestCase4b" ;
   	}
   
  +	// Now unInstall the external function "nodeset"
  +	transformEngine.uninstallExternalFunction(
  +		theNamespace,
  +		XalanDOMString("nodeset"));
  +
  +	// Perform the transform and check the results.
  +	theResult = transformEngine.transform(xmlInputSource, xslInputSource, theResultTarget);
  +	if (theResult == -1)
  +	{
  +		if (!strcmp(resultString, newEngine.getLastError()))
  +		{
  +			cout << endl << "Passed: TestCase4c" ;
  +		}
  +		else 
  +		{
  +			cout << endl << "Failed: TestCase4c" ;
  +		}
  +	}
  +	else
  +	{
  +		cout << endl << "Failed: TestCase4c" ;
  +	}
  +
   }
   
  -//TestCase5:
  -//	This tests the nodeset function as well as the 
  -//	installExternalFunction method of XalanTransformer
  +//	TestCase5:
  +//  API Call: 
  +//		XalanTransformer::installExternalFunctionGlobal
  +//	Comments:
  +//		This tests uses transformer method installExternalFunctionGlobal to add the nodeset
function. 
  +//		The output file should contain data.
  +//
   void TestCase5(XalanTransformer &transformEngine, const XalanDOMString &fileName)
   {
   	
   	XalanDOMString	xml, xsl, result, gold;
  -	char *resultString = "The specified function is not available: http://xml.apache.org/xalan:nodeset";
   
  -	generateFiles(fileName, xml, xsl, result, gold);
  +	generateFiles(fileName, xml, xsl, result, gold, "TestCase5");
   
   	// Create the InputSources and ResultTraget.
   	const XSLTInputSource	xmlInputSource(c_wstr(xml));
   	const XSLTInputSource	xslInputSource(c_wstr(xsl));
   	const XSLTResultTarget	theResultTarget(result);
   
  -	// Install the external function "nodeset"
  -	transformEngine.uninstallExternalFunctionGlobal(
  +	// Install the external function "nodeset" Globally
  +	transformEngine.installExternalFunctionGlobal(
   		theNamespace,
  -		XalanDOMString("nodeset"));
  +		XalanDOMString("nodeset"),
  +		FunctionNodeSet());
   
   	// Perform the transform and check the results.
   	int	theResult = transformEngine.transform(xmlInputSource, xslInputSource, theResultTarget);
  -	if (theResult == -1)
  +	if (!theResult)
   	{
  -		if (!strcmp(resultString, transformEngine.getLastError()))
  -		{
  -			cout << endl << "Passed: TestCase5a" ;
  -		}
  -		else 
  -		{
  -			cout << endl << "Failed: TestCase5a" ;
  -		}
  +		const XSLTInputSource resultInputSource(c_wstr(result));
  +		const XSLTInputSource goldInputSource(c_wstr(gold));
  +		futil.compareSerializedResults(resultInputSource, goldInputSource, fileName, "TestCase5a");

   	}
   	else
   	{
   		cout << endl << "Failed: TestCase5a" ;
   	}
   
  -
   	XalanTransformer newEngine;
   	int secondResult = newEngine.transform(xmlInputSource, xslInputSource, theResultTarget);
  -	if (secondResult == -1)
  +	if (!secondResult)
   	{
  -		if (!strcmp(resultString, transformEngine.getLastError()))
  -		{
  -			cout << endl << "Passed: TestCase5b" ;
  -		}
  -		else 
  -		{
  -			cout << endl << "Failed: TestCase5b" ;
  -		}
  +		const XSLTInputSource resultInputSource(c_wstr(result));
  +		const XSLTInputSource goldInputSource(c_wstr(gold));
  +		futil.compareSerializedResults(resultInputSource, goldInputSource, fileName, "TestCase5b");

   	}
   	else
   	{
   		cout << endl << "Failed: TestCase5b" ;
   	}
  -
   }
   
   int
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


Mime
View raw message