summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-01-08 17:43:49 +0100
committerCarl Hetherington <cth@carlh.net>2021-01-08 17:43:49 +0100
commitb555355546af8f9091eaaba46479400b53b10a39 (patch)
tree04b7232e6b8556512752adbd5ab5d50dfdd346ab
parentd39880eef211a296fa8ef4712cdef5945d08527c (diff)
Remove use of xmldiff in tests.
-rwxr-xr-xrun/tests2
-rw-r--r--test/kdm_test.cc13
-rw-r--r--test/test.cc78
-rw-r--r--test/test.h2
4 files changed, 59 insertions, 36 deletions
diff --git a/run/tests b/run/tests
index 9f018b93..98a37823 100755
--- a/run/tests
+++ b/run/tests
@@ -16,7 +16,7 @@ export DYLD_LIBRARY_PATH=/Users/ci/osx-environment/64/lib
export LIBDCP_SHARE_PREFIX=.
# Make sure we have the required tools
-for c in xmlsec1 xmldiff xmllint; do
+for c in xmlsec1 xmllint; do
hash $c 2>/dev/null || { echo >&2 "$c required but not found; aborting"; exit 1; }
done
diff --git a/test/kdm_test.cc b/test/kdm_test.cc
index 21c922a2..2e877312 100644
--- a/test/kdm_test.cc
+++ b/test/kdm_test.cc
@@ -87,15 +87,12 @@ BOOST_AUTO_TEST_CASE (kdm_passthrough_test)
shared_ptr<xmlpp::DomParser> parser (new xmlpp::DomParser ());
parser->parse_memory (kdm.as_xml ());
parser->get_document()->write_to_file_formatted ("build/kdm.xml", "UTF-8");
- int const r = system (
- "xmldiff -c test/data/kdm_TONEPLATES-SMPTE-ENC_.smpte-430-2.ROOT.NOT_FOR_PRODUCTION_20130706_20230702_CAR_OV_t1_8971c838.xml build/kdm.xml"
+ check_xml (
+ dcp::file_to_string("test/data/kdm_TONEPLATES-SMPTE-ENC_.smpte-430-2.ROOT.NOT_FOR_PRODUCTION_20130706_20230702_CAR_OV_t1_8971c838.xml"),
+ dcp::file_to_string("build/kdm.xml"),
+ {},
+ true
);
-
-#ifdef LIBDCP_WINDOWS
- BOOST_CHECK_EQUAL (r, 0);
-#else
- BOOST_CHECK_EQUAL (WEXITSTATUS (r), 0);
-#endif
}
/** Test some of the utility methods of DecryptedKDM */
diff --git a/test/test.cc b/test/test.cc
index 76a6c4c5..cd162d5a 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -105,49 +105,75 @@ check_xml (xmlpp::Element* ref, xmlpp::Element* test, list<string> ignore_tags,
return;
}
- xmlpp::Element::NodeList ref_children = ref->get_children ();
- xmlpp::Element::NodeList test_children = test->get_children ();
- BOOST_REQUIRE_MESSAGE (
- ref_children.size () == test_children.size (),
- "child counts of " << ref->get_name() << " differ; ref has " << ref_children.size() << ", test has " << test_children.size()
- );
+ auto whitespace_content = [](xmlpp::Node* node) {
+ auto content = dynamic_cast<xmlpp::ContentNode*>(node);
+ return content && content->get_content().find_first_not_of(" \t\r\n") == string::npos;
+ };
+
+ auto ref_children = ref->get_children ();
+ auto test_children = test->get_children ();
+
+ auto k = ref_children.begin ();
+ auto l = test_children.begin ();
+ while (k != ref_children.end() && l != test_children.end()) {
+
+ if (dynamic_cast<xmlpp::CommentNode*>(*k)) {
+ ++k;
+ continue;
+ }
- xmlpp::Element::NodeList::iterator k = ref_children.begin ();
- xmlpp::Element::NodeList::iterator l = test_children.begin ();
- while (k != ref_children.end ()) {
+ if (dynamic_cast<xmlpp::CommentNode*>(*l)) {
+ ++l;
+ continue;
+ }
+
+ if (whitespace_content(*k) && ignore_whitespace) {
+ ++k;
+ continue;
+ }
+
+ if (whitespace_content(*l) && ignore_whitespace) {
+ ++l;
+ continue;
+ }
/* XXX: should be doing xmlpp::EntityReference, xmlpp::XIncludeEnd, xmlpp::XIncludeStart */
- xmlpp::Element* ref_el = dynamic_cast<xmlpp::Element*> (*k);
- xmlpp::Element* test_el = dynamic_cast<xmlpp::Element*> (*l);
+ auto ref_el = dynamic_cast<xmlpp::Element*> (*k);
+ auto test_el = dynamic_cast<xmlpp::Element*> (*l);
BOOST_CHECK ((ref_el && test_el) || (!ref_el && !test_el));
if (ref_el && test_el) {
check_xml (ref_el, test_el, ignore_tags, ignore_whitespace);
}
- xmlpp::ContentNode* ref_cn = dynamic_cast<xmlpp::ContentNode*> (*k);
- xmlpp::ContentNode* test_cn = dynamic_cast<xmlpp::ContentNode*> (*l);
+ auto ref_cn = dynamic_cast<xmlpp::ContentNode*> (*k);
+ auto test_cn = dynamic_cast<xmlpp::ContentNode*> (*l);
BOOST_CHECK ((ref_cn && test_cn) || (!ref_cn && !test_cn));
if (ref_cn && test_cn) {
- if (
- !ignore_whitespace ||
- ref_cn->get_content().find_first_not_of(" \t\r\n") != string::npos ||
- test_cn->get_content().find_first_not_of(" \t\r\n") != string::npos) {
-
- BOOST_CHECK_EQUAL (ref_cn->get_content(), test_cn->get_content ());
- }
+ BOOST_CHECK_EQUAL (ref_cn->get_content(), test_cn->get_content());
}
++k;
++l;
}
- xmlpp::Element::AttributeList ref_attributes = ref->get_attributes ();
- xmlpp::Element::AttributeList test_attributes = test->get_attributes ();
+ while (k != ref_children.end() && ignore_whitespace && whitespace_content(*k)) {
+ ++k;
+ }
+
+ while (l != test_children.end() && ignore_whitespace && whitespace_content(*l)) {
+ ++l;
+ }
+
+ BOOST_REQUIRE (k == ref_children.end());
+ BOOST_REQUIRE (l == test_children.end());
+
+ auto ref_attributes = ref->get_attributes ();
+ auto test_attributes = test->get_attributes ();
BOOST_CHECK_EQUAL (ref_attributes.size(), test_attributes.size ());
- xmlpp::Element::AttributeList::const_iterator m = ref_attributes.begin();
- xmlpp::Element::AttributeList::const_iterator n = test_attributes.begin();
+ auto m = ref_attributes.begin();
+ auto n = test_attributes.begin();
while (m != ref_attributes.end ()) {
BOOST_CHECK_EQUAL ((*m)->get_name(), (*n)->get_name());
BOOST_CHECK_EQUAL ((*m)->get_value(), (*n)->get_value());
@@ -158,7 +184,7 @@ check_xml (xmlpp::Element* ref, xmlpp::Element* test, list<string> ignore_tags,
}
void
-check_xml (string ref, string test, list<string> ignore)
+check_xml (string ref, string test, list<string> ignore, bool ignore_whitespace)
{
xmlpp::DomParser* ref_parser = new xmlpp::DomParser ();
ref_parser->parse_memory (ref);
@@ -167,7 +193,7 @@ check_xml (string ref, string test, list<string> ignore)
test_parser->parse_memory (test);
xmlpp::Element* test_root = test_parser->get_document()->get_root_node ();
- check_xml (ref_root, test_root, ignore);
+ check_xml (ref_root, test_root, ignore, ignore_whitespace);
}
void
diff --git a/test/test.h b/test/test.h
index fdc3c4d7..2a064f96 100644
--- a/test/test.h
+++ b/test/test.h
@@ -40,7 +40,7 @@ extern boost::filesystem::path private_test;
extern boost::filesystem::path xsd_test;
extern void check_xml (xmlpp::Element* ref, xmlpp::Element* test, std::list<std::string> ignore_tags, bool ignore_whitespace = false);
-extern void check_xml (std::string ref, std::string test, std::list<std::string> ignore);
+extern void check_xml (std::string ref, std::string test, std::list<std::string> ignore, bool ignore_whitespace = false);
extern void check_file (boost::filesystem::path ref, boost::filesystem::path check);
extern std::shared_ptr<dcp::MonoPictureAsset> simple_picture (boost::filesystem::path path, std::string suffix);
extern std::shared_ptr<dcp::DCP> make_simple (boost::filesystem::path path, int reels = 1);