efl/edbus: Add initial testsuite
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 15 Jan 2013 21:50:57 +0000 (21:50 +0000)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 15 Jan 2013 21:50:57 +0000 (21:50 +0000)
Right now this contains only 2 tests, for checking if
init/shutdown works correctly.

SVN revision: 82842

.gitignore
src/Makefile_EDBus.am
src/tests/edbus/edbus_suite.c [new file with mode: 0644]
src/tests/edbus/edbus_suite.h [new file with mode: 0644]
src/tests/edbus/edbus_test_edbus_init.c [new file with mode: 0644]

index 5006a16..bc7597d 100644 (file)
@@ -277,6 +277,8 @@ Makefile.in
 /src/tests/emotion/emotion_test
 /src/tests/ecore/ecore_suite
 /src/tests/edbus/edbus_suite
+/src/tests/edbus/edbus_suite.log
+/src/tests/edbus/edbus_suite.trs
 /src/tests/edje/edje_suite
 /src/tests/eet/eet_suite
 /src/tests/eeze/eeze_suite
index 4920ae0..98f3069 100644 (file)
@@ -58,3 +58,21 @@ bin_edbus_edbus_codegen_CPPFLAGS = \
 @EDBUS_CFLAGS@
 bin_edbus_edbus_codegen_LDADD = @USE_EDBUS_LIBS@
 bin_edbus_edbus_codegen_DEPENDENCIES = @USE_EDBUS_INTERNAL_LIBS@
+
+### Unit tests
+
+if EFL_ENABLE_TESTS
+
+check_PROGRAMS += tests/edbus/edbus_suite
+TESTS += tests/edbus/edbus_suite
+
+tests_edbus_edbus_suite_SOURCES = \
+tests/edbus/edbus_suite.c \
+tests/edbus/edbus_test_edbus_init.c \
+tests/edbus/edbus_suite.h
+
+tests_edbus_edbus_suite_CPPFLAGS = @CHECK_CFLAGS@ @EDBUS_CFLAGS@
+tests_edbus_edbus_suite_LDADD = @CHECK_LIBS@ @USE_EDBUS_LIBS@
+tests_edbus_edbus_suite_DEPENDENCIES = @USE_EDBUS_INTERNAL_LIBS@
+
+endif
diff --git a/src/tests/edbus/edbus_suite.c b/src/tests/edbus/edbus_suite.c
new file mode 100644 (file)
index 0000000..ecd8d4c
--- /dev/null
@@ -0,0 +1,106 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <EDBus.h>
+
+#include "edbus_suite.h"
+
+typedef struct _EDBus_Test_Case Edbus_Test_Case;
+
+struct _EDBus_Test_Case
+{
+   const char *test_case;
+   void      (*build)(TCase *tc);
+};
+
+static const Edbus_Test_Case etc[] = {
+  { "edbus_init", edbus_test_edbus_init },
+  { }
+};
+
+static void
+_list_tests(void)
+{
+  const Edbus_Test_Case *itr;
+
+   itr = etc;
+   fputs("Available Test Cases:\n", stderr);
+   for (; itr->test_case; itr++)
+     printf("\t%s\n", itr->test_case);
+}
+
+static Eina_Bool
+_use_test(int argc, const char **argv, const char *test_case)
+{
+   if (argc < 1)
+     return 1;
+
+   for (; argc > 0; argc--, argv++)
+     {
+        if (strcmp(test_case, *argv) == 0)
+          return 1;
+     }
+   return 0;
+}
+
+static Suite *
+edbus_suite_build(int argc, const char **argv)
+{
+   TCase *tc;
+   Suite *s;
+   int i;
+
+   s = suite_create("Edbus");
+
+   for (i = 0; etc[i].test_case; ++i)
+     {
+       if (!_use_test(argc, argv, etc[i].test_case)) continue;
+       tc = tcase_create(etc[i].test_case);
+
+       etc[i].build(tc);
+
+       suite_add_tcase(s, tc);
+       tcase_set_timeout(tc, 0);
+     }
+
+   return s;
+}
+
+int
+main(int argc, char **argv)
+{
+   Suite *s;
+   SRunner *sr;
+   int i, failed_count;
+
+   for (i = 1; i < argc; i++)
+     if ((strcmp(argv[i], "-h") == 0) ||
+        (strcmp(argv[i], "--help") == 0))
+       {
+         fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
+                 argv[0]);
+         _list_tests();
+         return 0;
+       }
+     else if ((strcmp(argv[i], "-l") == 0) ||
+             (strcmp(argv[i], "--list") == 0))
+       {
+         _list_tests();
+         return 0;
+       }
+
+   putenv("EFL_RUN_IN_TREE=1");
+
+   s = edbus_suite_build(argc - 1, (const char **)argv + 1);
+   sr = srunner_create(s);
+
+   srunner_run_all(sr, CK_ENV);
+   failed_count = srunner_ntests_failed(sr);
+   srunner_free(sr);
+
+   return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/src/tests/edbus/edbus_suite.h b/src/tests/edbus/edbus_suite.h
new file mode 100644 (file)
index 0000000..01434a5
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _EDBUS_SUITE_H
+#define _EDBUS_SUITE_H
+
+#include <check.h>
+
+void edbus_test_edbus_init(TCase *tc);
+
+#endif
diff --git a/src/tests/edbus/edbus_test_edbus_init.c b/src/tests/edbus/edbus_test_edbus_init.c
new file mode 100644 (file)
index 0000000..a53393a
--- /dev/null
@@ -0,0 +1,59 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include <Eina.h>
+#include <Ecore.h>
+#include <EDBus.h>
+
+#include "edbus_suite.h"
+
+static Eina_Bool
+_quit_cb(void *data EINA_UNUSED)
+{
+   ecore_main_loop_quit();
+   return EINA_FALSE;
+}
+
+START_TEST(edbus_test_edbus)
+{
+   int ret;
+
+   ret = edbus_init();
+   fail_if(ret != 1);
+
+   ret = edbus_shutdown();
+   fail_if(ret != 0);
+}
+END_TEST
+
+START_TEST(edbus_test_edbus_main_loop)
+{
+   Ecore_Timer *timer;
+   int ret;
+
+   ecore_init();
+   ret = edbus_init();
+   fail_if(ret != 1);
+
+   timer = ecore_timer_add(0.1, _quit_cb, NULL);
+   fail_if(timer == NULL);
+
+   ecore_main_loop_begin();
+
+   ret = edbus_shutdown();
+   fail_if(ret != 0);
+
+   ecore_shutdown();
+
+}
+END_TEST
+
+void edbus_test_edbus_init(TCase *tc)
+{
+   tcase_add_test(tc, edbus_test_edbus);
+   tcase_add_test(tc, edbus_test_edbus_main_loop);
+}