3 * oFono - Open Source Telephony
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
37 #include <gatchat/gatserver.h>
39 #include "unit/stk-test-data.h"
41 #define OFONO_SERVICE "org.ofono"
42 #define STKTEST_PATH "/stktest"
43 #define STKTEST_ERROR "org.ofono.stktest.Error"
44 #define OFONO_ERROR "org.ofono.Error"
45 #define OFONO_MANAGER_INTERFACE OFONO_SERVICE ".Manager"
46 #define OFONO_MODEM_INTERFACE OFONO_SERVICE ".Modem"
47 #define OFONO_STK_INTERFACE OFONO_SERVICE ".SimToolkit"
48 #define OFONO_STKAGENT_INTERFACE OFONO_SERVICE ".SimToolkitAgent"
50 #define LISTEN_PORT 12765
53 TEST_STATE_POWERING_UP = 1,
54 TEST_STATE_REGISTERING_AGENT,
56 TEST_STATE_POWERING_DOWN,
60 TEST_RESULT_NOT_RUN = 0,
65 typedef DBusMessage *(*display_text_cb_t)(DBusMessage *msg, const char *text,
66 unsigned char icon_id,
68 typedef void (*terminal_response_func)(const unsigned char *pdu,
74 unsigned char *req_pdu;
76 unsigned char *rsp_pdu;
79 terminal_response_func tr_func;
80 enum test_result result;
83 static GMainLoop *main_loop = NULL;
84 static volatile sig_atomic_t __terminated = 0;
86 GList *cur_test = NULL;
89 static DBusConnection *conn;
90 static gboolean ofono_running = FALSE;
91 static guint modem_changed_watch;
92 enum test_state state;
93 DBusMessage *pending = NULL;
96 static guint server_watch;
97 static GAtServer *emulator;
99 /* Emulated modem state variables */
100 static int modem_mode = 0;
102 void __stktest_test_next();
103 void __stktest_test_finish(gboolean successful);
104 static gboolean create_tcp(void);
106 #define STKTEST_AGENT_ASSERT(expr) \
109 g_printerr("Assertion Failed %s:%d %s\n", \
110 __FILE__, __LINE__, #expr); \
111 __stktest_test_finish(FALSE); \
112 return stktest_error_failed(msg); \
116 #define STKTEST_RESPONSE_ASSERT(expect_pdu, expect_pdu_len, \
117 got_pdu, got_pdu_len) \
119 if ((expect_pdu_len) != (got_pdu_len)) { \
120 g_printerr("Assertion Failed %s:%d" \
121 " Wrong response len" \
122 " want: %d, got: %d\n", \
123 __FILE__, __LINE__, \
124 expect_pdu_len, got_pdu_len); \
125 __stktest_test_finish(FALSE); \
129 if (memcmp(expect_pdu, got_pdu, expect_pdu_len) != 0) { \
130 g_printerr("Assertion Failed %s:%d" \
131 "Wrong response\n", \
132 __FILE__, __LINE__); \
133 __stktest_test_finish(FALSE); \
138 static const char *to_hex(const unsigned char *data, unsigned int len)
140 static char buf[512+1];
143 for (i = 0; i < len; i++)
144 sprintf(buf + i * 2, "%02hhX", data[i]);
151 static void send_proactive_command(const unsigned char *pdu, unsigned int len)
155 sprintf(buf, "+CUSATP: %s", to_hex(pdu, len));
156 g_at_server_send_unsolicited(emulator, buf);
159 static DBusMessage *stktest_error_invalid_args(DBusMessage *msg)
161 return g_dbus_create_error(msg, STKTEST_ERROR ".InvalidArguments",
162 "Invalid arguments provided");
165 static DBusMessage *stktest_error_failed(DBusMessage *msg)
167 return g_dbus_create_error(msg, STKTEST_ERROR ".Failed",
171 static DBusMessage *stktest_error_end_session(DBusMessage *msg)
173 return g_dbus_create_error(msg, OFONO_ERROR ".EndSession",
174 "End Session Request");
177 static DBusMessage *stktest_error_go_back(DBusMessage *msg)
179 return g_dbus_create_error(msg, OFONO_ERROR ".GoBack",
183 static DBusMessage *stktest_error_busy(DBusMessage *msg)
185 return g_dbus_create_error(msg, OFONO_ERROR ".Busy",
189 static DBusMessage *agent_release(DBusConnection *conn, DBusMessage *msg,
192 g_print("Got Release\n");
195 dbus_message_unref(pending);
199 return dbus_message_new_method_return(msg);
202 static DBusMessage *agent_cancel(DBusConnection *conn, DBusMessage *msg,
206 dbus_message_unref(pending);
213 static DBusMessage *agent_display_text(DBusConnection *conn, DBusMessage *msg,
217 unsigned char icon_id;
220 display_text_cb_t func;
223 if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &text,
224 DBUS_TYPE_BYTE, &icon_id,
225 DBUS_TYPE_BOOLEAN, &urgent,
226 DBUS_TYPE_INVALID) == FALSE)
227 return stktest_error_invalid_args(msg);
229 if (cur_test == NULL)
230 return stktest_error_failed(msg);
232 test = cur_test->data;
233 func = test->agent_func;
235 if (strcmp(test->method, "DisplayText")) {
236 g_printerr("Wrong method called!\n");
237 __stktest_test_finish(FALSE);
238 return stktest_error_failed(msg);
242 g_printerr("DisplayText not expected to be called");
243 __stktest_test_finish(FALSE);
244 return stktest_error_failed(msg);
247 reply = func(msg, text, icon_id, urgent);
249 pending = dbus_message_ref(msg);
254 static void server_debug(const char *str, void *data)
256 g_print("%s: %s\n", (char *) data, str);
259 static void cgmi_cb(GAtServer *server, GAtServerRequestType type,
260 GAtResult *cmd, gpointer user)
263 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
264 g_at_server_send_info(server, "oFono", TRUE);
265 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
267 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
268 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
271 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
275 static void cgmm_cb(GAtServer *server, GAtServerRequestType type,
276 GAtResult *cmd, gpointer user)
279 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
280 g_at_server_send_info(server, "oFono pre-1.0", TRUE);
281 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
283 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
284 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
287 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
291 static void cgmr_cb(GAtServer *server, GAtServerRequestType type,
292 GAtResult *cmd, gpointer user)
297 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
298 sprintf(buf, "oFono pre-1.0 version: %s", VERSION);
299 g_at_server_send_info(server, buf, TRUE);
300 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
302 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
303 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
306 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
310 static void cgsn_cb(GAtServer *server, GAtServerRequestType type,
311 GAtResult *cmd, gpointer user)
314 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
315 g_at_server_send_info(server, "123456789", TRUE);
316 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
318 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
319 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
322 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
326 static gboolean send_ok(gpointer user)
328 GAtServer *server = user;
330 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
335 static void cfun_cb(GAtServer *server, GAtServerRequestType type,
336 GAtResult *cmd, gpointer user)
341 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
342 g_at_server_send_info(server, "+CFUN: (0-1,4)", TRUE);
343 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
345 case G_AT_SERVER_REQUEST_TYPE_QUERY:
346 snprintf(buf, sizeof(buf), "+CFUN: %d", modem_mode);
347 g_at_server_send_info(server, buf, TRUE);
348 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
350 case G_AT_SERVER_REQUEST_TYPE_SET:
355 g_at_result_iter_init(&iter, cmd);
356 g_at_result_iter_next(&iter, "");
358 if (g_at_result_iter_next_number(&iter, &mode) == FALSE)
361 if (mode != 0 && mode != 1)
364 if (modem_mode == mode) {
365 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
370 g_timeout_add_seconds(1, send_ok, server);
380 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
383 static void cusatt_cb(GAtServer *server, GAtServerRequestType type,
384 GAtResult *cmd, gpointer user)
387 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
388 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
390 case G_AT_SERVER_REQUEST_TYPE_QUERY:
391 g_at_server_send_ext_final(server, "+CME ERROR: 4");
393 case G_AT_SERVER_REQUEST_TYPE_SET:
396 const unsigned char *pdu;
399 terminal_response_func func;
401 g_at_result_iter_init(&iter, cmd);
402 g_at_result_iter_next(&iter, "");
404 if (g_at_result_iter_next_hexstring(&iter, &pdu, &len) == FALSE)
407 if (cur_test == NULL)
410 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
412 test = cur_test->data;
413 func = test->tr_func;
424 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
427 static void listen_again(gpointer user_data)
429 g_at_server_unref(emulator);
432 if (create_tcp() == TRUE)
435 g_print("Error listening to socket\n");
436 g_main_loop_quit(main_loop);
439 static void setup_emulator(GAtServer *server)
441 g_at_server_set_debug(server, server_debug, "Server");
443 g_at_server_register(server, "+CGMI", cgmi_cb, NULL, NULL);
444 g_at_server_register(server, "+CGMM", cgmm_cb, NULL, NULL);
445 g_at_server_register(server, "+CGMR", cgmr_cb, NULL, NULL);
446 g_at_server_register(server, "+CGSN", cgsn_cb, NULL, NULL);
447 g_at_server_register(server, "+CFUN", cfun_cb, NULL, NULL);
448 g_at_server_register(server, "+CUSATT", cusatt_cb, NULL, NULL);
450 g_at_server_set_disconnect_function(server, listen_again, NULL);
453 static gboolean on_socket_connected(GIOChannel *chan, GIOCondition cond,
456 struct sockaddr saddr;
457 unsigned int len = sizeof(saddr);
459 GIOChannel *client_io = NULL;
464 fd = accept(g_io_channel_unix_get_fd(chan), &saddr, &len);
468 client_io = g_io_channel_unix_new(fd);
470 emulator = g_at_server_new(client_io);
471 g_at_server_set_echo(emulator, FALSE);
472 g_io_channel_unref(client_io);
474 if (emulator == NULL)
477 setup_emulator(emulator);
484 static gboolean create_tcp(void)
486 struct sockaddr_in addr;
489 GIOChannel *server_io;
491 sk = socket(PF_INET, SOCK_STREAM, 0);
493 g_print("Can't create tcp/ip socket: %s (%d)\n",
494 strerror(errno), errno);
498 memset(&addr, 0, sizeof(addr));
500 addr.sin_family = AF_INET;
501 addr.sin_addr.s_addr = INADDR_ANY;
502 addr.sin_port = htons(LISTEN_PORT);
504 setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr));
505 if (bind(sk, (struct sockaddr *) &addr, sizeof(struct sockaddr)) < 0) {
506 g_print("Can't bind socket: %s (%d)", strerror(errno), errno);
511 if (listen(sk, 1) < 0) {
512 g_print("Can't listen on socket: %s (%d)",
513 strerror(errno), errno);
518 g_print("new tcp is created at tcp port %d\n", LISTEN_PORT);
520 server_io = g_io_channel_unix_new(sk);
521 g_io_channel_set_close_on_unref(server_io, TRUE);
523 server_watch = g_io_add_watch_full(server_io,
525 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
526 on_socket_connected, NULL, NULL);
528 g_io_channel_unref(server_io);
533 static gboolean has_stk_interface(DBusMessageIter *iter)
535 DBusMessageIter entry;
537 dbus_message_iter_recurse(iter, &entry);
539 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
540 const char *interface;
542 dbus_message_iter_get_basic(&entry, &interface);
544 if (g_str_equal(interface, OFONO_STK_INTERFACE) == TRUE)
547 dbus_message_iter_next(&entry);
553 static int send_with_reply(const char *path, const char *interface,
554 const char *method, DBusPendingCall **call,
555 DBusPendingCallNotifyFunction cb,
556 void *user_data, DBusFreeFunction free_func,
557 int timeout, int type, ...)
564 msg = dbus_message_new_method_call(OFONO_SERVICE, path,
567 g_printerr("Unable to allocate new D-Bus %s message\n", method);
572 va_start(args, type);
574 if (!dbus_message_append_args_valist(msg, type, args)) {
585 if (!dbus_connection_send_with_reply(conn, msg, &c, timeout)) {
586 g_printerr("Sending %s failed\n", method);
594 dbus_pending_call_set_notify(c, cb, user_data, free_func);
595 dbus_pending_call_unref(c);
597 dbus_message_unref(msg);
602 if (free_func && user_data)
603 free_func(user_data);
606 dbus_message_unref(msg);
611 static void set_property_reply(DBusPendingCall *call, void *user_data)
613 DBusMessage *reply = dbus_pending_call_steal_reply(call);
616 dbus_error_init(&err);
618 if (dbus_set_error_from_message(&err, reply) == TRUE) {
619 g_printerr("%s: %s\n", err.name, err.message);
620 dbus_error_free(&err);
623 dbus_message_unref(reply);
626 static int set_property(const char *path, const char *interface,
627 const char *key, int type, const void *val,
628 DBusPendingCallNotifyFunction notify,
630 DBusFreeFunction destroy)
633 DBusMessageIter iter, value;
634 DBusPendingCall *call;
635 const char *signature;
637 msg = dbus_message_new_method_call(OFONO_SERVICE, path, interface,
642 dbus_message_set_auto_start(msg, FALSE);
644 dbus_message_iter_init_append(msg, &iter);
646 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
649 case DBUS_TYPE_BOOLEAN:
650 signature = DBUS_TYPE_BOOLEAN_AS_STRING;
653 dbus_message_unref(msg);
657 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
659 dbus_message_iter_append_basic(&value, type, val);
660 dbus_message_iter_close_container(&iter, &value);
662 if (dbus_connection_send_with_reply(conn, msg, &call, -1) == FALSE) {
663 dbus_message_unref(msg);
667 dbus_message_unref(msg);
672 dbus_pending_call_set_notify(call, notify, user_data, destroy);
674 dbus_pending_call_unref(call);
679 static void register_agent_reply(DBusPendingCall *call, void *user_data)
681 DBusMessage *reply = dbus_pending_call_steal_reply(call);
685 dbus_error_init(&err);
687 if (dbus_set_error_from_message(&err, reply) == TRUE) {
688 g_printerr("%s: %s\n", err.name, err.message);
689 dbus_error_free(&err);
692 dbus_message_unref(reply);
694 state = TEST_STATE_RUNNING;
695 test = cur_test->data;
696 send_proactive_command(test->req_pdu, test->req_len);
699 static void register_agent()
701 const char *path = "/default";
704 g_print("Gained STK interface, registering agent...\n");
706 status = send_with_reply(STKTEST_PATH, OFONO_STK_INTERFACE,
707 "RegisterAgent", NULL,
708 register_agent_reply, NULL, NULL, 1,
709 DBUS_TYPE_OBJECT_PATH, &path,
713 g_printerr("Unable to register agent with oFono\n");
714 g_main_loop_quit(main_loop);
718 state = TEST_STATE_REGISTERING_AGENT;
721 static gboolean modem_changed(DBusConnection *conn,
722 DBusMessage *msg, void *user_data)
724 DBusMessageIter iter, value;
725 const char *path, *key;
728 if (dbus_message_iter_init(msg, &iter) == FALSE)
731 path = dbus_message_get_path(msg);
733 if (g_str_equal(STKTEST_PATH, path) == FALSE)
736 dbus_message_iter_get_basic(&iter, &key);
738 dbus_message_iter_next(&iter);
739 dbus_message_iter_recurse(&iter, &value);
741 if (g_str_equal(key, "Interfaces") == FALSE)
744 has_stk = has_stk_interface(&value);
747 case TEST_STATE_POWERING_UP:
751 case TEST_STATE_REGISTERING_AGENT:
752 case TEST_STATE_RUNNING:
753 if (has_stk == FALSE)
754 g_printerr("Unexpectedly lost STK interface\n");
756 case TEST_STATE_POWERING_DOWN:
763 static void powerup(void)
765 dbus_bool_t powered = TRUE;
767 state = TEST_STATE_POWERING_UP;
768 set_property(STKTEST_PATH, OFONO_MODEM_INTERFACE, "Powered",
769 DBUS_TYPE_BOOLEAN, &powered,
770 set_property_reply, NULL, NULL);
773 static void get_modems_reply(DBusPendingCall *call, void *user_data)
775 DBusMessage *reply = dbus_pending_call_steal_reply(call);
776 DBusMessageIter iter, list;
778 gboolean found = FALSE;
780 dbus_error_init(&err);
782 if (dbus_set_error_from_message(&err, reply) == TRUE) {
783 g_printerr("%s: %s\n", err.name, err.message);
784 dbus_error_free(&err);
788 if (dbus_message_has_signature(reply, "a(oa{sv})") == FALSE)
791 if (dbus_message_iter_init(reply, &iter) == FALSE)
794 dbus_message_iter_recurse(&iter, &list);
796 while (dbus_message_iter_get_arg_type(&list) == DBUS_TYPE_STRUCT) {
797 DBusMessageIter entry;
800 dbus_message_iter_recurse(&list, &entry);
801 dbus_message_iter_get_basic(&entry, &path);
803 if (g_str_equal(path, STKTEST_PATH))
806 dbus_message_iter_next(&list);
810 dbus_message_unref(reply);
812 if (found == FALSE) {
813 g_printerr("STK Test modem not found\n");
814 g_main_loop_quit(main_loop);
818 g_print("Test modem found\n");
820 modem_changed_watch = g_dbus_add_signal_watch(conn, OFONO_SERVICE,
822 OFONO_MODEM_INTERFACE,
827 if (create_tcp() == FALSE) {
828 g_printerr("Unable to listen on modem emulator socket\n");
829 g_main_loop_quit(main_loop);
832 __stktest_test_next();
835 static int get_modems(DBusConnection *conn)
838 DBusPendingCall *call;
840 msg = dbus_message_new_method_call(OFONO_SERVICE, "/",
841 OFONO_MANAGER_INTERFACE, "GetModems");
845 dbus_message_set_auto_start(msg, FALSE);
847 g_print("getting modems\n");
849 if (dbus_connection_send_with_reply(conn, msg, &call, -1) == FALSE) {
850 dbus_message_unref(msg);
854 dbus_message_unref(msg);
859 dbus_pending_call_set_notify(call, get_modems_reply, conn, NULL);
861 dbus_pending_call_unref(call);
866 static const GDBusMethodTable agent_methods[] = {
867 { GDBUS_METHOD("Release", NULL, NULL, agent_release) },
868 { GDBUS_ASYNC_METHOD("DisplayText",
869 GDBUS_ARGS({ "text", "s" }, { "icon_id", "y" },
870 { "urgent", "b" }), NULL,
871 agent_display_text) },
872 { GDBUS_NOREPLY_METHOD("Cancel", NULL, NULL, agent_cancel) },
876 static void ofono_connect(DBusConnection *conn, void *user_data)
878 g_print("starting telephony interface\n");
880 if (!g_dbus_register_interface(conn, "/default",
881 OFONO_STKAGENT_INTERFACE,
882 agent_methods, NULL, NULL,
884 g_printerr("Unable to register local agent");
885 g_main_loop_quit(main_loop);
888 ofono_running = TRUE;
892 static void ofono_disconnect(DBusConnection *conn, void *user_data)
894 g_print("stopping telephony interface\n");
896 g_dbus_unregister_interface(conn, "/default", OFONO_STKAGENT_INTERFACE);
898 ofono_running = FALSE;
900 g_dbus_remove_watch(conn, modem_changed_watch);
901 modem_changed_watch = 0;
904 g_source_remove(server_watch);
908 g_at_server_unref(emulator);
912 static void sig_term(int sig)
914 if (__terminated > 0)
919 g_print("Terminating\n");
921 g_main_loop_quit(main_loop);
924 static void disconnect_callback(DBusConnection *conn, void *user_data)
926 g_printerr("D-Bus disconnect\n");
928 g_main_loop_quit(main_loop);
931 static gboolean end_session_and_finish(gpointer user_data)
933 g_at_server_send_unsolicited(emulator, "+CUSATEND");
934 __stktest_test_finish(TRUE);
939 static void expect_response_and_finish(const unsigned char *pdu,
942 struct test *test = cur_test->data;
944 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
946 g_idle_add(end_session_and_finish, NULL);
949 static void expect_response(const unsigned char *pdu, unsigned int len)
951 struct test *test = cur_test->data;
953 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
956 static gboolean poweroff_not_canceled_after_3(gpointer user_data)
958 __stktest_test_finish(pending != NULL);
962 static gboolean end_session_and_not_canceled_after_3(gpointer user_data)
964 g_at_server_send_unsolicited(emulator, "+CUSATEND");
965 g_timeout_add_seconds(3, poweroff_not_canceled_after_3, NULL);
970 static void expect_response_and_not_canceled_after_3(const unsigned char *pdu,
973 struct test *test = cur_test->data;
975 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
977 g_idle_add(end_session_and_not_canceled_after_3, NULL);
980 static gboolean poweroff_and_canceled_after_21(gpointer user_data)
982 __stktest_test_finish(pending == NULL);
986 static gboolean end_session_and_canceled_after_21(gpointer user_data)
988 g_at_server_send_unsolicited(emulator, "+CUSATEND");
989 g_timeout_add_seconds(21, poweroff_and_canceled_after_21, NULL);
994 static void expect_response_and_canceled_after_21(const unsigned char *pdu,
997 struct test *test = cur_test->data;
999 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
1001 g_idle_add(end_session_and_canceled_after_21, NULL);
1004 static DBusMessage *test_display_text_11(DBusMessage *msg,
1006 unsigned char icon_id,
1009 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 1"));
1010 STKTEST_AGENT_ASSERT(icon_id == 0);
1011 STKTEST_AGENT_ASSERT(urgent == FALSE);
1013 return dbus_message_new_method_return(msg);
1016 static DBusMessage *test_display_text_12(DBusMessage *msg,
1018 unsigned char icon_id,
1021 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 1"));
1022 STKTEST_AGENT_ASSERT(icon_id == 0);
1023 STKTEST_AGENT_ASSERT(urgent == FALSE);
1025 return stktest_error_busy(msg);
1028 static DBusMessage *test_display_text_13(DBusMessage *msg,
1030 unsigned char icon_id,
1033 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 2"));
1034 STKTEST_AGENT_ASSERT(icon_id == 0);
1035 STKTEST_AGENT_ASSERT(urgent == TRUE);
1037 return dbus_message_new_method_return(msg);
1040 static DBusMessage *test_display_text_14(DBusMessage *msg,
1042 unsigned char icon_id,
1045 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 3"));
1046 STKTEST_AGENT_ASSERT(icon_id == 0);
1047 STKTEST_AGENT_ASSERT(urgent == FALSE);
1049 return dbus_message_new_method_return(msg);
1052 static DBusMessage *test_display_text_15(DBusMessage *msg,
1054 unsigned char icon_id,
1057 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 4"));
1058 STKTEST_AGENT_ASSERT(icon_id == 0);
1059 STKTEST_AGENT_ASSERT(urgent == FALSE);
1064 static DBusMessage *test_display_text_16(DBusMessage *msg,
1066 unsigned char icon_id,
1069 STKTEST_AGENT_ASSERT(g_str_equal(text, "This command instructs the ME"
1070 " to display a text message. "
1071 "It allows the SIM to define "
1072 "the priority of that message, "
1073 "and the text string format. "
1074 "Two types of prio"));
1075 STKTEST_AGENT_ASSERT(icon_id == 0);
1076 STKTEST_AGENT_ASSERT(urgent == FALSE);
1078 return dbus_message_new_method_return(msg);
1081 static DBusMessage *test_display_text_17(DBusMessage *msg,
1083 unsigned char icon_id,
1086 /* oFono gives rich text formatting in HTML */
1087 STKTEST_AGENT_ASSERT(g_str_equal(text, "<GO-BACKWARDS>"));
1088 STKTEST_AGENT_ASSERT(icon_id == 0);
1089 STKTEST_AGENT_ASSERT(urgent == FALSE);
1091 return stktest_error_go_back(msg);
1094 static DBusMessage *test_display_text_18(DBusMessage *msg,
1096 unsigned char icon_id,
1099 /* oFono gives rich text formatting in HTML */
1100 STKTEST_AGENT_ASSERT(g_str_equal(text, "<ABORT>"));
1101 STKTEST_AGENT_ASSERT(icon_id == 0);
1102 STKTEST_AGENT_ASSERT(urgent == FALSE);
1104 return stktest_error_end_session(msg);
1107 static DBusMessage *test_display_text_21(DBusMessage *msg,
1109 unsigned char icon_id,
1112 STKTEST_AGENT_ASSERT(g_str_equal(text, "<TIME-OUT>"));
1113 STKTEST_AGENT_ASSERT(icon_id == 0);
1114 STKTEST_AGENT_ASSERT(urgent == FALSE);
1119 static DBusMessage *test_display_text_31(DBusMessage *msg,
1121 unsigned char icon_id,
1124 static const char *expected = "This command instructs the ME to display"
1125 " a text message, and/or an icon "
1126 "(see 6.5.4). It allows the "
1127 "SIM to define the priority of that "
1128 "message, and the text string format. "
1129 "Two types of priority are defined:- "
1130 "display normal priority text and/";
1131 STKTEST_AGENT_ASSERT(g_str_equal(text, expected));
1132 STKTEST_AGENT_ASSERT(icon_id == 0);
1133 STKTEST_AGENT_ASSERT(urgent == FALSE);
1135 return dbus_message_new_method_return(msg);
1138 static DBusMessage *test_display_text_41(DBusMessage *msg,
1140 unsigned char icon_id,
1143 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 1"));
1144 STKTEST_AGENT_ASSERT(icon_id == 0);
1145 STKTEST_AGENT_ASSERT(urgent == FALSE);
1150 static DBusMessage *test_display_text_42(DBusMessage *msg,
1152 unsigned char icon_id,
1155 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 2"));
1156 STKTEST_AGENT_ASSERT(icon_id == 0);
1157 STKTEST_AGENT_ASSERT(urgent == FALSE);
1162 static gboolean user_response(gpointer user_data)
1164 if (pending == NULL) {
1165 __stktest_test_finish(FALSE);
1169 g_dbus_send_reply(conn, pending, DBUS_TYPE_INVALID);
1170 dbus_message_unref(pending);
1173 __stktest_test_finish(TRUE);
1178 static DBusMessage *test_display_text_43(DBusMessage *msg,
1180 unsigned char icon_id,
1183 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 3"));
1184 STKTEST_AGENT_ASSERT(icon_id == 0);
1185 STKTEST_AGENT_ASSERT(urgent == FALSE);
1187 g_timeout_add_seconds(3, user_response, NULL);
1191 static DBusMessage *test_display_text_51(DBusMessage *msg,
1193 unsigned char icon_id,
1196 STKTEST_AGENT_ASSERT(g_str_equal(text, "Basic Icon"));
1197 STKTEST_AGENT_ASSERT(icon_id == 1);
1198 STKTEST_AGENT_ASSERT(urgent == FALSE);
1200 return dbus_message_new_method_return(msg);
1203 static DBusMessage *test_display_text_52(DBusMessage *msg,
1205 unsigned char icon_id,
1208 STKTEST_AGENT_ASSERT(g_str_equal(text, "Colour Icon"));
1209 STKTEST_AGENT_ASSERT(icon_id == 2);
1210 STKTEST_AGENT_ASSERT(urgent == FALSE);
1212 return dbus_message_new_method_return(msg);
1215 static DBusMessage *test_display_text_53(DBusMessage *msg,
1217 unsigned char icon_id,
1220 STKTEST_AGENT_ASSERT(g_str_equal(text, "Basic Icon"));
1221 STKTEST_AGENT_ASSERT(icon_id == 1);
1222 STKTEST_AGENT_ASSERT(urgent == FALSE);
1224 return dbus_message_new_method_return(msg);
1227 static DBusMessage *test_display_text_61(DBusMessage *msg,
1229 unsigned char icon_id,
1232 STKTEST_AGENT_ASSERT(g_str_equal(text, "ЗДРАВСТВУЙТЕ"));
1233 STKTEST_AGENT_ASSERT(icon_id == 0);
1234 STKTEST_AGENT_ASSERT(urgent == FALSE);
1236 return dbus_message_new_method_return(msg);
1239 static DBusMessage *test_display_text_71(DBusMessage *msg,
1241 unsigned char icon_id,
1244 STKTEST_AGENT_ASSERT(g_str_equal(text, "10 Second"));
1245 STKTEST_AGENT_ASSERT(icon_id == 0);
1246 STKTEST_AGENT_ASSERT(urgent == FALSE);
1251 static DBusMessage *test_display_text_81(DBusMessage *msg,
1253 unsigned char icon_id,
1256 const char *expect =
1257 "<div style=\"text-align: left;\"><span style=\"color: "
1258 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1261 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1262 STKTEST_AGENT_ASSERT(icon_id == 0);
1263 STKTEST_AGENT_ASSERT(urgent == FALSE);
1265 return dbus_message_new_method_return(msg);
1268 static DBusMessage *test_display_text_82(DBusMessage *msg,
1270 unsigned char icon_id,
1273 const char *expect =
1274 "<div style=\"text-align: center;\"><span style=\"color: "
1275 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1278 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1279 STKTEST_AGENT_ASSERT(icon_id == 0);
1280 STKTEST_AGENT_ASSERT(urgent == FALSE);
1282 return dbus_message_new_method_return(msg);
1285 static DBusMessage *test_display_text_83(DBusMessage *msg,
1287 unsigned char icon_id,
1290 const char *expect =
1291 "<div style=\"text-align: right;\"><span style=\"color: "
1292 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1295 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1296 STKTEST_AGENT_ASSERT(icon_id == 0);
1297 STKTEST_AGENT_ASSERT(urgent == FALSE);
1299 return dbus_message_new_method_return(msg);
1302 static DBusMessage *test_display_text_84(DBusMessage *msg,
1304 unsigned char icon_id,
1307 const char *expect =
1308 "<div style=\"text-align: left;\"><span style=\"font-size: "
1309 "big;color: #347235;background-color: #FFFF00;\">"
1310 "Text Attribute 1</span></div>";
1312 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1313 STKTEST_AGENT_ASSERT(icon_id == 0);
1314 STKTEST_AGENT_ASSERT(urgent == FALSE);
1316 return dbus_message_new_method_return(msg);
1319 static DBusMessage *test_display_text_85(DBusMessage *msg,
1321 unsigned char icon_id,
1324 const char *expect =
1325 "<div style=\"text-align: left;\"><span style=\"font-size: "
1326 "small;color: #347235;background-color: #FFFF00;\">"
1327 "Text Attribute 1</span></div>";
1329 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1330 STKTEST_AGENT_ASSERT(icon_id == 0);
1331 STKTEST_AGENT_ASSERT(urgent == FALSE);
1333 return dbus_message_new_method_return(msg);
1336 static DBusMessage *test_display_text_86(DBusMessage *msg,
1338 unsigned char icon_id,
1341 const char *expect =
1342 "<div style=\"text-align: left;\"><span style=\"font-weight: "
1343 "bold;color: #347235;background-color: #FFFF00;\">"
1344 "Text Attribute 1</span></div>";
1346 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1347 STKTEST_AGENT_ASSERT(icon_id == 0);
1348 STKTEST_AGENT_ASSERT(urgent == FALSE);
1350 return dbus_message_new_method_return(msg);
1353 static DBusMessage *test_display_text_87(DBusMessage *msg,
1355 unsigned char icon_id,
1358 const char *expect =
1359 "<div style=\"text-align: left;\"><span style=\"font-style: "
1360 "italic;color: #347235;background-color: #FFFF00;\">"
1361 "Text Attribute 1</span></div>";
1363 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1364 STKTEST_AGENT_ASSERT(icon_id == 0);
1365 STKTEST_AGENT_ASSERT(urgent == FALSE);
1367 return dbus_message_new_method_return(msg);
1370 static DBusMessage *test_display_text_88(DBusMessage *msg,
1372 unsigned char icon_id,
1375 const char *expect =
1376 "<div style=\"text-align: left;\"><span style=\""
1377 "text-decoration: underline;color: #347235;"
1378 "background-color: #FFFF00;\">Text Attribute 1</span></div>";
1380 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1381 STKTEST_AGENT_ASSERT(icon_id == 0);
1382 STKTEST_AGENT_ASSERT(urgent == FALSE);
1384 return dbus_message_new_method_return(msg);
1387 static DBusMessage *test_display_text_89(DBusMessage *msg,
1389 unsigned char icon_id,
1392 const char *expect =
1393 "<div style=\"text-align: left;\"><span style=\""
1394 "text-decoration: line-through;color: #347235;"
1395 "background-color: #FFFF00;\">Text Attribute 1</span></div>";
1397 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1398 STKTEST_AGENT_ASSERT(icon_id == 0);
1399 STKTEST_AGENT_ASSERT(urgent == FALSE);
1401 return dbus_message_new_method_return(msg);
1404 static DBusMessage *test_display_text_810(DBusMessage *msg,
1406 unsigned char icon_id,
1409 const char *expect =
1410 "<div style=\"text-align: left;\"><span style=\"color: "
1411 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1414 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1415 STKTEST_AGENT_ASSERT(icon_id == 0);
1416 STKTEST_AGENT_ASSERT(urgent == FALSE);
1418 return dbus_message_new_method_return(msg);
1421 static void power_down_reply(DBusPendingCall *call, void *user_data)
1423 __stktest_test_next();
1426 void __stktest_test_finish(gboolean successful)
1428 struct test *test = cur_test->data;
1429 dbus_bool_t powered = FALSE;
1431 test->result = successful ? TEST_RESULT_PASSED : TEST_RESULT_FAILED;
1433 state = TEST_STATE_POWERING_DOWN;
1434 set_property(STKTEST_PATH, OFONO_MODEM_INTERFACE, "Powered",
1435 DBUS_TYPE_BOOLEAN, &powered,
1436 power_down_reply, NULL, NULL);
1439 void __stktest_test_next()
1441 if (cur_test == NULL)
1444 cur_test = cur_test->next;
1446 if (cur_test == NULL) {
1447 g_main_loop_quit(main_loop);
1454 static void stktest_add_test(const char *name, const char *method,
1455 const unsigned char *req, unsigned int req_len,
1456 const unsigned char *rsp, unsigned int rsp_len,
1458 terminal_response_func tr_func)
1460 struct test *test = g_new0(struct test, 1);
1462 test->name = g_strdup(name);
1463 test->method = g_strdup(method);
1464 test->req_pdu = g_memdup(req, req_len);
1465 test->req_len = req_len;
1466 test->rsp_pdu = g_memdup(rsp, rsp_len);
1467 test->rsp_len = rsp_len;
1468 test->agent_func = agent_func;
1469 test->tr_func = tr_func;
1471 tests = g_list_append(tests, test);
1474 static void __stktest_test_init(void)
1476 stktest_add_test("Display Text 1.1", "DisplayText",
1477 display_text_111, sizeof(display_text_111),
1478 display_text_response_111,
1479 sizeof(display_text_response_111),
1480 test_display_text_11,
1481 expect_response_and_finish);
1482 stktest_add_test("Display Text 1.2", "DisplayText",
1483 display_text_111, sizeof(display_text_111),
1484 display_text_response_121,
1485 sizeof(display_text_response_121),
1486 test_display_text_12,
1487 expect_response_and_finish);
1488 stktest_add_test("Display Text 1.3", "DisplayText",
1489 display_text_131, sizeof(display_text_131),
1490 display_text_response_131,
1491 sizeof(display_text_response_131),
1492 test_display_text_13,
1493 expect_response_and_finish);
1494 stktest_add_test("Display Text 1.4", "DisplayText",
1495 display_text_141, sizeof(display_text_141),
1496 display_text_response_141,
1497 sizeof(display_text_response_141),
1498 test_display_text_14,
1499 expect_response_and_finish);
1500 stktest_add_test("Display Text 1.5", "DisplayText",
1501 display_text_151, sizeof(display_text_151),
1502 display_text_response_151,
1503 sizeof(display_text_response_151),
1504 test_display_text_15,
1505 expect_response_and_finish);
1506 stktest_add_test("Display Text 1.6", "DisplayText",
1507 display_text_161, sizeof(display_text_161),
1508 display_text_response_161,
1509 sizeof(display_text_response_161),
1510 test_display_text_16,
1511 expect_response_and_finish);
1512 stktest_add_test("Display Text 1.7", "DisplayText",
1513 display_text_171, sizeof(display_text_171),
1514 display_text_response_171,
1515 sizeof(display_text_response_171),
1516 test_display_text_17,
1517 expect_response_and_finish);
1518 stktest_add_test("Display Text 1.8", "DisplayText",
1519 display_text_181, sizeof(display_text_181),
1520 display_text_response_181,
1521 sizeof(display_text_response_181),
1522 test_display_text_18,
1523 expect_response_and_finish);
1524 stktest_add_test("Display Text 1.9", "DisplayText",
1525 display_text_191, sizeof(display_text_191),
1526 display_text_response_191,
1527 sizeof(display_text_response_191),
1528 NULL, expect_response_and_finish);
1529 stktest_add_test("Display Text 2.1", "DisplayText",
1530 display_text_211, sizeof(display_text_211),
1531 display_text_response_211,
1532 sizeof(display_text_response_211),
1533 test_display_text_21,
1534 expect_response_and_finish);
1535 stktest_add_test("Display Text 3.1", "DisplayText",
1536 display_text_311, sizeof(display_text_311),
1537 display_text_response_311,
1538 sizeof(display_text_response_311),
1539 test_display_text_31,
1540 expect_response_and_finish);
1541 stktest_add_test("Display Text 4.1", "DisplayText",
1542 display_text_411, sizeof(display_text_411),
1543 display_text_response_411,
1544 sizeof(display_text_response_411),
1545 test_display_text_41,
1546 expect_response_and_not_canceled_after_3);
1547 stktest_add_test("Display Text 4.2", "DisplayText",
1548 display_text_421, sizeof(display_text_421),
1549 display_text_response_421,
1550 sizeof(display_text_response_421),
1551 test_display_text_42,
1552 expect_response_and_canceled_after_21);
1553 stktest_add_test("Display Text 4.3", "DisplayText",
1554 display_text_431, sizeof(display_text_431),
1555 display_text_response_431,
1556 sizeof(display_text_response_431),
1557 test_display_text_43, expect_response);
1558 stktest_add_test("Display Text 5.1A", "DisplayText",
1559 display_text_511, sizeof(display_text_511),
1560 display_text_response_511a,
1561 sizeof(display_text_response_511a),
1562 test_display_text_51,
1563 expect_response_and_finish);
1564 stktest_add_test("Display Text 5.2A", "DisplayText",
1565 display_text_521, sizeof(display_text_521),
1566 display_text_response_521a,
1567 sizeof(display_text_response_521a),
1568 test_display_text_52,
1569 expect_response_and_finish);
1570 stktest_add_test("Display Text 5.3A", "DisplayText",
1571 display_text_531, sizeof(display_text_531),
1572 display_text_response_531a,
1573 sizeof(display_text_response_531a),
1574 test_display_text_53,
1575 expect_response_and_finish);
1576 stktest_add_test("Display Text 6.1", "DisplayText",
1577 display_text_611, sizeof(display_text_611),
1578 display_text_response_611,
1579 sizeof(display_text_response_611),
1580 test_display_text_61,
1581 expect_response_and_finish);
1582 stktest_add_test("Display Text 7.1", "DisplayText",
1583 display_text_711, sizeof(display_text_711),
1584 display_text_response_711,
1585 sizeof(display_text_response_711),
1586 test_display_text_71,
1587 expect_response_and_finish);
1589 * We skip parts where the UI is asked to display simple text to ensure
1590 * that the alignment, font is set up correctly and not 'remembered'
1591 * from a previous state. oFono does not keep any state of the
1594 stktest_add_test("Display Text 8.1", "DisplayText",
1595 display_text_811, sizeof(display_text_811),
1596 display_text_response_811,
1597 sizeof(display_text_response_811),
1598 test_display_text_81,
1599 expect_response_and_finish);
1600 stktest_add_test("Display Text 8.2", "DisplayText",
1601 display_text_821, sizeof(display_text_821),
1602 display_text_response_821,
1603 sizeof(display_text_response_821),
1604 test_display_text_82,
1605 expect_response_and_finish);
1606 stktest_add_test("Display Text 8.3", "DisplayText",
1607 display_text_831, sizeof(display_text_831),
1608 display_text_response_831,
1609 sizeof(display_text_response_831),
1610 test_display_text_83,
1611 expect_response_and_finish);
1612 stktest_add_test("Display Text 8.4", "DisplayText",
1613 display_text_841, sizeof(display_text_841),
1614 display_text_response_841,
1615 sizeof(display_text_response_841),
1616 test_display_text_84,
1617 expect_response_and_finish);
1618 stktest_add_test("Display Text 8.5", "DisplayText",
1619 display_text_851, sizeof(display_text_851),
1620 display_text_response_851,
1621 sizeof(display_text_response_851),
1622 test_display_text_85,
1623 expect_response_and_finish);
1624 stktest_add_test("Display Text 8.6", "DisplayText",
1625 display_text_861, sizeof(display_text_861),
1626 display_text_response_861,
1627 sizeof(display_text_response_861),
1628 test_display_text_86,
1629 expect_response_and_finish);
1630 stktest_add_test("Display Text 8.7", "DisplayText",
1631 display_text_871, sizeof(display_text_871),
1632 display_text_response_871,
1633 sizeof(display_text_response_871),
1634 test_display_text_87,
1635 expect_response_and_finish);
1636 stktest_add_test("Display Text 8.8", "DisplayText",
1637 display_text_881, sizeof(display_text_881),
1638 display_text_response_881,
1639 sizeof(display_text_response_881),
1640 test_display_text_88,
1641 expect_response_and_finish);
1642 stktest_add_test("Display Text 8.9", "DisplayText",
1643 display_text_891, sizeof(display_text_891),
1644 display_text_response_891,
1645 sizeof(display_text_response_891),
1646 test_display_text_89,
1647 expect_response_and_finish);
1648 stktest_add_test("Display Text 8.10", "DisplayText",
1649 display_text_8101, sizeof(display_text_8101),
1650 display_text_response_8101,
1651 sizeof(display_text_response_8101),
1652 test_display_text_810,
1653 expect_response_and_finish);
1656 static void test_destroy(gpointer user_data)
1658 struct test *test = user_data;
1661 g_free(test->method);
1662 g_free(test->req_pdu);
1663 g_free(test->rsp_pdu);
1668 static void __stktest_test_summarize(void)
1672 g_print("\n\nTest Summary\n");
1673 g_print("============\n");
1675 for (l = tests; l; l = l->next) {
1676 struct test *test = l->data;
1678 g_print("%-60s", test->name);
1680 switch (test->result) {
1681 case TEST_RESULT_NOT_RUN:
1682 g_print("Not Run\n");
1684 case TEST_RESULT_PASSED:
1685 g_print("Passed\n");
1687 case TEST_RESULT_FAILED:
1688 g_print("Failed\n");
1694 static void __stktest_test_cleanup(void)
1696 g_list_free_full(tests, test_destroy);
1701 static gboolean option_version = FALSE;
1703 static GOptionEntry options[] = {
1704 { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
1705 "Show version information and exit" },
1709 int main(int argc, char **argv)
1711 GOptionContext *context;
1712 GError *error = NULL;
1715 struct sigaction sa;
1717 context = g_option_context_new(NULL);
1718 g_option_context_add_main_entries(context, options, NULL);
1720 if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
1721 if (error != NULL) {
1722 g_printerr("%s\n", error->message);
1723 g_error_free(error);
1725 g_printerr("An unknown error occurred\n");
1729 g_option_context_free(context);
1731 if (option_version == TRUE) {
1732 printf("%s\n", VERSION);
1736 __stktest_test_init();
1738 main_loop = g_main_loop_new(NULL, FALSE);
1740 dbus_error_init(&err);
1742 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
1744 if (dbus_error_is_set(&err) == TRUE) {
1745 fprintf(stderr, "%s\n", err.message);
1746 dbus_error_free(&err);
1748 fprintf(stderr, "Can't register with system bus\n");
1752 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
1754 memset(&sa, 0, sizeof(sa));
1755 sa.sa_handler = sig_term;
1756 sigaction(SIGINT, &sa, NULL);
1757 sigaction(SIGTERM, &sa, NULL);
1759 watch = g_dbus_add_service_watch(conn, OFONO_SERVICE,
1760 ofono_connect, ofono_disconnect, NULL, NULL);
1762 g_main_loop_run(main_loop);
1764 g_dbus_remove_watch(conn, watch);
1766 if (ofono_running == TRUE)
1767 ofono_disconnect(conn, NULL);
1769 dbus_connection_unref(conn);
1771 g_main_loop_unref(main_loop);
1773 __stktest_test_summarize();
1774 __stktest_test_cleanup();