Do XML comparisons better in tests.
authorCarl Hetherington <carl@carlh.net>
Mon, 18 Jun 2012 15:19:12 +0000 (15:19 +0000)
committerCarl Hetherington <carl@carlh.net>
Mon, 18 Jun 2012 15:19:12 +0000 (15:19 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12752 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/test/automation_list_property_test.cc
libs/ardour/test/data/automation_list_property_test1.ref
libs/ardour/test/data/automation_list_property_test2.ref
libs/ardour/test/data/automation_list_property_test3.ref
libs/ardour/test/data/automation_list_property_test4.ref
libs/ardour/test/test_util.cc
libs/ardour/test/test_util.h

index 9d1f448ad5f1dc8c436f23684e95ffdab905c965..90e2e229899a8a1be64e757a3fa518a72e6e6016 100644 (file)
@@ -31,6 +31,9 @@ using namespace ARDOUR;
 void
 AutomationListPropertyTest::basicTest ()
 {
+       list<string> ignore_properties;
+       ignore_properties.push_back ("id");
+
        PropertyDescriptor<boost::shared_ptr<AutomationList> > 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<boost::shared_ptr<AutomationList> > Fred::_descriptor;
 void
 AutomationListPropertyTest::undoTest ()
 {
+       list<string> ignore_properties;
+       ignore_properties.push_back ("id");
+
        Fred::make_property_quarks ();
 
        boost::shared_ptr<Fred> 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);
 }
index b7c11f153aea4dc120f3fbac1dbdd2885c3917e9..36e8389bf5e6404b5f638a4d45bafe3ca8ef5dbc 100644 (file)
@@ -1,16 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <test>
   <FadeIn>
     <from>
-      <AutomationList automation-id="fadein" id="162" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute">
-      </AutomationList>
+      <AutomationList automation-id="fadein" id="164" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute"/>
     </from>
     <to>
-      <AutomationList automation-id="fadein" id="162" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute">
-        <events>
-            1 2
+      <AutomationList automation-id="fadein" id="163" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute">
+        <events>1 2
 3 4
-
-        </events>
+</events>
       </AutomationList>
     </to>
   </FadeIn>
index 17df0e4f54c7bb7fbc2d1f7a02ca50a1bee4c08d..cacfe510aa3b875a92939c51b5dd1a9219949048 100644 (file)
@@ -1,23 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <test>
   <FadeIn>
     <from>
-      <AutomationList automation-id="fadein" id="162" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute">
-        <events>
-            1 2
+      <AutomationList automation-id="fadein" id="165" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute">
+        <events>1 2
 3 4
-
-        </events>
+</events>
       </AutomationList>
     </from>
     <to>
-      <AutomationList automation-id="fadein" id="162" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute">
-        <events>
-            1 2
+      <AutomationList automation-id="fadein" id="163" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute">
+        <events>1 2
 3 4
 5 6
 7 8
-
-        </events>
+</events>
       </AutomationList>
     </to>
   </FadeIn>
index edc1469d109a7bc7b2a751eb1704bd29b5c41838..e5e6117d69b533927e3587155b0b002b348c953a 100644 (file)
@@ -1,11 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <State>
   <FadeIn>
-    <AutomationList automation-id="fadein" id="166" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute">
-      <events>
-          1 2
+    <AutomationList automation-id="fadein" id="167" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute">
+      <events>1 2
 3 4
-
-      </events>
+</events>
     </AutomationList>
   </FadeIn>
 </State>
index 5a6024a42974b54e78a3fc9449fe68e59e09c2ff..573e16d29120be3f3ea9716c822b65897b3d60b6 100644 (file)
@@ -1,13 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <State>
   <FadeIn>
-    <AutomationList automation-id="fadein" id="166" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute">
-      <events>
-          1 2
+    <AutomationList automation-id="fadein" id="167" default="0" min-yval="0" max-yval="2" interpolation-style="Linear" state="Off" style="Absolute">
+      <events>1 2
 3 4
 5 6
 7 8
-
-      </events>
+</events>
     </AutomationList>
   </FadeIn>
 </State>
index 35b9e588f985da22a9143ee1becf0627fb258b38..f08b6759e71020630ae48eef0633423381ccc95e 100644 (file)
@@ -10,17 +10,62 @@ using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
+static void
+check_nodes (XMLNode const * p, XMLNode const * q, list<string> const & ignore_properties)
+{
+       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());
+       }
+
+       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<string> const & ignore_properties)
+{
+       XMLTree ref (ref_file);
+
+       XMLNode* p = node;
+       XMLNode* q = ref.root ();
+
+       check_nodes (p, q, ignore_properties);
+}
+
 void
-check_xml (XMLNode* node, string ref_file)
+write_ref (XMLNode* node, string ref_file)
 {
-       system ("rm -f libs/ardour/test/test.xml");
-       ofstream f ("libs/ardour/test/test.xml");
-       node->dump (f);
-       f.close ();
-
-       stringstream cmd;
-       cmd << "diff -u libs/ardour/test/test.xml " << ref_file;
-       CPPUNIT_ASSERT_EQUAL (0, system (cmd.str().c_str ()));
+       XMLTree ref;
+       ref.set_root (node);
+       ref.write (ref_file);
 }
 
 class TestReceiver : public Receiver 
index 436580d6cbfae4b559b0e8231e39f6e3677df405..fea74a2ea870b36c937a30c401855a788446850e 100644 (file)
@@ -1,4 +1,5 @@
 #include <string>
+#include <list>
 
 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<std::string> const &);
+extern void write_ref (XMLNode *, std::string);
 extern ARDOUR::Session* load_session (std::string, std::string);