[PATCH wayland] tests: Test wl_message_count_arrays

Pekka Paalanen ppaalanen at gmail.com
Thu Nov 10 15:15:31 UTC 2016


On Thu,  3 Nov 2016 13:42:54 -0700
Yong Bakos <junk at humanoriented.com> wrote:

> From: Yong Bakos <ybakos at humanoriented.com>
> 
> message-test.c did not cover wl_message_count_arrays, so add one test that
> specifically tests this method. Note that this exposes wl_message_count_arrays
> in a private header (wayland-private.h), and removes the `static` modifier of
> the implementation.
> 
> Signed-off-by: Yong Bakos <ybakos at humanoriented.com>
> ---
>  src/connection.c      |  2 +-
>  src/wayland-private.h |  3 +++
>  tests/message-test.c  | 37 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 41 insertions(+), 1 deletion(-)
> 
> diff --git a/src/connection.c b/src/connection.c
> index c3293a9..5c3d187 100644
> --- a/src/connection.c
> +++ b/src/connection.c
> @@ -392,7 +392,7 @@ wl_connection_queue(struct wl_connection *connection,
>  	return wl_buffer_put(&connection->out, data, count);
>  }
>  
> -static int
> +int
>  wl_message_count_arrays(const struct wl_message *message)
>  {
>  	int i, arrays;

Hi,

Yeah, it's pretty interesting how the test gets access to a
non-exported symbol.

connection.c is built into helper library libwayland-private.la which
is linked to by libtest-runner.la. Both these libtool archives being
static helper libraries, you actually get a copy of connection.c in
every test program. Hence the non-exported symbol becomes available.

Symbols won't (must not) get exported without WL_EXPORT attribute. We
could probably use a test for checking the exported symbols from the
final shared objects, so they don't ever change by accident.

> diff --git a/src/wayland-private.h b/src/wayland-private.h
> index ef58ccf..676b181 100644
> --- a/src/wayland-private.h
> +++ b/src/wayland-private.h
> @@ -163,6 +163,9 @@ int
>  arg_count_for_signature(const char *signature);
>  
>  int
> +wl_message_count_arrays(const struct wl_message *message);
> +
> +int
>  wl_message_get_since(const struct wl_message *message);
>  
>  void
> diff --git a/tests/message-test.c b/tests/message-test.c
> index cb08f90..389f788 100644
> --- a/tests/message-test.c
> +++ b/tests/message-test.c
> @@ -51,3 +51,40 @@ TEST(message_version)
>  		       messages[i].expected_version);
>  	}
>  }
> +
> +TEST(message_count_arrays)
> +{
> +	unsigned int i;
> +	struct wl_message fake_messages[] = {
> +		{ "empty", "", NULL },
> +		{ "non_present", "iufsonh", NULL },
> +		{ "leading", "aiufsonh", NULL},
> +		{ "trailing", "iufsonha", NULL },
> +		{ "middle", "iufasonh", NULL },
> +		{ "multiple", "aaiufaasonhaa", NULL },
> +		{ "leading_version", "2aaiufaasonhaa", NULL },
> +		{ "among_nullables", "iufsa?oa?nah", NULL },
> +		{ "all_mixed", "2aiufas?oa?na", NULL },
> +	};
> +	const struct {
> +		const struct wl_message *message;
> +		int expected_array_count;
> +	} messages[] = {
> +		{ &wl_pointer_interface.events[WL_POINTER_ENTER], 0 },
> +		{ &wl_keyboard_interface.events[WL_KEYBOARD_ENTER], 1 },
> +		{ &fake_messages[0], 0 },
> +		{ &fake_messages[1], 0 },
> +		{ &fake_messages[2], 1 },
> +		{ &fake_messages[3], 1 },
> +		{ &fake_messages[4], 1 },
> +		{ &fake_messages[5], 6 },
> +		{ &fake_messages[6], 6 },
> +		{ &fake_messages[7], 3 },
> +		{ &fake_messages[8], 4 }
> +	};
> +
> +	for (i = 0; i < ARRAY_LENGTH(messages); ++i) {
> +		assert(wl_message_count_arrays(messages[i].message) ==
> +		       messages[i].expected_array_count);
> +	}
> +}

This looks good, pushed:
   66a26ae..9618087  master -> master


btw. it seems like array arguments can also be nullable. There seems to
be handling for passing in NULL in addition to an empty array. On the
other side on dispatch, it gets converted into a wl_array in any case.

A new_id cannot be nullable AFAIK, so your test has a tiny mistake
there, but it's irrelevant for this use.


Thanks,
pq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20161110/8e341a6f/attachment.sig>


More information about the wayland-devel mailing list