3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2012 Intel Corporation. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include "src/shared/tester.h"
31 #include "src/shared/hciemu.h"
33 static DBusConnection *dbus_conn = NULL;
34 static GDBusClient *dbus_client = NULL;
35 static GDBusProxy *adapter_proxy = NULL;
37 static struct hciemu *hciemu_stack = NULL;
39 static void connect_handler(DBusConnection *connection, void *user_data)
41 tester_print("Connected to daemon");
43 hciemu_stack = hciemu_new(HCIEMU_TYPE_BREDRLE);
46 static void disconnect_handler(DBusConnection *connection, void *user_data)
48 tester_print("Disconnected from daemon");
50 dbus_connection_unref(dbus_conn);
53 tester_teardown_complete();
56 static gboolean compare_string_property(GDBusProxy *proxy, const char *name,
62 if (g_dbus_proxy_get_property(proxy, name, &iter) == FALSE)
65 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
68 dbus_message_iter_get_basic(&iter, &str);
70 return g_str_equal(str, value);
73 static void proxy_added(GDBusProxy *proxy, void *user_data)
75 const char *interface;
77 interface = g_dbus_proxy_get_interface(proxy);
79 if (g_str_equal(interface, "org.bluez.Adapter1") == TRUE) {
80 if (compare_string_property(proxy, "Address",
81 hciemu_get_address(hciemu_stack)) == TRUE) {
82 adapter_proxy = proxy;
83 tester_print("Found adapter");
85 tester_setup_complete();
90 static void proxy_removed(GDBusProxy *proxy, void *user_data)
92 const char *interface;
94 interface = g_dbus_proxy_get_interface(proxy);
96 if (g_str_equal(interface, "org.bluez.Adapter1") == TRUE) {
97 if (adapter_proxy == proxy) {
99 tester_print("Adapter removed");
101 g_dbus_client_unref(dbus_client);
107 static void test_setup(const void *test_data)
109 dbus_conn = g_dbus_setup_private(DBUS_BUS_SYSTEM, NULL, NULL);
111 dbus_client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
113 g_dbus_client_set_connect_watch(dbus_client, connect_handler, NULL);
114 g_dbus_client_set_disconnect_watch(dbus_client,
115 disconnect_handler, NULL);
117 g_dbus_client_set_proxy_handlers(dbus_client, proxy_added,
118 proxy_removed, NULL, NULL);
121 static void test_run(const void *test_data)
123 tester_test_passed();
126 static void test_teardown(const void *test_data)
128 hciemu_unref(hciemu_stack);
132 int main(int argc, char *argv[])
134 tester_init(&argc, &argv);
136 tester_add("Adapter setup", NULL, test_setup, test_run, test_teardown);