summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2016-09-26 12:16:01 +1000
committerTim Mayberry <mojofunk@gmail.com>2016-10-10 08:45:34 +1000
commit4b2987d0f2937c1d7c2e63ad573b7e8d4abf6614 (patch)
treec47b2fc5b32819e48179b92030811a12a1e82885 /libs/pbd
parent734a4c10e4460d6eff4c4f9037298084823ac593 (diff)
Add XMLNode::operator==/!=() for comparing XMLNode instances
Implemented to be able to test that when writing an XML document via XMLTree and then reading back into another XMLTree the structure is equivalent as a general API test of pbd/xml++.h to check for breakage when changing implementation.
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/pbd/xml++.h3
-rw-r--r--libs/pbd/xml++.cc64
2 files changed, 67 insertions, 0 deletions
diff --git a/libs/pbd/pbd/xml++.h b/libs/pbd/pbd/xml++.h
index f0956edd25..fa55f11c35 100644
--- a/libs/pbd/pbd/xml++.h
+++ b/libs/pbd/pbd/xml++.h
@@ -101,6 +101,9 @@ public:
XMLNode& operator= (const XMLNode& other);
+ bool operator== (const XMLNode& other) const;
+ bool operator!= (const XMLNode& other) const;
+
const std::string& name() const { return _name; }
bool is_content() const { return _is_content; }
diff --git a/libs/pbd/xml++.cc b/libs/pbd/xml++.cc
index 80fc88242d..b12eb69252 100644
--- a/libs/pbd/xml++.cc
+++ b/libs/pbd/xml++.cc
@@ -289,6 +289,70 @@ XMLNode::operator= (const XMLNode& from)
return *this;
}
+bool
+XMLNode::operator== (const XMLNode& other) const
+{
+ if (is_content () != other.is_content ()) {
+ return false;
+ }
+
+ if (is_content ()) {
+ if (content () != other.content ()) {
+ return false;
+ }
+ } else {
+ if (name () != other.name ()) {
+ return false;
+ }
+ }
+
+ XMLPropertyList const& other_properties = other.properties ();
+
+ if (_proplist.size () != other_properties.size ()) {
+ return false;
+ }
+
+ XMLPropertyConstIterator our_prop_iter = _proplist.begin();
+ XMLPropertyConstIterator other_prop_iter = other_properties.begin();
+
+ while (our_prop_iter != _proplist.end ()) {
+ XMLProperty const* our_prop = *our_prop_iter;
+ XMLProperty const* other_prop = *other_prop_iter;
+ if (our_prop->name () != other_prop->name () || our_prop->value () != other_prop->value ()) {
+ return false;
+ }
+ ++our_prop_iter;
+ ++other_prop_iter;
+ }
+
+ XMLNodeList const& other_children = other.children();
+
+ if (_children.size() != other_children.size()) {
+ return false;
+ }
+
+ XMLNodeConstIterator our_child_iter = _children.begin ();
+ XMLNodeConstIterator other_child_iter = other_children.begin ();
+
+ while (our_child_iter != _children.end()) {
+ XMLNode const* our_child = *our_child_iter;
+ XMLNode const* other_child = *other_child_iter;
+
+ if (*our_child != *other_child) {
+ return false;
+ }
+ ++our_child_iter;
+ ++other_child_iter;
+ }
+ return true;
+}
+
+bool
+XMLNode::operator!= (const XMLNode& other) const
+{
+ return !(*this == other);
+}
+
const string&
XMLNode::set_content(const string& c)
{