summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2013-01-15 21:50:57 +0000
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2013-01-15 21:50:57 +0000
commit48e207859a3b46295f8ff227b6594b2a6f6539dd (patch)
tree242dc7198a1ce1ca2f815ca4626875a4317dd567
parent1d295abac0340e18fa20aa2abc67be76cdc0b8d3 (diff)
efl/edbus: Add initial testsuite
Right now this contains only 2 tests, for checking if init/shutdown works correctly. SVN revision: 82842
-rw-r--r--.gitignore2
-rw-r--r--src/Makefile_EDBus.am18
-rw-r--r--src/tests/edbus/edbus_suite.c106
-rw-r--r--src/tests/edbus/edbus_suite.h8
-rw-r--r--src/tests/edbus/edbus_test_edbus_init.c59
5 files changed, 193 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 5006a1613a..bc7597d5ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -277,6 +277,8 @@ Makefile.in
277/src/tests/emotion/emotion_test 277/src/tests/emotion/emotion_test
278/src/tests/ecore/ecore_suite 278/src/tests/ecore/ecore_suite
279/src/tests/edbus/edbus_suite 279/src/tests/edbus/edbus_suite
280/src/tests/edbus/edbus_suite.log
281/src/tests/edbus/edbus_suite.trs
280/src/tests/edje/edje_suite 282/src/tests/edje/edje_suite
281/src/tests/eet/eet_suite 283/src/tests/eet/eet_suite
282/src/tests/eeze/eeze_suite 284/src/tests/eeze/eeze_suite
diff --git a/src/Makefile_EDBus.am b/src/Makefile_EDBus.am
index 4920ae02a3..98f30696ff 100644
--- a/src/Makefile_EDBus.am
+++ b/src/Makefile_EDBus.am
@@ -58,3 +58,21 @@ bin_edbus_edbus_codegen_CPPFLAGS = \
58@EDBUS_CFLAGS@ 58@EDBUS_CFLAGS@
59bin_edbus_edbus_codegen_LDADD = @USE_EDBUS_LIBS@ 59bin_edbus_edbus_codegen_LDADD = @USE_EDBUS_LIBS@
60bin_edbus_edbus_codegen_DEPENDENCIES = @USE_EDBUS_INTERNAL_LIBS@ 60bin_edbus_edbus_codegen_DEPENDENCIES = @USE_EDBUS_INTERNAL_LIBS@
61
62### Unit tests
63
64if EFL_ENABLE_TESTS
65
66check_PROGRAMS += tests/edbus/edbus_suite
67TESTS += tests/edbus/edbus_suite
68
69tests_edbus_edbus_suite_SOURCES = \
70tests/edbus/edbus_suite.c \
71tests/edbus/edbus_test_edbus_init.c \
72tests/edbus/edbus_suite.h
73
74tests_edbus_edbus_suite_CPPFLAGS = @CHECK_CFLAGS@ @EDBUS_CFLAGS@
75tests_edbus_edbus_suite_LDADD = @CHECK_LIBS@ @USE_EDBUS_LIBS@
76tests_edbus_edbus_suite_DEPENDENCIES = @USE_EDBUS_INTERNAL_LIBS@
77
78endif
diff --git a/src/tests/edbus/edbus_suite.c b/src/tests/edbus/edbus_suite.c
new file mode 100644
index 0000000000..ecd8d4c6b0
--- /dev/null
+++ b/src/tests/edbus/edbus_suite.c
@@ -0,0 +1,106 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdlib.h>
6#include <stdio.h>
7
8#include <EDBus.h>
9
10#include "edbus_suite.h"
11
12typedef struct _EDBus_Test_Case Edbus_Test_Case;
13
14struct _EDBus_Test_Case
15{
16 const char *test_case;
17 void (*build)(TCase *tc);
18};
19
20static const Edbus_Test_Case etc[] = {
21 { "edbus_init", edbus_test_edbus_init },
22 { }
23};
24
25static void
26_list_tests(void)
27{
28 const Edbus_Test_Case *itr;
29
30 itr = etc;
31 fputs("Available Test Cases:\n", stderr);
32 for (; itr->test_case; itr++)
33 printf("\t%s\n", itr->test_case);
34}
35
36static Eina_Bool
37_use_test(int argc, const char **argv, const char *test_case)
38{
39 if (argc < 1)
40 return 1;
41
42 for (; argc > 0; argc--, argv++)
43 {
44 if (strcmp(test_case, *argv) == 0)
45 return 1;
46 }
47 return 0;
48}
49
50static Suite *
51edbus_suite_build(int argc, const char **argv)
52{
53 TCase *tc;
54 Suite *s;
55 int i;
56
57 s = suite_create("Edbus");
58
59 for (i = 0; etc[i].test_case; ++i)
60 {
61 if (!_use_test(argc, argv, etc[i].test_case)) continue;
62 tc = tcase_create(etc[i].test_case);
63
64 etc[i].build(tc);
65
66 suite_add_tcase(s, tc);
67 tcase_set_timeout(tc, 0);
68 }
69
70 return s;
71}
72
73int
74main(int argc, char **argv)
75{
76 Suite *s;
77 SRunner *sr;
78 int i, failed_count;
79
80 for (i = 1; i < argc; i++)
81 if ((strcmp(argv[i], "-h") == 0) ||
82 (strcmp(argv[i], "--help") == 0))
83 {
84 fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
85 argv[0]);
86 _list_tests();
87 return 0;
88 }
89 else if ((strcmp(argv[i], "-l") == 0) ||
90 (strcmp(argv[i], "--list") == 0))
91 {
92 _list_tests();
93 return 0;
94 }
95
96 putenv("EFL_RUN_IN_TREE=1");
97
98 s = edbus_suite_build(argc - 1, (const char **)argv + 1);
99 sr = srunner_create(s);
100
101 srunner_run_all(sr, CK_ENV);
102 failed_count = srunner_ntests_failed(sr);
103 srunner_free(sr);
104
105 return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
106}
diff --git a/src/tests/edbus/edbus_suite.h b/src/tests/edbus/edbus_suite.h
new file mode 100644
index 0000000000..01434a5a4f
--- /dev/null
+++ b/src/tests/edbus/edbus_suite.h
@@ -0,0 +1,8 @@
1#ifndef _EDBUS_SUITE_H
2#define _EDBUS_SUITE_H
3
4#include <check.h>
5
6void edbus_test_edbus_init(TCase *tc);
7
8#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
index 0000000000..a53393acba
--- /dev/null
+++ b/src/tests/edbus/edbus_test_edbus_init.c
@@ -0,0 +1,59 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdio.h>
6#include <unistd.h>
7
8#include <Eina.h>
9#include <Ecore.h>
10#include <EDBus.h>
11
12#include "edbus_suite.h"
13
14static Eina_Bool
15_quit_cb(void *data EINA_UNUSED)
16{
17 ecore_main_loop_quit();
18 return EINA_FALSE;
19}
20
21START_TEST(edbus_test_edbus)
22{
23 int ret;
24
25 ret = edbus_init();
26 fail_if(ret != 1);
27
28 ret = edbus_shutdown();
29 fail_if(ret != 0);
30}
31END_TEST
32
33START_TEST(edbus_test_edbus_main_loop)
34{
35 Ecore_Timer *timer;
36 int ret;
37
38 ecore_init();
39 ret = edbus_init();
40 fail_if(ret != 1);
41
42 timer = ecore_timer_add(0.1, _quit_cb, NULL);
43 fail_if(timer == NULL);
44
45 ecore_main_loop_begin();
46
47 ret = edbus_shutdown();
48 fail_if(ret != 0);
49
50 ecore_shutdown();
51
52}
53END_TEST
54
55void edbus_test_edbus_init(TCase *tc)
56{
57 tcase_add_test(tc, edbus_test_edbus);
58 tcase_add_test(tc, edbus_test_edbus_main_loop);
59}