2 Copyright (C) 2012 Paul Davis
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.
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.
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.
19 #include <glibmm/fileutils.h>
20 #include <glibmm/miscutils.h>
22 #include "pbd/properties.h"
23 #include "pbd/stateful_diff_command.h"
24 #include "ardour/automation_list.h"
25 #include "automation_list_property_test.h"
26 #include "test_util.h"
27 #include "test_common.h"
29 CPPUNIT_TEST_SUITE_REGISTRATION (AutomationListPropertyTest);
33 using namespace ARDOUR;
36 write_automation_list_xml (XMLNode* node, std::string filename)
38 // use the same output dir for all of them
39 static std::string test_output_dir = new_test_output_dir ("automation_list_property");
40 std::string output_file = Glib::build_filename (test_output_dir, filename);
42 CPPUNIT_ASSERT (write_ref (node, output_file));
46 AutomationListPropertyTest::basicTest ()
48 list<string> ignore_properties;
49 ignore_properties.push_back ("id");
51 PropertyDescriptor<boost::shared_ptr<AutomationList> > descriptor;
52 descriptor.property_id = g_quark_from_static_string ("FadeIn");
53 AutomationListProperty property (
55 boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (FadeInAutomation)))
58 property.clear_changes ();
60 /* No change since we just cleared them */
61 CPPUNIT_ASSERT_EQUAL (false, property.changed());
66 /* Now it has changed */
67 CPPUNIT_ASSERT_EQUAL (true, property.changed());
69 std::string test_data_filename = "automation_list_property_test1.ref";
70 std::string test_data_file1 = Glib::build_filename (test_search_path().front(), test_data_filename);
71 CPPUNIT_ASSERT (Glib::file_test (test_data_file1, Glib::FILE_TEST_EXISTS));
73 XMLNode* foo = new XMLNode ("test");
74 property.get_changes_as_xml (foo);
75 write_automation_list_xml (foo, test_data_filename);
76 check_xml (foo, test_data_file1, ignore_properties);
78 test_data_filename = "automation_list_property_test2.ref";
79 std::string test_data_file2 = Glib::build_filename (test_search_path().front(), test_data_filename);
80 CPPUNIT_ASSERT (Glib::file_test (test_data_file2, Glib::FILE_TEST_EXISTS));
83 property.clear_changes ();
84 CPPUNIT_ASSERT_EQUAL (false, property.changed());
87 CPPUNIT_ASSERT_EQUAL (true, property.changed());
88 foo = new XMLNode ("test");
89 property.get_changes_as_xml (foo);
90 write_automation_list_xml (foo, test_data_filename);
91 check_xml (foo, test_data_file2, ignore_properties);
94 /** Here's a StatefulDestructible class that has a AutomationListProperty */
95 class Fred : public StatefulDestructible
99 : _jim (_descriptor, boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (FadeInAutomation))))
105 XMLNode & get_state () {
106 XMLNode* n = new XMLNode ("State");
111 int set_state (XMLNode const & node, int) {
116 static void make_property_quarks () {
117 _descriptor.property_id = g_quark_from_static_string ("FadeIn");
120 AutomationListProperty _jim;
121 static PropertyDescriptor<boost::shared_ptr<AutomationList> > _descriptor;
124 PropertyDescriptor<boost::shared_ptr<AutomationList> > Fred::_descriptor;
127 AutomationListPropertyTest::undoTest ()
129 list<string> ignore_properties;
130 ignore_properties.push_back ("id");
132 Fred::make_property_quarks ();
134 boost::shared_ptr<Fred> sheila (new Fred);
137 sheila->_jim->add (1, 2);
138 sheila->_jim->add (3, 4);
141 sheila->clear_changes ();
142 sheila->_jim->add (5, 6);
143 sheila->_jim->add (7, 8);
144 StatefulDiffCommand sdc (sheila);
146 std::string test_data_filename = "automation_list_property_test3.ref";
147 std::string test_data_file3 = Glib::build_filename (test_search_path().front(), test_data_filename);
148 CPPUNIT_ASSERT (Glib::file_test (test_data_file3, Glib::FILE_TEST_EXISTS));
152 write_automation_list_xml (&sheila->get_state(), test_data_filename);
153 check_xml (&sheila->get_state(), test_data_file3, ignore_properties);
155 test_data_filename = "automation_list_property_test4.ref";
156 std::string test_data_file4 = Glib::build_filename (test_search_path().front(), test_data_filename);
157 CPPUNIT_ASSERT (Glib::file_test (test_data_file4, Glib::FILE_TEST_EXISTS));
161 write_automation_list_xml (&sheila->get_state(), test_data_filename);
162 check_xml (&sheila->get_state(), test_data_file4, ignore_properties);