Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for libxml2 2.12 #1237

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .codespellexclude
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
if (index < pFunc()->mErrors.size()) {
issue = pFunc()->mIssues.at(pFunc()->mErrors.at(index));
return pFunc()->mErrors.size();
identity and expression, level of experience, education, socio-economic status,
"W3C MathML DTD error: Element apply content does not follow the DTD, expecting (csymbol | ci | cn | apply | reln | lambda | condition | declare | sep | semantics | annotation | annotation-xml | integers | reals | rationals | naturalnumbers | complexes | primes | exponentiale | imaginaryi | notanumber | true | false | emptyset | pi | eulergamma | infinity | interval | list | matrix | matrixrow | set | vector | piecewise | lowlimit | uplimit | bvar | degree | logbase | momentabout | domainofapplication | inverse | ident | domain | codomain | image | abs | conjugate | exp | factorial | arg | real | imaginary | floor | ceiling | not | ln | sin | cos | tan | sec | csc | cot | sinh | cosh | tanh | sech | csch | coth | arcsin | arccos | arctan | arccosh | arccot | arccoth | arccsc | arccsch | arcsec | arcsech | arcsinh | arctanh | determinant | transpose | card | quotient | divide | power | rem | implies | vectorproduct | scalarproduct | outerproduct | setdiff | fn | compose | plus | times | max | min | gcd | lcm | and | or | xor | union | intersect | cartesianproduct | mean | sdev | variance | median | mode | selector | root | minus | log | int | diff | partialdiff | divergence | grad | curl | laplacian | sum | product | limit | moment | exists | forall | neq | factorof | in | notin | notsubset | notprsubset | tendsto | eq | leq | lt | geq | gt | equivalent | approx | subset | prsubset | mi | mn | mo | mtext | ms | mspace | mrow | mfrac | msqrt | mroot | menclose | mstyle | merror | mpadded | mphantom | mfenced | msub | msup | msubsup | munder | mover | munderover | mmultiscripts | mtable | mtr | mlabeledtr | mtd | maligngroup | malignmark | maction)*, got (CDATA bvar ).",
2 changes: 0 additions & 2 deletions src/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ std::string Printer::PrinterImpl::printMath(const std::string &math)
static const std::regex xmlDeclaration(R"|(<\?xml[[:space:]]+version=.*\?>)|");

XmlDocPtr xmlDoc = std::make_shared<XmlDoc>();
xmlKeepBlanksDefault(0);
// Remove any XML declarations from the string.
std::string normalisedMath = std::regex_replace(math, xmlDeclaration, "");
xmlDoc->parse("<" + wrapElementName + ">" + normalisedMath + "</" + wrapElementName + ">");
Expand Down Expand Up @@ -592,7 +591,6 @@ std::string Printer::printModel(const ModelPtr &model, bool autoIds)
// See http://www.xmlsoft.org/html/libxml-tree.html#xmlDocDumpFormatMemoryEnc
// for details.
XmlDocPtr xmlDoc = std::make_shared<XmlDoc>();
xmlKeepBlanksDefault(0);
xmlDoc->parse(repr);
return xmlDoc->prettyPrint();
}
Expand Down
10 changes: 7 additions & 3 deletions src/xmldoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ namespace libcellml {
*
* @param error The @c xmlErrorPtr to the error raised by libxml.
*/
void structuredErrorCallback(void *userData, xmlErrorPtr error)
#if LIBXML_VERSION >= 21200
# define XmlErrorPtr const xmlError *
#else
# define XmlErrorPtr xmlErrorPtr
#endif

void structuredErrorCallback(void *userData, XmlErrorPtr error)
{
static const std::regex newLineRegex("\\n");
// Swap libxml2 carriage return for a period.
Expand Down Expand Up @@ -89,7 +95,6 @@ void XmlDoc::parse(const std::string &input)
xmlFreeParserCtxt(context);
xmlSetStructuredErrorFunc(nullptr, nullptr);
xmlCleanupParser();
xmlCleanupGlobals();
}

std::string decompressMathMLDTD()
Expand Down Expand Up @@ -129,7 +134,6 @@ void XmlDoc::parseMathML(const std::string &input)
xmlFreeParserCtxt(context);
xmlSetStructuredErrorFunc(nullptr, nullptr);
xmlCleanupParser();
xmlCleanupGlobals();
}

std::string XmlDoc::prettyPrint() const
Expand Down
1 change: 0 additions & 1 deletion src/xmlnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ XmlNodePtr XmlNode::parent() const

