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 DBusMessage *(*get_inkey_cb_t)(DBusMessage *msg, const char *alpha,
69 unsigned char icon_id);
70 typedef void (*terminal_response_func)(const unsigned char *pdu,
76 unsigned char *req_pdu;
78 unsigned char *rsp_pdu;
81 terminal_response_func tr_func;
82 enum test_result result;
85 static GMainLoop *main_loop = NULL;
86 static volatile sig_atomic_t __terminated = 0;
87 static GList *tests = NULL;
88 static GList *cur_test = NULL;
91 static DBusConnection *conn;
92 static gboolean ofono_running = FALSE;
93 static guint modem_changed_watch;
94 static enum test_state state;
95 static DBusMessage *pending = NULL;
98 static guint server_watch;
99 static GAtServer *emulator;
101 /* Emulated modem state variables */
102 static int modem_mode = 0;
104 void __stktest_test_next();
105 void __stktest_test_finish(gboolean successful);
106 static gboolean create_tcp(void);
108 #define STKTEST_AGENT_ASSERT(expr) \
111 g_printerr("Assertion Failed %s:%d %s\n", \
112 __FILE__, __LINE__, #expr); \
113 __stktest_test_finish(FALSE); \
114 return stktest_error_failed(msg); \
118 #define STKTEST_RESPONSE_ASSERT(expect_pdu, expect_pdu_len, \
119 got_pdu, got_pdu_len) \
121 if ((expect_pdu_len) != (got_pdu_len)) { \
122 g_printerr("Assertion Failed %s:%d" \
123 " Wrong response len" \
124 " want: %d, got: %d\n", \
125 __FILE__, __LINE__, \
126 expect_pdu_len, got_pdu_len); \
127 __stktest_test_finish(FALSE); \
131 if (memcmp(expect_pdu, got_pdu, expect_pdu_len) != 0) { \
132 g_printerr("Assertion Failed %s:%d" \
133 "Wrong response\n", \
134 __FILE__, __LINE__); \
135 __stktest_test_finish(FALSE); \
140 static const char *to_hex(const unsigned char *data, unsigned int len)
142 static char buf[512+1];
145 for (i = 0; i < len; i++)
146 sprintf(buf + i * 2, "%02hhX", data[i]);
153 static void send_proactive_command(const unsigned char *pdu, unsigned int len)
157 sprintf(buf, "+CUSATP: %s", to_hex(pdu, len));
158 g_at_server_send_unsolicited(emulator, buf);
161 static DBusMessage *stktest_error_invalid_args(DBusMessage *msg)
163 return g_dbus_create_error(msg, STKTEST_ERROR ".InvalidArguments",
164 "Invalid arguments provided");
167 static DBusMessage *stktest_error_failed(DBusMessage *msg)
169 return g_dbus_create_error(msg, STKTEST_ERROR ".Failed",
173 static DBusMessage *stktest_error_end_session(DBusMessage *msg)
175 return g_dbus_create_error(msg, OFONO_ERROR ".EndSession",
176 "End Session Request");
179 static DBusMessage *stktest_error_go_back(DBusMessage *msg)
181 return g_dbus_create_error(msg, OFONO_ERROR ".GoBack",
185 static DBusMessage *stktest_error_busy(DBusMessage *msg)
187 return g_dbus_create_error(msg, OFONO_ERROR ".Busy",
191 static DBusMessage *agent_release(DBusConnection *conn, DBusMessage *msg,
194 g_print("Got Release\n");
197 dbus_message_unref(pending);
201 return dbus_message_new_method_return(msg);
204 static DBusMessage *agent_cancel(DBusConnection *conn, DBusMessage *msg,
208 dbus_message_unref(pending);
215 static DBusMessage *agent_display_text(DBusConnection *conn, DBusMessage *msg,
219 unsigned char icon_id;
222 display_text_cb_t func;
225 if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &text,
226 DBUS_TYPE_BYTE, &icon_id,
227 DBUS_TYPE_BOOLEAN, &urgent,
228 DBUS_TYPE_INVALID) == FALSE)
229 return stktest_error_invalid_args(msg);
231 if (cur_test == NULL)
232 return stktest_error_failed(msg);
234 test = cur_test->data;
235 func = test->agent_func;
237 if (strcmp(test->method, "DisplayText")) {
238 g_printerr("Wrong method called!\n");
239 __stktest_test_finish(FALSE);
240 return stktest_error_failed(msg);
244 g_printerr("DisplayText not expected to be called");
245 __stktest_test_finish(FALSE);
246 return stktest_error_failed(msg);
249 reply = func(msg, text, icon_id, urgent);
251 pending = dbus_message_ref(msg);
256 #define GET_INKEY_TEMPLATE(func, method_name) \
257 static DBusMessage *func(DBusConnection *conn, DBusMessage *msg, \
261 unsigned char icon_id; \
263 get_inkey_cb_t func; \
264 DBusMessage *reply; \
266 if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &alpha, \
267 DBUS_TYPE_BYTE, &icon_id, \
268 DBUS_TYPE_INVALID) == FALSE) \
269 return stktest_error_invalid_args(msg); \
271 if (cur_test == NULL) \
272 return stktest_error_failed(msg); \
274 test = cur_test->data; \
275 func = test->agent_func; \
277 if (strcmp(test->method, method_name)) { \
278 g_printerr("Wrong method called!\n"); \
279 __stktest_test_finish(FALSE); \
280 return stktest_error_failed(msg); \
283 if (func == NULL) { \
284 g_printerr(method_name " not expected to be called"); \
285 __stktest_test_finish(FALSE); \
286 return stktest_error_failed(msg); \
289 reply = func(msg, alpha, icon_id); \
291 pending = dbus_message_ref(msg); \
296 GET_INKEY_TEMPLATE(agent_request_key, "RequestKey")
297 GET_INKEY_TEMPLATE(agent_request_digit, "RequestDigit")
298 GET_INKEY_TEMPLATE(agent_request_confirmation, "RequestConfirmation")
300 static void server_debug(const char *str, void *data)
302 g_print("%s: %s\n", (char *) data, str);
305 static void cgmi_cb(GAtServer *server, GAtServerRequestType type,
306 GAtResult *cmd, gpointer user)
309 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
310 g_at_server_send_info(server, "oFono", TRUE);
311 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
313 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
314 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
317 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
321 static void cgmm_cb(GAtServer *server, GAtServerRequestType type,
322 GAtResult *cmd, gpointer user)
325 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
326 g_at_server_send_info(server, "oFono pre-1.0", TRUE);
327 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
329 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
330 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
333 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
337 static void cgmr_cb(GAtServer *server, GAtServerRequestType type,
338 GAtResult *cmd, gpointer user)
343 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
344 sprintf(buf, "oFono pre-1.0 version: %s", VERSION);
345 g_at_server_send_info(server, buf, TRUE);
346 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
348 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
349 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
352 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
356 static void cgsn_cb(GAtServer *server, GAtServerRequestType type,
357 GAtResult *cmd, gpointer user)
360 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
361 g_at_server_send_info(server, "123456789", TRUE);
362 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
364 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
365 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
368 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
372 static gboolean send_ok(gpointer user)
374 GAtServer *server = user;
376 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
381 static void cfun_cb(GAtServer *server, GAtServerRequestType type,
382 GAtResult *cmd, gpointer user)
387 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
388 g_at_server_send_info(server, "+CFUN: (0-1,4)", TRUE);
389 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
391 case G_AT_SERVER_REQUEST_TYPE_QUERY:
392 snprintf(buf, sizeof(buf), "+CFUN: %d", modem_mode);
393 g_at_server_send_info(server, buf, TRUE);
394 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
396 case G_AT_SERVER_REQUEST_TYPE_SET:
401 g_at_result_iter_init(&iter, cmd);
402 g_at_result_iter_next(&iter, "");
404 if (g_at_result_iter_next_number(&iter, &mode) == FALSE)
407 if (mode != 0 && mode != 1)
410 if (modem_mode == mode) {
411 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
416 g_timeout_add_seconds(1, send_ok, server);
426 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
429 static void cusatt_cb(GAtServer *server, GAtServerRequestType type,
430 GAtResult *cmd, gpointer user)
433 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
434 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
436 case G_AT_SERVER_REQUEST_TYPE_QUERY:
437 g_at_server_send_ext_final(server, "+CME ERROR: 4");
439 case G_AT_SERVER_REQUEST_TYPE_SET:
442 const unsigned char *pdu;
445 terminal_response_func func;
447 g_at_result_iter_init(&iter, cmd);
448 g_at_result_iter_next(&iter, "");
450 if (g_at_result_iter_next_hexstring(&iter, &pdu, &len) == FALSE)
453 if (cur_test == NULL)
456 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
458 test = cur_test->data;
459 func = test->tr_func;
470 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
473 static void listen_again(gpointer user_data)
475 g_at_server_unref(emulator);
478 if (create_tcp() == TRUE)
481 g_print("Error listening to socket\n");
482 g_main_loop_quit(main_loop);
485 static void setup_emulator(GAtServer *server)
487 g_at_server_set_debug(server, server_debug, "Server");
489 g_at_server_register(server, "+CGMI", cgmi_cb, NULL, NULL);
490 g_at_server_register(server, "+CGMM", cgmm_cb, NULL, NULL);
491 g_at_server_register(server, "+CGMR", cgmr_cb, NULL, NULL);
492 g_at_server_register(server, "+CGSN", cgsn_cb, NULL, NULL);
493 g_at_server_register(server, "+CFUN", cfun_cb, NULL, NULL);
494 g_at_server_register(server, "+CUSATT", cusatt_cb, NULL, NULL);
496 g_at_server_set_disconnect_function(server, listen_again, NULL);
499 static gboolean on_socket_connected(GIOChannel *chan, GIOCondition cond,
502 struct sockaddr saddr;
503 unsigned int len = sizeof(saddr);
505 GIOChannel *client_io = NULL;
510 fd = accept(g_io_channel_unix_get_fd(chan), &saddr, &len);
514 client_io = g_io_channel_unix_new(fd);
516 emulator = g_at_server_new(client_io);
517 g_at_server_set_echo(emulator, FALSE);
518 g_io_channel_unref(client_io);
520 if (emulator == NULL)
523 setup_emulator(emulator);
530 static gboolean create_tcp(void)
532 struct sockaddr_in addr;
535 GIOChannel *server_io;
537 sk = socket(PF_INET, SOCK_STREAM, 0);
539 g_print("Can't create tcp/ip socket: %s (%d)\n",
540 strerror(errno), errno);
544 memset(&addr, 0, sizeof(addr));
546 addr.sin_family = AF_INET;
547 addr.sin_addr.s_addr = INADDR_ANY;
548 addr.sin_port = htons(LISTEN_PORT);
550 setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr));
551 if (bind(sk, (struct sockaddr *) &addr, sizeof(struct sockaddr)) < 0) {
552 g_print("Can't bind socket: %s (%d)", strerror(errno), errno);
557 if (listen(sk, 1) < 0) {
558 g_print("Can't listen on socket: %s (%d)",
559 strerror(errno), errno);
564 g_print("new tcp is created at tcp port %d\n", LISTEN_PORT);
566 server_io = g_io_channel_unix_new(sk);
567 g_io_channel_set_close_on_unref(server_io, TRUE);
569 server_watch = g_io_add_watch_full(server_io,
571 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
572 on_socket_connected, NULL, NULL);
574 g_io_channel_unref(server_io);
579 static gboolean has_stk_interface(DBusMessageIter *iter)
581 DBusMessageIter entry;
583 dbus_message_iter_recurse(iter, &entry);
585 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
586 const char *interface;
588 dbus_message_iter_get_basic(&entry, &interface);
590 if (g_str_equal(interface, OFONO_STK_INTERFACE) == TRUE)
593 dbus_message_iter_next(&entry);
599 static int send_with_reply(const char *path, const char *interface,
600 const char *method, DBusPendingCall **call,
601 DBusPendingCallNotifyFunction cb,
602 void *user_data, DBusFreeFunction free_func,
603 int timeout, int type, ...)
610 msg = dbus_message_new_method_call(OFONO_SERVICE, path,
613 g_printerr("Unable to allocate new D-Bus %s message\n", method);
618 va_start(args, type);
620 if (!dbus_message_append_args_valist(msg, type, args)) {
631 if (!dbus_connection_send_with_reply(conn, msg, &c, timeout)) {
632 g_printerr("Sending %s failed\n", method);
640 dbus_pending_call_set_notify(c, cb, user_data, free_func);
641 dbus_pending_call_unref(c);
643 dbus_message_unref(msg);
648 if (free_func && user_data)
649 free_func(user_data);
652 dbus_message_unref(msg);
657 static void set_property_reply(DBusPendingCall *call, void *user_data)
659 DBusMessage *reply = dbus_pending_call_steal_reply(call);
662 dbus_error_init(&err);
664 if (dbus_set_error_from_message(&err, reply) == TRUE) {
665 g_printerr("%s: %s\n", err.name, err.message);
666 dbus_error_free(&err);
669 dbus_message_unref(reply);
672 static int set_property(const char *path, const char *interface,
673 const char *key, int type, const void *val,
674 DBusPendingCallNotifyFunction notify,
676 DBusFreeFunction destroy)
679 DBusMessageIter iter, value;
680 DBusPendingCall *call;
681 const char *signature;
683 msg = dbus_message_new_method_call(OFONO_SERVICE, path, interface,
688 dbus_message_set_auto_start(msg, FALSE);
690 dbus_message_iter_init_append(msg, &iter);
692 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
695 case DBUS_TYPE_BOOLEAN:
696 signature = DBUS_TYPE_BOOLEAN_AS_STRING;
699 dbus_message_unref(msg);
703 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
705 dbus_message_iter_append_basic(&value, type, val);
706 dbus_message_iter_close_container(&iter, &value);
708 if (dbus_connection_send_with_reply(conn, msg, &call, -1) == FALSE) {
709 dbus_message_unref(msg);
713 dbus_message_unref(msg);
718 dbus_pending_call_set_notify(call, notify, user_data, destroy);
720 dbus_pending_call_unref(call);
725 static void register_agent_reply(DBusPendingCall *call, void *user_data)
727 DBusMessage *reply = dbus_pending_call_steal_reply(call);
731 dbus_error_init(&err);
733 if (dbus_set_error_from_message(&err, reply) == TRUE) {
734 g_printerr("%s: %s\n", err.name, err.message);
735 dbus_error_free(&err);
738 dbus_message_unref(reply);
740 state = TEST_STATE_RUNNING;
741 test = cur_test->data;
742 send_proactive_command(test->req_pdu, test->req_len);
745 static void register_agent()
747 const char *path = "/default";
750 g_print("Gained STK interface, registering agent...\n");
752 status = send_with_reply(STKTEST_PATH, OFONO_STK_INTERFACE,
753 "RegisterAgent", NULL,
754 register_agent_reply, NULL, NULL, 1,
755 DBUS_TYPE_OBJECT_PATH, &path,
759 g_printerr("Unable to register agent with oFono\n");
760 g_main_loop_quit(main_loop);
764 state = TEST_STATE_REGISTERING_AGENT;
767 static gboolean modem_changed(DBusConnection *conn,
768 DBusMessage *msg, void *user_data)
770 DBusMessageIter iter, value;
771 const char *path, *key;
774 if (dbus_message_iter_init(msg, &iter) == FALSE)
777 path = dbus_message_get_path(msg);
779 if (g_str_equal(STKTEST_PATH, path) == FALSE)
782 dbus_message_iter_get_basic(&iter, &key);
784 dbus_message_iter_next(&iter);
785 dbus_message_iter_recurse(&iter, &value);
787 if (g_str_equal(key, "Interfaces") == FALSE)
790 has_stk = has_stk_interface(&value);
793 case TEST_STATE_POWERING_UP:
797 case TEST_STATE_REGISTERING_AGENT:
798 case TEST_STATE_RUNNING:
799 if (has_stk == FALSE)
800 g_printerr("Unexpectedly lost STK interface\n");
802 case TEST_STATE_POWERING_DOWN:
809 static void powerup(void)
811 dbus_bool_t powered = TRUE;
813 state = TEST_STATE_POWERING_UP;
814 set_property(STKTEST_PATH, OFONO_MODEM_INTERFACE, "Powered",
815 DBUS_TYPE_BOOLEAN, &powered,
816 set_property_reply, NULL, NULL);
819 static void get_modems_reply(DBusPendingCall *call, void *user_data)
821 DBusMessage *reply = dbus_pending_call_steal_reply(call);
822 DBusMessageIter iter, list;
824 gboolean found = FALSE;
826 dbus_error_init(&err);
828 if (dbus_set_error_from_message(&err, reply) == TRUE) {
829 g_printerr("%s: %s\n", err.name, err.message);
830 dbus_error_free(&err);
834 if (dbus_message_has_signature(reply, "a(oa{sv})") == FALSE)
837 if (dbus_message_iter_init(reply, &iter) == FALSE)
840 dbus_message_iter_recurse(&iter, &list);
842 while (dbus_message_iter_get_arg_type(&list) == DBUS_TYPE_STRUCT) {
843 DBusMessageIter entry;
846 dbus_message_iter_recurse(&list, &entry);
847 dbus_message_iter_get_basic(&entry, &path);
849 if (g_str_equal(path, STKTEST_PATH))
852 dbus_message_iter_next(&list);
856 dbus_message_unref(reply);
858 if (found == FALSE) {
859 g_printerr("STK Test modem not found\n");
860 g_main_loop_quit(main_loop);
864 g_print("Test modem found\n");
866 modem_changed_watch = g_dbus_add_signal_watch(conn, OFONO_SERVICE,
868 OFONO_MODEM_INTERFACE,
873 if (create_tcp() == FALSE) {
874 g_printerr("Unable to listen on modem emulator socket\n");
875 g_main_loop_quit(main_loop);
878 __stktest_test_next();
881 static int get_modems(DBusConnection *conn)
884 DBusPendingCall *call;
886 msg = dbus_message_new_method_call(OFONO_SERVICE, "/",
887 OFONO_MANAGER_INTERFACE, "GetModems");
891 dbus_message_set_auto_start(msg, FALSE);
893 g_print("getting modems\n");
895 if (dbus_connection_send_with_reply(conn, msg, &call, -1) == FALSE) {
896 dbus_message_unref(msg);
900 dbus_message_unref(msg);
905 dbus_pending_call_set_notify(call, get_modems_reply, conn, NULL);
907 dbus_pending_call_unref(call);
912 static const GDBusMethodTable agent_methods[] = {
913 { GDBUS_METHOD("Release", NULL, NULL, agent_release) },
914 { GDBUS_ASYNC_METHOD("DisplayText",
915 GDBUS_ARGS({ "text", "s" }, { "icon_id", "y" },
916 { "urgent", "b" }), NULL,
917 agent_display_text) },
918 { GDBUS_ASYNC_METHOD("RequestDigit",
919 GDBUS_ARGS({ "alpha", "s" }, { "icon_id", "y" }),
920 GDBUS_ARGS({ "digit", "s" }),
921 agent_request_digit) },
922 { GDBUS_ASYNC_METHOD("RequestKey",
923 GDBUS_ARGS({ "alpha", "s" }, { "icon_id", "y" }),
924 GDBUS_ARGS({ "key", "s" }),
925 agent_request_key) },
926 { GDBUS_ASYNC_METHOD("RequestConfirmation",
927 GDBUS_ARGS({ "alpha", "s" }, { "icon_id", "y" }),
928 GDBUS_ARGS({ "confirmation", "b" }),
929 agent_request_confirmation) },
930 { GDBUS_NOREPLY_METHOD("Cancel", NULL, NULL, agent_cancel) },
934 static void ofono_connect(DBusConnection *conn, void *user_data)
936 g_print("starting telephony interface\n");
938 if (!g_dbus_register_interface(conn, "/default",
939 OFONO_STKAGENT_INTERFACE,
940 agent_methods, NULL, NULL,
942 g_printerr("Unable to register local agent");
943 g_main_loop_quit(main_loop);
946 ofono_running = TRUE;
950 static void ofono_disconnect(DBusConnection *conn, void *user_data)
952 g_print("stopping telephony interface\n");
954 g_dbus_unregister_interface(conn, "/default", OFONO_STKAGENT_INTERFACE);
956 ofono_running = FALSE;
958 g_dbus_remove_watch(conn, modem_changed_watch);
959 modem_changed_watch = 0;
962 g_source_remove(server_watch);
966 g_at_server_unref(emulator);
970 static void sig_term(int sig)
972 if (__terminated > 0)
977 g_print("Terminating\n");
979 g_main_loop_quit(main_loop);
982 static void disconnect_callback(DBusConnection *conn, void *user_data)
984 g_printerr("D-Bus disconnect\n");
986 g_main_loop_quit(main_loop);
989 static gboolean end_session_and_finish(gpointer user_data)
991 g_at_server_send_unsolicited(emulator, "+CUSATEND");
992 __stktest_test_finish(TRUE);
997 static void expect_response_and_finish(const unsigned char *pdu,
1000 struct test *test = cur_test->data;
1002 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
1004 g_idle_add(end_session_and_finish, NULL);
1007 static void expect_response(const unsigned char *pdu, unsigned int len)
1009 struct test *test = cur_test->data;
1011 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
1014 static gboolean poweroff_not_canceled_after_3(gpointer user_data)
1016 __stktest_test_finish(pending != NULL);
1020 static gboolean end_session_and_not_canceled_after_3(gpointer user_data)
1022 g_at_server_send_unsolicited(emulator, "+CUSATEND");
1023 g_timeout_add_seconds(3, poweroff_not_canceled_after_3, NULL);
1028 static void expect_response_and_not_canceled_after_3(const unsigned char *pdu,
1031 struct test *test = cur_test->data;
1033 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
1035 g_idle_add(end_session_and_not_canceled_after_3, NULL);
1038 static gboolean poweroff_and_canceled_after_21(gpointer user_data)
1040 __stktest_test_finish(pending == NULL);
1044 static gboolean end_session_and_canceled_after_21(gpointer user_data)
1046 g_at_server_send_unsolicited(emulator, "+CUSATEND");
1047 g_timeout_add_seconds(21, poweroff_and_canceled_after_21, NULL);
1052 static void expect_response_and_canceled_after_21(const unsigned char *pdu,
1055 struct test *test = cur_test->data;
1057 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
1059 g_idle_add(end_session_and_canceled_after_21, NULL);
1062 static DBusMessage *test_display_text_11(DBusMessage *msg,
1064 unsigned char icon_id,
1067 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 1"));
1068 STKTEST_AGENT_ASSERT(icon_id == 0);
1069 STKTEST_AGENT_ASSERT(urgent == FALSE);
1071 return dbus_message_new_method_return(msg);
1074 static DBusMessage *test_display_text_12(DBusMessage *msg,
1076 unsigned char icon_id,
1079 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 1"));
1080 STKTEST_AGENT_ASSERT(icon_id == 0);
1081 STKTEST_AGENT_ASSERT(urgent == FALSE);
1083 return stktest_error_busy(msg);
1086 static DBusMessage *test_display_text_13(DBusMessage *msg,
1088 unsigned char icon_id,
1091 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 2"));
1092 STKTEST_AGENT_ASSERT(icon_id == 0);
1093 STKTEST_AGENT_ASSERT(urgent == TRUE);
1095 return dbus_message_new_method_return(msg);
1098 static DBusMessage *test_display_text_14(DBusMessage *msg,
1100 unsigned char icon_id,
1103 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 3"));
1104 STKTEST_AGENT_ASSERT(icon_id == 0);
1105 STKTEST_AGENT_ASSERT(urgent == FALSE);
1107 return dbus_message_new_method_return(msg);
1110 static DBusMessage *test_display_text_15(DBusMessage *msg,
1112 unsigned char icon_id,
1115 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 4"));
1116 STKTEST_AGENT_ASSERT(icon_id == 0);
1117 STKTEST_AGENT_ASSERT(urgent == FALSE);
1122 static DBusMessage *test_display_text_16(DBusMessage *msg,
1124 unsigned char icon_id,
1127 STKTEST_AGENT_ASSERT(g_str_equal(text, "This command instructs the ME"
1128 " to display a text message. "
1129 "It allows the SIM to define "
1130 "the priority of that message, "
1131 "and the text string format. "
1132 "Two types of prio"));
1133 STKTEST_AGENT_ASSERT(icon_id == 0);
1134 STKTEST_AGENT_ASSERT(urgent == FALSE);
1136 return dbus_message_new_method_return(msg);
1139 static DBusMessage *test_display_text_17(DBusMessage *msg,
1141 unsigned char icon_id,
1144 /* oFono gives rich text formatting in HTML */
1145 STKTEST_AGENT_ASSERT(g_str_equal(text, "<GO-BACKWARDS>"));
1146 STKTEST_AGENT_ASSERT(icon_id == 0);
1147 STKTEST_AGENT_ASSERT(urgent == FALSE);
1149 return stktest_error_go_back(msg);
1152 static DBusMessage *test_display_text_18(DBusMessage *msg,
1154 unsigned char icon_id,
1157 /* oFono gives rich text formatting in HTML */
1158 STKTEST_AGENT_ASSERT(g_str_equal(text, "<ABORT>"));
1159 STKTEST_AGENT_ASSERT(icon_id == 0);
1160 STKTEST_AGENT_ASSERT(urgent == FALSE);
1162 return stktest_error_end_session(msg);
1165 static DBusMessage *test_display_text_21(DBusMessage *msg,
1167 unsigned char icon_id,
1170 STKTEST_AGENT_ASSERT(g_str_equal(text, "<TIME-OUT>"));
1171 STKTEST_AGENT_ASSERT(icon_id == 0);
1172 STKTEST_AGENT_ASSERT(urgent == FALSE);
1177 static DBusMessage *test_display_text_31(DBusMessage *msg,
1179 unsigned char icon_id,
1182 static const char *expected = "This command instructs the ME to display"
1183 " a text message, and/or an icon "
1184 "(see 6.5.4). It allows the "
1185 "SIM to define the priority of that "
1186 "message, and the text string format. "
1187 "Two types of priority are defined:- "
1188 "display normal priority text and/";
1189 STKTEST_AGENT_ASSERT(g_str_equal(text, expected));
1190 STKTEST_AGENT_ASSERT(icon_id == 0);
1191 STKTEST_AGENT_ASSERT(urgent == FALSE);
1193 return dbus_message_new_method_return(msg);
1196 static DBusMessage *test_display_text_41(DBusMessage *msg,
1198 unsigned char icon_id,
1201 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 1"));
1202 STKTEST_AGENT_ASSERT(icon_id == 0);
1203 STKTEST_AGENT_ASSERT(urgent == FALSE);
1208 static DBusMessage *test_display_text_42(DBusMessage *msg,
1210 unsigned char icon_id,
1213 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 2"));
1214 STKTEST_AGENT_ASSERT(icon_id == 0);
1215 STKTEST_AGENT_ASSERT(urgent == FALSE);
1220 static gboolean user_response(gpointer user_data)
1222 if (pending == NULL) {
1223 __stktest_test_finish(FALSE);
1227 g_dbus_send_reply(conn, pending, DBUS_TYPE_INVALID);
1228 dbus_message_unref(pending);
1231 __stktest_test_finish(TRUE);
1236 static DBusMessage *test_display_text_43(DBusMessage *msg,
1238 unsigned char icon_id,
1241 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 3"));
1242 STKTEST_AGENT_ASSERT(icon_id == 0);
1243 STKTEST_AGENT_ASSERT(urgent == FALSE);
1245 g_timeout_add_seconds(3, user_response, NULL);
1249 static DBusMessage *test_display_text_51(DBusMessage *msg,
1251 unsigned char icon_id,
1254 STKTEST_AGENT_ASSERT(g_str_equal(text, "Basic Icon"));
1255 STKTEST_AGENT_ASSERT(icon_id == 1);
1256 STKTEST_AGENT_ASSERT(urgent == FALSE);
1258 return dbus_message_new_method_return(msg);
1261 static DBusMessage *test_display_text_52(DBusMessage *msg,
1263 unsigned char icon_id,
1266 STKTEST_AGENT_ASSERT(g_str_equal(text, "Colour Icon"));
1267 STKTEST_AGENT_ASSERT(icon_id == 2);
1268 STKTEST_AGENT_ASSERT(urgent == FALSE);
1270 return dbus_message_new_method_return(msg);
1273 static DBusMessage *test_display_text_53(DBusMessage *msg,
1275 unsigned char icon_id,
1278 STKTEST_AGENT_ASSERT(g_str_equal(text, "Basic Icon"));
1279 STKTEST_AGENT_ASSERT(icon_id == 1);
1280 STKTEST_AGENT_ASSERT(urgent == FALSE);
1282 return dbus_message_new_method_return(msg);
1285 static DBusMessage *test_display_text_61(DBusMessage *msg,
1287 unsigned char icon_id,
1290 STKTEST_AGENT_ASSERT(g_str_equal(text, "ЗДРАВСТВУЙТЕ"));
1291 STKTEST_AGENT_ASSERT(icon_id == 0);
1292 STKTEST_AGENT_ASSERT(urgent == FALSE);
1294 return dbus_message_new_method_return(msg);
1297 static DBusMessage *test_display_text_71(DBusMessage *msg,
1299 unsigned char icon_id,
1302 STKTEST_AGENT_ASSERT(g_str_equal(text, "10 Second"));
1303 STKTEST_AGENT_ASSERT(icon_id == 0);
1304 STKTEST_AGENT_ASSERT(urgent == FALSE);
1309 static DBusMessage *test_display_text_81(DBusMessage *msg,
1311 unsigned char icon_id,
1314 const char *expect =
1315 "<div style=\"text-align: left;\"><span style=\"color: "
1316 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1319 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1320 STKTEST_AGENT_ASSERT(icon_id == 0);
1321 STKTEST_AGENT_ASSERT(urgent == FALSE);
1323 return dbus_message_new_method_return(msg);
1326 static DBusMessage *test_display_text_82(DBusMessage *msg,
1328 unsigned char icon_id,
1331 const char *expect =
1332 "<div style=\"text-align: center;\"><span style=\"color: "
1333 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1336 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1337 STKTEST_AGENT_ASSERT(icon_id == 0);
1338 STKTEST_AGENT_ASSERT(urgent == FALSE);
1340 return dbus_message_new_method_return(msg);
1343 static DBusMessage *test_display_text_83(DBusMessage *msg,
1345 unsigned char icon_id,
1348 const char *expect =
1349 "<div style=\"text-align: right;\"><span style=\"color: "
1350 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1353 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1354 STKTEST_AGENT_ASSERT(icon_id == 0);
1355 STKTEST_AGENT_ASSERT(urgent == FALSE);
1357 return dbus_message_new_method_return(msg);
1360 static DBusMessage *test_display_text_84(DBusMessage *msg,
1362 unsigned char icon_id,
1365 const char *expect =
1366 "<div style=\"text-align: left;\"><span style=\"font-size: "
1367 "big;color: #347235;background-color: #FFFF00;\">"
1368 "Text Attribute 1</span></div>";
1370 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1371 STKTEST_AGENT_ASSERT(icon_id == 0);
1372 STKTEST_AGENT_ASSERT(urgent == FALSE);
1374 return dbus_message_new_method_return(msg);
1377 static DBusMessage *test_display_text_85(DBusMessage *msg,
1379 unsigned char icon_id,
1382 const char *expect =
1383 "<div style=\"text-align: left;\"><span style=\"font-size: "
1384 "small;color: #347235;background-color: #FFFF00;\">"
1385 "Text Attribute 1</span></div>";
1387 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1388 STKTEST_AGENT_ASSERT(icon_id == 0);
1389 STKTEST_AGENT_ASSERT(urgent == FALSE);
1391 return dbus_message_new_method_return(msg);
1394 static DBusMessage *test_display_text_86(DBusMessage *msg,
1396 unsigned char icon_id,
1399 const char *expect =
1400 "<div style=\"text-align: left;\"><span style=\"font-weight: "
1401 "bold;color: #347235;background-color: #FFFF00;\">"
1402 "Text Attribute 1</span></div>";
1404 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1405 STKTEST_AGENT_ASSERT(icon_id == 0);
1406 STKTEST_AGENT_ASSERT(urgent == FALSE);
1408 return dbus_message_new_method_return(msg);
1411 static DBusMessage *test_display_text_87(DBusMessage *msg,
1413 unsigned char icon_id,
1416 const char *expect =
1417 "<div style=\"text-align: left;\"><span style=\"font-style: "
1418 "italic;color: #347235;background-color: #FFFF00;\">"
1419 "Text Attribute 1</span></div>";
1421 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1422 STKTEST_AGENT_ASSERT(icon_id == 0);
1423 STKTEST_AGENT_ASSERT(urgent == FALSE);
1425 return dbus_message_new_method_return(msg);
1428 static DBusMessage *test_display_text_88(DBusMessage *msg,
1430 unsigned char icon_id,
1433 const char *expect =
1434 "<div style=\"text-align: left;\"><span style=\""
1435 "text-decoration: underline;color: #347235;"
1436 "background-color: #FFFF00;\">Text Attribute 1</span></div>";
1438 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1439 STKTEST_AGENT_ASSERT(icon_id == 0);
1440 STKTEST_AGENT_ASSERT(urgent == FALSE);
1442 return dbus_message_new_method_return(msg);
1445 static DBusMessage *test_display_text_89(DBusMessage *msg,
1447 unsigned char icon_id,
1450 const char *expect =
1451 "<div style=\"text-align: left;\"><span style=\""
1452 "text-decoration: line-through;color: #347235;"
1453 "background-color: #FFFF00;\">Text Attribute 1</span></div>";
1455 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1456 STKTEST_AGENT_ASSERT(icon_id == 0);
1457 STKTEST_AGENT_ASSERT(urgent == FALSE);
1459 return dbus_message_new_method_return(msg);
1462 static DBusMessage *test_display_text_810(DBusMessage *msg,
1464 unsigned char icon_id,
1467 const char *expect =
1468 "<div style=\"text-align: left;\"><span style=\"color: "
1469 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1472 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1473 STKTEST_AGENT_ASSERT(icon_id == 0);
1474 STKTEST_AGENT_ASSERT(urgent == FALSE);
1476 return dbus_message_new_method_return(msg);
1479 static DBusMessage *test_display_text_91(DBusMessage *msg,
1481 unsigned char icon_id,
1484 const char *expect = "你好";
1486 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1487 STKTEST_AGENT_ASSERT(icon_id == 0);
1488 STKTEST_AGENT_ASSERT(urgent == FALSE);
1490 return dbus_message_new_method_return(msg);
1493 static DBusMessage *test_display_text_101(DBusMessage *msg,
1495 unsigned char icon_id,
1498 const char *expect = "80ル";
1500 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1501 STKTEST_AGENT_ASSERT(icon_id == 0);
1502 STKTEST_AGENT_ASSERT(urgent == FALSE);
1504 return dbus_message_new_method_return(msg);
1507 static DBusMessage *test_get_inkey_11(DBusMessage *msg,
1509 unsigned char icon_id)
1512 const char *ret = "+";
1514 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "Enter \"+\""));
1515 STKTEST_AGENT_ASSERT(icon_id == 0);
1517 reply = dbus_message_new_method_return(msg);
1518 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1524 static DBusMessage *test_get_inkey_12(DBusMessage *msg,
1526 unsigned char icon_id)
1529 const char *ret = "0";
1531 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "Enter \"0\""));
1532 STKTEST_AGENT_ASSERT(icon_id == 0);
1534 reply = dbus_message_new_method_return(msg);
1535 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1541 static DBusMessage *test_get_inkey_13(DBusMessage *msg,
1543 unsigned char icon_id)
1545 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "<GO-BACKWARDS>"));
1546 STKTEST_AGENT_ASSERT(icon_id == 0);
1548 return stktest_error_go_back(msg);
1551 static DBusMessage *test_get_inkey_14(DBusMessage *msg,
1553 unsigned char icon_id)
1555 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "<ABORT>"));
1556 STKTEST_AGENT_ASSERT(icon_id == 0);
1558 return stktest_error_end_session(msg);
1561 static DBusMessage *test_get_inkey_15(DBusMessage *msg,
1563 unsigned char icon_id)
1566 const char *ret = "q";
1568 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "Enter \"q\""));
1569 STKTEST_AGENT_ASSERT(icon_id == 0);
1571 reply = dbus_message_new_method_return(msg);
1572 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1578 static DBusMessage *test_get_inkey_16(DBusMessage *msg,
1580 unsigned char icon_id)
1583 const char *ret = "x";
1584 const char *expected =
1585 "Enter \"x\". This command instructs the ME to display text, "
1586 "and to expect the user to enter a single character. Any "
1587 "response entered by the user shall be passed t";
1589 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expected));
1590 STKTEST_AGENT_ASSERT(icon_id == 0);
1592 reply = dbus_message_new_method_return(msg);
1593 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1599 static DBusMessage *test_get_inkey_21(DBusMessage *msg,
1600 const char *text, unsigned char icon_id)
1602 STKTEST_AGENT_ASSERT(g_str_equal(text, "<TIME-OUT>"));
1603 STKTEST_AGENT_ASSERT(icon_id == 0);
1608 static DBusMessage *test_get_inkey_31(DBusMessage *msg,
1610 unsigned char icon_id)
1613 const char *ret = "+";
1615 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "ЗДРАВСТВУЙТЕ"));
1616 STKTEST_AGENT_ASSERT(icon_id == 0);
1618 reply = dbus_message_new_method_return(msg);
1619 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1625 static DBusMessage *test_get_inkey_32(DBusMessage *msg,
1627 unsigned char icon_id)
1630 const char *ret = "+";
1631 const char *expect = "ЗДРАВСТВУЙТЕЗДРАВСТВУЙТЕ"
1632 "ЗДРАВСТВУЙТЕЗДРАВСТВУЙТЕ"
1633 "ЗДРАВСТВУЙТЕЗДРАВСТВУЙ";
1635 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1636 STKTEST_AGENT_ASSERT(icon_id == 0);
1638 reply = dbus_message_new_method_return(msg);
1639 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1645 static DBusMessage *test_get_inkey_41(DBusMessage *msg,
1647 unsigned char icon_id)
1650 const char *ret = "Д";
1652 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "Enter"));
1653 STKTEST_AGENT_ASSERT(icon_id == 0);
1655 reply = dbus_message_new_method_return(msg);
1656 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1662 static DBusMessage *test_get_inkey_51a(DBusMessage *msg,
1664 unsigned char icon_id)
1667 dbus_bool_t ret = 1;
1669 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "Enter YES"));
1670 STKTEST_AGENT_ASSERT(icon_id == 0);
1672 reply = dbus_message_new_method_return(msg);
1673 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &ret,
1679 static DBusMessage *test_get_inkey_51b(DBusMessage *msg,
1681 unsigned char icon_id)
1684 dbus_bool_t ret = 0;
1686 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "Enter NO"));
1687 STKTEST_AGENT_ASSERT(icon_id == 0);
1689 reply = dbus_message_new_method_return(msg);
1690 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &ret,
1696 static DBusMessage *test_get_inkey_61(DBusMessage *msg,
1698 unsigned char icon_id)
1701 const char *ret = "+";
1703 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "<NO-ICON>"));
1704 STKTEST_AGENT_ASSERT(icon_id == 1);
1706 reply = dbus_message_new_method_return(msg);
1707 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1713 static DBusMessage *test_get_inkey_62(DBusMessage *msg,
1715 unsigned char icon_id)
1718 const char *ret = "+";
1720 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "<BASIC-ICON>"));
1721 STKTEST_AGENT_ASSERT(icon_id == 1);
1723 reply = dbus_message_new_method_return(msg);
1724 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1730 static DBusMessage *test_get_inkey_63(DBusMessage *msg,
1732 unsigned char icon_id)
1735 const char *ret = "+";
1737 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "<NO-ICON>"));
1738 STKTEST_AGENT_ASSERT(icon_id == 2);
1740 reply = dbus_message_new_method_return(msg);
1741 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1747 static DBusMessage *test_get_inkey_64(DBusMessage *msg,
1749 unsigned char icon_id)
1752 const char *ret = "+";
1754 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "<COLOUR-ICON>"));
1755 STKTEST_AGENT_ASSERT(icon_id == 2);
1757 reply = dbus_message_new_method_return(msg);
1758 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1764 static DBusMessage *test_get_inkey_81(DBusMessage *msg,
1766 unsigned char icon_id)
1769 const char *ret = "+";
1771 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "Enter \"+\""));
1772 STKTEST_AGENT_ASSERT(icon_id == 0);
1777 static DBusMessage *test_get_inkey_91(DBusMessage *msg,
1779 unsigned char icon_id)
1782 const char *ret = "+";
1783 const char *expect =
1784 "<div style=\"text-align: left;\"><span style=\"color: "
1785 "#347235;background-color: #FFFF00;\">Enter \"+\"</span></div>";
1787 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1788 STKTEST_AGENT_ASSERT(icon_id == 0);
1790 reply = dbus_message_new_method_return(msg);
1791 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1797 static DBusMessage *test_get_inkey_92(DBusMessage *msg,
1799 unsigned char icon_id)
1802 const char *ret = "+";
1803 const char *expect =
1804 "<div style=\"text-align: center;\"><span style=\"color: "
1805 "#347235;background-color: #FFFF00;\">Enter \"+\"</span>"
1808 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1809 STKTEST_AGENT_ASSERT(icon_id == 0);
1811 reply = dbus_message_new_method_return(msg);
1812 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1818 static DBusMessage *test_get_inkey_93(DBusMessage *msg,
1820 unsigned char icon_id)
1823 const char *ret = "+";
1824 const char *expect =
1825 "<div style=\"text-align: right;\"><span style=\"color: "
1826 "#347235;background-color: #FFFF00;\">Enter \"+\"</span>"
1829 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1830 STKTEST_AGENT_ASSERT(icon_id == 0);
1832 reply = dbus_message_new_method_return(msg);
1833 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1839 static DBusMessage *test_get_inkey_94(DBusMessage *msg,
1841 unsigned char icon_id)
1844 const char *ret = "+";
1845 const char *expect =
1846 "<div style=\"text-align: left;\"><span style=\"font-size: "
1847 "big;color: #347235;background-color: #FFFF00;\">Enter \"+\""
1850 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1851 STKTEST_AGENT_ASSERT(icon_id == 0);
1853 reply = dbus_message_new_method_return(msg);
1854 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1860 static DBusMessage *test_get_inkey_95(DBusMessage *msg,
1862 unsigned char icon_id)
1865 const char *ret = "+";
1866 const char *expect =
1867 "<div style=\"text-align: left;\"><span style=\"font-size: "
1868 "small;color: #347235;background-color: #FFFF00;\">"
1869 "Enter \"+\"</span></div>";
1871 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1872 STKTEST_AGENT_ASSERT(icon_id == 0);
1874 reply = dbus_message_new_method_return(msg);
1875 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1881 static DBusMessage *test_get_inkey_96(DBusMessage *msg,
1883 unsigned char icon_id)
1886 const char *ret = "+";
1887 const char *expect =
1888 "<div style=\"text-align: left;\"><span style=\"font-weight: "
1889 "bold;color: #347235;background-color: #FFFF00;\">Enter \"+\""
1892 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1893 STKTEST_AGENT_ASSERT(icon_id == 0);
1895 reply = dbus_message_new_method_return(msg);
1896 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1902 static DBusMessage *test_get_inkey_97(DBusMessage *msg,
1904 unsigned char icon_id)
1907 const char *ret = "+";
1908 const char *expect =
1909 "<div style=\"text-align: left;\"><span style=\"font-style: "
1910 "italic;color: #347235;background-color: #FFFF00;\">"
1911 "Enter \"+\"</span></div>";
1913 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1914 STKTEST_AGENT_ASSERT(icon_id == 0);
1916 reply = dbus_message_new_method_return(msg);
1917 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1923 static DBusMessage *test_get_inkey_98(DBusMessage *msg,
1925 unsigned char icon_id)
1928 const char *ret = "+";
1929 const char *expect =
1930 "<div style=\"text-align: left;\"><span style=\""
1931 "text-decoration: underline;color: #347235;"
1932 "background-color: #FFFF00;\">Enter \"+\"</span></div>";
1934 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1935 STKTEST_AGENT_ASSERT(icon_id == 0);
1937 reply = dbus_message_new_method_return(msg);
1938 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1944 static DBusMessage *test_get_inkey_99(DBusMessage *msg,
1946 unsigned char icon_id)
1949 const char *ret = "+";
1950 const char *expect =
1951 "<div style=\"text-align: left;\"><span style=\""
1952 "text-decoration: line-through;color: #347235;"
1953 "background-color: #FFFF00;\">Enter \"+\"</span></div>";
1955 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1956 STKTEST_AGENT_ASSERT(icon_id == 0);
1958 reply = dbus_message_new_method_return(msg);
1959 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1965 static DBusMessage *test_get_inkey_910(DBusMessage *msg,
1967 unsigned char icon_id)
1970 const char *ret = "+";
1971 const char *expect =
1972 "<div style=\"text-align: left;\"><span style=\"color: "
1973 "#347235;background-color: #FFFF00;\">Enter \"+\"</span></div>";
1975 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1976 STKTEST_AGENT_ASSERT(icon_id == 0);
1978 reply = dbus_message_new_method_return(msg);
1979 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1985 static void power_down_reply(DBusPendingCall *call, void *user_data)
1987 __stktest_test_next();
1990 void __stktest_test_finish(gboolean successful)
1992 struct test *test = cur_test->data;
1993 dbus_bool_t powered = FALSE;
1995 test->result = successful ? TEST_RESULT_PASSED : TEST_RESULT_FAILED;
1997 state = TEST_STATE_POWERING_DOWN;
1998 set_property(STKTEST_PATH, OFONO_MODEM_INTERFACE, "Powered",
1999 DBUS_TYPE_BOOLEAN, &powered,
2000 power_down_reply, NULL, NULL);
2003 void __stktest_test_next()
2005 if (cur_test == NULL)
2008 cur_test = cur_test->next;
2010 if (cur_test == NULL) {
2011 g_main_loop_quit(main_loop);
2018 static void stktest_add_test(const char *name, const char *method,
2019 const unsigned char *req, unsigned int req_len,
2020 const unsigned char *rsp, unsigned int rsp_len,
2022 terminal_response_func tr_func)
2024 struct test *test = g_new0(struct test, 1);
2026 test->name = g_strdup(name);
2027 test->method = g_strdup(method);
2028 test->req_pdu = g_memdup(req, req_len);
2029 test->req_len = req_len;
2030 test->rsp_pdu = g_memdup(rsp, rsp_len);
2031 test->rsp_len = rsp_len;
2032 test->agent_func = agent_func;
2033 test->tr_func = tr_func;
2035 tests = g_list_append(tests, test);
2038 static void __stktest_test_init(void)
2040 stktest_add_test("Display Text 1.1", "DisplayText",
2041 display_text_111, sizeof(display_text_111),
2042 display_text_response_111,
2043 sizeof(display_text_response_111),
2044 test_display_text_11,
2045 expect_response_and_finish);
2046 stktest_add_test("Display Text 1.2", "DisplayText",
2047 display_text_111, sizeof(display_text_111),
2048 display_text_response_121,
2049 sizeof(display_text_response_121),
2050 test_display_text_12,
2051 expect_response_and_finish);
2052 stktest_add_test("Display Text 1.3", "DisplayText",
2053 display_text_131, sizeof(display_text_131),
2054 display_text_response_131,
2055 sizeof(display_text_response_131),
2056 test_display_text_13,
2057 expect_response_and_finish);
2058 stktest_add_test("Display Text 1.4", "DisplayText",
2059 display_text_141, sizeof(display_text_141),
2060 display_text_response_141,
2061 sizeof(display_text_response_141),
2062 test_display_text_14,
2063 expect_response_and_finish);
2064 stktest_add_test("Display Text 1.5", "DisplayText",
2065 display_text_151, sizeof(display_text_151),
2066 display_text_response_151,
2067 sizeof(display_text_response_151),
2068 test_display_text_15,
2069 expect_response_and_finish);
2070 stktest_add_test("Display Text 1.6", "DisplayText",
2071 display_text_161, sizeof(display_text_161),
2072 display_text_response_161,
2073 sizeof(display_text_response_161),
2074 test_display_text_16,
2075 expect_response_and_finish);
2076 stktest_add_test("Display Text 1.7", "DisplayText",
2077 display_text_171, sizeof(display_text_171),
2078 display_text_response_171,
2079 sizeof(display_text_response_171),
2080 test_display_text_17,
2081 expect_response_and_finish);
2082 stktest_add_test("Display Text 1.8", "DisplayText",
2083 display_text_181, sizeof(display_text_181),
2084 display_text_response_181,
2085 sizeof(display_text_response_181),
2086 test_display_text_18,
2087 expect_response_and_finish);
2088 stktest_add_test("Display Text 1.9", "DisplayText",
2089 display_text_191, sizeof(display_text_191),
2090 display_text_response_191,
2091 sizeof(display_text_response_191),
2092 NULL, expect_response_and_finish);
2093 stktest_add_test("Display Text 2.1", "DisplayText",
2094 display_text_211, sizeof(display_text_211),
2095 display_text_response_211,
2096 sizeof(display_text_response_211),
2097 test_display_text_21,
2098 expect_response_and_finish);
2099 stktest_add_test("Display Text 3.1", "DisplayText",
2100 display_text_311, sizeof(display_text_311),
2101 display_text_response_311,
2102 sizeof(display_text_response_311),
2103 test_display_text_31,
2104 expect_response_and_finish);
2105 stktest_add_test("Display Text 4.1", "DisplayText",
2106 display_text_411, sizeof(display_text_411),
2107 display_text_response_411,
2108 sizeof(display_text_response_411),
2109 test_display_text_41,
2110 expect_response_and_not_canceled_after_3);
2111 stktest_add_test("Display Text 4.2", "DisplayText",
2112 display_text_421, sizeof(display_text_421),
2113 display_text_response_421,
2114 sizeof(display_text_response_421),
2115 test_display_text_42,
2116 expect_response_and_canceled_after_21);
2117 stktest_add_test("Display Text 4.3", "DisplayText",
2118 display_text_431, sizeof(display_text_431),
2119 display_text_response_431,
2120 sizeof(display_text_response_431),
2121 test_display_text_43, expect_response);
2122 stktest_add_test("Display Text 5.1A", "DisplayText",
2123 display_text_511, sizeof(display_text_511),
2124 display_text_response_511a,
2125 sizeof(display_text_response_511a),
2126 test_display_text_51,
2127 expect_response_and_finish);
2128 stktest_add_test("Display Text 5.2A", "DisplayText",
2129 display_text_521, sizeof(display_text_521),
2130 display_text_response_521a,
2131 sizeof(display_text_response_521a),
2132 test_display_text_52,
2133 expect_response_and_finish);
2134 stktest_add_test("Display Text 5.3A", "DisplayText",
2135 display_text_531, sizeof(display_text_531),
2136 display_text_response_531a,
2137 sizeof(display_text_response_531a),
2138 test_display_text_53,
2139 expect_response_and_finish);
2140 stktest_add_test("Display Text 6.1", "DisplayText",
2141 display_text_611, sizeof(display_text_611),
2142 display_text_response_611,
2143 sizeof(display_text_response_611),
2144 test_display_text_61,
2145 expect_response_and_finish);
2146 stktest_add_test("Display Text 7.1", "DisplayText",
2147 display_text_711, sizeof(display_text_711),
2148 display_text_response_711,
2149 sizeof(display_text_response_711),
2150 test_display_text_71,
2151 expect_response_and_finish);
2153 * We skip parts where the UI is asked to display simple text to ensure
2154 * that the alignment, font is set up correctly and not 'remembered'
2155 * from a previous state. oFono does not keep any state of the
2158 stktest_add_test("Display Text 8.1", "DisplayText",
2159 display_text_811, sizeof(display_text_811),
2160 display_text_response_811,
2161 sizeof(display_text_response_811),
2162 test_display_text_81,
2163 expect_response_and_finish);
2164 stktest_add_test("Display Text 8.2", "DisplayText",
2165 display_text_821, sizeof(display_text_821),
2166 display_text_response_821,
2167 sizeof(display_text_response_821),
2168 test_display_text_82,
2169 expect_response_and_finish);
2170 stktest_add_test("Display Text 8.3", "DisplayText",
2171 display_text_831, sizeof(display_text_831),
2172 display_text_response_831,
2173 sizeof(display_text_response_831),
2174 test_display_text_83,
2175 expect_response_and_finish);
2176 stktest_add_test("Display Text 8.4", "DisplayText",
2177 display_text_841, sizeof(display_text_841),
2178 display_text_response_841,
2179 sizeof(display_text_response_841),
2180 test_display_text_84,
2181 expect_response_and_finish);
2182 stktest_add_test("Display Text 8.5", "DisplayText",
2183 display_text_851, sizeof(display_text_851),
2184 display_text_response_851,
2185 sizeof(display_text_response_851),
2186 test_display_text_85,
2187 expect_response_and_finish);
2188 stktest_add_test("Display Text 8.6", "DisplayText",
2189 display_text_861, sizeof(display_text_861),
2190 display_text_response_861,
2191 sizeof(display_text_response_861),
2192 test_display_text_86,
2193 expect_response_and_finish);
2194 stktest_add_test("Display Text 8.7", "DisplayText",
2195 display_text_871, sizeof(display_text_871),
2196 display_text_response_871,
2197 sizeof(display_text_response_871),
2198 test_display_text_87,
2199 expect_response_and_finish);
2200 stktest_add_test("Display Text 8.8", "DisplayText",
2201 display_text_881, sizeof(display_text_881),
2202 display_text_response_881,
2203 sizeof(display_text_response_881),
2204 test_display_text_88,
2205 expect_response_and_finish);
2206 stktest_add_test("Display Text 8.9", "DisplayText",
2207 display_text_891, sizeof(display_text_891),
2208 display_text_response_891,
2209 sizeof(display_text_response_891),
2210 test_display_text_89,
2211 expect_response_and_finish);
2212 stktest_add_test("Display Text 8.10", "DisplayText",
2213 display_text_8101, sizeof(display_text_8101),
2214 display_text_response_8101,
2215 sizeof(display_text_response_8101),
2216 test_display_text_810,
2217 expect_response_and_finish);
2218 stktest_add_test("Display Text 9.1", "DisplayText",
2219 display_text_911, sizeof(display_text_911),
2220 display_text_response_911,
2221 sizeof(display_text_response_911),
2222 test_display_text_91,
2223 expect_response_and_finish);
2224 stktest_add_test("Display Text 10.1", "DisplayText",
2225 display_text_1011, sizeof(display_text_1011),
2226 display_text_response_1011,
2227 sizeof(display_text_response_1011),
2228 test_display_text_101,
2229 expect_response_and_finish);
2230 stktest_add_test("Get Inkey 1.1", "RequestDigit",
2231 get_inkey_111, sizeof(get_inkey_111),
2232 get_inkey_response_111,
2233 sizeof(get_inkey_response_111),
2235 expect_response_and_finish);
2236 stktest_add_test("Get Inkey 1.2", "RequestDigit",
2237 get_inkey_121, sizeof(get_inkey_121),
2238 get_inkey_response_121,
2239 sizeof(get_inkey_response_121),
2241 expect_response_and_finish);
2242 stktest_add_test("Get Inkey 1.3", "RequestDigit",
2243 get_inkey_131, sizeof(get_inkey_131),
2244 get_inkey_response_131,
2245 sizeof(get_inkey_response_131),
2247 expect_response_and_finish);
2248 stktest_add_test("Get Inkey 1.4", "RequestDigit",
2249 get_inkey_141, sizeof(get_inkey_141),
2250 get_inkey_response_141,
2251 sizeof(get_inkey_response_141),
2253 expect_response_and_finish);
2254 stktest_add_test("Get Inkey 1.5", "RequestKey",
2255 get_inkey_151, sizeof(get_inkey_151),
2256 get_inkey_response_151,
2257 sizeof(get_inkey_response_151),
2259 expect_response_and_finish);
2260 stktest_add_test("Get Inkey 1.6", "RequestKey",
2261 get_inkey_161, sizeof(get_inkey_161),
2262 get_inkey_response_161,
2263 sizeof(get_inkey_response_161),
2265 expect_response_and_finish);
2266 stktest_add_test("Get Inkey 2.1", "RequestDigit",
2267 get_inkey_211, sizeof(get_inkey_211),
2268 get_inkey_response_211,
2269 sizeof(get_inkey_response_211),
2271 expect_response_and_finish);
2272 stktest_add_test("Get Inkey 3.1", "RequestDigit",
2273 get_inkey_311, sizeof(get_inkey_311),
2274 get_inkey_response_311,
2275 sizeof(get_inkey_response_311),
2277 expect_response_and_finish);
2278 stktest_add_test("Get Inkey 3.2", "RequestDigit",
2279 get_inkey_321, sizeof(get_inkey_321),
2280 get_inkey_response_321,
2281 sizeof(get_inkey_response_321),
2283 expect_response_and_finish);
2284 stktest_add_test("Get Inkey 4.1", "RequestKey",
2285 get_inkey_411, sizeof(get_inkey_411),
2286 get_inkey_response_411,
2287 sizeof(get_inkey_response_411),
2289 expect_response_and_finish);
2290 stktest_add_test("Get Inkey 5.1a", "RequestConfirmation",
2291 get_inkey_511, sizeof(get_inkey_511),
2292 get_inkey_response_511,
2293 sizeof(get_inkey_response_511),
2295 expect_response_and_finish);
2296 stktest_add_test("Get Inkey 5.1b", "RequestConfirmation",
2297 get_inkey_512, sizeof(get_inkey_512),
2298 get_inkey_response_512,
2299 sizeof(get_inkey_response_512),
2301 expect_response_and_finish);
2302 stktest_add_test("Get Inkey 6.1", "RequestDigit",
2303 get_inkey_611, sizeof(get_inkey_611),
2304 get_inkey_response_611,
2305 sizeof(get_inkey_response_611),
2307 expect_response_and_finish);
2308 stktest_add_test("Get Inkey 6.2", "RequestDigit",
2309 get_inkey_621, sizeof(get_inkey_621),
2310 get_inkey_response_621,
2311 sizeof(get_inkey_response_621),
2313 expect_response_and_finish);
2314 stktest_add_test("Get Inkey 6.3", "RequestDigit",
2315 get_inkey_631, sizeof(get_inkey_631),
2316 get_inkey_response_631,
2317 sizeof(get_inkey_response_631),
2319 expect_response_and_finish);
2320 stktest_add_test("Get Inkey 6.4", "RequestDigit",
2321 get_inkey_641, sizeof(get_inkey_641),
2322 get_inkey_response_641,
2323 sizeof(get_inkey_response_641),
2325 expect_response_and_finish);
2326 /* Test Sequence for GetInkey 7.1 skipped, we do not support help */
2327 stktest_add_test("Get Inkey 8.1", "RequestDigit",
2328 get_inkey_811, sizeof(get_inkey_811),
2329 get_inkey_response_811,
2330 sizeof(get_inkey_response_811),
2332 expect_response_and_finish);
2333 stktest_add_test("Get Inkey 9.1", "RequestDigit",
2334 get_inkey_911, sizeof(get_inkey_911),
2335 get_inkey_response_911,
2336 sizeof(get_inkey_response_911),
2338 expect_response_and_finish);
2339 stktest_add_test("Get Inkey 9.2", "RequestDigit",
2340 get_inkey_921, sizeof(get_inkey_921),
2341 get_inkey_response_921,
2342 sizeof(get_inkey_response_921),
2344 expect_response_and_finish);
2345 stktest_add_test("Get Inkey 9.3", "RequestDigit",
2346 get_inkey_931, sizeof(get_inkey_931),
2347 get_inkey_response_931,
2348 sizeof(get_inkey_response_931),
2350 expect_response_and_finish);
2351 stktest_add_test("Get Inkey 9.4", "RequestDigit",
2352 get_inkey_941, sizeof(get_inkey_941),
2353 get_inkey_response_941,
2354 sizeof(get_inkey_response_941),
2356 expect_response_and_finish);
2357 stktest_add_test("Get Inkey 9.5", "RequestDigit",
2358 get_inkey_951, sizeof(get_inkey_951),
2359 get_inkey_response_951,
2360 sizeof(get_inkey_response_951),
2362 expect_response_and_finish);
2363 stktest_add_test("Get Inkey 9.6", "RequestDigit",
2364 get_inkey_961, sizeof(get_inkey_961),
2365 get_inkey_response_961,
2366 sizeof(get_inkey_response_961),
2368 expect_response_and_finish);
2369 stktest_add_test("Get Inkey 9.7", "RequestDigit",
2370 get_inkey_971, sizeof(get_inkey_971),
2371 get_inkey_response_971,
2372 sizeof(get_inkey_response_971),
2374 expect_response_and_finish);
2375 stktest_add_test("Get Inkey 9.8", "RequestDigit",
2376 get_inkey_981, sizeof(get_inkey_981),
2377 get_inkey_response_981,
2378 sizeof(get_inkey_response_981),
2380 expect_response_and_finish);
2381 stktest_add_test("Get Inkey 9.9", "RequestDigit",
2382 get_inkey_991, sizeof(get_inkey_991),
2383 get_inkey_response_991,
2384 sizeof(get_inkey_response_991),
2386 expect_response_and_finish);
2387 stktest_add_test("Get Inkey 9.10", "RequestDigit",
2388 get_inkey_9101, sizeof(get_inkey_9101),
2389 get_inkey_response_9101,
2390 sizeof(get_inkey_response_9101),
2392 expect_response_and_finish);
2395 static void test_destroy(gpointer user_data)
2397 struct test *test = user_data;
2400 g_free(test->method);
2401 g_free(test->req_pdu);
2402 g_free(test->rsp_pdu);
2407 static void __stktest_test_summarize(void)
2410 unsigned int not_run = 0;
2411 unsigned int passed = 0;
2412 unsigned int failed = 0;
2414 g_print("\n\nTest Summary\n");
2415 g_print("============\n");
2417 for (l = tests; l; l = l->next) {
2418 struct test *test = l->data;
2420 g_print("%-60s", test->name);
2422 switch (test->result) {
2423 case TEST_RESULT_NOT_RUN:
2424 g_print("Not Run\n");
2427 case TEST_RESULT_PASSED:
2428 g_print("Passed\n");
2431 case TEST_RESULT_FAILED:
2432 g_print("Failed\n");
2438 g_print("\nTotal: %d, Passed: %d(%.1f%%), Failed: %d, NotRun: %d\n",
2439 not_run + passed + failed, passed,
2440 (float) passed * 100 / (not_run + passed + failed),
2444 static void __stktest_test_cleanup(void)
2446 g_list_free_full(tests, test_destroy);
2451 static gboolean option_version = FALSE;
2453 static GOptionEntry options[] = {
2454 { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
2455 "Show version information and exit" },
2459 int main(int argc, char **argv)
2461 GOptionContext *context;
2462 GError *error = NULL;
2465 struct sigaction sa;
2467 context = g_option_context_new(NULL);
2468 g_option_context_add_main_entries(context, options, NULL);
2470 if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
2471 if (error != NULL) {
2472 g_printerr("%s\n", error->message);
2473 g_error_free(error);
2475 g_printerr("An unknown error occurred\n");
2479 g_option_context_free(context);
2481 if (option_version == TRUE) {
2482 printf("%s\n", VERSION);
2486 __stktest_test_init();
2488 main_loop = g_main_loop_new(NULL, FALSE);
2490 dbus_error_init(&err);
2492 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
2494 if (dbus_error_is_set(&err) == TRUE) {
2495 fprintf(stderr, "%s\n", err.message);
2496 dbus_error_free(&err);
2498 fprintf(stderr, "Can't register with system bus\n");
2502 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
2504 memset(&sa, 0, sizeof(sa));
2505 sa.sa_handler = sig_term;
2506 sigaction(SIGINT, &sa, NULL);
2507 sigaction(SIGTERM, &sa, NULL);
2509 watch = g_dbus_add_service_watch(conn, OFONO_SERVICE,
2510 ofono_connect, ofono_disconnect, NULL, NULL);
2512 g_main_loop_run(main_loop);
2514 g_dbus_remove_watch(conn, watch);
2516 if (ofono_running == TRUE)
2517 ofono_disconnect(conn, NULL);
2519 dbus_connection_unref(conn);
2521 g_main_loop_unref(main_loop);
2523 __stktest_test_summarize();
2524 __stktest_test_cleanup();