Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rottmann <a.rottmann@gmx.at>2009-03-24 19:26:36 (GMT)
committer Andreas Rottmann <a.rottmann@gmx.at>2009-03-24 19:26:36 (GMT)
commitc71ce6f7f51a181e5db345dd88d5872cc73db68a (patch)
tree3f218056a61a29fdf913bbfbed5925dd9e9446d4
parent0fc035242ec0eccf2d9c9c163fc6da8da2850cfa (diff)
Additions to the 'Everything' namespace
- Make the destroy-notfied callback test harder by retaining the callbacks until test_callback_thaw_notifications() is called.
-rw-r--r--tests/everything/everything.c54
-rw-r--r--tests/everything/everything.h2
2 files changed, 53 insertions, 3 deletions
diff --git a/tests/everything/everything.c b/tests/everything/everything.c
index 570b79c..7348a50 100644
--- a/tests/everything/everything.c
+++ b/tests/everything/everything.c
@@ -892,6 +892,16 @@ test_obj_do_matrix (TestObj *obj, const char *somestr)
return TEST_OBJ_GET_CLASS (obj)->matrix (obj, somestr);
}
+typedef struct _CallbackInfo CallbackInfo;
+
+struct _CallbackInfo
+{
+ TestCallbackUserData callback;
+ GDestroyNotify notify;
+ gpointer user_data;
+};
+
+
/**
* test_callback:
* @callback: (scope call):
@@ -917,6 +927,8 @@ test_callback_user_data (TestCallbackUserData callback,
return callback(user_data);
}
+static GSList *notified_callbacks = NULL;
+
/**
* test_callback_destroy_notify:
* @callback: (scope notified):
@@ -930,11 +942,47 @@ test_callback_destroy_notify (TestCallbackUserData callback,
GDestroyNotify notify)
{
int retval;
-
+ CallbackInfo *info;
+
retval = callback(user_data);
- if (notify)
- notify(user_data);
+
+ info = g_new(CallbackInfo, 1);
+ info->callback = callback;
+ info->notify = notify;
+ info->user_data = user_data;
+
+ notified_callbacks = g_slist_prepend(notified_callbacks, info);
+
+ return retval;
+}
+
+/**
+ * test_callback_thaw_notifications:
+ *
+ * Invokes all callbacks installed by #test_callback_destroy_notify(),
+ * adding up their return values, and removes them, invoking the
+ * corresponding destroy notfications.
+ *
+ * Return value: Sum of the return values of the invoked callbacks.
+ */
+int
+test_callback_thaw_notifications (void)
+{
+ int retval = 0;
+ GSList *node;
+
+ for (node = notified_callbacks; node != NULL; node = node->next)
+ {
+ CallbackInfo *info = (CallbackInfo *)node->data;
+ retval += info->callback (info->user_data);
+ if (info->notify)
+ info->notify (info->user_data);
+ g_free (info);
+ }
+ g_slist_free (notified_callbacks);
+ notified_callbacks = NULL;
+
return retval;
}
diff --git a/tests/everything/everything.h b/tests/everything/everything.h
index df054ff..c4016eb 100644
--- a/tests/everything/everything.h
+++ b/tests/everything/everything.h
@@ -192,6 +192,7 @@ struct _TestObj
GObject parent_instance;
GObject *bare;
+ GSList *handlers;
};
struct _TestObjClass
@@ -222,6 +223,7 @@ int test_callback_user_data (TestCallbackUserData callback,
int test_callback_destroy_notify (TestCallbackUserData callback,
gpointer user_data,
GDestroyNotify notify);
+int test_callback_thaw_notifications (void);
int test_callback_infinte (TestCallbackUserData callback,
gpointer user_data);