std::string XmlNode::convertToString() const
{
xmlKeepBlanksDefault(1);
xmlBufferPtr buffer = xmlBufferCreate();
xmlNodeDump(buffer, mPimpl->mXmlNodePtr->doc, mPimpl->mXmlNodePtr, 0, 0);
std::string contentString = std::string(reinterpret_cast<const char *>(buffer->content));
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ set(TEST_UTILS_HDR ${CMAKE_CURRENT_SOURCE_DIR}/test_utils.h)

if(NOT DEFINED LIBXML2_VERSION_STRING)
set(LIBXML2_VERSION_STRING "2.9.10")
elseif(LIBXML2_VERSION_STRING VERSION_GREATER_EQUAL "2.12")
set(LIBXML2_VERSION_STRING "2.12")
elseif(LIBXML2_VERSION_STRING VERSION_GREATER_EQUAL "2.9.13")
set(LIBXML2_VERSION_STRING "2.9.13")
elseif(LIBXML2_VERSION_STRING VERSION_GREATER_EQUAL "2.9.11")
Expand Down
12 changes: 12 additions & 0 deletions tests/libxml2issues.2.12.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "string"
#include "vector"

// Version 2.12(.7) of LibXml2 reports the following errors,
// used on Windows CI machines.
const std::vector<std::string> expectedLibXml2Issues = {
"LibXml2 error: Opening and ending tag mismatch: ci line 6 and apply.",
"LibXml2 error: Opening and ending tag mismatch: ci line 6 and math.",
"LibXml2 error: Opening and ending tag mismatch: apply line 3 and math_wrap_as_single_root_element.",
};
10 changes: 7 additions & 3 deletions tests/parser/libxml_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ limitations under the License.

#include <libxml/parser.h>

void structuredErrorCallback(void *userData, xmlErrorPtr error)
#if LIBXML_VERSION >= 21200
# define XmlErrorPtr const xmlError *
#else
# define XmlErrorPtr xmlErrorPtr
#endif

void structuredErrorCallback(void *userData, XmlErrorPtr error)
{
if (userData != nullptr && error != nullptr) {
// Suppress any error messages raised from using LibXml2.
Expand Down Expand Up @@ -54,7 +60,6 @@ TEST(Parser, parseValidXmlDirectlyUsingLibxml)
xmlFreeDoc(doc);
xmlSetStructuredErrorFunc(nullptr, nullptr);
xmlCleanupParser();
xmlCleanupGlobals();
}

TEST(Parser, parseInvalidXmlDirectlyUsingLibxml)
Expand All @@ -76,7 +81,6 @@ TEST(Parser, parseInvalidXmlDirectlyUsingLibxml)
xmlFreeParserCtxt(context);
xmlSetStructuredErrorFunc(nullptr, nullptr);
xmlCleanupParser();
xmlCleanupGlobals();

EXPECT_EQ(nullptr, doc);
}
28 changes: 22 additions & 6 deletions tests/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,27 @@ TEST(Parser, invalidXMLElements)
"LibXml2 error: EndTag: '</' not found.",
"Could not get a valid XML root node from the provided input.",
};
const std::vector<std::string> expectedIssues_2_12 = {
"LibXml2 error: Specification mandates value for attribute bearded.",
"LibXml2 error: Opening and ending tag mismatch: Dwarf line 3 and ShortGuy.",
"LibXml2 error: Opening and ending tag mismatch: Hobbit line 4 and EvenShorterGuy.",
"LibXml2 error: Opening and ending tag mismatch: Wizard line 5 and SomeGuyWithAStaff.",
"LibXml2 error: Opening and ending tag mismatch: Elf line 6 and fellows.",
"Could not get a valid XML root node from the provided input.",
};

libcellml::ParserPtr p = libcellml::Parser::create();
p->parseModel(in);

EXPECT_EQ(expectedIssues_2_2.size(), p->issueCount());
EXPECT_TRUE((expectedIssues_2_2.size() == p->issueCount())
|| (expectedIssues_2_9_10.size() == p->issueCount())
|| (expectedIssues_2_12.size() == p->issueCount()));

for (size_t i = 0; i < p->issueCount(); ++i) {
auto message = p->issue(i)->description();
EXPECT_TRUE((expectedIssues_2_2.at(i) == message) || (expectedIssues_2_9_10.at(i) == message));
EXPECT_TRUE((expectedIssues_2_2.at(i) == message)
|| (expectedIssues_2_9_10.at(i) == message)
|| (expectedIssues_2_12.at(i) == message));
}
}

Expand Down Expand Up @@ -1861,13 +1873,17 @@ TEST(Parser, parseResets)
EXPECT_EQ("variable2", v2->name());

std::string testValueString = r->testValue();
std::string t =
"<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><apply/></math>\n";
const std::string t =
"<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
" <apply/>\n"
" </math>\n";
EXPECT_EQ(t, testValueString);

std::string resetValueString = r->resetValue();
std::string rt =
"<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><apply/></math>\n";
const std::string rt =
"<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
" <apply/>\n"
" </math>\n";
EXPECT_EQ(rt, resetValueString);
}

Expand Down