summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2012-09-28 17:41:21 -0500
committerDenis Kenzior <denkenz@gmail.com>2012-10-03 09:10:42 -0500
commit1a3047ac84c9887ef10dc33edb925cd86a75c1fd (patch)
tree575d88e0d1707c48d88bb91ab27960cf3fa7acce /tools
parent9dbf05bec0e116c2b0f6206690c787c89def2ffc (diff)
downloadofono-1a3047ac84c9887ef10dc33edb925cd86a75c1fd.tar.bz2
stktest: Add test framework skeleton
Diffstat (limited to 'tools')
-rw-r--r--tools/stktest.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/tools/stktest.c b/tools/stktest.c
index 354a1894..77e7b8a6 100644
--- a/tools/stktest.c
+++ b/tools/stktest.c
@@ -54,8 +54,34 @@ enum test_state {
TEST_STATE_POWERING_DOWN,
};
+enum test_result {
+ TEST_RESULT_NOT_RUN = 0,
+ TEST_RESULT_PASSED,
+ TEST_RESULT_FAILED
+};
+
+typedef DBusMessage *(*display_text_cb_t)(DBusMessage *msg, const char *text,
+ unsigned char icon_id,
+ gboolean urgent);
+typedef void (*terminal_response_func)(const unsigned char *pdu,
+ unsigned int len);
+
+struct test {
+ char *name;
+ char *method;
+ unsigned char *req_pdu;
+ unsigned int req_len;
+ unsigned char *rsp_pdu;
+ unsigned int rsp_len;
+ void *agent_func;
+ terminal_response_func tr_func;
+ enum test_result result;
+};
+
static GMainLoop *main_loop = NULL;
static volatile sig_atomic_t __terminated = 0;
+GList *tests = NULL;
+GList *cur_test = NULL;
/* DBus related */
static DBusConnection *conn;
@@ -810,6 +836,75 @@ static void disconnect_callback(DBusConnection *conn, void *user_data)
g_main_loop_quit(main_loop);
}
+static void stktest_add_test(const char *name, const char *method,
+ const unsigned char *req, unsigned int req_len,
+ const unsigned char *rsp, unsigned int rsp_len,
+ void *agent_func,
+ terminal_response_func tr_func)
+{
+ struct test *test = g_new0(struct test, 1);
+
+ test->name = g_strdup(name);
+ test->method = g_strdup(method);
+ test->req_pdu = g_memdup(req, req_len);
+ test->req_len = req_len;
+ test->rsp_pdu = g_memdup(rsp, rsp_len);
+ test->rsp_len = rsp_len;
+ test->agent_func = agent_func;
+ test->tr_func = tr_func;
+
+ tests = g_list_append(tests, test);
+}
+
+static void __stktest_test_init(void)
+{
+}
+
+static void test_destroy(gpointer user_data)
+{
+ struct test *test = user_data;
+
+ g_free(test->name);
+ g_free(test->method);
+ g_free(test->req_pdu);
+ g_free(test->rsp_pdu);
+
+ g_free(test);
+}
+
+static void __stktest_test_summarize(void)
+{
+ GList *l;
+
+ g_print("\n\nTest Summary\n");
+ g_print("============\n");
+
+ for (l = tests; l; l = l->next) {
+ struct test *test = l->data;
+
+ g_print("%-60s", test->name);
+
+ switch (test->result) {
+ case TEST_RESULT_NOT_RUN:
+ g_print("Not Run\n");
+ break;
+ case TEST_RESULT_PASSED:
+ g_print("Passed\n");
+ break;
+ case TEST_RESULT_FAILED:
+ g_print("Failed\n");
+ break;
+ }
+ }
+}
+
+static void __stktest_test_cleanup(void)
+{
+ g_list_free_full(tests, test_destroy);
+ tests = NULL;
+ cur_test = NULL;
+}
+
static gboolean option_version = FALSE;
static GOptionEntry options[] = {
@@ -845,6 +940,8 @@ int main(int argc, char **argv)
exit(0);
}
+ __stktest_test_init();
+
main_loop = g_main_loop_new(NULL, FALSE);
dbus_error_init(&err);
@@ -880,5 +977,8 @@ int main(int argc, char **argv)
g_main_loop_unref(main_loop);
+ __stktest_test_summarize();
+ __stktest_test_cleanup();
+
return 0;
}