This commit is contained in:
jez 2007-11-19 22:11:05 +00:00
parent 0d385d1ab2
commit a0083c14d2
7 changed files with 920 additions and 442 deletions

View file

@ -7,6 +7,7 @@
#include <SAX/InputSource.hpp>
#include <DOM/SAX2DOM/SAX2DOM.hpp>
#include <DOM/io/Stream.hpp>
#include <XSLT/XSLT.hpp>
void test_suite(int argc, const char* argv[]);
@ -44,6 +45,16 @@ int main(int argc, const char* argv[])
} // if ...
document.normalize();
stylesheet->execute(document);
std::cout << "==============" << std::endl;
Arabica::XSLT::DOMSink output;
stylesheet->set_output(output);
stylesheet->execute(document);
Arabica::DOM::Node<std::string> node = output.node();
std::cout << node << std::endl;
}
catch(const std::runtime_error& ex)
{

View file

@ -76,7 +76,6 @@ public:
return;
} // if ...
throw SAX::SAXException("xsl:stylesheet does not allowed " + qName + " here.");
} // startElement
virtual void endElement(const std::string& namespaceURI,

View file

@ -11,7 +11,9 @@ LIBSILLY = ../CppUnit/libsillystring.la
TESTLIBS = $(LIBARABICA) ../CppUnit/libcppunit.la
test_sources = scope_test.hpp \
xslt_test.hpp
xslt_test.hpp \
xslt_test.cpp
xslt_test_SOURCES = main.cpp \
$(test_sources)

View file

@ -5,9 +5,6 @@
#include <string>
#include <sstream>
#include <SAX/InputSource.hpp>
#include <DOM/SAX2DOM/SAX2DOM.hpp>
#include <XSLT/XSLT.hpp>
///////////////////////////////////////////////
#include "../CppUnit/TestRunner.hpp"
@ -18,15 +15,18 @@
// #include "scope_test.hpp"
#include "xslt_test.hpp"
/*
typedef std::string string_type;
typedef Arabica::default_string_adaptor<std::string> string_adaptor;
*/
int main(int argc, const char* argv[])
{
TestRunner runner;
// runner.addTest("ScopeTest", ScopeTest_suite<string_type, string_adaptor>());
// Xalan supplied test cases
/*
//runner.addTest("attribset", XSLTTest_suite("attribset"));
runner.addTest("attribvaltemplate", XSLTTest_suite("attribvaltemplate"));
runner.addTest("axes", XSLTTest_suite("axes"));
@ -38,7 +38,9 @@ int main(int argc, const char* argv[])
runner.addTest("expression", XSLTTest_suite("expression"));
runner.addTest("extend", XSLTTest_suite("extend"));
//runner.addTest("idkey", XSLTTest_suite("idkey"));
*/
runner.addTest("impincl", XSLTTest_suite("impincl"));
/*
runner.addTest("lre", XSLTTest_suite("lre"));
runner.addTest("match", XSLTTest_suite("match"));
runner.addTest("math", XSLTTest_suite("math"));
@ -61,7 +63,47 @@ int main(int argc, const char* argv[])
runner.addTest("variable", XSLTTest_suite("variable"));
runner.addTest("ver", XSLTTest_suite("ver"));
runner.addTest("whitespace", XSLTTest_suite("whitespace"));
// MSFT supplied test cases
runner.addTest("AVTs", XSLTTest_suite("AVTs"));
//runner.addTest("AttributeSets", XSLTTest_suite("AttributeSets"));
runner.addTest("Attributes", XSLTTest_suite("Attributes"));
runner.addTest("BVTs", XSLTTest_suite("BVTs"));
runner.addTest("Comment", XSLTTest_suite("Comment"));
runner.addTest("Completeness", XSLTTest_suite("Completeness"));
runner.addTest("ConflictResolution", XSLTTest_suite("ConflictResolution"));
runner.addTest("Copying", XSLTTest_suite("Copying"));
runner.addTest("Elements", XSLTTest_suite("Elements"));
*/
runner.addTest("Errors", XSLTTest_suite("Errors"));
/*
runner.addTest("Fallback", XSLTTest_suite("Fallback"));
runner.addTest("ForEach", XSLTTest_suite("ForEach"));
//runner.addTest("FormatNumber", XSLTTest_suite("FormatNumber"));
runner.addTest("ForwardComp", XSLTTest_suite("ForwardComp"));
runner.addTest("Import", XSLTTest_suite("Import"));
//runner.addTest("Keys", XSLTTest_suite("Keys"));
runner.addTest("Messages", XSLTTest_suite("Messages"));
runner.addTest("Miscellaneous", XSLTTest_suite("Miscellaneous"));
runner.addTest("Modes", XSLTTest_suite("Modes"));
runner.addTest("NamedTemplates", XSLTTest_suite("NamedTemplates"));
runner.addTest("Namespace", XSLTTest_suite("Namespace"));
runner.addTest("Namespace-alias", XSLTTest_suite("Namespace-alias"));
runner.addTest("Namespace_XPath", XSLTTest_suite("Namespace_XPath"));
//runner.addTest("Number", XSLTTest_suite("Number"));
runner.addTest("Output", XSLTTest_suite("Output"));
runner.addTest("ProcessingInstruction", XSLTTest_suite("ProcessingInstruction"));
runner.addTest("RTF", XSLTTest_suite("RTF"));
runner.addTest("Sorting", XSLTTest_suite("Sorting"));
runner.addTest("Stylesheet", XSLTTest_suite("Stylesheet"));
runner.addTest("Template", XSLTTest_suite("Template"));
runner.addTest("Text", XSLTTest_suite("Text"));
runner.addTest("Valueof", XSLTTest_suite("Valueof"));
runner.addTest("Variables", XSLTTest_suite("Variables"));
runner.addTest("Whitespaces", XSLTTest_suite("Whitespaces"));
runner.addTest("XSLTFunctions", XSLTTest_suite("XSLTFunctions"));
*/
runner.run(argc, argv);
return 77;

View file

@ -150,4 +150,224 @@
<test-case id="whitespace_whitespace12" compiles="no"/>
<test-case id="whitespace_whitespace22" compiles="no"/>
<test-case id="whitespace_whitespace35" compiles="no"/>
<test-case id="AVTs__77531" compare="fragment" reason="XML Fragment output"/>
<test-case id="AVTs__77558" compare="fragment" reason="XML Fragment output"/>
<test-case id="AVTs__77564" compare="fragment" reason="XML Fragment output"/>
<test-case id="AVTs__77570" compare="fragment" reason="XML Fragment output"/>
<test-case id="AVTs__77575" compare="fragment" reason="XML Fragment output"/>
<test-case id="AVTs__77576" compare="fragment" reason="XML Fragment output"/>
<test-case id="AVTs__77577" compare="fragment" reason="XML Fragment output"/>
<test-case id="AVTs__77579" compare="fragment" reason="XML Fragment output"/>
<test-case id="AVTs__77580" compare="fragment" reason="XML Fragment output"/>
<test-case id="AVTs__77582" compare="fragment" reason="XML Fragment output"/>
<test-case id="AVTs__77599" compare="fragment" reason="XML Fragment output"/>
<test-case id="Attributes__78366" compiles="no" reason="Error case: empty namespace"/>
<test-case id="Attributes__78382" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
<test-case id="Attributes__78386" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
<test-case id="Attributes__81430" compare="fragment" reason="XML Fragment output"/>
<test-case id="Attributes__81431" compare="fragment" reason="XML Fragment output"/>
<test-case id="Attributes__81482" compare="text"/>
<test-case id="Attributes__81483" compare="text"/>
<test-case id="Attributes__81484" compare="text"/>
<test-case id="Attributes__81485" compare="fragment"/>
<test-case id="Attributes__81486" compare="fragment"/>
<test-case id="Attributes__81487" compare="fragment"/>
<test-case id="Attributes__81489" compare="text"/>
<test-case id="Attributes__81491" compare="text"/>
<test-case id="Attributes__81492" compare="text"/>
<test-case id="Attributes__81493" compare="text"/>
<test-case id="Attributes__81494" compare="text"/>
<test-case id="Attributes__81495" compare="text"/>
<test-case id="Attributes__81496" compare="fragment"/>
<test-case id="Attributes__81497" compare="fragment"/>
<test-case id="Attributes__81499" compare="fragment"/>
<test-case id="Attributes__81544" compare="fragment"/>
<test-case id="Attributes__81545" compare="text"/>
<test-case id="Attributes__81546" compare="text"/>
<test-case id="Attributes__81547" compare="text"/>
<test-case id="Attributes__81548" compare="fragment"/>
<test-case id="Attributes__81550" compare="fragment"/>
<test-case id="Attributes__81551" compare="fragment"/>
<test-case id="Attributes__83030" compare="fragment"/>
<test-case id="Attributes__83822" compare="text"/>
<test-case id="Attributes__84169" compare="text"/>
<test-case id="Attributes__89433" compare="text"/>
<test-case id="Attributes__89434" compare="text"/>
<test-case id="Attributes__89435" compare="text"/>
<test-case id="Attributes__89436" compare="text"/>
<test-case id="Attributes__89437" compare="text"/>
<test-case id="Attributes__89438" compare="text"/>
<test-case id="Attributes__89439" compare="fragment"/>
<test-case id="Attributes__89440" compare="fragment"/>
<test-case id="Attributes__89441" compare="fragment"/>
<test-case id="Attributes__89442" compare="fragment"/>
<test-case id="Attributes__89459" compare="fragment"/>
<test-case id="Attributes__89466" compare="fragment"/>
<test-case id="Attributes_Attribute_WhitespaceInUseAttributeSets" compiles="no" reason="Haven't implemented attribute-sets"/>
<test-case id="Attributes_EmptyStringInUseAttribSets" compiles="no" reason="Haven't implemented attribute-sets"/>
<test-case id="BVTs_bvt001" compiles="no" reason="Doesn't understand xml:space properly"/>
<test-case id="BVTs_bvt002" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
<test-case id="BVTs_bvt003" compiles="no" reason="Needs attribute sets"/>
<test-case id="BVTs_bvt004" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
<test-case id="BVTs_bvt005" compiles="no" reason="Doesn't understand xml:space properly"/>
<test-case id="BVTs_bvt007" compare="text"/>
<test-case id="BVTs_bvt008" compare="fragment"/>
<test-case id="BVTs_bvt013" compare="fragment"/>
<test-case id="BVTs_bvt014" compare="text"/>
<test-case id="BVTs_bvt017" skip="yes" reason="Needs funky output encoding"/>
<test-case id="BVTs_bvt018" skip="yes" reason="Needs funky output encoding"/>
<test-case id="BVTs_bvt019" skip="yes" reason="Needs funky output encoding"/>
<test-case id="BVTs_bvt020" compiles="no" reason="Needs xsl:fall-back"/>
<test-case id="BVTs_bvt021" compare="fragment"/>
<test-case id="BVTs_bvt022" compiles="no" reason="Needs xsl:fall-back"/>
<test-case id="BVTs_bvt023" compiles="no" reason="Needs xsl:fall-back"/>
<test-case id="BVTs_bvt024" compiles="no" reason="Needs format-number"/>
<test-case id="BVTs_bvt027" compare="fragment"/>
<test-case id="BVTs_bvt033" compiles="no"/>
<test-case id="BVTs_bvt034" compiles="no"/>
<test-case id="BVTs_bvt035" compare="text"/>
<test-case id="BVTs_bvt036" compare="text"/>
<test-case id="BVTs_bvt037" compare="fragment"/>
<test-case id="BVTs_bvt038" compare="fragment"/>
<test-case id="BVTs_bvt040" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
<test-case id="BVTs_bvt044" skip="yes" reason="Segfault!"/>
<test-case id="BVTs_bvt045" skip="yes" reason="Bad result data"/>
<test-case id="BVTs_bvt047" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
<test-case id="BVTs_bvt052" skip="yes" reason="Uses MSXML specific extension function"/>
<test-case id="BVTs_bvt053" compare="text"/>
<test-case id="BVTs_bvt054" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
<test-case id="BVTs_bvt055" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
<test-case id="BVTs_bvt056" compare="text"/>
<test-case id="BVTs_bvt057" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
<test-case id="BVTs_bvt060" compiles="no" reason="Needs xsl:number"/>
<test-case id="BVTs_bvt061" compiles="no" reason="Needs xsl:number"/>
<test-case id="BVTs_bvt062" compare="fragment"/>
<test-case id="BVTs_bvt065" compare="fragment"/>
<test-case id="BVTs_bvt069" compare="text"/>
<test-case id="BVTs_bvt070" compare="text"/>
<test-case id="BVTs_bvt072" compare="fragment"/>
<test-case id="BVTs_bvt073" compare="fragment"/>
<test-case id="BVTs_bvt075" compare="text"/>
<test-case id="BVTs_bvt076" compare="text"/>
<test-case id="BVTs_bvt078" compare="text"/>
<test-case id="BVTs_bvt079" compare="fragment"/>
<test-case id="BVTs_bvt080" compare="fragment"/>
<test-case id="BVTs_bvt081" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
<test-case id="BVTs_bvt083" compiles="no"/>
<test-case id="BVTs_bvt085" skip="yes" reason="Bad result data"/>
<test-case id="BVTs_bvt086" compiles="no"/>
<test-case id="BVTs_bvt089" compiles="no" reason="Haven't implemented unparsed-entity-uri"/>
<test-case id="BVTs_bvt090" compare="fragment"/>
<test-case id="BVTs_bvt092" compare="fragment"/>
<test-case id="BVTs_bvt094" compare="text"/>
<test-case id="BVTs_bvt095" compare="fragment"/>
<test-case id="BVTs_bvt096" compare="text"/>
<test-case id="BVTs_bvt098" compiles="no" reason="Haven't implemented embedded stylesheets yet"/>
<test-case id="BVTs_bvt099" compare="fragment"/>
<test-case id="BVTs_bvt100" compare="fragment"/>
<test-case id="Comment_Comment_CDATAWithDoubleHyphen" compare="fragment"/>
<test-case id="Comment_Comment_CDATAWithDoubleHyphenEntities" compare="fragment"/>
<test-case id="Comment_Comment_CDATAWithSingleHyphen" compare="fragment"/>
<test-case id="Comment_Comment_CommentWithCDATAValidText" compare="fragment"/>
<test-case id="Comment_Comment_CommentWithForeignCharacters" skip="yes" reason="Only support UTF-8 at the moment"/>
<test-case id="Comment_Comment_CommentWithOnlyValidText" compare="fragment"/>
<test-case id="Comment_Comment_DoubleHypenEntitywithDelCharacter" skip="yes" reason="Only support UTF-8 at the moment"/>
<test-case id="Comment_Comment_DoubleHypenInText" skip="yes" reason="Only support UTF-8 at the moment"/>
<test-case id="Comment_Comment_DoubleHyphenONLY" compare="fragment"/>
<test-case id="Comment_Comment_EmptyComment" compare="fragment"/>
<test-case id="Comment_Comment_HyphenEntityAndHyphen" compare="fragment"/>
<test-case id="Comment_Comment_LineOfAllHyphens" compare="fragment"/>
<test-case id="Comment_Comment_SingleHyphenOnly" compare="fragment"/>
<test-case id="Comment_Comment_Test1" compare="fragment"/>
<test-case id="Comment_Comment_Test2" compare="fragment"/>
<test-case id="Comment_Comment_Test3" compiles="no" reason="Haven't implemented attribute-sets"/>
<test-case id="Completeness__84351" compare="text"/>
<test-case id="Completeness__84354" compare="fragment"/>
<test-case id="Completeness__84359" compare="text"/>
<test-case id="Completeness__84361" compare="fragment"/>
<test-case id="ConflictResolution__77619" compare="fragment"/>
<test-case id="ConflictResolution__77621" compare="fragment"/>
<test-case id="ConflictResolution__77622" compare="fragment"/>
<test-case id="ConflictResolution__77746" compare="fragment"/>
<test-case id="ConflictResolution__77781" compare="fragment"/>
<test-case id="ConflictResolution__77782" compare="fragment"/>
<test-case id="ConflictResolution__77783" compare="fragment"/>
<test-case id="ConflictResolution__77784" compare="fragment"/>
<test-case id="ConflictResolution__77833" compare="fragment"/>
<test-case id="ConflictResolution__77847" compare="fragment"/>
<test-case id="ConflictResolution__77870" compare="fragment"/>
<test-case id="ConflictResolution__77871" compare="fragment"/>
<test-case id="ConflictResolution__77872" compare="fragment"/>
<test-case id="ConflictResolution__77875" compare="fragment"/>
<test-case id="ConflictResolution__77876" compare="fragment"/>
<test-case id="ConflictResolution__77877" compare="fragment"/>
<test-case id="ConflictResolution__77878" compare="fragment"/>
<test-case id="ConflictResolution__77879" compare="fragment"/>
<test-case id="ConflictResolution__77881" compare="fragment"/>
<test-case id="ConflictResolution__77882" compare="fragment"/>
<test-case id="ConflictResolution__77885" compare="fragment"/>
<test-case id="ConflictResolution__77886" compare="fragment"/>
<test-case id="ConflictResolution__77889" compare="fragment"/>
<test-case id="ConflictResolution__77891" compare="fragment"/>
<test-case id="ConflictResolution__77893" compare="fragment"/>
<test-case id="ConflictResolution__77902" compare="fragment"/>
<test-case id="ConflictResolution__77904" compare="fragment"/>
<test-case id="ConflictResolution__84476" compare="fragment"/>
<test-case id="ConflictResolution__84477" compare="fragment"/>
<test-case id="ConflictResolution_ConflictResBetweenStripSpaceAndPreserveSpace" compiles="no"/>
<test-case id="Copying__84388" compare="fragment"/>
<test-case id="Copying__84389" compare="fragment"/>
<test-case id="Copying_UseXmlnsWithEmptyStringAsDefaultNs" skip="yes" reason="Stylesheet encoding in Windows-1251"/>
<test-case id="Elements__78364" compiles="no" reason="Haven't implemented embedded stylesheets"/>
<test-case id="Elements__83968" compiles="no" reason="Haven't implemented embedded stylesheets"/>
<test-case id="Elements__89062" compare="text"/>
<test-case id="Elements__89063" compare="text"/>
<test-case id="Elements__89065" compare="text"/>
<test-case id="Elements__89066" compare="text"/>
<test-case id="Elements__89071" compare="fragment"/>
<test-case id="Elements__89072" compare="fragment"/>
<test-case id="Elements__89104" compare="text"/>
<test-case id="Elements__89107" compare="text"/>
<test-case id="Elements__89108" compare="text"/>
<test-case id="Elements__89112" compare="fragment"/>
<test-case id="Elements__89113" compare="fragment"/>
<test-case id="Elements__89207" compare="fragment"/>
<test-case id="Elements__89278" compare="text"/>
<test-case id="Elements__89279" compare="text"/>
<test-case id="Elements__89280" compare="text"/>
<test-case id="Elements__89281" compare="text"/>
<test-case id="Elements__89286" compare="fragment"/>
<test-case id="Elements__89287" compare="fragment"/>
<test-case id="Elements__89705" compare="fragment"/>
<test-case id="Elements__89709" compare="fragment"/>
<test-case id="Elements__89710" compare="fragment"/>
<test-case id="Elements__89711" compare="fragment"/>
<test-case id="Elements__89712" compare="fragment"/>
<test-case id="Elements__89713" compare="text"/>
<test-case id="Elements__89717" compare="fragment"/>
<test-case id="Elements__89718" compare="fragment"/>
<test-case id="Elements__89723" compare="fragment"/>
<test-case id="Errors_err073" skip="yes" reason="Test throws Mangle into an infinite loop or something"/>
<test-case id="Fallback__91817" compiles="no"/>
<test-case id="Fallback__91818" compiles="no"/>
<test-case id="Fallback__91819" compiles="no"/>
<test-case id="Fallback__91820" compiles="no"/>
<test-case id="Fallback__91821" compiles="no"/>
<test-case id="Fallback__91823" compiles="no"/>
<test-case id="Fallback__91824" compiles="no"/>
<test-case id="ForEach_ForEach_ForeachWithXPATHEvaluatesToNull" compare="text"/>
<test-case id="ForwardComp__91837" compiles="no"/>
<test-case id="ForwardComp__91838" compiles="no"/>
<test-case id="ForwardComp__91839" compiles="no"/>
<test-case id="ForwardComp__91840" compiles="no"/>
<test-case id="ForwardComp__91842" compiles="no"/>
<test-case id="ForwardComp__91843" compiles="no"/>
<test-case id="ForwardComp__91845" compiles="no"/>
<test-case id="ForwardComp__91846" compiles="no"/>
<test-case id="ForwardComp__91847" compiles="no"/>
<test-case id="ForwardComp__91848" compiles="no"/>
<test-case id="ForwardComp__91849" compiles="no"/>
<test-case id="ForwardComp__91853" compiles="no"/>
<test-case id="ForwardComp__91855" compiles="no"/>
</test-suite>

638
tests/XSLT/xslt_test.cpp Executable file
View file

@ -0,0 +1,638 @@
#ifndef XSLT_XSLT_TEST_HPP
#define XSLT_XSLT_TEST_HPP
#include <SAX/InputSource.hpp>
#include <DOM/SAX2DOM/SAX2DOM.hpp>
#include <DOM/io/Stream.hpp>
#include <XSLT/XSLT.hpp>
#include <fstream>
#include "../CppUnit/framework/Test.h"
#include "../CppUnit/framework/TestCase.h"
#include "../CppUnit/framework/TestSuite.h"
//#include <elephant/newdelete.h>
//#include <elephant/memorymonitorholder.h>
//#include <elephant/leakdetector.h>
//#include <elephant/leakdisplayfunc.h>
#ifdef ARABICA_WINDOWS
const std::string PATH_PREFIX="../tests/XSLT/testsuite/TESTS/";
const std::string SEPERATOR = "/";
#else
#include "test_path.hpp"
const std::string PATH_PREFIX=test_path;
const std::string SEPERATOR = "/";
#endif
Arabica::DOM::Document<std::string> buildDOM(const std::string& filename)
{
Arabica::SAX::InputSource<std::string> is(filename);
Arabica::SAX2DOM::Parser<std::string> parser;
parser.parse(is);
Arabica::DOM::Document<std::string> d = parser.getDocument();
if(d != 0)
d.normalize();
return d;
} // buildDOM
Arabica::DOM::Document<std::string> buildDOMFromString(const std::string& xml)
{
std::stringstream ss;
ss << xml;
Arabica::SAX::InputSource<std::string> is(ss);
Arabica::SAX2DOM::Parser<std::string> parser;
parser.parse(is);
Arabica::DOM::Document<std::string> d = parser.getDocument();
if(d != 0)
d.normalize();
return d;
} // buildDOMFromString
std::string readFile(const std::string& filename)
{
std::ifstream in(filename.c_str());
std::string file = std::string(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());
if((file[0] == (char)0xff) && (file[1] == (char)0xfe)) // UTF16 BOM
{
// this is absolutely not a sensible thing to do
// in this case, I know it's ok for the test data but in the general case don't even think about it
file.erase(0, 2);
for(std::string::size_type i = file.length() - 1; i != std::string::npos; i -= 2)
file.erase(i, 1);
} // if ...
if((file[0] == (char)0xef) && (file[1] == (char)0xbb) && (file[2] == (char)0xbf)) // UTF-8 BOM
file.erase(0, 3);
return file;
} // readFile
std::string readFragment(const std::string& filename)
{
std::string frag = readFile(filename);
if(frag.find("<?xml") == 0)
frag.erase(0, frag.find("?>") + 2);
return frag;
} // readFragment
Arabica::XPath::NodeSet<std::string> selectNodes(const std::string& path, const Arabica::DOM::Node<std::string>& node)
{
Arabica::XPath::XPath<std::string> xpath;
return xpath.evaluate(path, node).asNodeSet();
} // selectNodes
Arabica::DOM::Node<std::string> selectNode(const std::string& path, const Arabica::DOM::Node<std::string>& node)
{
return selectNodes(path, node)[0];
} // selectNode
std::string selectString(const std::string& path, const Arabica::DOM::Node<std::string>& node)
{
Arabica::XPath::XPath<std::string> xpath;
return xpath.evaluate_expr(path, node).asString();
} // selectString
std::string make_path(const std::string& path, const std::string& filename)
{
return PATH_PREFIX + path + SEPERATOR + filename;
} // make_path
class SkipTest : public TestCase
{
public:
SkipTest(const std::string& name,
const std::string& reason) :
TestCase(name),
reason_(reason)
{
} // SkipTest
protected:
virtual void runTest()
{
throw SkipException(reason_);
} // runTest
private:
std::string reason_;
}; // class SkipTest
class CompileFailsTest : public TestCase
{
public:
CompileFailsTest(const std::string& name,
const std::string& input_xslt,
const std::string& reason) :
TestCase(name),
input_xslt_(input_xslt),
reason_(reason)
{
} // CompileFailsTest
protected:
virtual void runTest()
{
Arabica::XSLT::StylesheetCompiler compiler;
Arabica::SAX::InputSource<std::string> source(input_xslt_);
std::auto_ptr<Arabica::XSLT::Stylesheet> stylesheet = compiler.compile(source);
if(stylesheet.get() != 0)
assertImplementation(false, "Expected " + input_xslt_ + " not to compile. But it did :o");
throw SkipException(reason_ + " : " + compiler.error());
} // runTest
private:
std::string input_xslt_;
std::string reason_;
}; // CompileFailsTest
class RunFailsTest : public TestCase
{
public:
RunFailsTest(const std::string& name,
const std::string& input_xml,
const std::string& input_xslt,
const std::string& reason) :
TestCase(name),
input_xml_(input_xml),
input_xslt_(input_xslt),
reason_(reason)
{
} // RunFailsTest
protected:
virtual void runTest()
{
Arabica::XSLT::StylesheetCompiler compiler;
Arabica::SAX::InputSource<std::string> source(input_xslt_);
std::auto_ptr<Arabica::XSLT::Stylesheet> stylesheet = compiler.compile(source);
if(stylesheet.get() == 0)
assertImplementation(false, "Failed to compile " + input_xslt_ + " : " + compiler.error());
Arabica::XSLT::DOMSink output;
stylesheet->set_output(output);
std::ostringstream errors;
stylesheet->set_error_output(errors);
Arabica::DOM::Document<std::string> document = buildDOM(input_xml_);
try {
stylesheet->execute(document);
}
catch(const std::exception& e) {
throw SkipException(reason_ + " : " + e.what());
}
assertImplementation(false, "Expected " + input_xslt_ + " to fail to execute. But it did :o");
} // runTest
private:
std::string input_xml_;
std::string input_xslt_;
std::string reason_;
}; // RunFailsTest
class ExecutionErrorTest : public TestCase
{
public:
ExecutionErrorTest(const std::string& name,
const std::string& input_xml,
const std::string& input_xslt) :
TestCase(name),
input_xml_(input_xml),
input_xslt_(input_xslt)
{
} // ExecutionErrorTest
protected:
virtual void runTest()
{
Arabica::XSLT::StylesheetCompiler compiler;
Arabica::SAX::InputSource<std::string> source(input_xslt_);
std::auto_ptr<Arabica::XSLT::Stylesheet> stylesheet = compiler.compile(source);
if(stylesheet.get() == 0)
return;
Arabica::XSLT::DOMSink output;
stylesheet->set_output(output);
std::ostringstream errors;
stylesheet->set_error_output(errors);
Arabica::DOM::Document<std::string> document = buildDOM(input_xml_);
try {
stylesheet->execute(document);
}
catch(const std::exception& e) {
return;
}
assertImplementation(false, "Marked in catalog.xml as an execution error, but actually ran.");
} // runTest
private:
std::string input_xml_;
std::string input_xslt_;
}; // ExecutionErrorTest
class CompareAsTextXSLTTest : public TestCase
{
public:
CompareAsTextXSLTTest(const std::string& name,
const std::string& input_xml,
const std::string& input_xslt,
const std::string& output_xml) :
TestCase(name),
input_xml_(input_xml),
input_xslt_(input_xslt),
output_xml_(output_xml)
{
} // CompareAsTextXSLTTest
protected:
virtual void runTest()
{
Arabica::XSLT::StylesheetCompiler compiler;
Arabica::SAX::InputSource<std::string> source(input_xslt_);
std::auto_ptr<Arabica::XSLT::Stylesheet> stylesheet = compiler.compile(source);
if(stylesheet.get() == 0)
assertImplementation(false, "Failed to compile " + input_xslt_ + " : " + compiler.error());
std::ostringstream xml_output;
Arabica::XSLT::StreamSink output(xml_output);
stylesheet->set_output(output);
std::ostringstream errors;
stylesheet->set_error_output(errors);
Arabica::DOM::Document<std::string> document = buildDOM(input_xml_);
try {
stylesheet->execute(document);
}
catch(const std::exception& e) {
assertImplementation(false, "Failed to run " + input_xslt_ + " : " + e.what());
} // catch
std::string ref = readFile(output_xml_);
std::string out = xml_output.str();
if(ref == out)
return;
std::string refs = trimXMLDecl(ref);
std::string outs = trimXMLDecl(out);
if(refs == outs)
return;
refs = stripWhitespace(refs);
outs = stripWhitespace(outs);
if(refs == outs)
return;
assertImplementation(false, "Expected text:\n" + ref + "\nbut got:\n" + out + "\n" + refs + "\nbut got:" + outs + "\n=====");
} // runTest
private:
std::string stripWhitespace(const std::string& str)
{
std::string s = Arabica::text::normalize_whitespace<std::string, Arabica::default_string_adaptor<std::string> >(str);
std::string::size_type i = s.find("> ");
while(i != std::string::npos)
{
s.erase(i+1, 1);
i = s.find("> ");
} // while ..
i = s.find(" <");
while(i != std::string::npos)
{
s.erase(i, 1);
i = s.find(" <");
} // while ..
return s;
} // stripWhitespace
std::string trimXMLDecl(const std::string& str)
{
if(str.find("<?") != 0)
return str;
return str.substr(str.find("?>") + 2);
} // trimXMLDecl
std::string input_xml_;
std::string input_xslt_;
std::string output_xml_;
}; // class CompareAsTextXSLTTest
class CompareAsXMLFragmentXSLTTest : public TestCase
{
public:
CompareAsXMLFragmentXSLTTest(const std::string& name,
const std::string& input_xml,
const std::string& input_xslt,
const std::string& output_xml) :
TestCase(name),
input_xml_(input_xml),
input_xslt_(input_xslt),
output_xml_(output_xml)
{
} //
protected:
virtual void runTest()
{
Arabica::XSLT::StylesheetCompiler compiler;
Arabica::SAX::InputSource<std::string> source(input_xslt_);
std::auto_ptr<Arabica::XSLT::Stylesheet> stylesheet = compiler.compile(source);
if(stylesheet.get() == 0)
assertImplementation(false, "Failed to compile " + input_xslt_ + " : " + compiler.error());
Arabica::XSLT::DOMSink output;
stylesheet->set_output(output);
std::ostringstream errors;
stylesheet->set_error_output(errors);
Arabica::DOM::Document<std::string> document = buildDOM(input_xml_);
try {
stylesheet->execute(document);
}
catch(const std::exception& e) {
assertImplementation(false, "Failed to run " + input_xslt_ + " : " + e.what());
}
std::string refStr = "<wrapper>" + readFragment(output_xml_) + "</wrapper>";
Arabica::DOM::Document<std::string> refDoc = buildDOMFromString(refStr);
if(refDoc == 0)
assertImplementation(false, "Couldn't read " + output_xml_ + ". Perhaps it isn't well-formed XML?");
Arabica::DOM::DocumentFragment<std::string> ref = refDoc.createDocumentFragment();
for(Arabica::DOM::Node<std::string> n = refDoc.getDocumentElement().getFirstChild(); n != 0; n = refDoc.getDocumentElement().getFirstChild())
ref.appendChild(n);
Arabica::DOM::Node<std::string> out = output.node();
out.normalize();
std::string refs = docToString(ref);
std::string outs = docToString(out);
if(refs == outs)
return;
stripWhitespace(ref);
stripWhitespace(out);
std::string refs2 = docToString(ref);
std::string outs2 = docToString(out);
if(refs2 == outs2)
return;
assertImplementation(false, "Expected:\n" + refs + "\nbut got:\n" + outs);
} // runTest
std::string docToString(Arabica::DOM::Node<std::string> node)
{
std::ostringstream ss;
ss << node;
return Arabica::text::normalize_whitespace<std::string, Arabica::default_string_adaptor<std::string> >(ss.str());
} // docToString
void stripWhitespace(Arabica::DOM::Node<std::string> doc)
{
Arabica::XPath::NodeSet<std::string> textNodes = selectNodes("//text()", doc);
for(int i = 0; i != textNodes.size(); ++i)
{
Arabica::DOM::Node<std::string> t = textNodes[i];
std::string text = t.getNodeValue();
text = Arabica::text::normalize_whitespace<std::string, Arabica::default_string_adaptor<std::string> >(text);
size_t index = text.find_first_of(" ");
while(index != std::string::npos)
{
text.replace(index, 1, "");
index = text.find_first_of(" ");
}
t.setNodeValue(text);
}
} // stripWhitespace
std::string input_xml_;
std::string input_xslt_;
std::string output_xml_;
}; // class CompareAsXMLFragment
class StandardXSLTTest : public TestCase
{
public:
StandardXSLTTest(const std::string& name,
const std::string& input_xml,
const std::string& input_xslt,
const std::string& output_xml) :
TestCase(name),
input_xml_(input_xml),
input_xslt_(input_xslt),
output_xml_(output_xml)
{
} // StandardXSLTTest
protected:
virtual void runTest()
{
Arabica::XSLT::StylesheetCompiler compiler;
Arabica::SAX::InputSource<std::string> source(input_xslt_);
std::auto_ptr<Arabica::XSLT::Stylesheet> stylesheet = compiler.compile(source);
if(stylesheet.get() == 0)
assertImplementation(false, "Failed to compile " + input_xslt_ + " : " + compiler.error());
Arabica::XSLT::DOMSink output;
stylesheet->set_output(output);
std::ostringstream errors;
stylesheet->set_error_output(errors);
Arabica::DOM::Document<std::string> document = buildDOM(input_xml_);
if(document == 0)
assertImplementation(false, "Couldn't read " + input_xml_ + ". Perhaps it isn't well-formed XML?");
try {
stylesheet->execute(document);
}
catch(const std::exception& e) {
assertImplementation(false, "Failed to run " + input_xslt_ + " : " + e.what());
}
Arabica::DOM::Document<std::string> ref = buildDOM(output_xml_);
if(ref == 0)
assertImplementation(false, "Couldn't read " + output_xml_ + ". Perhaps it isn't well-formed XML?");
Arabica::DOM::Node<std::string> out = output.node();
out.normalize();
std::string refs = docToString(ref);
std::string outs = docToString(out);
if(refs == outs)
return;
stripWhitespace(ref);
stripWhitespace(out);
std::string refs2 = docToString(ref);
std::string outs2 = docToString(out);
if(refs2 == outs2)
return;
assertImplementation(false, "Expected:\n" + refs + "\nbut got:\n" + outs);
} // runTest
std::string docToString(Arabica::DOM::Node<std::string> node)
{
std::ostringstream ss;
ss << node;
std::string xml = Arabica::text::normalize_whitespace<std::string, Arabica::default_string_adaptor<std::string> >(ss.str());
if(xml.find("<?xml version=\"1.0\"?> ") == 0)
xml.replace(0, 22, "");
return xml;
} // docToString
void stripWhitespace(Arabica::DOM::Node<std::string> doc)
{
Arabica::XPath::NodeSet<std::string> textNodes = selectNodes("//text()", doc);
for(int i = 0; i != textNodes.size(); ++i)
{
Arabica::DOM::Node<std::string> t = textNodes[i];
std::string text = t.getNodeValue();
text = Arabica::text::normalize_whitespace<std::string, Arabica::default_string_adaptor<std::string> >(text);
size_t index = text.find_first_of(" ");
while(index != std::string::npos)
{
text.replace(index, 1, "");
index = text.find_first_of(" ");
}
t.setNodeValue(text);
}
} // stripWhitespace
std::string input_xml_;
std::string input_xslt_;
std::string output_xml_;
}; // class StandardXSLTTest
class Expected
{
public:
Expected()
{
Arabica::DOM::Document<std::string> fail_doc = buildDOM(PATH_PREFIX + "arabica-expected-fails.xml");
Arabica::XPath::NodeSet<std::string> failcases = selectNodes("/test-suite/test-case", fail_doc);
for(int i = 0; i != failcases.size(); ++i)
{
std::string name = selectString("@id", failcases[i]);
std::string compiles = selectString("@compiles", failcases[i]);
std::string runs = selectString("@runs", failcases[i]);
std::string skip = selectString("@skip", failcases[i]);
std::string reason = selectString("@reason", failcases[i]);
std::string compare = selectString("@compare", failcases[i]);
if(compiles == "no")
fails[name] = "compile";
else if(runs == "no")
fails[name] = "run";
else if(skip == "yes")
fails[name] = "skip";
else if(compare == "text")
fails[name] = "text";
else if(compare == "fragment")
fails[name] = "fragment";
reasons[name] = reason;
} // for ...
}
std::map<std::string, std::string>& Fails() { return fails; }
std::map<std::string, std::string>& Reasons() { return reasons; }
private:
std::map<std::string, std::string> fails;
std::map<std::string, std::string> reasons;
};
static Expected expected;
TestSuite* XSLTTest_suite(const std::string& path)
{
//#define new ELEPHANTNEW
// using namespace elephant;
// LeakDetector leakDetector;
// MemoryMonitorHolder().Instance().AddObserver(&leakDetector);
//
// poo();
//
// MemoryMonitorHolder().Instance().RemoveObserver(&leakDetector);
// LeakDisplayFunc leakDisplay(std::cout);
// std::for_each(leakDetector.begin(), leakDetector.end(), leakDisplay);
//#undef new
static Arabica::DOM::Document<std::string> catalog = buildDOM(PATH_PREFIX + "catalog.xml");
TestSuite *suiteOfTests = new TestSuite;
Arabica::XPath::NodeSet<std::string> tests =
// selectNodes("/test-suite/test-catalog/test-case[scenario/@operation='standard']", catalog);
// selectNodes("/test-suite/test-catalog/test-case[@id='boolean_boolean86']", catalog);
selectNodes("/test-suite/test-catalog/test-case[file-path='" + path + "']", catalog);
for(int i = 0; i != tests.size(); ++i)
{
std::string operation = selectString("scenario/@operation", tests[i]);
std::string name = selectString("@id", tests[i]);
std::string path = selectString("concat(../major-path, '" + SEPERATOR + "', file-path)", tests[i]);
std::string out_path = selectString("concat(../major-path, '" + SEPERATOR + "REF_OUT" + SEPERATOR + "', file-path)", tests[i]);
std::string input_xml = selectString(".//input-file[@role='principal-data']", tests[i]);
std::string input_xslt = selectString(".//input-file[@role='principal-stylesheet']", tests[i]);
std::string output_xml = selectString(".//output-file[@role='principal']", tests[i]);
if(expected.Fails().find(name) == expected.Fails().end())
{
if(operation == "execution-error")
suiteOfTests->addTest(new ExecutionErrorTest(name,
make_path(path, input_xml),
make_path(path, input_xslt)));
else
suiteOfTests->addTest(new StandardXSLTTest(name,
make_path(path, input_xml),
make_path(path, input_xslt),
make_path(out_path, output_xml)));
}
else if(expected.Fails()[name] == "compile")
suiteOfTests->addTest(new CompileFailsTest(name,
make_path(path, input_xslt),
expected.Reasons()[name]));
else if(expected.Fails()[name] == "run")
suiteOfTests->addTest(new RunFailsTest(name,
make_path(path, input_xml),
make_path(path, input_xslt),
expected.Reasons()[name]));
else if(expected.Fails()[name] == "skip")
suiteOfTests->addTest(new SkipTest(name, expected.Reasons()[name]));
else if(expected.Fails()[name] == "text")
suiteOfTests->addTest(new CompareAsTextXSLTTest(name,
make_path(path, input_xml),
make_path(path, input_xslt),
make_path(out_path, output_xml)));
else if(expected.Fails()[name] == "fragment")
suiteOfTests->addTest(new CompareAsXMLFragmentXSLTTest(name,
make_path(path, input_xml),
make_path(path, input_xslt),
make_path(out_path, output_xml)));
} // for ...
return suiteOfTests;
} // XSLTTest_suite
#endif

View file

@ -1,440 +1,6 @@
#ifndef XSLT_XSLT_TEST_HPP
#define XSLT_XSLT_TEST_HPP
#include <SAX/InputSource.hpp>
#include <DOM/SAX2DOM/SAX2DOM.hpp>
#include <DOM/io/Stream.hpp>
#include <XSLT/XSLT.hpp>
#include <fstream>
//#include <elephant/newdelete.h>
//#include <elephant/memorymonitorholder.h>
//#include <elephant/leakdetector.h>
//#include <elephant/leakdisplayfunc.h>
#ifdef ARABICA_WINDOWS
const std::string PATH_PREFIX="../tests/XSLT/testsuite/TESTS/";
const std::string SEPERATOR = "/";
#else
#include "test_path.hpp"
const std::string PATH_PREFIX=test_path;
const std::string SEPERATOR = "/";
#endif
Arabica::DOM::Document<std::string> buildDOM(const std::string& filename)
{
Arabica::SAX::InputSource<std::string> is(filename);
Arabica::SAX2DOM::Parser<std::string> parser;
parser.parse(is);
Arabica::DOM::Document<std::string> d = parser.getDocument();
if(d != 0)
d.normalize();
return d;
} // buildDOM
std::string readFile(const std::string& filename)
{
std::ifstream in(filename.c_str());
return std::string(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());
} // readFile
Arabica::XPath::NodeSet<std::string> selectNodes(const std::string& path, const Arabica::DOM::Node<std::string>& node)
{
Arabica::XPath::XPath<std::string> xpath;
return xpath.evaluate(path, node).asNodeSet();
} // selectNodes
Arabica::DOM::Node<std::string> selectNode(const std::string& path, const Arabica::DOM::Node<std::string>& node)
{
return selectNodes(path, node)[0];
} // selectNode
std::string selectString(const std::string& path, const Arabica::DOM::Node<std::string>& node)
{
Arabica::XPath::XPath<std::string> xpath;
return xpath.evaluate_expr(path, node).asString();
} // selectString
std::string make_path(const std::string& path, const std::string& filename)
{
return PATH_PREFIX + path + SEPERATOR + filename;
} // make_path
class SkipTest : public TestCase
{
public:
SkipTest(const std::string& name,
const std::string& reason) :
TestCase(name),
reason_(reason)
{
} // SkipTest
protected:
virtual void runTest()
{
throw SkipException(reason_);
} // runTest
private:
std::string reason_;
}; // class SkipTest
class CompileFailsTest : public TestCase
{
public:
CompileFailsTest(const std::string& name,
const std::string& input_xslt,
const std::string& reason) :
TestCase(name),
input_xslt_(input_xslt),
reason_(reason)
{
} // CompileFailsTest
protected:
virtual void runTest()
{
Arabica::XSLT::StylesheetCompiler compiler;
Arabica::SAX::InputSource<std::string> source(input_xslt_);
std::auto_ptr<Arabica::XSLT::Stylesheet> stylesheet = compiler.compile(source);
if(stylesheet.get() != 0)
assertImplementation(false, "Expected " + input_xslt_ + " not to compile. But it did :o");
throw SkipException(reason_ + " : " + compiler.error());
} // runTest
private:
std::string input_xslt_;
std::string reason_;
}; // CompileFailsTest
class RunFailsTest : public TestCase
{
public:
RunFailsTest(const std::string& name,
const std::string& input_xml,
const std::string& input_xslt,
const std::string& reason) :
TestCase(name),
input_xml_(input_xml),
input_xslt_(input_xslt),
reason_(reason)
{
} // RunFailsTest
protected:
virtual void runTest()
{
Arabica::XSLT::StylesheetCompiler compiler;
Arabica::SAX::InputSource<std::string> source(input_xslt_);
std::auto_ptr<Arabica::XSLT::Stylesheet> stylesheet = compiler.compile(source);
if(stylesheet.get() == 0)
assertImplementation(false, "Failed to compile " + input_xslt_ + " : " + compiler.error());
Arabica::XSLT::DOMSink output;
stylesheet->set_output(output);
std::ostringstream errors;
stylesheet->set_error_output(errors);
Arabica::DOM::Document<std::string> document = buildDOM(input_xml_);
try {
stylesheet->execute(document);
}
catch(const std::exception& e) {
throw SkipException(reason_ + " : " + e.what());
}
assertImplementation(false, "Expected " + input_xslt_ + " to fail to execute. But it did :o");
} // runTest
private:
std::string input_xml_;
std::string input_xslt_;
std::string reason_;
}; // RunFailsTest
class CompareAsTextXSLTTest : public TestCase
{
public:
CompareAsTextXSLTTest(const std::string& name,
const std::string& input_xml,
const std::string& input_xslt,
const std::string& output_xml) :
TestCase(name),
input_xml_(input_xml),
input_xslt_(input_xslt),
output_xml_(output_xml)
{
} // CompareAsTextXSLTTest
protected:
virtual void runTest()
{
Arabica::XSLT::StylesheetCompiler compiler;
Arabica::SAX::InputSource<std::string> source(input_xslt_);
std::auto_ptr<Arabica::XSLT::Stylesheet> stylesheet = compiler.compile(source);
if(stylesheet.get() == 0)
assertImplementation(false, "Failed to compile " + input_xslt_ + " : " + compiler.error());
std::ostringstream xml_output;
Arabica::XSLT::StreamSink output(xml_output);
stylesheet->set_output(output);
std::ostringstream errors;
stylesheet->set_error_output(errors);
Arabica::DOM::Document<std::string> document = buildDOM(input_xml_);
try {
stylesheet->execute(document);
}
catch(const std::exception& e) {
assertImplementation(false, "Failed to run " + input_xslt_ + " : " + e.what());
} // catch
std::string ref = readFile(output_xml_);
std::string out = xml_output.str();
if(ref == out)
return;
std::string refs = trimXMLDecl(ref);
std::string outs = trimXMLDecl(out);
if(refs == outs)
return;
refs = stripWhitespace(refs);
outs = stripWhitespace(outs);
if(refs == outs)
return;
assertImplementation(false, "Expected text:\n" + ref + "\nbut got:\n" + out + "\n" + refs + "\nbut got:" + outs + "\n=====");
} // runTest
private:
std::string stripWhitespace(const std::string& str)
{
std::string s = Arabica::text::normalize_whitespace<std::string, Arabica::default_string_adaptor<std::string> >(str);
std::string::size_type i = s.find("> ");
while(i != std::string::npos)
{
s.erase(i+1, 1);
i = s.find("> ");
} // while ..
i = s.find(" <");
while(i != std::string::npos)
{
s.erase(i, 1);
i = s.find(" <");
} // while ..
return s;
} // stripWhitespace
std::string trimXMLDecl(const std::string& str)
{
if(str.find("<?") != 0)
return str;
return str.substr(str.find("?>") + 2);
} // trimXMLDecl
std::string input_xml_;
std::string input_xslt_;
std::string output_xml_;
}; // class CompareAsTextXSLTTest
class StandardXSLTTest : public TestCase
{
public:
StandardXSLTTest(const std::string& name,
const std::string& input_xml,
const std::string& input_xslt,
const std::string& output_xml) :
TestCase(name),
input_xml_(input_xml),
input_xslt_(input_xslt),
output_xml_(output_xml)
{
} // StandardXSLTTest
protected:
virtual void runTest()
{
Arabica::XSLT::StylesheetCompiler compiler;
Arabica::SAX::InputSource<std::string> source(input_xslt_);
std::auto_ptr<Arabica::XSLT::Stylesheet> stylesheet = compiler.compile(source);
if(stylesheet.get() == 0)
assertImplementation(false, "Failed to compile " + input_xslt_ + " : " + compiler.error());
Arabica::XSLT::DOMSink output;
stylesheet->set_output(output);
std::ostringstream errors;
stylesheet->set_error_output(errors);
Arabica::DOM::Document<std::string> document = buildDOM(input_xml_);
try {
stylesheet->execute(document);
}
catch(const std::exception& e) {
assertImplementation(false, "Failed to run " + input_xslt_ + " : " + e.what());
}
Arabica::DOM::Document<std::string> ref = buildDOM(output_xml_);
if(ref == 0)
assertImplementation(false, "Couldn't read " + output_xml_ + ". Perhaps it isn't well-formed XML?");
Arabica::DOM::Node<std::string> out = output.node();
out.normalize();
std::string refs = docToString(ref.getFirstChild());
std::string outs = docToString(out.getFirstChild());
if(refs == outs)
return;
stripWhitespace(ref);
stripWhitespace(out);
std::string refs2 = docToString(ref.getFirstChild());
std::string outs2 = docToString(out.getFirstChild());
if(refs2 == outs2)
return;
assertImplementation(false, "Expected:\n" + refs + "\nbut got:\n" + outs);
} // runTest
std::string docToString(Arabica::DOM::Node<std::string> node)
{
std::ostringstream ss;
ss << node;
return Arabica::text::normalize_whitespace<std::string, Arabica::default_string_adaptor<std::string> >(ss.str());
} // docToString
void stripWhitespace(Arabica::DOM::Node<std::string> doc)
{
Arabica::XPath::NodeSet<std::string> textNodes = selectNodes("//text()", doc);
for(int i = 0; i != textNodes.size(); ++i)
{
Arabica::DOM::Node<std::string> t = textNodes[i];
std::string text = t.getNodeValue();
text = Arabica::text::normalize_whitespace<std::string, Arabica::default_string_adaptor<std::string> >(text);
size_t index = text.find_first_of(" ");
while(index != std::string::npos)
{
text.replace(index, 1, "");
index = text.find_first_of(" ");
}
t.setNodeValue(text);
}
} // stripWhitespace
std::string input_xml_;
std::string input_xslt_;
std::string output_xml_;
}; // class StandardXSLTTest
class Expected
{
public:
Expected()
{
Arabica::DOM::Document<std::string> fail_doc = buildDOM(PATH_PREFIX + "arabica-expected-fails.xml");
Arabica::XPath::NodeSet<std::string> failcases = selectNodes("/test-suite/test-case", fail_doc);
for(int i = 0; i != failcases.size(); ++i)
{
std::string name = selectString("@id", failcases[i]);
std::string compiles = selectString("@compiles", failcases[i]);
std::string runs = selectString("@runs", failcases[i]);
std::string skip = selectString("@skip", failcases[i]);
std::string reason = selectString("@reason", failcases[i]);
std::string compare = selectString("@compare", failcases[i]);
if(compiles == "no")
fails[name] = "compile";
else if(runs == "no")
fails[name] = "run";
else if(skip == "yes")
fails[name] = "skip";
else if(compare == "text")
fails[name] = "text";
reasons[name] = reason;
} // for ...
}
std::map<std::string, std::string>& Fails() { return fails; }
std::map<std::string, std::string>& Reasons() { return reasons; }
private:
std::map<std::string, std::string> fails;
std::map<std::string, std::string> reasons;
};
static Expected expected;
TestSuite* XSLTTest_suite(const std::string& path)
{
//#define new ELEPHANTNEW
// using namespace elephant;
// LeakDetector leakDetector;
// MemoryMonitorHolder().Instance().AddObserver(&leakDetector);
//
// poo();
//
// MemoryMonitorHolder().Instance().RemoveObserver(&leakDetector);
// LeakDisplayFunc leakDisplay(std::cout);
// std::for_each(leakDetector.begin(), leakDetector.end(), leakDisplay);
//#undef new
static Arabica::DOM::Document<std::string> catalog = buildDOM(PATH_PREFIX + "catalog.xml");
TestSuite *suiteOfTests = new TestSuite;
Arabica::XPath::NodeSet<std::string> tests =
// selectNodes("/test-suite/test-catalog/test-case[scenario/@operation='standard']", catalog);
// selectNodes("/test-suite/test-catalog/test-case[@id='boolean_boolean86']", catalog);
selectNodes("/test-suite/test-catalog/test-case[scenario/@operation='standard' and file-path='" + path + "']", catalog);
for(int i = 0; i != tests.size(); ++i)
{
std::string name = selectString("@id", tests[i]);
std::string path = selectString("concat(../major-path, '" + SEPERATOR + "', file-path)", tests[i]);
std::string out_path = selectString("concat(../major-path, '" + SEPERATOR + "REF_OUT" + SEPERATOR + "', file-path)", tests[i]);
std::string input_xml = selectString(".//input-file[@role='principal-data']", tests[i]);
std::string input_xslt = selectString(".//input-file[@role='principal-stylesheet']", tests[i]);
std::string output_xml = selectString(".//output-file[@role='principal']", tests[i]);
if(expected.Fails().find(name) == expected.Fails().end())
suiteOfTests->addTest(new StandardXSLTTest(name,
make_path(path, input_xml),
make_path(path, input_xslt),
make_path(out_path, output_xml)));
else if(expected.Fails()[name] == "compile")
suiteOfTests->addTest(new CompileFailsTest(name,
make_path(path, input_xslt),
expected.Reasons()[name]));
else if(expected.Fails()[name] == "run")
suiteOfTests->addTest(new RunFailsTest(name,
make_path(path, input_xml),
make_path(path, input_xslt),
expected.Reasons()[name]));
else if(expected.Fails()[name] == "skip")
suiteOfTests->addTest(new SkipTest(name, expected.Reasons()[name]));
else if(expected.Fails()[name] == "text")
suiteOfTests->addTest(new CompareAsTextXSLTTest(name,
make_path(path, input_xml),
make_path(path, input_xslt),
make_path(out_path, output_xml)));
} // for ...
return suiteOfTests;
} // XSLTTest_suitoo
TestSuite* XSLTTest_suite(const std::string& path);
#endif