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
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/mpd/base/xml/scoped_xml_ptr.h>
|
|
|
|
#include <packager/mpd/base/xml/xml_node.h>
|
2023-08-05 03:45:21 +00:00
|
|
|
#include <optional>
|
2017-12-14 06:33:47 +00:00
|
|
|
|
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);
|
2020-11-10 00:32:58 +00:00
|
|
|
bool XmlEqual(const std::string& xml1, const xml::XmlNode& xml2);
|
2023-08-05 03:45:21 +00:00
|
|
|
bool XmlEqual(const std::string& xml1, const std::optional<xml::XmlNode>& xml2);
|
2017-12-14 06:33:47 +00:00
|
|
|
|
|
|
|
/// Get string representation of the xml node.
|
2020-11-10 00:32:58 +00:00
|
|
|
std::string XmlNodeToString(const xml::XmlNode& xml_node);
|
2023-08-05 03:45:21 +00:00
|
|
|
std::string XmlNodeToString(const std::optional<xml::XmlNode>& xml_node);
|
2017-12-14 06:33:47 +00:00
|
|
|
|
|
|
|
/// Match an xmlNodePtr with an xml in string representation.
|
2018-01-03 00:10:54 +00:00
|
|
|
MATCHER_P(XmlNodeEqual,
|
|
|
|
xml,
|
|
|
|
std::string("xml node equal (ignore extra white spaces)\n") + xml) {
|
2017-12-14 06:33:47 +00:00
|
|
|
*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, "") {
|
2020-11-10 00:32:58 +00:00
|
|
|
if (!arg) {
|
|
|
|
*result_listener << "returned error";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string actual_value;
|
|
|
|
if (!arg->GetAttribute(attribute, &actual_value)) {
|
2017-12-14 06:33:47 +00:00
|
|
|
*result_listener << "no attribute '" << attribute << "'";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*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, "") {
|
2020-11-10 00:32:58 +00:00
|
|
|
if (!arg) {
|
|
|
|
*result_listener << "returned error";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::string unused;
|
|
|
|
return arg->GetAttribute(attribute, &unused);
|
2017-12-14 06:33:47 +00:00
|
|
|
}
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2014-04-12 01:23:20 +00:00
|
|
|
|
|
|
|
#endif // MPD_TEST_XML_COMPARE_H_
|