From c25347dc7e2a633843fe25769026d1f5699de848 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 28 Jan 2010 12:47:08 +0100 Subject: [PATCH] Add second CAIF test for using character interface --- unit/test-caif.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/unit/test-caif.c b/unit/test-caif.c index 9fd46e7d..a460fdae 100644 --- a/unit/test-caif.c +++ b/unit/test-caif.c @@ -24,6 +24,7 @@ #endif #include +#include #include #include #include @@ -38,6 +39,19 @@ static GMainLoop *mainloop; +static int do_open(void) +{ + int fd; + + fd = open("/dev/chnlat10", O_RDWR); + if (fd < 0) { + g_printerr("Open of chnlat10 failed (%d)\n", errno); + return -EIO; + } + + return fd; +} + static int do_connect(void) { struct sockaddr_caif addr; @@ -86,18 +100,22 @@ static void caif_init(gboolean ok, GAtResult *result, gpointer data) g_main_loop_quit(mainloop); } -static void test_connect(void) +static void test_connect(gboolean use_socket) { GIOChannel *io; GAtChat *chat; GAtSyntax *syntax; - int sk; + int fd; - sk = do_connect(); - if (sk < 0) + if (use_socket == TRUE) + fd = do_connect(); + else + fd = do_open(); + + if (fd < 0) return; - io = g_io_channel_unix_new(sk); + io = g_io_channel_unix_new(fd); g_io_channel_set_close_on_unref(io, TRUE); syntax = g_at_syntax_new_gsm_permissive(); @@ -123,7 +141,18 @@ static void test_connect(void) static void test_basic(void) { if (g_test_trap_fork(60 * 1000 * 1000, 0) == TRUE) { - test_connect(); + test_connect(TRUE); + exit(0); + } + + g_test_trap_assert_passed(); + //g_test_trap_assert_stderr("failed"); +} + +static void test_chnlat(void) +{ + if (g_test_trap_fork(60 * 1000 * 1000, 0) == TRUE) { + test_connect(FALSE); exit(0); } @@ -136,6 +165,7 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); g_test_add_func("/testcaif/basic", test_basic); + g_test_add_func("/testcaif/chnlat", test_chnlat); return g_test_run(); }