summaryrefslogtreecommitdiff
path: root/src/tests/eldbus
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2013-04-23 11:40:05 -0300
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2013-04-23 12:36:29 -0300
commit4e3804041f8e865e007b2a6a0d45a05f39500c3b (patch)
treea493b9c8f8a610d2667651f3ba81819ed16fbe8c /src/tests/eldbus
parent4cf68bf728b5a858ce1c0efac25ded1a49ba8d9d (diff)
Rename edbus->eldbus
git grep -l edbus2 | while read f; do sed -i 's/edbus2/eldbus/g' "$f"; done find . -name '*edbus2*' -exec rename edbus2 eldbus {} \; git grep -l "EDBUS" | while read f; do sed -i 's/EDBUS/ELDBUS/g' "$f"; done git grep -l "EDBus" | while read f; do sed -i 's/EDBus/Eldbus/g' "$f"; done git grep -l "edbus (v2)" | while read f; do sed -i 's/edbus (v2)/eldbus/g' "$f"; done git grep -l "Edbus" | while read f; do sed -i 's/Edbus/Eldbus/g' "$f"; done git grep -l "edbus" | while read f; do sed -i 's/edbus/eldbus/g' "$f"; done find . -name '*edbus*' -exec rename edbus eldbus {} \; find . -name '*EDBus*' -exec rename EDBus Eldbus {} \;
Diffstat (limited to 'src/tests/eldbus')
-rw-r--r--src/tests/eldbus/eldbus_suite.c108
-rw-r--r--src/tests/eldbus/eldbus_suite.h8
-rw-r--r--src/tests/eldbus/eldbus_test_eldbus_init.c166
3 files changed, 282 insertions, 0 deletions
diff --git a/src/tests/eldbus/eldbus_suite.c b/src/tests/eldbus/eldbus_suite.c
new file mode 100644
index 0000000000..3a47998962
--- /dev/null
+++ b/src/tests/eldbus/eldbus_suite.c
@@ -0,0 +1,108 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdlib.h>
6#include <stdio.h>
7
8#include <Eldbus.h>
9
10#include "eldbus_suite.h"
11
12typedef struct _Eldbus_Test_Case Eldbus_Test_Case;
13
14struct _Eldbus_Test_Case
15{
16 const char *test_case;
17 void (*build)(TCase *tc);
18};
19
20static const Eldbus_Test_Case etc[] = {
21 { "eldbus_init", eldbus_test_eldbus_init },
22 { }
23};
24
25static void
26_list_tests(void)
27{
28 const Eldbus_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 *
51eldbus_suite_build(int argc, const char **argv)
52{
53 TCase *tc;
54 Suite *s;
55 int i;
56
57 s = suite_create("Eldbus");
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 = eldbus_suite_build(argc - 1, (const char **)argv + 1);
99 sr = srunner_create(s);
100
101 srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml");
102
103 srunner_run_all(sr, CK_ENV);
104 failed_count = srunner_ntests_failed(sr);
105 srunner_free(sr);
106
107 return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
108}
diff --git a/src/tests/eldbus/eldbus_suite.h b/src/tests/eldbus/eldbus_suite.h
new file mode 100644
index 0000000000..400d2278ae
--- /dev/null
+++ b/src/tests/eldbus/eldbus_suite.h
@@ -0,0 +1,8 @@
1#ifndef _ELDBUS_SUITE_H
2#define _ELDBUS_SUITE_H
3
4#include <check.h>
5
6void eldbus_test_eldbus_init(TCase *tc);
7
8#endif
diff --git a/src/tests/eldbus/eldbus_test_eldbus_init.c b/src/tests/eldbus/eldbus_test_eldbus_init.c
new file mode 100644
index 0000000000..efe92cdfaf
--- /dev/null
+++ b/src/tests/eldbus/eldbus_test_eldbus_init.c
@@ -0,0 +1,166 @@
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 <Eldbus.h>
11
12#include "eldbus_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(eldbus_test_eldbus)
22{
23 int ret;
24
25 ret = eldbus_init();
26 fail_if(ret != 1);
27
28 ret = eldbus_shutdown();
29 fail_if(ret != 0);
30}
31END_TEST
32
33START_TEST(eldbus_test_eldbus_main_loop)
34{
35 Ecore_Timer *timer;
36 int ret;
37
38 ecore_init();
39 ret = eldbus_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 = eldbus_shutdown();
48 fail_if(ret != 0);
49
50 ecore_shutdown();
51
52}
53END_TEST
54
55#if 0
56/* TODO: This test assumes an existing dbus-daemon running. It
57 * shouldn't do this, instead we should launch dbus-daemon ourselves
58 * and create our private instance, use it and then kill it
59 * afterwards.
60 */
61
62START_TEST(eldbus_test_eldbus_conn)
63{
64 Eldbus_Connection *conn;
65 int ret;
66
67 ecore_init();
68
69 ret = eldbus_init();
70 fail_if(ret != 1);
71
72 /*
73 * let's use connection type == system, so it works without a session,
74 * however security rules may apply differently depending on the
75 * machine/user
76 */
77 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
78 fail_if(conn == NULL);
79
80 eldbus_connection_unref(conn);
81
82 ret = eldbus_shutdown();
83 fail_if(ret != 0);
84
85 ecore_shutdown();
86
87}
88END_TEST
89
90START_TEST(eldbus_test_eldbus_conn_object)
91{
92 Eldbus_Connection *conn;
93 Eldbus_Object *obj;
94 int ret;
95
96 ecore_init();
97
98 ret = eldbus_init();
99 fail_if(ret != 1);
100
101 /*
102 * let's use connection type == system, so it works without a D-Bus session.
103 * However security rules may apply differently depending on the
104 * machine/user
105 */
106 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
107 fail_if(conn == NULL);
108
109 obj = eldbus_object_get(conn, "org.buu", "/org/buu");
110 fail_if(obj == NULL);
111
112 eldbus_object_unref(obj);
113
114 eldbus_connection_unref(conn);
115
116 ret = eldbus_shutdown();
117 fail_if(ret != 0);
118
119 ecore_shutdown();
120
121}
122END_TEST
123
124void name_owner_changed_cb(void *data, const char *bus EINA_UNUSED, const char *old_id EINA_UNUSED, const char *new_id)
125{
126 const char **id = data;
127 *id = new_id;
128}
129
130START_TEST(eldbus_test_eldbus_name_owner_changed)
131{
132 Eldbus_Connection *conn;
133 const char *id = NULL;
134
135 ecore_init();
136 eldbus_init();
137
138 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
139 fail_if(conn == NULL);
140
141 eldbus_name_owner_changed_callback_add(conn, "org.bus.that.not.exist",
142 name_owner_changed_cb, &id, EINA_TRUE);
143 ecore_timer_add(0.5, _quit_cb, NULL);
144
145 ecore_main_loop_begin();
146
147 fail_if(id == NULL);
148
149 eldbus_connection_unref(conn);
150
151 eldbus_shutdown();
152 ecore_shutdown();
153}
154END_TEST
155#endif
156
157void eldbus_test_eldbus_init(TCase *tc)
158{
159 tcase_add_test(tc, eldbus_test_eldbus);
160 tcase_add_test(tc, eldbus_test_eldbus_main_loop);
161#if 0
162 tcase_add_test(tc, eldbus_test_eldbus_conn);
163 tcase_add_test(tc, eldbus_test_eldbus_conn_object);
164 tcase_add_test(tc, eldbus_test_eldbus_name_owner_changed);
165#endif
166}