diff options
author | Carl Hetherington <carl@carlh.net> | 2012-06-16 17:20:10 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2012-06-16 17:20:10 +0000 |
commit | 5ac22e9095d5f851b5238029e3f813bc86fe2280 (patch) | |
tree | 51460c63aa9ace692dedceb01494f2a92d4bc364 /libs/ardour/test/automation_list_property_test.cc | |
parent | 9429401f11ffa0ee1729dbdc5e14e87cf06e2dc1 (diff) |
Add new SharedStatefulProperty which manages a shared_ptr to
some Stateful object, and a subclass to use this for
AutomationList. SharedStatefulProperty will manage undo / redo
using full copies of the XML state, like MementoCommand,
but does it within the Property undo system.
git-svn-id: svn://localhost/ardour2/branches/3.0@12740 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/test/automation_list_property_test.cc')
-rw-r--r-- | libs/ardour/test/automation_list_property_test.cc | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/libs/ardour/test/automation_list_property_test.cc b/libs/ardour/test/automation_list_property_test.cc new file mode 100644 index 0000000000..9d1f448ad5 --- /dev/null +++ b/libs/ardour/test/automation_list_property_test.cc @@ -0,0 +1,123 @@ +/* + Copyright (C) 2012 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "pbd/properties.h" +#include "pbd/stateful_diff_command.h" +#include "ardour/automation_list.h" +#include "automation_list_property_test.h" +#include "test_util.h" + +CPPUNIT_TEST_SUITE_REGISTRATION (AutomationListPropertyTest); + +using namespace std; +using namespace PBD; +using namespace ARDOUR; + +void +AutomationListPropertyTest::basicTest () +{ + PropertyDescriptor<boost::shared_ptr<AutomationList> > descriptor; + descriptor.property_id = g_quark_from_static_string ("FadeIn"); + AutomationListProperty property ( + descriptor, + boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (FadeInAutomation))) + ); + + property.clear_changes (); + + /* No change since we just cleared them */ + CPPUNIT_ASSERT_EQUAL (false, property.changed()); + + property->add (1, 2); + property->add (3, 4); + + /* Now it has changed */ + CPPUNIT_ASSERT_EQUAL (true, property.changed()); + + XMLNode* foo = new XMLNode ("test"); + property.get_changes_as_xml (foo); + check_xml (foo, "../libs/ardour/test/data/automation_list_property_test1.ref"); + + /* Do some more */ + property.clear_changes (); + CPPUNIT_ASSERT_EQUAL (false, property.changed()); + property->add (5, 6); + property->add (7, 8); + 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"); +} + +/** Here's a StatefulDestructible class that has a AutomationListProperty */ +class Fred : public StatefulDestructible +{ +public: + Fred () + : _jim (_descriptor, boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (FadeInAutomation)))) + + { + add_property (_jim); + } + + XMLNode & get_state () { + XMLNode* n = new XMLNode ("State"); + add_properties (*n); + return *n; + } + + int set_state (XMLNode const & node, int) { + set_values (node); + return 0; + } + + static void make_property_quarks () { + _descriptor.property_id = g_quark_from_static_string ("FadeIn"); + } + + AutomationListProperty _jim; + static PropertyDescriptor<boost::shared_ptr<AutomationList> > _descriptor; +}; + +PropertyDescriptor<boost::shared_ptr<AutomationList> > Fred::_descriptor; + +void +AutomationListPropertyTest::undoTest () +{ + Fred::make_property_quarks (); + + boost::shared_ptr<Fred> sheila (new Fred); + + /* Add some data */ + sheila->_jim->add (1, 2); + sheila->_jim->add (3, 4); + + /* Do a `command' */ + sheila->clear_changes (); + sheila->_jim->add (5, 6); + sheila->_jim->add (7, 8); + StatefulDiffCommand sdc (sheila); + + /* Undo */ + sdc.undo (); + check_xml (&sheila->get_state(), "../libs/ardour/test/data/automation_list_property_test3.ref"); + + /* Redo */ + sdc.redo (); + check_xml (&sheila->get_state(), "../libs/ardour/test/data/automation_list_property_test4.ref"); +} |