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"
28 CPPUNIT_TEST_SUITE_REGISTRATION (AutomationListPropertyTest);
32 using namespace ARDOUR;
35 write_automation_list_xml (XMLNode* node, std::string filename)
37 // use the same output dir for all of them
38 static std::string test_output_dir = new_test_output_dir ("automation_list_property");
39 std::string output_file = Glib::build_filename (test_output_dir, filename);
41 CPPUNIT_ASSERT (write_ref (node, output_file));
45 AutomationListPropertyTest::basicTest ()
47 list<string> ignore_properties;
48 ignore_properties.push_back ("id");
50 PropertyDescriptor<boost::shared_ptr<AutomationList> > descriptor;
51 descriptor.property_id = g_quark_from_static_string ("FadeIn");
52 AutomationListProperty property (
54 boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (FadeInAutomation)))
57 property.clear_changes ();
59 /* No change since we just cleared them */
60 CPPUNIT_ASSERT_EQUAL (false, property.changed());
62 property->add (1, 2, false, false);
63 property->add (3, 4, false, false);
65 /* Now it has changed */
66 CPPUNIT_ASSERT_EQUAL (true, property.changed());
68 std::string test_data_filename = "automation_list_property_test1.ref";
69 std::string test_data_file1 = Glib::build_filename (test_search_path().front(), test_data_filename);
70 CPPUNIT_ASSERT (Glib::file_test (test_data_file1, Glib::FILE_TEST_EXISTS));
72 XMLNode* foo = new XMLNode ("test");
73 property.get_changes_as_xml (foo);
74 write_automation_list_xml (foo, test_data_filename);
75 check_xml (foo, test_data_file1, ignore_properties);
77 test_data_filename = "automation_list_property_test2.ref";
78 std::string test_data_file2 = Glib::build_filename (test_search_path().front(), test_data_filename);
79 CPPUNIT_ASSERT (Glib::file_test (test_data_file2, Glib::FILE_TEST_EXISTS));
82 property.clear_changes ();
83 CPPUNIT_ASSERT_EQUAL (false, property.changed());
84 property->add (5, 6, false, false);
85 property->add (7, 8, false, false);
86 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);
95 /** Here's a StatefulDestructible class that has a AutomationListProperty */
96 class Fred : public StatefulDestructible
100 : _jim (_descriptor, boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (FadeInAutomation))))
106 XMLNode & get_state () {
107 XMLNode* n = new XMLNode ("State");
112 int set_state (XMLNode const & node, int) {
117 static void make_property_quarks () {
118 _descriptor.property_id = g_quark_from_static_string ("FadeIn");
121 AutomationListProperty _jim;
122 static PropertyDescriptor<boost::shared_ptr<AutomationList> > _descriptor;
125 PropertyDescriptor<boost::shared_ptr<AutomationList> > Fred::_descriptor;
128 AutomationListPropertyTest::undoTest ()
130 list<string> ignore_properties;
131 ignore_properties.push_back ("id");
133 Fred::make_property_quarks ();
135 boost::shared_ptr<Fred> sheila (new Fred);
138 sheila->_jim->add (1, 2, false, false);
139 sheila->_jim->add (3, 4, false, false);
142 sheila->clear_changes ();
143 sheila->_jim->add (5, 6, false, false);
144 sheila->_jim->add (7, 8, false, false);
145 StatefulDiffCommand sdc (sheila);
147 std::string test_data_filename = "automation_list_property_test3.ref";
148 std::string test_data_file3 = Glib::build_filename (test_search_path().front(), test_data_filename);
149 CPPUNIT_ASSERT (Glib::file_test (test_data_file3, Glib::FILE_TEST_EXISTS));
153 write_automation_list_xml (&sheila->get_state(), test_data_filename);
154 check_xml (&sheila->get_state(), test_data_file3, ignore_properties);
156 test_data_filename = "automation_list_property_test4.ref";
157 std::string test_data_file4 = Glib::build_filename (test_search_path().front(), test_data_filename);
158 CPPUNIT_ASSERT (Glib::file_test (test_data_file4, Glib::FILE_TEST_EXISTS));
162 write_automation_list_xml (&sheila->get_state(), test_data_filename);
163 check_xml (&sheila->get_state(), test_data_file4, ignore_properties);