All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ell@lists.01.org
Subject: Re: [PATCH v3 4/4] unit: dbus: Add test for disconnect watch API
Date: Thu, 19 Feb 2015 10:07:17 -0600	[thread overview]
Message-ID: <54E60A35.7070002@gmail.com> (raw)
In-Reply-To: <1424275716-7198-5-git-send-email-jukka.rissanen@linux.intel.com>

[-- Attachment #1: Type: text/plain, Size: 6266 bytes --]

Hi Jukka,

On 02/18/2015 10:08 AM, Jukka Rissanen wrote:
> Test the dbus disconnect watch support.
> ---
>   Makefile.am            |   3 +
>   unit/test-dbus-watch.c | 153 +++++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 156 insertions(+)
>   create mode 100644 unit/test-dbus-watch.c
>

Okay, now we're getting much closer to what I had in mind.

> diff --git a/Makefile.am b/Makefile.am
> index 50f81eb..eff88f7 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -102,6 +102,7 @@ unit_tests = unit/test-unit \
>   			unit/test-dbus-util \
>   			unit/test-dbus-message \
>   			unit/test-dbus-service \
> +			unit/test-dbus-watch \
>   			unit/test-gvariant-util \
>   			unit/test-gvariant-message \
>   			unit/test-siphash \
> @@ -147,6 +148,8 @@ unit_test_dbus_util_LDADD = ell/libell-private.la
>
>   unit_test_dbus_service_LDADD = ell/libell-private.la
>
> +unit_test_dbus_watch_LDADD = ell/libell-private.la
> +
>   unit_test_gvariant_util_LDADD = ell/libell-private.la
>
>   unit_test_gvariant_message_LDADD = ell/libell-private.la
> diff --git a/unit/test-dbus-watch.c b/unit/test-dbus-watch.c
> new file mode 100644
> index 0000000..5e7cf60
> --- /dev/null
> +++ b/unit/test-dbus-watch.c
> @@ -0,0 +1,153 @@
> +/*
> + *
> + *  Embedded Linux library
> + *
> + *  Copyright (C) 2011-2015  Intel Corporation. All rights reserved.
> + *
> + *  This library is free software; you can redistribute it and/or
> + *  modify it under the terms of the GNU Lesser General Public
> + *  License as published by the Free Software Foundation; either
> + *  version 2.1 of the License, or (at your option) any later version.
> + *
> + *  This library is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + *  Lesser General Public License for more details.
> + *
> + *  You should have received a copy of the GNU Lesser General Public
> + *  License along with this library; if not, write to the Free Software
> + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> + *
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <sys/wait.h>
> +#include <assert.h>
> +#include <time.h>
> +#include <stdio.h>
> +
> +#include <ell/ell.h>
> +#include "ell/dbus-private.h"
> +
> +#define DBUS_SERVICE_DBUS	"org.freedesktop.DBus"
> +#define DBUS_PATH_DBUS		"/org/freedesktop/DBus"
> +#define DBUS_INTERFACE_DBUS	"org.freedesktop.DBus"
> +#define DBUS_MAXIMUM_MATCH_RULE_LENGTH	1024
> +
> +struct watch_test {
> +	const char *name;
> +	const char *expected;
> +	int count;
> +};

Split this up into two structures and test things separately.

One structure and test to handle the actual AddMatch/RemoveMatch 
strings.  These should be in a separate patch like I already mentioned.

The other tests to cover the actual dispatcher.

> +
> +static struct watch_test match_test = {
> +	.name = ":1.101",
> +	.expected = "type='signal',"
> +		"sender='org.freedesktop.DBus',"
> +		"path='/org/freedesktop/DBus',"
> +		"interface='org.freedesktop.DBus',"
> +		"member='NameOwnerChanged',"
> +		"arg0=':1.101'",
> +};
> +
> +static struct watch_test disconnect_test = {
> +	.name = ":101.1",
> +	.count = 0,
> +};
> +
> +static void verify_match(struct _dbus_filter_data *data,
> +						l_dbus_message_func_t filter)
> +{
> +	struct watch_test *test = data->user_data;
> +	char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
> +
> +	_dbus1_format_rule(data, rule, sizeof(rule));
> +
> +	assert(strcmp(rule, test->expected) == 0);
> +}
> +
> +static void test_match(const void *test_data)
> +{
> +	struct watch_test *test = (struct watch_test *)test_data;
> +	struct _dbus_filter_data *data;
> +
> +	data = _dbus1_filter_data_get(NULL, _dbus1_service_filter,
> +				DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
> +				DBUS_INTERFACE_DBUS, "NameOwnerChanged",
> +				test->name,
> +				NULL,
> +				test,
> +				NULL,
> +				verify_match);
> +
> +	_dbus1_filter_data_destroy(data, verify_match);

Just call _dbus1_format_rule directly here.

> +}
> +
> +static void match(struct _dbus_filter_data *data, l_dbus_message_func_t filter)
> +{
> +	data->handle_func = filter;
> +}
> +
> +static void disconnect_cb(struct l_dbus *dbus, void *user_data)
> +{
> +	struct watch_test *data = user_data;
> +
> +	data->count++;

count is not part of the test data, so just pass in a pointer to some 
arbitrary integer here.

> +}
> +
> +static void send_filter_signal(struct _dbus_filter_data *data,
> +			const char *name, const char *old, const char *new)
> +{
> +	struct l_dbus_message *message;
> +
> +	message = _dbus_message_new_signal(2, DBUS_PATH_DBUS,
> +					DBUS_INTERFACE_DBUS,
> +					"NameOwnerChanged");
> +	l_dbus_message_set_arguments(message, "sss", name, old, new);
> +	_dbus_message_set_sender(message, DBUS_SERVICE_DBUS);
> +	_dbus_message_filter_dispatcher(message, data);
> +	l_dbus_message_unref(message);
> +}
> +
> +static void test_disconnect_watch(const void *test_data)
> +{
> +	struct watch_test *test = (struct watch_test *)test_data;
> +	struct _dbus_filter_data *data;
> +
> +	data = _dbus1_filter_data_get(NULL, _dbus1_service_filter,
> +				DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
> +				DBUS_INTERFACE_DBUS, "NameOwnerChanged",
> +				test->name,
> +				disconnect_cb,
> +				test,
> +				NULL,
> +				match);
> +
> +	send_filter_signal(data, ":0.1", ":0.1", "");
> +	assert(test->count == 0);
> +
> +	send_filter_signal(data, ":0.1", ":0.1", ":0.2");
> +	assert(test->count == 0);
> +
> +	send_filter_signal(data, ":101.1", ":101.1", "");
> +	assert(test->count == 1);
> +
> +	_dbus1_filter_data_destroy(data, match);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +	l_test_init(&argc, &argv);
> +
> +	l_test_add("DBus filter", test_match, &match_test);
> +
> +	l_test_add("DBus disconnect watch", test_disconnect_watch,
> +			&disconnect_test);
> +
> +	return l_test_run();
> +}
>

Regards,
-Denis

      reply	other threads:[~2015-02-19 16:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-18 16:08 [PATCH v3 0/4] Add DBus disconnect watch support Jukka Rissanen
2015-02-18 16:08 ` [PATCH v3 1/4] dbus: Add AddMatch and RemoveMatch support Jukka Rissanen
2015-02-19 15:21   ` Denis Kenzior
2015-02-18 16:08 ` [PATCH v3 2/4] gvariant: dbus.h need to be included before private header Jukka Rissanen
2015-02-18 16:08 ` [PATCH v3 3/4] dbus: Add disconnect watch support Jukka Rissanen
2015-02-19 15:57   ` Denis Kenzior
2015-02-18 16:08 ` [PATCH v3 4/4] unit: dbus: Add test for disconnect watch API Jukka Rissanen
2015-02-19 16:07   ` Denis Kenzior [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54E60A35.7070002@gmail.com \
    --to=denkenz@gmail.com \
    --cc=ell@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.