[gnome-builder] egg-state-machine: add state transition failure test
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] egg-state-machine: add state transition failure test
- Date: Mon, 4 May 2015 23:52:08 +0000 (UTC)
commit 6fb7fcad24e77c5f0a312f5ca5597066507855d5
Author: Christian Hergert <christian hergert me>
Date: Mon May 4 16:52:03 2015 -0700
egg-state-machine: add state transition failure test
Add test that fails to switch between two states. Then try followup
transition that works.
tests/test-egg-state-machine.c | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/tests/test-egg-state-machine.c b/tests/test-egg-state-machine.c
index 6a8db03..46c990e 100644
--- a/tests/test-egg-state-machine.c
+++ b/tests/test-egg-state-machine.c
@@ -180,6 +180,20 @@ assert_prop_equal (gpointer obja,
g_value_unset (&vb);
}
+static EggStateTransition
+transition_cb (EggStateMachine *machine,
+ const gchar *old_state,
+ const gchar *new_state,
+ gpointer user_data)
+{
+ /* allow any state to state3, except state2 */
+
+ if ((g_strcmp0 (old_state, "state2") == 0) && (g_strcmp0 (new_state, "state3") == 0))
+ return EGG_STATE_TRANSITION_INVALID;
+
+ return EGG_STATE_TRANSITION_IGNORED;
+}
+
static void
test_state_machine_basic (void)
{
@@ -207,6 +221,8 @@ test_state_machine_basic (void)
egg_state_machine_bind (machine, "state1", obj1, "string", dummy, "string", 0);
egg_state_machine_bind (machine, "state2", obj2, "string", dummy, "string", 0);
+ g_signal_connect (machine, "transition", G_CALLBACK (transition_cb), NULL);
+
ret = egg_state_machine_transition (machine, "state1", &error);
g_assert_no_error (error);
g_assert_cmpint (ret, ==, EGG_STATE_TRANSITION_SUCCESS);
@@ -237,6 +253,12 @@ test_state_machine_basic (void)
g_object_set (obj1, "string", "obj1", NULL);
assert_prop_equal (obj2, dummy, "string");
+ /* state2 -> state3 should fail */
+ ret = egg_state_machine_transition (machine, "state3", &error);
+ g_assert (ret == EGG_STATE_TRANSITION_INVALID);
+ g_assert (error != NULL);
+ g_clear_error (&error);
+
ret = egg_state_machine_transition (machine, "state1", &error);
g_assert_no_error (error);
g_assert_cmpint (ret, ==, EGG_STATE_TRANSITION_SUCCESS);
@@ -247,6 +269,11 @@ test_state_machine_basic (void)
g_object_set (obj2, "string", "obj2-1", NULL);
assert_prop_equal (obj1, dummy, "string");
+ /* state1 -> state3 should succeed */
+ ret = egg_state_machine_transition (machine, "state3", &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (ret, ==, EGG_STATE_TRANSITION_SUCCESS);
+
g_object_unref (machine);
g_assert (machine == NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]