2014-04-12 01:23:20 +00:00
|
|
|
#ifndef MPD_TEST_XML_COMPARE_H_
|
|
|
|
#define MPD_TEST_XML_COMPARE_H_
|
|
|
|
|
2017-12-14 06:33:47 +00:00
|
|
|
#include <gmock/gmock.h>
|
2014-08-28 18:35:15 +00:00
|
|
|
#include <libxml/tree.h>
|
2014-04-12 01:23:20 +00:00
|
|
|
|
2014-08-28 18:35:15 +00:00
|
|
|
#include <string>
|
2014-04-12 01:23:20 +00:00
|
|
|
|
2017-12-14 06:33:47 +00:00
|
|
|
#include "packager/mpd/base/xml/scoped_xml_ptr.h"
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-04-12 01:23:20 +00:00
|
|
|
|
|
|
|
/// Checks whether the XMLs are equivalent. An XML schema can specify strict
|
|
|
|
/// ordering of children and MPD does. These functions are currently tuned to
|
|
|
|
/// compare subsets of MPD. Therefore this function requires strict ordering of
|
|
|
|
/// the child elements of an element. Attributes can be in any order since XML
|
|
|
|
/// cannot enforce ordering of attributes.
|
|
|
|
/// @param xml1 is compared against @a xml2.
|
|
|
|
/// @param xml2 is compared against @a xml1.
|
|
|
|
/// @return true if @a xml1 and @a xml2 are equivalent, false otherwise.
|
|
|
|
bool XmlEqual(const std::string& xml1, const std::string& xml2);
|
|
|
|
bool XmlEqual(const std::string& xml1, xmlDocPtr xml2);
|
|
|
|
bool XmlEqual(xmlDocPtr xml1, xmlDocPtr xml2);
|
2017-12-14 06:33:47 +00:00
|
|
|
bool XmlEqual(const std::string& xml1, xmlNodePtr xml2);
|
|
|
|
|
|
|
|
/// Get string representation of the xml node.
|
|
|
|
/// Note that the ownership is not transferred.
|
|
|
|
std::string XmlNodeToString(xmlNodePtr xml_node);
|
|
|
|
|
|
|
|
/// Match an xmlNodePtr with an xml in string representation.
|
|
|
|
MATCHER_P(XmlNodeEqual, xml, "") {
|
|
|
|
*result_listener << "\n" << XmlNodeToString(arg);
|
|
|
|
return XmlEqual(xml, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Match the attribute of an xmlNodePtr with expected value.
|
|
|
|
/// Note that the ownership is not transferred.
|
|
|
|
MATCHER_P2(AttributeEqual, attribute, expected_value, "") {
|
|
|
|
xml::scoped_xml_ptr<xmlChar> attribute_xml_str(
|
|
|
|
xmlGetProp(arg, BAD_CAST attribute));
|
|
|
|
if (!attribute_xml_str) {
|
|
|
|
*result_listener << "no attribute '" << attribute << "'";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::string actual_value =
|
|
|
|
reinterpret_cast<const char*>(attribute_xml_str.get());
|
|
|
|
*result_listener << actual_value;
|
|
|
|
return expected_value == actual_value;
|
|
|
|
}
|
2014-04-12 01:23:20 +00:00
|
|
|
|
2017-12-14 06:33:47 +00:00
|
|
|
/// Check if the attribute is set in an xmlNodePtr.
|
|
|
|
/// Note that the ownership is not transferred.
|
|
|
|
MATCHER_P(AttributeSet, attribute, "") {
|
|
|
|
xml::scoped_xml_ptr<xmlChar> attribute_xml_str(
|
|
|
|
xmlGetProp(arg, BAD_CAST attribute));
|
|
|
|
return attribute_xml_str != nullptr;
|
|
|
|
}
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2014-04-12 01:23:20 +00:00
|
|
|
|
|
|
|
#endif // MPD_TEST_XML_COMPARE_H_
|