Do XML comparisons better in tests.
[ardour.git] / libs / ardour / test / automation_list_property_test.cc
1 /*
2     Copyright (C) 2012 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include "pbd/properties.h"
20 #include "pbd/stateful_diff_command.h"
21 #include "ardour/automation_list.h"
22 #include "automation_list_property_test.h"
23 #include "test_util.h"
24
25 CPPUNIT_TEST_SUITE_REGISTRATION (AutomationListPropertyTest);
26
27 using namespace std;
28 using namespace PBD;
29 using namespace ARDOUR;
30
31 void
32 AutomationListPropertyTest::basicTest ()
33 {
34         list<string> ignore_properties;
35         ignore_properties.push_back ("id");
36
37         PropertyDescriptor<boost::shared_ptr<AutomationList> > descriptor;
38         descriptor.property_id = g_quark_from_static_string ("FadeIn");
39         AutomationListProperty property (
40                 descriptor,
41                 boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (FadeInAutomation)))
42                 );
43
44         property.clear_changes ();
45
46         /* No change since we just cleared them */
47         CPPUNIT_ASSERT_EQUAL (false, property.changed());
48         
49         property->add (1, 2);
50         property->add (3, 4);
51
52         /* Now it has changed */
53         CPPUNIT_ASSERT_EQUAL (true, property.changed());
54
55         XMLNode* foo = new XMLNode ("test");
56         property.get_changes_as_xml (foo);
57         check_xml (foo, "../libs/ardour/test/data/automation_list_property_test1.ref", ignore_properties);
58
59         /* Do some more */
60         property.clear_changes ();
61         CPPUNIT_ASSERT_EQUAL (false, property.changed());
62         property->add (5, 6);
63         property->add (7, 8);
64         CPPUNIT_ASSERT_EQUAL (true, property.changed());
65         foo = new XMLNode ("test");
66         property.get_changes_as_xml (foo);
67         check_xml (foo, "../libs/ardour/test/data/automation_list_property_test2.ref", ignore_properties);
68 }
69
70 /** Here's a StatefulDestructible class that has a AutomationListProperty */
71 class Fred : public StatefulDestructible
72 {
73 public:
74         Fred ()
75                 : _jim (_descriptor, boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (FadeInAutomation))))
76
77         {
78                 add_property (_jim);
79         }
80
81         XMLNode & get_state () {
82                 XMLNode* n = new XMLNode ("State");
83                 add_properties (*n);
84                 return *n;
85         }
86
87         int set_state (XMLNode const & node, int) {
88                 set_values (node);
89                 return 0;
90         }
91
92         static void make_property_quarks () {
93                 _descriptor.property_id = g_quark_from_static_string ("FadeIn");
94         }
95
96         AutomationListProperty _jim;
97         static PropertyDescriptor<boost::shared_ptr<AutomationList> > _descriptor;
98 };
99
100 PropertyDescriptor<boost::shared_ptr<AutomationList> > Fred::_descriptor;
101
102 void
103 AutomationListPropertyTest::undoTest ()
104 {
105         list<string> ignore_properties;
106         ignore_properties.push_back ("id");
107
108         Fred::make_property_quarks ();
109
110         boost::shared_ptr<Fred> sheila (new Fred);
111
112         /* Add some data */
113         sheila->_jim->add (1, 2);
114         sheila->_jim->add (3, 4);
115
116         /* Do a `command' */
117         sheila->clear_changes ();
118         sheila->_jim->add (5, 6);
119         sheila->_jim->add (7, 8);
120         StatefulDiffCommand sdc (sheila);
121
122         /* Undo */
123         sdc.undo ();
124         check_xml (&sheila->get_state(), "../libs/ardour/test/data/automation_list_property_test3.ref", ignore_properties);
125
126         /* Redo */
127         sdc.redo ();
128         check_xml (&sheila->get_state(), "../libs/ardour/test/data/automation_list_property_test4.ref", ignore_properties);
129 }