2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2023 Google LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2014-04-12 01:23:20 +00:00
|
|
|
#ifndef MPD_TEST_XML_COMPARE_H_
|
|
|
|
#define MPD_TEST_XML_COMPARE_H_
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
|
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
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/mpd/base/xml/scoped_xml_ptr.h>
|
|
|
|
#include <packager/mpd/base/xml/xml_node.h>
|
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-12-01 17:32:19 +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-12-01 17:32:19 +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_
|