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")
299 static void server_debug(const char *str, void *data)
301 g_print("%s: %s\n", (char *) data, str);
304 static void cgmi_cb(GAtServer *server, GAtServerRequestType type,
305 GAtResult *cmd, gpointer user)
308 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
309 g_at_server_send_info(server, "oFono", TRUE);
310 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
312 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
313 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
316 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
320 static void cgmm_cb(GAtServer *server, GAtServerRequestType type,
321 GAtResult *cmd, gpointer user)
324 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
325 g_at_server_send_info(server, "oFono pre-1.0", TRUE);
326 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
328 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
329 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
332 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
336 static void cgmr_cb(GAtServer *server, GAtServerRequestType type,
337 GAtResult *cmd, gpointer user)
342 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
343 sprintf(buf, "oFono pre-1.0 version: %s", VERSION);
344 g_at_server_send_info(server, buf, TRUE);
345 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
347 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
348 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
351 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
355 static void cgsn_cb(GAtServer *server, GAtServerRequestType type,
356 GAtResult *cmd, gpointer user)
359 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
360 g_at_server_send_info(server, "123456789", TRUE);
361 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
363 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
364 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
367 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
371 static gboolean send_ok(gpointer user)
373 GAtServer *server = user;
375 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
380 static void cfun_cb(GAtServer *server, GAtServerRequestType type,
381 GAtResult *cmd, gpointer user)
386 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
387 g_at_server_send_info(server, "+CFUN: (0-1,4)", TRUE);
388 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
390 case G_AT_SERVER_REQUEST_TYPE_QUERY:
391 snprintf(buf, sizeof(buf), "+CFUN: %d", modem_mode);
392 g_at_server_send_info(server, buf, TRUE);
393 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
395 case G_AT_SERVER_REQUEST_TYPE_SET:
400 g_at_result_iter_init(&iter, cmd);
401 g_at_result_iter_next(&iter, "");
403 if (g_at_result_iter_next_number(&iter, &mode) == FALSE)
406 if (mode != 0 && mode != 1)
409 if (modem_mode == mode) {
410 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
415 g_timeout_add_seconds(1, send_ok, server);
425 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
428 static void cusatt_cb(GAtServer *server, GAtServerRequestType type,
429 GAtResult *cmd, gpointer user)
432 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
433 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
435 case G_AT_SERVER_REQUEST_TYPE_QUERY:
436 g_at_server_send_ext_final(server, "+CME ERROR: 4");
438 case G_AT_SERVER_REQUEST_TYPE_SET:
441 const unsigned char *pdu;
444 terminal_response_func func;
446 g_at_result_iter_init(&iter, cmd);
447 g_at_result_iter_next(&iter, "");
449 if (g_at_result_iter_next_hexstring(&iter, &pdu, &len) == FALSE)
452 if (cur_test == NULL)
455 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
457 test = cur_test->data;
458 func = test->tr_func;
469 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
472 static void listen_again(gpointer user_data)
474 g_at_server_unref(emulator);
477 if (create_tcp() == TRUE)
480 g_print("Error listening to socket\n");
481 g_main_loop_quit(main_loop);
484 static void setup_emulator(GAtServer *server)
486 g_at_server_set_debug(server, server_debug, "Server");
488 g_at_server_register(server, "+CGMI", cgmi_cb, NULL, NULL);
489 g_at_server_register(server, "+CGMM", cgmm_cb, NULL, NULL);
490 g_at_server_register(server, "+CGMR", cgmr_cb, NULL, NULL);
491 g_at_server_register(server, "+CGSN", cgsn_cb, NULL, NULL);
492 g_at_server_register(server, "+CFUN", cfun_cb, NULL, NULL);
493 g_at_server_register(server, "+CUSATT", cusatt_cb, NULL, NULL);
495 g_at_server_set_disconnect_function(server, listen_again, NULL);
498 static gboolean on_socket_connected(GIOChannel *chan, GIOCondition cond,
501 struct sockaddr saddr;
502 unsigned int len = sizeof(saddr);
504 GIOChannel *client_io = NULL;
509 fd = accept(g_io_channel_unix_get_fd(chan), &saddr, &len);
513 client_io = g_io_channel_unix_new(fd);
515 emulator = g_at_server_new(client_io);
516 g_at_server_set_echo(emulator, FALSE);
517 g_io_channel_unref(client_io);
519 if (emulator == NULL)
522 setup_emulator(emulator);
529 static gboolean create_tcp(void)
531 struct sockaddr_in addr;
534 GIOChannel *server_io;
536 sk = socket(PF_INET, SOCK_STREAM, 0);
538 g_print("Can't create tcp/ip socket: %s (%d)\n",
539 strerror(errno), errno);
543 memset(&addr, 0, sizeof(addr));
545 addr.sin_family = AF_INET;
546 addr.sin_addr.s_addr = INADDR_ANY;
547 addr.sin_port = htons(LISTEN_PORT);
549 setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr));
550 if (bind(sk, (struct sockaddr *) &addr, sizeof(struct sockaddr)) < 0) {
551 g_print("Can't bind socket: %s (%d)", strerror(errno), errno);
556 if (listen(sk, 1) < 0) {
557 g_print("Can't listen on socket: %s (%d)",
558 strerror(errno), errno);
563 g_print("new tcp is created at tcp port %d\n", LISTEN_PORT);
565 server_io = g_io_channel_unix_new(sk);
566 g_io_channel_set_close_on_unref(server_io, TRUE);
568 server_watch = g_io_add_watch_full(server_io,
570 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
571 on_socket_connected, NULL, NULL);
573 g_io_channel_unref(server_io);
578 static gboolean has_stk_interface(DBusMessageIter *iter)
580 DBusMessageIter entry;
582 dbus_message_iter_recurse(iter, &entry);
584 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
585 const char *interface;
587 dbus_message_iter_get_basic(&entry, &interface);
589 if (g_str_equal(interface, OFONO_STK_INTERFACE) == TRUE)
592 dbus_message_iter_next(&entry);
598 static int send_with_reply(const char *path, const char *interface,
599 const char *method, DBusPendingCall **call,
600 DBusPendingCallNotifyFunction cb,
601 void *user_data, DBusFreeFunction free_func,
602 int timeout, int type, ...)
609 msg = dbus_message_new_method_call(OFONO_SERVICE, path,
612 g_printerr("Unable to allocate new D-Bus %s message\n", method);
617 va_start(args, type);
619 if (!dbus_message_append_args_valist(msg, type, args)) {
630 if (!dbus_connection_send_with_reply(conn, msg, &c, timeout)) {
631 g_printerr("Sending %s failed\n", method);
639 dbus_pending_call_set_notify(c, cb, user_data, free_func);
640 dbus_pending_call_unref(c);
642 dbus_message_unref(msg);
647 if (free_func && user_data)
648 free_func(user_data);
651 dbus_message_unref(msg);
656 static void set_property_reply(DBusPendingCall *call, void *user_data)
658 DBusMessage *reply = dbus_pending_call_steal_reply(call);
661 dbus_error_init(&err);
663 if (dbus_set_error_from_message(&err, reply) == TRUE) {
664 g_printerr("%s: %s\n", err.name, err.message);
665 dbus_error_free(&err);
668 dbus_message_unref(reply);
671 static int set_property(const char *path, const char *interface,
672 const char *key, int type, const void *val,
673 DBusPendingCallNotifyFunction notify,
675 DBusFreeFunction destroy)
678 DBusMessageIter iter, value;
679 DBusPendingCall *call;
680 const char *signature;
682 msg = dbus_message_new_method_call(OFONO_SERVICE, path, interface,
687 dbus_message_set_auto_start(msg, FALSE);
689 dbus_message_iter_init_append(msg, &iter);
691 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
694 case DBUS_TYPE_BOOLEAN:
695 signature = DBUS_TYPE_BOOLEAN_AS_STRING;
698 dbus_message_unref(msg);
702 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
704 dbus_message_iter_append_basic(&value, type, val);
705 dbus_message_iter_close_container(&iter, &value);
707 if (dbus_connection_send_with_reply(conn, msg, &call, -1) == FALSE) {
708 dbus_message_unref(msg);
712 dbus_message_unref(msg);
717 dbus_pending_call_set_notify(call, notify, user_data, destroy);
719 dbus_pending_call_unref(call);
724 static void register_agent_reply(DBusPendingCall *call, void *user_data)
726 DBusMessage *reply = dbus_pending_call_steal_reply(call);
730 dbus_error_init(&err);
732 if (dbus_set_error_from_message(&err, reply) == TRUE) {
733 g_printerr("%s: %s\n", err.name, err.message);
734 dbus_error_free(&err);
737 dbus_message_unref(reply);
739 state = TEST_STATE_RUNNING;
740 test = cur_test->data;
741 send_proactive_command(test->req_pdu, test->req_len);
744 static void register_agent()
746 const char *path = "/default";
749 g_print("Gained STK interface, registering agent...\n");
751 status = send_with_reply(STKTEST_PATH, OFONO_STK_INTERFACE,
752 "RegisterAgent", NULL,
753 register_agent_reply, NULL, NULL, 1,
754 DBUS_TYPE_OBJECT_PATH, &path,
758 g_printerr("Unable to register agent with oFono\n");
759 g_main_loop_quit(main_loop);
763 state = TEST_STATE_REGISTERING_AGENT;
766 static gboolean modem_changed(DBusConnection *conn,
767 DBusMessage *msg, void *user_data)
769 DBusMessageIter iter, value;
770 const char *path, *key;
773 if (dbus_message_iter_init(msg, &iter) == FALSE)
776 path = dbus_message_get_path(msg);
778 if (g_str_equal(STKTEST_PATH, path) == FALSE)
781 dbus_message_iter_get_basic(&iter, &key);
783 dbus_message_iter_next(&iter);
784 dbus_message_iter_recurse(&iter, &value);
786 if (g_str_equal(key, "Interfaces") == FALSE)
789 has_stk = has_stk_interface(&value);
792 case TEST_STATE_POWERING_UP:
796 case TEST_STATE_REGISTERING_AGENT:
797 case TEST_STATE_RUNNING:
798 if (has_stk == FALSE)
799 g_printerr("Unexpectedly lost STK interface\n");
801 case TEST_STATE_POWERING_DOWN:
808 static void powerup(void)
810 dbus_bool_t powered = TRUE;
812 state = TEST_STATE_POWERING_UP;
813 set_property(STKTEST_PATH, OFONO_MODEM_INTERFACE, "Powered",
814 DBUS_TYPE_BOOLEAN, &powered,
815 set_property_reply, NULL, NULL);
818 static void get_modems_reply(DBusPendingCall *call, void *user_data)
820 DBusMessage *reply = dbus_pending_call_steal_reply(call);
821 DBusMessageIter iter, list;
823 gboolean found = FALSE;
825 dbus_error_init(&err);
827 if (dbus_set_error_from_message(&err, reply) == TRUE) {
828 g_printerr("%s: %s\n", err.name, err.message);
829 dbus_error_free(&err);
833 if (dbus_message_has_signature(reply, "a(oa{sv})") == FALSE)
836 if (dbus_message_iter_init(reply, &iter) == FALSE)
839 dbus_message_iter_recurse(&iter, &list);
841 while (dbus_message_iter_get_arg_type(&list) == DBUS_TYPE_STRUCT) {
842 DBusMessageIter entry;
845 dbus_message_iter_recurse(&list, &entry);
846 dbus_message_iter_get_basic(&entry, &path);
848 if (g_str_equal(path, STKTEST_PATH))
851 dbus_message_iter_next(&list);
855 dbus_message_unref(reply);
857 if (found == FALSE) {
858 g_printerr("STK Test modem not found\n");
859 g_main_loop_quit(main_loop);
863 g_print("Test modem found\n");
865 modem_changed_watch = g_dbus_add_signal_watch(conn, OFONO_SERVICE,
867 OFONO_MODEM_INTERFACE,
872 if (create_tcp() == FALSE) {
873 g_printerr("Unable to listen on modem emulator socket\n");
874 g_main_loop_quit(main_loop);
877 __stktest_test_next();
880 static int get_modems(DBusConnection *conn)
883 DBusPendingCall *call;
885 msg = dbus_message_new_method_call(OFONO_SERVICE, "/",
886 OFONO_MANAGER_INTERFACE, "GetModems");
890 dbus_message_set_auto_start(msg, FALSE);
892 g_print("getting modems\n");
894 if (dbus_connection_send_with_reply(conn, msg, &call, -1) == FALSE) {
895 dbus_message_unref(msg);
899 dbus_message_unref(msg);
904 dbus_pending_call_set_notify(call, get_modems_reply, conn, NULL);
906 dbus_pending_call_unref(call);
911 static const GDBusMethodTable agent_methods[] = {
912 { GDBUS_METHOD("Release", NULL, NULL, agent_release) },
913 { GDBUS_ASYNC_METHOD("DisplayText",
914 GDBUS_ARGS({ "text", "s" }, { "icon_id", "y" },
915 { "urgent", "b" }), NULL,
916 agent_display_text) },
917 { GDBUS_ASYNC_METHOD("RequestDigit",
918 GDBUS_ARGS({ "alpha", "s" }, { "icon_id", "y" }),
919 GDBUS_ARGS({ "digit", "s" }),
920 agent_request_digit) },
921 { GDBUS_ASYNC_METHOD("RequestKey",
922 GDBUS_ARGS({ "alpha", "s" }, { "icon_id", "y" }),
923 GDBUS_ARGS({ "key", "s" }),
924 agent_request_key) },
925 { GDBUS_NOREPLY_METHOD("Cancel", NULL, NULL, agent_cancel) },
929 static void ofono_connect(DBusConnection *conn, void *user_data)
931 g_print("starting telephony interface\n");
933 if (!g_dbus_register_interface(conn, "/default",
934 OFONO_STKAGENT_INTERFACE,
935 agent_methods, NULL, NULL,
937 g_printerr("Unable to register local agent");
938 g_main_loop_quit(main_loop);
941 ofono_running = TRUE;
945 static void ofono_disconnect(DBusConnection *conn, void *user_data)
947 g_print("stopping telephony interface\n");
949 g_dbus_unregister_interface(conn, "/default", OFONO_STKAGENT_INTERFACE);
951 ofono_running = FALSE;
953 g_dbus_remove_watch(conn, modem_changed_watch);
954 modem_changed_watch = 0;
957 g_source_remove(server_watch);
961 g_at_server_unref(emulator);
965 static void sig_term(int sig)
967 if (__terminated > 0)
972 g_print("Terminating\n");
974 g_main_loop_quit(main_loop);
977 static void disconnect_callback(DBusConnection *conn, void *user_data)
979 g_printerr("D-Bus disconnect\n");
981 g_main_loop_quit(main_loop);
984 static gboolean end_session_and_finish(gpointer user_data)
986 g_at_server_send_unsolicited(emulator, "+CUSATEND");
987 __stktest_test_finish(TRUE);
992 static void expect_response_and_finish(const unsigned char *pdu,
995 struct test *test = cur_test->data;
997 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
999 g_idle_add(end_session_and_finish, NULL);
1002 static void expect_response(const unsigned char *pdu, unsigned int len)
1004 struct test *test = cur_test->data;
1006 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
1009 static gboolean poweroff_not_canceled_after_3(gpointer user_data)
1011 __stktest_test_finish(pending != NULL);
1015 static gboolean end_session_and_not_canceled_after_3(gpointer user_data)
1017 g_at_server_send_unsolicited(emulator, "+CUSATEND");
1018 g_timeout_add_seconds(3, poweroff_not_canceled_after_3, NULL);
1023 static void expect_response_and_not_canceled_after_3(const unsigned char *pdu,
1026 struct test *test = cur_test->data;
1028 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
1030 g_idle_add(end_session_and_not_canceled_after_3, NULL);
1033 static gboolean poweroff_and_canceled_after_21(gpointer user_data)
1035 __stktest_test_finish(pending == NULL);
1039 static gboolean end_session_and_canceled_after_21(gpointer user_data)
1041 g_at_server_send_unsolicited(emulator, "+CUSATEND");
1042 g_timeout_add_seconds(21, poweroff_and_canceled_after_21, NULL);
1047 static void expect_response_and_canceled_after_21(const unsigned char *pdu,
1050 struct test *test = cur_test->data;
1052 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
1054 g_idle_add(end_session_and_canceled_after_21, NULL);
1057 static DBusMessage *test_display_text_11(DBusMessage *msg,
1059 unsigned char icon_id,
1062 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 1"));
1063 STKTEST_AGENT_ASSERT(icon_id == 0);
1064 STKTEST_AGENT_ASSERT(urgent == FALSE);
1066 return dbus_message_new_method_return(msg);
1069 static DBusMessage *test_display_text_12(DBusMessage *msg,
1071 unsigned char icon_id,
1074 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 1"));
1075 STKTEST_AGENT_ASSERT(icon_id == 0);
1076 STKTEST_AGENT_ASSERT(urgent == FALSE);
1078 return stktest_error_busy(msg);
1081 static DBusMessage *test_display_text_13(DBusMessage *msg,
1083 unsigned char icon_id,
1086 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 2"));
1087 STKTEST_AGENT_ASSERT(icon_id == 0);
1088 STKTEST_AGENT_ASSERT(urgent == TRUE);
1090 return dbus_message_new_method_return(msg);
1093 static DBusMessage *test_display_text_14(DBusMessage *msg,
1095 unsigned char icon_id,
1098 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 3"));
1099 STKTEST_AGENT_ASSERT(icon_id == 0);
1100 STKTEST_AGENT_ASSERT(urgent == FALSE);
1102 return dbus_message_new_method_return(msg);
1105 static DBusMessage *test_display_text_15(DBusMessage *msg,
1107 unsigned char icon_id,
1110 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 4"));
1111 STKTEST_AGENT_ASSERT(icon_id == 0);
1112 STKTEST_AGENT_ASSERT(urgent == FALSE);
1117 static DBusMessage *test_display_text_16(DBusMessage *msg,
1119 unsigned char icon_id,
1122 STKTEST_AGENT_ASSERT(g_str_equal(text, "This command instructs the ME"
1123 " to display a text message. "
1124 "It allows the SIM to define "
1125 "the priority of that message, "
1126 "and the text string format. "
1127 "Two types of prio"));
1128 STKTEST_AGENT_ASSERT(icon_id == 0);
1129 STKTEST_AGENT_ASSERT(urgent == FALSE);
1131 return dbus_message_new_method_return(msg);
1134 static DBusMessage *test_display_text_17(DBusMessage *msg,
1136 unsigned char icon_id,
1139 /* oFono gives rich text formatting in HTML */
1140 STKTEST_AGENT_ASSERT(g_str_equal(text, "<GO-BACKWARDS>"));
1141 STKTEST_AGENT_ASSERT(icon_id == 0);
1142 STKTEST_AGENT_ASSERT(urgent == FALSE);
1144 return stktest_error_go_back(msg);
1147 static DBusMessage *test_display_text_18(DBusMessage *msg,
1149 unsigned char icon_id,
1152 /* oFono gives rich text formatting in HTML */
1153 STKTEST_AGENT_ASSERT(g_str_equal(text, "<ABORT>"));
1154 STKTEST_AGENT_ASSERT(icon_id == 0);
1155 STKTEST_AGENT_ASSERT(urgent == FALSE);
1157 return stktest_error_end_session(msg);
1160 static DBusMessage *test_display_text_21(DBusMessage *msg,
1162 unsigned char icon_id,
1165 STKTEST_AGENT_ASSERT(g_str_equal(text, "<TIME-OUT>"));
1166 STKTEST_AGENT_ASSERT(icon_id == 0);
1167 STKTEST_AGENT_ASSERT(urgent == FALSE);
1172 static DBusMessage *test_display_text_31(DBusMessage *msg,
1174 unsigned char icon_id,
1177 static const char *expected = "This command instructs the ME to display"
1178 " a text message, and/or an icon "
1179 "(see 6.5.4). It allows the "
1180 "SIM to define the priority of that "
1181 "message, and the text string format. "
1182 "Two types of priority are defined:- "
1183 "display normal priority text and/";
1184 STKTEST_AGENT_ASSERT(g_str_equal(text, expected));
1185 STKTEST_AGENT_ASSERT(icon_id == 0);
1186 STKTEST_AGENT_ASSERT(urgent == FALSE);
1188 return dbus_message_new_method_return(msg);
1191 static DBusMessage *test_display_text_41(DBusMessage *msg,
1193 unsigned char icon_id,
1196 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 1"));
1197 STKTEST_AGENT_ASSERT(icon_id == 0);
1198 STKTEST_AGENT_ASSERT(urgent == FALSE);
1203 static DBusMessage *test_display_text_42(DBusMessage *msg,
1205 unsigned char icon_id,
1208 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 2"));
1209 STKTEST_AGENT_ASSERT(icon_id == 0);
1210 STKTEST_AGENT_ASSERT(urgent == FALSE);
1215 static gboolean user_response(gpointer user_data)
1217 if (pending == NULL) {
1218 __stktest_test_finish(FALSE);
1222 g_dbus_send_reply(conn, pending, DBUS_TYPE_INVALID);
1223 dbus_message_unref(pending);
1226 __stktest_test_finish(TRUE);
1231 static DBusMessage *test_display_text_43(DBusMessage *msg,
1233 unsigned char icon_id,
1236 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 3"));
1237 STKTEST_AGENT_ASSERT(icon_id == 0);
1238 STKTEST_AGENT_ASSERT(urgent == FALSE);
1240 g_timeout_add_seconds(3, user_response, NULL);
1244 static DBusMessage *test_display_text_51(DBusMessage *msg,
1246 unsigned char icon_id,
1249 STKTEST_AGENT_ASSERT(g_str_equal(text, "Basic Icon"));
1250 STKTEST_AGENT_ASSERT(icon_id == 1);
1251 STKTEST_AGENT_ASSERT(urgent == FALSE);
1253 return dbus_message_new_method_return(msg);
1256 static DBusMessage *test_display_text_52(DBusMessage *msg,
1258 unsigned char icon_id,
1261 STKTEST_AGENT_ASSERT(g_str_equal(text, "Colour Icon"));
1262 STKTEST_AGENT_ASSERT(icon_id == 2);
1263 STKTEST_AGENT_ASSERT(urgent == FALSE);
1265 return dbus_message_new_method_return(msg);
1268 static DBusMessage *test_display_text_53(DBusMessage *msg,
1270 unsigned char icon_id,
1273 STKTEST_AGENT_ASSERT(g_str_equal(text, "Basic Icon"));
1274 STKTEST_AGENT_ASSERT(icon_id == 1);
1275 STKTEST_AGENT_ASSERT(urgent == FALSE);
1277 return dbus_message_new_method_return(msg);
1280 static DBusMessage *test_display_text_61(DBusMessage *msg,
1282 unsigned char icon_id,
1285 STKTEST_AGENT_ASSERT(g_str_equal(text, "ЗДРАВСТВУЙТЕ"));
1286 STKTEST_AGENT_ASSERT(icon_id == 0);
1287 STKTEST_AGENT_ASSERT(urgent == FALSE);
1289 return dbus_message_new_method_return(msg);
1292 static DBusMessage *test_display_text_71(DBusMessage *msg,
1294 unsigned char icon_id,
1297 STKTEST_AGENT_ASSERT(g_str_equal(text, "10 Second"));
1298 STKTEST_AGENT_ASSERT(icon_id == 0);
1299 STKTEST_AGENT_ASSERT(urgent == FALSE);
1304 static DBusMessage *test_display_text_81(DBusMessage *msg,
1306 unsigned char icon_id,
1309 const char *expect =
1310 "<div style=\"text-align: left;\"><span style=\"color: "
1311 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1314 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1315 STKTEST_AGENT_ASSERT(icon_id == 0);
1316 STKTEST_AGENT_ASSERT(urgent == FALSE);
1318 return dbus_message_new_method_return(msg);
1321 static DBusMessage *test_display_text_82(DBusMessage *msg,
1323 unsigned char icon_id,
1326 const char *expect =
1327 "<div style=\"text-align: center;\"><span style=\"color: "
1328 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1331 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1332 STKTEST_AGENT_ASSERT(icon_id == 0);
1333 STKTEST_AGENT_ASSERT(urgent == FALSE);
1335 return dbus_message_new_method_return(msg);
1338 static DBusMessage *test_display_text_83(DBusMessage *msg,
1340 unsigned char icon_id,
1343 const char *expect =
1344 "<div style=\"text-align: right;\"><span style=\"color: "
1345 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1348 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1349 STKTEST_AGENT_ASSERT(icon_id == 0);
1350 STKTEST_AGENT_ASSERT(urgent == FALSE);
1352 return dbus_message_new_method_return(msg);
1355 static DBusMessage *test_display_text_84(DBusMessage *msg,
1357 unsigned char icon_id,
1360 const char *expect =
1361 "<div style=\"text-align: left;\"><span style=\"font-size: "
1362 "big;color: #347235;background-color: #FFFF00;\">"
1363 "Text Attribute 1</span></div>";
1365 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1366 STKTEST_AGENT_ASSERT(icon_id == 0);
1367 STKTEST_AGENT_ASSERT(urgent == FALSE);
1369 return dbus_message_new_method_return(msg);
1372 static DBusMessage *test_display_text_85(DBusMessage *msg,
1374 unsigned char icon_id,
1377 const char *expect =
1378 "<div style=\"text-align: left;\"><span style=\"font-size: "
1379 "small;color: #347235;background-color: #FFFF00;\">"
1380 "Text Attribute 1</span></div>";
1382 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1383 STKTEST_AGENT_ASSERT(icon_id == 0);
1384 STKTEST_AGENT_ASSERT(urgent == FALSE);
1386 return dbus_message_new_method_return(msg);
1389 static DBusMessage *test_display_text_86(DBusMessage *msg,
1391 unsigned char icon_id,
1394 const char *expect =
1395 "<div style=\"text-align: left;\"><span style=\"font-weight: "
1396 "bold;color: #347235;background-color: #FFFF00;\">"
1397 "Text Attribute 1</span></div>";
1399 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1400 STKTEST_AGENT_ASSERT(icon_id == 0);
1401 STKTEST_AGENT_ASSERT(urgent == FALSE);
1403 return dbus_message_new_method_return(msg);
1406 static DBusMessage *test_display_text_87(DBusMessage *msg,
1408 unsigned char icon_id,
1411 const char *expect =
1412 "<div style=\"text-align: left;\"><span style=\"font-style: "
1413 "italic;color: #347235;background-color: #FFFF00;\">"
1414 "Text Attribute 1</span></div>";
1416 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1417 STKTEST_AGENT_ASSERT(icon_id == 0);
1418 STKTEST_AGENT_ASSERT(urgent == FALSE);
1420 return dbus_message_new_method_return(msg);
1423 static DBusMessage *test_display_text_88(DBusMessage *msg,
1425 unsigned char icon_id,
1428 const char *expect =
1429 "<div style=\"text-align: left;\"><span style=\""
1430 "text-decoration: underline;color: #347235;"
1431 "background-color: #FFFF00;\">Text Attribute 1</span></div>";
1433 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1434 STKTEST_AGENT_ASSERT(icon_id == 0);
1435 STKTEST_AGENT_ASSERT(urgent == FALSE);
1437 return dbus_message_new_method_return(msg);
1440 static DBusMessage *test_display_text_89(DBusMessage *msg,
1442 unsigned char icon_id,
1445 const char *expect =
1446 "<div style=\"text-align: left;\"><span style=\""
1447 "text-decoration: line-through;color: #347235;"
1448 "background-color: #FFFF00;\">Text Attribute 1</span></div>";
1450 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1451 STKTEST_AGENT_ASSERT(icon_id == 0);
1452 STKTEST_AGENT_ASSERT(urgent == FALSE);
1454 return dbus_message_new_method_return(msg);
1457 static DBusMessage *test_display_text_810(DBusMessage *msg,
1459 unsigned char icon_id,
1462 const char *expect =
1463 "<div style=\"text-align: left;\"><span style=\"color: "
1464 "#347235;background-color: #FFFF00;\">Text Attribute 1</span>"
1467 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1468 STKTEST_AGENT_ASSERT(icon_id == 0);
1469 STKTEST_AGENT_ASSERT(urgent == FALSE);
1471 return dbus_message_new_method_return(msg);
1474 static DBusMessage *test_display_text_91(DBusMessage *msg,
1476 unsigned char icon_id,
1479 const char *expect = "你好";
1481 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1482 STKTEST_AGENT_ASSERT(icon_id == 0);
1483 STKTEST_AGENT_ASSERT(urgent == FALSE);
1485 return dbus_message_new_method_return(msg);
1488 static DBusMessage *test_display_text_101(DBusMessage *msg,
1490 unsigned char icon_id,
1493 const char *expect = "80ル";
1495 STKTEST_AGENT_ASSERT(g_str_equal(text, expect));
1496 STKTEST_AGENT_ASSERT(icon_id == 0);
1497 STKTEST_AGENT_ASSERT(urgent == FALSE);
1499 return dbus_message_new_method_return(msg);
1502 static DBusMessage *test_get_inkey_11(DBusMessage *msg,
1504 unsigned char icon_id)
1507 const char *ret = "+";
1509 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "Enter \"+\""));
1510 STKTEST_AGENT_ASSERT(icon_id == 0);
1512 reply = dbus_message_new_method_return(msg);
1513 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1519 static DBusMessage *test_get_inkey_12(DBusMessage *msg,
1521 unsigned char icon_id)
1524 const char *ret = "0";
1526 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "Enter \"0\""));
1527 STKTEST_AGENT_ASSERT(icon_id == 0);
1529 reply = dbus_message_new_method_return(msg);
1530 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1536 static DBusMessage *test_get_inkey_13(DBusMessage *msg,
1538 unsigned char icon_id)
1540 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "<GO-BACKWARDS>"));
1541 STKTEST_AGENT_ASSERT(icon_id == 0);
1543 return stktest_error_go_back(msg);
1546 static DBusMessage *test_get_inkey_14(DBusMessage *msg,
1548 unsigned char icon_id)
1550 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "<ABORT>"));
1551 STKTEST_AGENT_ASSERT(icon_id == 0);
1553 return stktest_error_end_session(msg);
1556 static DBusMessage *test_get_inkey_15(DBusMessage *msg,
1558 unsigned char icon_id)
1561 const char *ret = "q";
1563 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "Enter \"q\""));
1564 STKTEST_AGENT_ASSERT(icon_id == 0);
1566 reply = dbus_message_new_method_return(msg);
1567 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1573 static DBusMessage *test_get_inkey_16(DBusMessage *msg,
1575 unsigned char icon_id)
1578 const char *ret = "x";
1579 const char *expected =
1580 "Enter \"x\". This command instructs the ME to display text, "
1581 "and to expect the user to enter a single character. Any "
1582 "response entered by the user shall be passed t";
1584 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expected));
1585 STKTEST_AGENT_ASSERT(icon_id == 0);
1587 reply = dbus_message_new_method_return(msg);
1588 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1594 static DBusMessage *test_get_inkey_21(DBusMessage *msg,
1595 const char *text, unsigned char icon_id)
1597 STKTEST_AGENT_ASSERT(g_str_equal(text, "<TIME-OUT>"));
1598 STKTEST_AGENT_ASSERT(icon_id == 0);
1603 static DBusMessage *test_get_inkey_31(DBusMessage *msg,
1605 unsigned char icon_id)
1608 const char *ret = "+";
1610 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "ЗДРАВСТВУЙТЕ"));
1611 STKTEST_AGENT_ASSERT(icon_id == 0);
1613 reply = dbus_message_new_method_return(msg);
1614 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1620 static DBusMessage *test_get_inkey_32(DBusMessage *msg,
1622 unsigned char icon_id)
1625 const char *ret = "+";
1626 const char *expect = "ЗДРАВСТВУЙТЕЗДРАВСТВУЙТЕ"
1627 "ЗДРАВСТВУЙТЕЗДРАВСТВУЙТЕ"
1628 "ЗДРАВСТВУЙТЕЗДРАВСТВУЙ";
1630 STKTEST_AGENT_ASSERT(g_str_equal(alpha, expect));
1631 STKTEST_AGENT_ASSERT(icon_id == 0);
1633 reply = dbus_message_new_method_return(msg);
1634 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1640 static DBusMessage *test_get_inkey_41(DBusMessage *msg,
1642 unsigned char icon_id)
1645 const char *ret = "Д";
1647 STKTEST_AGENT_ASSERT(g_str_equal(alpha, "Enter"));
1648 STKTEST_AGENT_ASSERT(icon_id == 0);
1650 reply = dbus_message_new_method_return(msg);
1651 dbus_message_append_args(reply, DBUS_TYPE_STRING, &ret,
1657 static void power_down_reply(DBusPendingCall *call, void *user_data)
1659 __stktest_test_next();
1662 void __stktest_test_finish(gboolean successful)
1664 struct test *test = cur_test->data;
1665 dbus_bool_t powered = FALSE;
1667 test->result = successful ? TEST_RESULT_PASSED : TEST_RESULT_FAILED;
1669 state = TEST_STATE_POWERING_DOWN;
1670 set_property(STKTEST_PATH, OFONO_MODEM_INTERFACE, "Powered",
1671 DBUS_TYPE_BOOLEAN, &powered,
1672 power_down_reply, NULL, NULL);
1675 void __stktest_test_next()
1677 if (cur_test == NULL)
1680 cur_test = cur_test->next;
1682 if (cur_test == NULL) {
1683 g_main_loop_quit(main_loop);
1690 static void stktest_add_test(const char *name, const char *method,
1691 const unsigned char *req, unsigned int req_len,
1692 const unsigned char *rsp, unsigned int rsp_len,
1694 terminal_response_func tr_func)
1696 struct test *test = g_new0(struct test, 1);
1698 test->name = g_strdup(name);
1699 test->method = g_strdup(method);
1700 test->req_pdu = g_memdup(req, req_len);
1701 test->req_len = req_len;
1702 test->rsp_pdu = g_memdup(rsp, rsp_len);
1703 test->rsp_len = rsp_len;
1704 test->agent_func = agent_func;
1705 test->tr_func = tr_func;
1707 tests = g_list_append(tests, test);
1710 static void __stktest_test_init(void)
1712 stktest_add_test("Display Text 1.1", "DisplayText",
1713 display_text_111, sizeof(display_text_111),
1714 display_text_response_111,
1715 sizeof(display_text_response_111),
1716 test_display_text_11,
1717 expect_response_and_finish);
1718 stktest_add_test("Display Text 1.2", "DisplayText",
1719 display_text_111, sizeof(display_text_111),
1720 display_text_response_121,
1721 sizeof(display_text_response_121),
1722 test_display_text_12,
1723 expect_response_and_finish);
1724 stktest_add_test("Display Text 1.3", "DisplayText",
1725 display_text_131, sizeof(display_text_131),
1726 display_text_response_131,
1727 sizeof(display_text_response_131),
1728 test_display_text_13,
1729 expect_response_and_finish);
1730 stktest_add_test("Display Text 1.4", "DisplayText",
1731 display_text_141, sizeof(display_text_141),
1732 display_text_response_141,
1733 sizeof(display_text_response_141),
1734 test_display_text_14,
1735 expect_response_and_finish);
1736 stktest_add_test("Display Text 1.5", "DisplayText",
1737 display_text_151, sizeof(display_text_151),
1738 display_text_response_151,
1739 sizeof(display_text_response_151),
1740 test_display_text_15,
1741 expect_response_and_finish);
1742 stktest_add_test("Display Text 1.6", "DisplayText",
1743 display_text_161, sizeof(display_text_161),
1744 display_text_response_161,
1745 sizeof(display_text_response_161),
1746 test_display_text_16,
1747 expect_response_and_finish);
1748 stktest_add_test("Display Text 1.7", "DisplayText",
1749 display_text_171, sizeof(display_text_171),
1750 display_text_response_171,
1751 sizeof(display_text_response_171),
1752 test_display_text_17,
1753 expect_response_and_finish);
1754 stktest_add_test("Display Text 1.8", "DisplayText",
1755 display_text_181, sizeof(display_text_181),
1756 display_text_response_181,
1757 sizeof(display_text_response_181),
1758 test_display_text_18,
1759 expect_response_and_finish);
1760 stktest_add_test("Display Text 1.9", "DisplayText",
1761 display_text_191, sizeof(display_text_191),
1762 display_text_response_191,
1763 sizeof(display_text_response_191),
1764 NULL, expect_response_and_finish);
1765 stktest_add_test("Display Text 2.1", "DisplayText",
1766 display_text_211, sizeof(display_text_211),
1767 display_text_response_211,
1768 sizeof(display_text_response_211),
1769 test_display_text_21,
1770 expect_response_and_finish);
1771 stktest_add_test("Display Text 3.1", "DisplayText",
1772 display_text_311, sizeof(display_text_311),
1773 display_text_response_311,
1774 sizeof(display_text_response_311),
1775 test_display_text_31,
1776 expect_response_and_finish);
1777 stktest_add_test("Display Text 4.1", "DisplayText",
1778 display_text_411, sizeof(display_text_411),
1779 display_text_response_411,
1780 sizeof(display_text_response_411),
1781 test_display_text_41,
1782 expect_response_and_not_canceled_after_3);
1783 stktest_add_test("Display Text 4.2", "DisplayText",
1784 display_text_421, sizeof(display_text_421),
1785 display_text_response_421,
1786 sizeof(display_text_response_421),
1787 test_display_text_42,
1788 expect_response_and_canceled_after_21);
1789 stktest_add_test("Display Text 4.3", "DisplayText",
1790 display_text_431, sizeof(display_text_431),
1791 display_text_response_431,
1792 sizeof(display_text_response_431),
1793 test_display_text_43, expect_response);
1794 stktest_add_test("Display Text 5.1A", "DisplayText",
1795 display_text_511, sizeof(display_text_511),
1796 display_text_response_511a,
1797 sizeof(display_text_response_511a),
1798 test_display_text_51,
1799 expect_response_and_finish);
1800 stktest_add_test("Display Text 5.2A", "DisplayText",
1801 display_text_521, sizeof(display_text_521),
1802 display_text_response_521a,
1803 sizeof(display_text_response_521a),
1804 test_display_text_52,
1805 expect_response_and_finish);
1806 stktest_add_test("Display Text 5.3A", "DisplayText",
1807 display_text_531, sizeof(display_text_531),
1808 display_text_response_531a,
1809 sizeof(display_text_response_531a),
1810 test_display_text_53,
1811 expect_response_and_finish);
1812 stktest_add_test("Display Text 6.1", "DisplayText",
1813 display_text_611, sizeof(display_text_611),
1814 display_text_response_611,
1815 sizeof(display_text_response_611),
1816 test_display_text_61,
1817 expect_response_and_finish);
1818 stktest_add_test("Display Text 7.1", "DisplayText",
1819 display_text_711, sizeof(display_text_711),
1820 display_text_response_711,
1821 sizeof(display_text_response_711),
1822 test_display_text_71,
1823 expect_response_and_finish);
1825 * We skip parts where the UI is asked to display simple text to ensure
1826 * that the alignment, font is set up correctly and not 'remembered'
1827 * from a previous state. oFono does not keep any state of the
1830 stktest_add_test("Display Text 8.1", "DisplayText",
1831 display_text_811, sizeof(display_text_811),
1832 display_text_response_811,
1833 sizeof(display_text_response_811),
1834 test_display_text_81,
1835 expect_response_and_finish);
1836 stktest_add_test("Display Text 8.2", "DisplayText",
1837 display_text_821, sizeof(display_text_821),
1838 display_text_response_821,
1839 sizeof(display_text_response_821),
1840 test_display_text_82,
1841 expect_response_and_finish);
1842 stktest_add_test("Display Text 8.3", "DisplayText",
1843 display_text_831, sizeof(display_text_831),
1844 display_text_response_831,
1845 sizeof(display_text_response_831),
1846 test_display_text_83,
1847 expect_response_and_finish);
1848 stktest_add_test("Display Text 8.4", "DisplayText",
1849 display_text_841, sizeof(display_text_841),
1850 display_text_response_841,
1851 sizeof(display_text_response_841),
1852 test_display_text_84,
1853 expect_response_and_finish);
1854 stktest_add_test("Display Text 8.5", "DisplayText",
1855 display_text_851, sizeof(display_text_851),
1856 display_text_response_851,
1857 sizeof(display_text_response_851),
1858 test_display_text_85,
1859 expect_response_and_finish);
1860 stktest_add_test("Display Text 8.6", "DisplayText",
1861 display_text_861, sizeof(display_text_861),
1862 display_text_response_861,
1863 sizeof(display_text_response_861),
1864 test_display_text_86,
1865 expect_response_and_finish);
1866 stktest_add_test("Display Text 8.7", "DisplayText",
1867 display_text_871, sizeof(display_text_871),
1868 display_text_response_871,
1869 sizeof(display_text_response_871),
1870 test_display_text_87,
1871 expect_response_and_finish);
1872 stktest_add_test("Display Text 8.8", "DisplayText",
1873 display_text_881, sizeof(display_text_881),
1874 display_text_response_881,
1875 sizeof(display_text_response_881),
1876 test_display_text_88,
1877 expect_response_and_finish);
1878 stktest_add_test("Display Text 8.9", "DisplayText",
1879 display_text_891, sizeof(display_text_891),
1880 display_text_response_891,
1881 sizeof(display_text_response_891),
1882 test_display_text_89,
1883 expect_response_and_finish);
1884 stktest_add_test("Display Text 8.10", "DisplayText",
1885 display_text_8101, sizeof(display_text_8101),
1886 display_text_response_8101,
1887 sizeof(display_text_response_8101),
1888 test_display_text_810,
1889 expect_response_and_finish);
1890 stktest_add_test("Display Text 9.1", "DisplayText",
1891 display_text_911, sizeof(display_text_911),
1892 display_text_response_911,
1893 sizeof(display_text_response_911),
1894 test_display_text_91,
1895 expect_response_and_finish);
1896 stktest_add_test("Display Text 10.1", "DisplayText",
1897 display_text_1011, sizeof(display_text_1011),
1898 display_text_response_1011,
1899 sizeof(display_text_response_1011),
1900 test_display_text_101,
1901 expect_response_and_finish);
1902 stktest_add_test("Get Inkey 1.1", "RequestDigit",
1903 get_inkey_111, sizeof(get_inkey_111),
1904 get_inkey_response_111,
1905 sizeof(get_inkey_response_111),
1907 expect_response_and_finish);
1908 stktest_add_test("Get Inkey 1.2", "RequestDigit",
1909 get_inkey_121, sizeof(get_inkey_121),
1910 get_inkey_response_121,
1911 sizeof(get_inkey_response_121),
1913 expect_response_and_finish);
1914 stktest_add_test("Get Inkey 1.3", "RequestDigit",
1915 get_inkey_131, sizeof(get_inkey_131),
1916 get_inkey_response_131,
1917 sizeof(get_inkey_response_131),
1919 expect_response_and_finish);
1920 stktest_add_test("Get Inkey 1.4", "RequestDigit",
1921 get_inkey_141, sizeof(get_inkey_141),
1922 get_inkey_response_141,
1923 sizeof(get_inkey_response_141),
1925 expect_response_and_finish);
1926 stktest_add_test("Get Inkey 1.5", "RequestKey",
1927 get_inkey_151, sizeof(get_inkey_151),
1928 get_inkey_response_151,
1929 sizeof(get_inkey_response_151),
1931 expect_response_and_finish);
1932 stktest_add_test("Get Inkey 1.6", "RequestKey",
1933 get_inkey_161, sizeof(get_inkey_161),
1934 get_inkey_response_161,
1935 sizeof(get_inkey_response_161),
1937 expect_response_and_finish);
1938 stktest_add_test("Get Inkey 2.1", "RequestDigit",
1939 get_inkey_211, sizeof(get_inkey_211),
1940 get_inkey_response_211,
1941 sizeof(get_inkey_response_211),
1943 expect_response_and_finish);
1944 stktest_add_test("Get Inkey 3.1", "RequestDigit",
1945 get_inkey_311, sizeof(get_inkey_311),
1946 get_inkey_response_311,
1947 sizeof(get_inkey_response_311),
1949 expect_response_and_finish);
1950 stktest_add_test("Get Inkey 3.2", "RequestDigit",
1951 get_inkey_321, sizeof(get_inkey_321),
1952 get_inkey_response_321,
1953 sizeof(get_inkey_response_321),
1955 expect_response_and_finish);
1956 stktest_add_test("Get Inkey 4.1", "RequestKey",
1957 get_inkey_411, sizeof(get_inkey_411),
1958 get_inkey_response_411,
1959 sizeof(get_inkey_response_411),
1961 expect_response_and_finish);
1964 static void test_destroy(gpointer user_data)
1966 struct test *test = user_data;
1969 g_free(test->method);
1970 g_free(test->req_pdu);
1971 g_free(test->rsp_pdu);
1976 static void __stktest_test_summarize(void)
1979 unsigned int not_run = 0;
1980 unsigned int passed = 0;
1981 unsigned int failed = 0;
1983 g_print("\n\nTest Summary\n");
1984 g_print("============\n");
1986 for (l = tests; l; l = l->next) {
1987 struct test *test = l->data;
1989 g_print("%-60s", test->name);
1991 switch (test->result) {
1992 case TEST_RESULT_NOT_RUN:
1993 g_print("Not Run\n");
1996 case TEST_RESULT_PASSED:
1997 g_print("Passed\n");
2000 case TEST_RESULT_FAILED:
2001 g_print("Failed\n");
2007 g_print("\nTotal: %d, Passed: %d(%.1f%%), Failed: %d, NotRun: %d\n",
2008 not_run + passed + failed, passed,
2009 (float) passed * 100 / (not_run + passed + failed),
2013 static void __stktest_test_cleanup(void)
2015 g_list_free_full(tests, test_destroy);
2020 static gboolean option_version = FALSE;
2022 static GOptionEntry options[] = {
2023 { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
2024 "Show version information and exit" },
2028 int main(int argc, char **argv)
2030 GOptionContext *context;
2031 GError *error = NULL;
2034 struct sigaction sa;
2036 context = g_option_context_new(NULL);
2037 g_option_context_add_main_entries(context, options, NULL);
2039 if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
2040 if (error != NULL) {
2041 g_printerr("%s\n", error->message);
2042 g_error_free(error);
2044 g_printerr("An unknown error occurred\n");
2048 g_option_context_free(context);
2050 if (option_version == TRUE) {
2051 printf("%s\n", VERSION);
2055 __stktest_test_init();
2057 main_loop = g_main_loop_new(NULL, FALSE);
2059 dbus_error_init(&err);
2061 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
2063 if (dbus_error_is_set(&err) == TRUE) {
2064 fprintf(stderr, "%s\n", err.message);
2065 dbus_error_free(&err);
2067 fprintf(stderr, "Can't register with system bus\n");
2071 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
2073 memset(&sa, 0, sizeof(sa));
2074 sa.sa_handler = sig_term;
2075 sigaction(SIGINT, &sa, NULL);
2076 sigaction(SIGTERM, &sa, NULL);
2078 watch = g_dbus_add_service_watch(conn, OFONO_SERVICE,
2079 ofono_connect, ofono_disconnect, NULL, NULL);
2081 g_main_loop_run(main_loop);
2083 g_dbus_remove_watch(conn, watch);
2085 if (ofono_running == TRUE)
2086 ofono_disconnect(conn, NULL);
2088 dbus_connection_unref(conn);
2090 g_main_loop_unref(main_loop);
2092 __stktest_test_summarize();
2093 __stktest_test_cleanup();