[PATCH 7/7] Test for proper usage of custom vs. default dispatchers

Jason Ekstrand jason at jlekstrand.net
Fri Feb 1 08:09:48 PST 2013


Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
 tests/dispatcher-test.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/tests/dispatcher-test.c b/tests/dispatcher-test.c
index 54b6a41..894f20d 100644
--- a/tests/dispatcher-test.c
+++ b/tests/dispatcher-test.c
@@ -95,3 +95,69 @@ TEST(default_dispatcher)
 	assert(args_out[8].o == &target);
 }
 
+static void
+test_implementation_func(void *data, struct wl_object *target, int32_t i)
+{
+	*(int *)data = -i;
+}
+
+static void
+test_dispatcher_func(struct wl_object *obj, uint32_t opcode,
+		     const struct wl_message *message, void *data,
+		     union wl_argument *args)
+{
+	*(int *)data = args[0].i + opcode;
+}
+
+static void
+run_dispatcher_test(int *result, struct wl_interface *interface,
+		    void *implementation, uint32_t opcode, int value)
+{
+	struct wl_object sender = { interface, implementation, 1234 };
+	struct wl_object target = { interface, implementation, 1234 };
+	struct wl_closure *closure;
+	union wl_argument arg;
+
+	arg.i = value;
+	implementation = &test_implementation_func;
+	closure = wl_closure_marshal(&sender, opcode, &arg, interface->events);
+	wl_closure_invoke(closure, &target, opcode, result);
+	wl_closure_destroy(closure);
+}
+
+TEST(custom_dispatcher)
+{
+	struct wl_message message = { "test", "i", NULL };
+	struct wl_interface interface = {
+		"test",
+		0,
+		1, &message,
+		1, &message,
+		NULL
+	};
+	void (*implementation_func)(void *, struct wl_object *, int32_t);
+	int i;
+
+	implementation_func = &test_implementation_func;
+
+	interface.version = 1;
+	interface.dispatcher = NULL;
+	run_dispatcher_test(&i, &interface, &implementation_func, 0, 1234);
+	assert(i == -1234);
+
+	interface.version = (1 << 16) | 1;
+	interface.dispatcher = NULL;
+	run_dispatcher_test(&i, &interface, &implementation_func, 0, 1234);
+	assert(i == -1234);
+
+	interface.version = (1 << 16) | 1;
+	interface.dispatcher = &test_dispatcher_func;
+	run_dispatcher_test(&i, &interface, NULL, 0, 1234);
+	assert(i == 1234);
+
+	interface.version = (1 << 16) | 1;
+	interface.dispatcher = &test_dispatcher_func;
+	run_dispatcher_test(&i, &interface, NULL, 42, 1234);
+	assert(i == 1234 + 42);
+}
-- 
1.8.1



More information about the wayland-devel mailing list