From: Denis Kenzior <denkenz@gmail.com>
To: ell@lists.01.org
Subject: Re: [PATCH v4 4/6] unit: dbus: Add test for filter rule
Date: Fri, 20 Feb 2015 11:27:57 -0600 [thread overview]
Message-ID: <54E76E9D.8070009@gmail.com> (raw)
In-Reply-To: <1424434601-2211-5-git-send-email-jukka.rissanen@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 4901 bytes --]
Hi Jukka,
On 02/20/2015 06:16 AM, Jukka Rissanen wrote:
> Testing the _dbus1_format_rule() function.
> ---
> Makefile.am | 3 ++
> unit/test-dbus-watch.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 112 insertions(+)
> create mode 100644 unit/test-dbus-watch.c
>
> diff --git a/Makefile.am b/Makefile.am
> index 36a680b..cea1b7a 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -107,6 +107,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 \
> @@ -154,6 +155,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..e1d3f9d
> --- /dev/null
> +++ b/unit/test-dbus-watch.c
> @@ -0,0 +1,109 @@
> +/*
> + *
> + * 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 dbus_filter_data {
> + struct l_dbus *dbus;
> + l_dbus_message_func_t handle_func;
> + l_dbus_watch_func_t disconnect_func;
> + char *sender;
> + char *path;
> + char *interface;
> + char *member;
> + char *argument;
> + void *user_data;
> + l_dbus_destroy_func_t destroy_func;
> +};
Don't ever do this. If you need to use an opaque data structure, ask
yourself why. If it is genuinely required, then expose that in the
header file. Do not re-define opaque data structures in a unit test.
> +
> +struct watch_test {
> + const char *name;
> + const char *expected;
> +};
> +
> +static const 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 void setup_data(struct dbus_filter_data *data, const char *name)
> +{
> + data->sender = l_strdup(DBUS_SERVICE_DBUS);
> + data->path = l_strdup(DBUS_PATH_DBUS);
> + data->interface = l_strdup(DBUS_INTERFACE_DBUS);
> + data->member = l_strdup("NameOwnerChanged");
> + data->argument = l_strdup(name);
> +}
> +
> +static void clean_data(struct dbus_filter_data *data)
> +{
> + l_free(data->sender);
> + l_free(data->path);
> + l_free(data->interface);
> + l_free(data->member);
> + l_free(data->argument);
> +}
> +static void test_match(const void *test_data)
> +{
> + const struct watch_test *test = test_data;
> + struct dbus_filter_data data;
> + char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
> +
> + setup_data(&data, test->name);
Use _dbus1_filter_data_get
> +
> + _dbus1_format_rule(&data, rule, sizeof(rule));
> +
> + assert(strcmp(rule, test->expected) == 0);
> +
> + clean_data(&data);
Use _dbus1_filter_data_destroy
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + l_test_init(&argc, &argv);
> +
> + l_test_add("DBus filter", test_match, &match_test);
Add more cases please, especially focusing on each type of filter
combination. E.g. interface only, member only, interface + member, etc.
> +
> + return l_test_run();
> +}
>
Regards,
-Denis
next prev parent reply other threads:[~2015-02-20 17:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-20 12:16 [PATCH v4 0/6] Add DBus disconnect watch support Jukka Rissanen
2015-02-20 12:16 ` [PATCH v4 1/6] dbus: Add AddMatch and RemoveMatch support Jukka Rissanen
2015-02-20 12:16 ` [PATCH v4 2/6] gvariant: dbus.h need to be included before private header Jukka Rissanen
2015-02-20 17:21 ` Denis Kenzior
2015-02-20 12:16 ` [PATCH v4 3/6] dbus: Add filter rule creator Jukka Rissanen
2015-02-20 17:23 ` Denis Kenzior
2015-02-20 12:16 ` [PATCH v4 4/6] unit: dbus: Add test for filter rule Jukka Rissanen
2015-02-20 17:27 ` Denis Kenzior [this message]
2015-02-20 12:16 ` [PATCH v4 5/6] dbus: Add disconnect watch support Jukka Rissanen
2015-02-20 17:23 ` Denis Kenzior
2015-02-20 12:16 ` [PATCH v4 6/6] unit: dbus: Add test for disconnect watch API Jukka Rissanen
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=54E76E9D.8070009@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.