From 20ceeb6d3ea5ed9caa78aaaa6fc88f5219e3886c Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 18 Jun 2012 15:19:12 +0000 Subject: [PATCH] Do XML comparisons better in tests. git-svn-id: svn://localhost/ardour2/branches/3.0@12752 d708f5d6-7413-0410-9779-e7cbd77b26cf --- .../test/automation_list_property_test.cc | 14 +++-- .../data/automation_list_property_test1.ref | 12 ++-- .../data/automation_list_property_test2.ref | 17 +++-- .../data/automation_list_property_test3.ref | 9 ++- .../data/automation_list_property_test4.ref | 9 ++- libs/ardour/test/test_util.cc | 63 ++++++++++++++++--- libs/ardour/test/test_util.h | 4 +- 7 files changed, 87 insertions(+), 41 deletions(-) diff --git a/libs/ardour/test/automation_list_property_test.cc b/libs/ardour/test/automation_list_property_test.cc index 9d1f448ad5..90e2e22989 100644 --- a/libs/ardour/test/automation_list_property_test.cc +++ b/libs/ardour/test/automation_list_property_test.cc @@ -31,6 +31,9 @@ using namespace ARDOUR; void AutomationListPropertyTest::basicTest () { + list ignore_properties; + ignore_properties.push_back ("id"); + PropertyDescriptor > descriptor; descriptor.property_id = g_quark_from_static_string ("FadeIn"); AutomationListProperty property ( @@ -51,7 +54,7 @@ AutomationListPropertyTest::basicTest () XMLNode* foo = new XMLNode ("test"); property.get_changes_as_xml (foo); - check_xml (foo, "../libs/ardour/test/data/automation_list_property_test1.ref"); + check_xml (foo, "../libs/ardour/test/data/automation_list_property_test1.ref", ignore_properties); /* Do some more */ property.clear_changes (); @@ -61,7 +64,7 @@ AutomationListPropertyTest::basicTest () CPPUNIT_ASSERT_EQUAL (true, property.changed()); foo = new XMLNode ("test"); property.get_changes_as_xml (foo); - check_xml (foo, "../libs/ardour/test/data/automation_list_property_test2.ref"); + check_xml (foo, "../libs/ardour/test/data/automation_list_property_test2.ref", ignore_properties); } /** Here's a StatefulDestructible class that has a AutomationListProperty */ @@ -99,6 +102,9 @@ PropertyDescriptor > Fred::_descriptor; void AutomationListPropertyTest::undoTest () { + list ignore_properties; + ignore_properties.push_back ("id"); + Fred::make_property_quarks (); boost::shared_ptr sheila (new Fred); @@ -115,9 +121,9 @@ AutomationListPropertyTest::undoTest () /* Undo */ sdc.undo (); - check_xml (&sheila->get_state(), "../libs/ardour/test/data/automation_list_property_test3.ref"); + check_xml (&sheila->get_state(), "../libs/ardour/test/data/automation_list_property_test3.ref", ignore_properties); /* Redo */ sdc.redo (); - check_xml (&sheila->get_state(), "../libs/ardour/test/data/automation_list_property_test4.ref"); + check_xml (&sheila->get_state(), "../libs/ardour/test/data/automation_list_property_test4.ref", ignore_properties); } diff --git a/libs/ardour/test/data/automation_list_property_test1.ref b/libs/ardour/test/data/automation_list_property_test1.ref index b7c11f153a..36e8389bf5 100644 --- a/libs/ardour/test/data/automation_list_property_test1.ref +++ b/libs/ardour/test/data/automation_list_property_test1.ref @@ -1,16 +1,14 @@ + - - + - - - 1 2 + + 1 2 3 4 - - + diff --git a/libs/ardour/test/data/automation_list_property_test2.ref b/libs/ardour/test/data/automation_list_property_test2.ref index 17df0e4f54..cacfe510aa 100644 --- a/libs/ardour/test/data/automation_list_property_test2.ref +++ b/libs/ardour/test/data/automation_list_property_test2.ref @@ -1,23 +1,20 @@ + - - - 1 2 + + 1 2 3 4 - - + - - - 1 2 + + 1 2 3 4 5 6 7 8 - - + diff --git a/libs/ardour/test/data/automation_list_property_test3.ref b/libs/ardour/test/data/automation_list_property_test3.ref index edc1469d10..e5e6117d69 100644 --- a/libs/ardour/test/data/automation_list_property_test3.ref +++ b/libs/ardour/test/data/automation_list_property_test3.ref @@ -1,11 +1,10 @@ + - - - 1 2 + + 1 2 3 4 - - + diff --git a/libs/ardour/test/data/automation_list_property_test4.ref b/libs/ardour/test/data/automation_list_property_test4.ref index 5a6024a429..573e16d291 100644 --- a/libs/ardour/test/data/automation_list_property_test4.ref +++ b/libs/ardour/test/data/automation_list_property_test4.ref @@ -1,13 +1,12 @@ + - - - 1 2 + + 1 2 3 4 5 6 7 8 - - + diff --git a/libs/ardour/test/test_util.cc b/libs/ardour/test/test_util.cc index 35b9e588f9..f08b6759e7 100644 --- a/libs/ardour/test/test_util.cc +++ b/libs/ardour/test/test_util.cc @@ -10,17 +10,62 @@ using namespace std; using namespace ARDOUR; using namespace PBD; -void -check_xml (XMLNode* node, string ref_file) +static void +check_nodes (XMLNode const * p, XMLNode const * q, list const & ignore_properties) { - system ("rm -f libs/ardour/test/test.xml"); - ofstream f ("libs/ardour/test/test.xml"); - node->dump (f); - f.close (); + CPPUNIT_ASSERT_EQUAL (p->is_content(), q->is_content()); + if (!p->is_content()) { + CPPUNIT_ASSERT_EQUAL (p->name(), q->name()); + } else { + CPPUNIT_ASSERT_EQUAL (p->content(), q->content()); + } - stringstream cmd; - cmd << "diff -u libs/ardour/test/test.xml " << ref_file; - CPPUNIT_ASSERT_EQUAL (0, system (cmd.str().c_str ())); + XMLPropertyList const & pp = p->properties (); + XMLPropertyList const & qp = q->properties (); + CPPUNIT_ASSERT_EQUAL (pp.size(), qp.size()); + + XMLPropertyList::const_iterator i = pp.begin (); + XMLPropertyList::const_iterator j = qp.begin (); + while (i != pp.end ()) { + CPPUNIT_ASSERT_EQUAL ((*i)->name(), (*j)->name()); + if (find (ignore_properties.begin(), ignore_properties.end(), (*i)->name ()) == ignore_properties.end ()) { + CPPUNIT_ASSERT_EQUAL ((*i)->value(), (*j)->value()); + } + ++i; + ++j; + } + + XMLNodeList const & pc = p->children (); + XMLNodeList const & qc = q->children (); + + CPPUNIT_ASSERT_EQUAL (pc.size(), qc.size()); + XMLNodeList::const_iterator k = pc.begin (); + XMLNodeList::const_iterator l = qc.begin (); + + while (k != pc.end ()) { + check_nodes (*k, *l, ignore_properties); + ++k; + ++l; + } +} + +void +check_xml (XMLNode* node, string ref_file, list const & ignore_properties) +{ + XMLTree ref (ref_file); + + XMLNode* p = node; + XMLNode* q = ref.root (); + + check_nodes (p, q, ignore_properties); +} + +void +write_ref (XMLNode* node, string ref_file) +{ + XMLTree ref; + ref.set_root (node); + ref.write (ref_file); } class TestReceiver : public Receiver diff --git a/libs/ardour/test/test_util.h b/libs/ardour/test/test_util.h index 436580d6cb..fea74a2ea8 100644 --- a/libs/ardour/test/test_util.h +++ b/libs/ardour/test/test_util.h @@ -1,4 +1,5 @@ #include +#include class XMLNode; @@ -6,5 +7,6 @@ namespace ARDOUR { class Session; } -extern void check_xml (XMLNode *, std::string); +extern void check_xml (XMLNode *, std::string, std::list const &); +extern void write_ref (XMLNode *, std::string); extern ARDOUR::Session* load_session (std::string, std::string);