From 87c6beddfb684cee702ec1c9225497b8541a780d Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 13 Jul 2012 12:29:03 +0200 Subject: test: move XMLDiff implementation details to cxx file This makes it unnecessary to link clients against libxml2. Change-Id: Ifd295623c01bdc6f579afbf81d5b609a2b29f4bf --- test/source/diff/diff.cxx | 84 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) (limited to 'test/source/diff') diff --git a/test/source/diff/diff.cxx b/test/source/diff/diff.cxx index 00e144436e61..048e7835384f 100644 --- a/test/source/diff/diff.cxx +++ b/test/source/diff/diff.cxx @@ -26,10 +26,16 @@ * instead of those above. */ +#define USE_CPPUNIT 1 #include "test/xmldiff.hxx" + #include -#include +#include +#include +#include + +#include #include #include #include @@ -39,6 +45,73 @@ #include #endif +#include + + +struct tolerance +{ + ~tolerance() + { + xmlFree(elementName); + xmlFree(attribName); + } + + tolerance() + { + elementName = NULL; + attribName = NULL; + } + + tolerance(const tolerance& tol) + { + elementName = xmlStrdup(tol.elementName); + attribName = xmlStrdup(tol.attribName); + relative = tol.relative; + value = tol.value; + } + + xmlChar* elementName; + xmlChar* attribName; + bool relative; + double value; + bool operator==(const tolerance& rTol) const { return xmlStrEqual(elementName, rTol.elementName) && xmlStrEqual(attribName, rTol.attribName); } + bool operator<(const tolerance& rTol) const + { + int cmp = xmlStrcmp(elementName, rTol.elementName); + if(cmp == 0) + { + cmp = xmlStrcmp(attribName, rTol.attribName); + } + + if(cmp>=0) + return false; + else + return true; + } +}; + +class XMLDiff +{ +public: + XMLDiff(const char* pFileName, const char* pContent, int size, const char* pToleranceFileName); + ~XMLDiff(); + + bool compare(); +private: + typedef std::set ToleranceContainer; + + void loadToleranceFile(xmlDocPtr xmlTolerance); + bool compareAttributes(xmlNodePtr node1, xmlNodePtr node2); + bool compareElements(xmlNodePtr node1, xmlNodePtr node2); + + ToleranceContainer toleranceContainer; + xmlDocPtr xmlFile1; + xmlDocPtr xmlFile2; +}; + + + + XMLDiff::XMLDiff( const char* pFileName, const char* pContent, int size, const char* pToleranceFile) { xmlFile1 = xmlParseFile(pFileName); @@ -290,4 +363,13 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2) return true; } + +bool +doXMLDiff(char const*const pFileName, char const*const pContent, int const size, + char const*const pToleranceFileName) +{ + XMLDiff aDiff(pFileName, pContent, size, pToleranceFileName); + return aDiff.compare(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit