]> git.mxchange.org Git - simgear.git/blobdiff - simgear/structure/state_machine_test.cxx
Some Linux platforms need <cstdio> for snprintf.
[simgear.git] / simgear / structure / state_machine_test.cxx
index d1a4d26dcb2b0d60cdfed0dbd6b9f0d7101231f4..0703ce622ef12e8016c1bd1b5d3c1ea611af5028 100644 (file)
@@ -23,6 +23,7 @@
 #include <simgear/props/props.hxx>
 #include <simgear/props/props_io.hxx>
 #include <simgear/structure/commands.hxx>
+#include <simgear/misc/test_macros.hxx>
 
 using std::string;
 using std::cout;
@@ -43,27 +44,20 @@ public:
     bool _state;
 };
 
-static int dummy_cmd_state = 0;
-
-bool dummyCommand(const SGPropertyNode* arg)
+class DummyThing
 {
-    ++dummy_cmd_state;
-    return true;
-}
-
-#define COMPARE(a, b) \
-    if ((a) != (b))  { \
-        cerr << "failed:" << #a << " != " << #b << endl; \
-        cerr << "\tgot:'" << a << "'" << endl; \
-        exit(1); \
-    }
-
-#define VERIFY(a) \
-    if (!(a))  { \
-        cerr << "failed:" << #a << endl; \
-        exit(1); \
+public:
+    DummyThing() : dummy_cmd_state(0) { }
+    
+    bool someCommand(const SGPropertyNode* arg)
+    {
+        dummy_cmd_state++;
+        return true;
     }
     
+    int dummy_cmd_state;
+};
+
 using namespace simgear;
 
 #define BUILD_MACHINE_1() \
@@ -171,7 +165,8 @@ void testNoSourcesTransition()
 void testBindings()
 {    
     SGCommandMgr* cmdMgr = SGCommandMgr::instance();
-    cmdMgr->addCommand("dummy", dummyCommand);
+    DummyThing thing;
+    cmdMgr->addCommand("dummy", &thing, &DummyThing::someCommand);
     BUILD_MACHINE_1();
     
     t2->addBinding(new SGBinding("dummy"));
@@ -186,20 +181,20 @@ void testBindings()
     sm->update(1.0);
     trigger1->_state = false;
     COMPARE(sm->state()->name(), "b");
-    COMPARE(dummy_cmd_state, 1); // exit state A
+    COMPARE(thing.dummy_cmd_state, 1); // exit state A
     
     trigger2->_state = true;
     sm->update(1.0);
     trigger2->_state = false;
-    COMPARE(dummy_cmd_state, 3); // fire transition 2, enter state C
+    COMPARE(thing.dummy_cmd_state, 3); // fire transition 2, enter state C
     
-    dummy_cmd_state = 0;
+    thing.dummy_cmd_state = 0;
     sm->changeToState(stateA);
-    COMPARE(dummy_cmd_state, 1); // enter state A
+    COMPARE(thing.dummy_cmd_state, 1); // enter state A
     trigger1->_state = true;
     sm->update(1.0);
     trigger1->_state = false;
-    COMPARE(dummy_cmd_state, 2); // exit state A
+    COMPARE(thing.dummy_cmd_state, 2); // exit state A
     
 ////////////////////////
     t3->addBinding(new SGBinding("dummy"));
@@ -207,11 +202,11 @@ void testBindings()
     t3->addBinding(new SGBinding("dummy"));
     
     sm->changeToStateName("b");
-    dummy_cmd_state = 0;
+    thing.dummy_cmd_state = 0;
     trigger3->_state = true;
     sm->update(1.0);
     trigger3->_state = false;
-    COMPARE(dummy_cmd_state, 4); // three transition bindings, enter A
+    COMPARE(thing.dummy_cmd_state, 4); // three transition bindings, enter A
 }
 
 void testParse()