A few more libpbd test tweaks.
[ardour.git] / libs / pbd / test / scalar_properties.cc
1 #include "scalar_properties.h"
2
3 CPPUNIT_TEST_SUITE_REGISTRATION (ScalarPropertiesTest);
4
5 using namespace std;
6 using namespace PBD;
7
8 namespace Properties {
9         PBD::PropertyDescriptor<int> fred;
10 };
11
12 void
13 ScalarPropertiesTest::make_property_quarks ()
14 {
15         Properties::fred.property_id = g_quark_from_static_string ("fred");
16 }
17
18 ScalarPropertiesTest::ScalarPropertiesTest ()
19         : _fred (Properties::fred, 0)
20 {
21 }
22
23 void
24 ScalarPropertiesTest::testBasic ()
25 {
26         CPPUNIT_ASSERT (_fred.changed() == false);
27
28         _fred = 4;
29         CPPUNIT_ASSERT (_fred == 4);
30         CPPUNIT_ASSERT (_fred.changed() == true);
31
32         _fred.clear_history ();
33         CPPUNIT_ASSERT (_fred.changed() == false);
34         
35         _fred = 5;
36         CPPUNIT_ASSERT (_fred == 5);
37         CPPUNIT_ASSERT (_fred.changed() == true);
38
39         PropertyList undo;
40         PropertyList redo;
41         _fred.diff (undo, redo);
42
43         CPPUNIT_ASSERT (undo.size() == 1);
44         CPPUNIT_ASSERT (redo.size() == 1);
45
46         PropertyTemplate<int>* t = dynamic_cast<Property<int>*> (undo.begin()->second);
47         CPPUNIT_ASSERT (t);
48         CPPUNIT_ASSERT (t->val() == 4);
49
50         t = dynamic_cast<Property<int>*> (redo.begin()->second);
51         CPPUNIT_ASSERT (t);
52         CPPUNIT_ASSERT (t->val() == 5);
53 }