[PATCH wayland v2 2/6] tests: Add should_fail argument to marshal_demarshal

Daniel Stone daniel at fooishbar.org
Wed May 2 08:53:31 PDT 2012


Allows us to check that obviously incorrect data gets rejected as it
should by the marshalling code.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 tests/connection-test.c |   17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

v2: New, no functional changes.

diff --git a/tests/connection-test.c b/tests/connection-test.c
index 54ac423..d17a456 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -339,7 +339,7 @@ TEST(connection_demarshal)
 }
 
 static void
-marshal_demarshal(struct marshal_data *data, 
+marshal_demarshal(unsigned int should_fail, struct marshal_data *data,
 		  void (*func)(void), int size, const char *format, ...)
 {
 	struct wl_closure closure;
@@ -356,6 +356,11 @@ marshal_demarshal(struct marshal_data *data,
 	ret = wl_closure_vmarshal(&closure, &sender, opcode, ap, &message);
 	va_end(ap);
 
+	if (should_fail) {
+		assert(ret != 0);
+		return;
+	}
+
 	assert(ret == 0);
 	assert(wl_closure_send(&closure, data->write_connection) == 0);
 	wl_closure_destroy(&closure);
@@ -384,20 +389,20 @@ TEST(connection_marshal_demarshal)
 	setup_marshal_data(&data);
 
 	data.value.u = 889911;
-	marshal_demarshal(&data, (void *) validate_demarshal_u,
+	marshal_demarshal(0, &data, (void *) validate_demarshal_u,
 			  12, "u", data.value.u);
 
 	data.value.i = -13;
-	marshal_demarshal(&data, (void *) validate_demarshal_i,
+	marshal_demarshal(0, &data, (void *) validate_demarshal_i,
 			  12, "i", data.value.i);
 
 	data.value.s = "cookie robots";
-	marshal_demarshal(&data, (void *) validate_demarshal_s,
+	marshal_demarshal(0, &data, (void *) validate_demarshal_s,
 			  28, "s", data.value.s);
 
 	data.value.h = mkstemp(f);
 	assert(data.value.h >= 0);
-	marshal_demarshal(&data, (void *) validate_demarshal_h,
+	marshal_demarshal(0, &data, (void *) validate_demarshal_h,
 			  8, "h", data.value.h);
 
 	release_marshal_data(&data);
@@ -418,7 +423,7 @@ TEST(connection_marshal_alot)
 		strcpy(f, "/tmp/weston-tests-XXXXXX");
 		data.value.h = mkstemp(f);
 		assert(data.value.h >= 0);
-		marshal_demarshal(&data, (void *) validate_demarshal_h,
+		marshal_demarshal(0, &data, (void *) validate_demarshal_h,
 				  8, "h", data.value.h);
 	}
 
-- 
1.7.10



More information about the wayland-devel mailing list