summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent dot torri at gmail dot com>2016-02-04 14:05:17 +0100
committerTom Hacohen <tom@stosb.com>2016-02-16 12:41:06 +0000
commitda98142de67e2ccefa0d8afa37e9fd3411183660 (patch)
treedd6823e630d058764242e67f057c8c70cc370b38
parent0fa24ee17501c632225cfe7c979f9f005b194d20 (diff)
Test rework #1: Ecore
Factorisation of the infra make uniform all the tests
Diffstat (limited to '')
-rw-r--r--src/tests/ecore/ecore_suite.c92
-rw-r--r--src/tests/ecore/ecore_test_animator.c3
-rw-r--r--src/tests/ecore/ecore_test_ecore_audio.c6
-rw-r--r--src/tests/ecore/ecore_test_ecore_file.c4
-rw-r--r--src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c7
-rw-r--r--src/tests/ecore/ecore_test_ecore_x.c4
-rw-r--r--src/tests/efl_check.h115
7 files changed, 134 insertions, 97 deletions
diff --git a/src/tests/ecore/ecore_suite.c b/src/tests/ecore/ecore_suite.c
index ce75f00..787a455 100644
--- a/src/tests/ecore/ecore_suite.c
+++ b/src/tests/ecore/ecore_suite.c
@@ -2,22 +2,10 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#include <stdlib.h>
6#include <stdio.h>
7
8#include <Ecore.h>
9
10#include "ecore_suite.h" 5#include "ecore_suite.h"
6#include "../efl_check.h"
11 7
12typedef struct _Ecore_Test_Case Ecore_Test_Case; 8static const Efl_Test_Case etc[] = {
13
14struct _Ecore_Test_Case
15{
16 const char *test_case;
17 void (*build)(TCase *tc);
18};
19
20static const Ecore_Test_Case etc[] = {
21 { "Ecore", ecore_test_ecore }, 9 { "Ecore", ecore_test_ecore },
22#if HAVE_ECORE_X 10#if HAVE_ECORE_X
23 { "Ecore_X", ecore_test_ecore_x }, 11 { "Ecore_X", ecore_test_ecore_x },
@@ -41,84 +29,18 @@ static const Ecore_Test_Case etc[] = {
41 { NULL, NULL } 29 { NULL, NULL }
42}; 30};
43 31
44static void
45_list_tests(void)
46{
47 const Ecore_Test_Case *itr;
48
49 itr = etc;
50 fputs("Available Test Cases:\n", stderr);
51 for (; itr->test_case; itr++)
52 fprintf(stderr, "\t%s\n", itr->test_case);
53}
54static Eina_Bool
55_use_test(int argc, const char **argv, const char *test_case)
56{
57 if (argc < 1)
58 return 1;
59
60 for (; argc > 0; argc--, argv++)
61 if (strcmp(test_case, *argv) == 0)
62 return 1;
63 return 0;
64}
65
66static Suite *
67ecore_suite_build(int argc, const char **argv)
68{
69 TCase *tc;
70 Suite *s;
71 int i;
72
73 s = suite_create("Ecore");
74
75 for (i = 0; etc[i].test_case; ++i)
76 {
77 if (!_use_test(argc, argv, etc[i].test_case)) continue;
78 tc = tcase_create(etc[i].test_case);
79
80 etc[i].build(tc);
81
82 suite_add_tcase(s, tc);
83 tcase_set_timeout(tc, 0);
84 }
85
86 return s;
87}
88
89int 32int
90main(int argc, char **argv) 33main(int argc, char **argv)
91{ 34{
92 Suite *s; 35 int failed_count;
93 SRunner *sr;
94 int i, failed_count;
95 36
96 for (i = 1; i < argc; i++) 37 if (!_efl_test_option_disp(argc, argv, etc))
97 if ((strcmp(argv[i], "-h") == 0) || 38 return 0;
98 (strcmp(argv[i], "--help") == 0))
99 {
100 fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
101 argv[0]);
102 _list_tests();
103 return 0;
104 }
105 else if ((strcmp(argv[i], "-l") == 0) ||
106 (strcmp(argv[i], "--list") == 0))
107 {
108 _list_tests();
109 return 0;
110 }
111 39
112 putenv("EFL_RUN_IN_TREE=1"); 40 putenv("EFL_RUN_IN_TREE=1");
113 41
114 s = ecore_suite_build(argc - 1, (const char **)argv + 1); 42 failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1,
115 sr = srunner_create(s); 43 "Ecore", etc);
116
117 srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml");
118
119 srunner_run_all(sr, CK_ENV);
120 failed_count = srunner_ntests_failed(sr);
121 srunner_free(sr);
122 44
123 return (failed_count == 0) ? 0 : 255; 45 return (failed_count == 0) ? 0 : 255;
124} 46}
diff --git a/src/tests/ecore/ecore_test_animator.c b/src/tests/ecore/ecore_test_animator.c
index ed7f4ee..98c7192 100644
--- a/src/tests/ecore/ecore_test_animator.c
+++ b/src/tests/ecore/ecore_test_animator.c
@@ -2,10 +2,11 @@
2#include <config.h> 2#include <config.h>
3#endif 3#endif
4 4
5#include <math.h>
6
5#include <Ecore.h> 7#include <Ecore.h>
6 8
7#include "ecore_suite.h" 9#include "ecore_suite.h"
8#include <math.h>
9 10
10static double prev = 0; 11static double prev = 0;
11static Eina_Bool _anim_cb(void *data EINA_UNUSED, double pos) 12static Eina_Bool _anim_cb(void *data EINA_UNUSED, double pos)
diff --git a/src/tests/ecore/ecore_test_ecore_audio.c b/src/tests/ecore/ecore_test_ecore_audio.c
index 4be231c..5bceee2 100644
--- a/src/tests/ecore/ecore_test_ecore_audio.c
+++ b/src/tests/ecore/ecore_test_ecore_audio.c
@@ -2,17 +2,15 @@
2#include <config.h> 2#include <config.h>
3#endif 3#endif
4 4
5#include <stdio.h>
5#include <math.h> 6#include <math.h>
6 7
8#include <Ecore.h>
7#include <Ecore_Audio.h> 9#include <Ecore_Audio.h>
8#include <Ecore_File.h> 10#include <Ecore_File.h>
9 11
10#include "ecore_suite.h" 12#include "ecore_suite.h"
11 13
12#include <stdio.h>
13#include <Ecore.h>
14#include <Ecore_Audio.h>
15
16static Eina_Bool _failed_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) 14static Eina_Bool _failed_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
17{ 15{
18 Eina_Bool *pulse_context_failed = data; 16 Eina_Bool *pulse_context_failed = data;
diff --git a/src/tests/ecore/ecore_test_ecore_file.c b/src/tests/ecore/ecore_test_ecore_file.c
index 9100362..cb3928a 100644
--- a/src/tests/ecore/ecore_test_ecore_file.c
+++ b/src/tests/ecore/ecore_test_ecore_file.c
@@ -9,9 +9,9 @@
9#include <fcntl.h> 9#include <fcntl.h>
10#include <libgen.h> 10#include <libgen.h>
11 11
12#include <Ecore_File.h>
13#include <Ecore.h>
14#include <Eina.h> 12#include <Eina.h>
13#include <Ecore.h>
14#include <Ecore_File.h>
15 15
16#include "ecore_suite.h" 16#include "ecore_suite.h"
17 17
diff --git a/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c b/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c
index d5bdc27..fe5e32a 100644
--- a/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c
+++ b/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c
@@ -2,10 +2,11 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#include <Ecore.h>
6#include <Eina.h>
7#include <unistd.h>
8#include <stdio.h> 5#include <stdio.h>
6#include <unistd.h>
7
8#include <Eina.h>
9#include <Ecore.h>
9 10
10#include "ecore_suite.h" 11#include "ecore_suite.h"
11 12
diff --git a/src/tests/ecore/ecore_test_ecore_x.c b/src/tests/ecore/ecore_test_ecore_x.c
index 8baa9a5..bb33374 100644
--- a/src/tests/ecore/ecore_test_ecore_x.c
+++ b/src/tests/ecore/ecore_test_ecore_x.c
@@ -2,10 +2,10 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#include "ecore_suite.h"
6
7#include <Eina.h> 5#include <Eina.h>
8 6
7#include "ecore_suite.h"
8
9/* FIXME: Currently disable these tests. They are useless ATM and they just 9/* FIXME: Currently disable these tests. They are useless ATM and they just
10 * make buildbot complain. Once we add useful tests here we'll also bother 10 * make buildbot complain. Once we add useful tests here we'll also bother
11 * with getting X on the server. */ 11 * with getting X on the server. */
diff --git a/src/tests/efl_check.h b/src/tests/efl_check.h
new file mode 100644
index 0000000..9680312
--- /dev/null
+++ b/src/tests/efl_check.h
@@ -0,0 +1,115 @@
1#ifndef EFL_CHECK_H
2#define EFL_CHECK_H
3
4#include <stdlib.h> /* getenv */
5#include <stdio.h> /* fprintf, fputs */
6#include <string.h> /* strcmp */
7
8typedef struct _Efl_Test_Case Efl_Test_Case;
9struct _Efl_Test_Case
10{
11 const char *test_case;
12 void (*build)(TCase *tc);
13};
14
15static void
16_efl_tests_list(const Efl_Test_Case *etc)
17{
18 const Efl_Test_Case *itr = etc;
19 fputs("Available Test Cases:\n", stderr);
20 for (; itr->test_case; itr++)
21 fprintf(stderr, "\t%s\n", itr->test_case);
22}
23
24static int
25_efl_test_option_disp(int argc, char **argv, const Efl_Test_Case *etc)
26{
27 int i;
28
29 for (i = 1; i < argc; i++)
30 if ((strcmp(argv[i], "-h") == 0) ||
31 (strcmp(argv[i], "--help") == 0))
32 {
33 fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
34 argv[0]);
35 _efl_tests_list(etc);
36 return 1;
37 }
38 else if ((strcmp(argv[i], "-l") == 0) ||
39 (strcmp(argv[i], "--list") == 0))
40 {
41 _efl_tests_list(etc);
42 return 1;
43 }
44
45 return 0;
46}
47
48static int
49_efl_test_use(int argc, const char **argv, const char *test_case)
50{
51 if (argc < 1)
52 return 1;
53
54 for (; argc > 0; argc--, argv++)
55 if (strcmp(test_case, *argv) == 0)
56 return 1;
57 return 0;
58}
59
60static int
61_efl_test_fork_has(SRunner *sr)
62{
63 if (srunner_fork_status(sr) == CK_FORK)
64 return 1;
65 else if (srunner_fork_status(sr) == CK_NOFORK)
66 return 0;
67 else if (srunner_fork_status(sr) == CK_FORK_GETENV)
68 {
69 char *res;
70
71 res = getenv("CF_FORK");
72 if (res && (strcmp(res, "no") == 0))
73 return 0;
74 else
75 return 1;
76 }
77
78 /* should never get there */
79 return 0;
80}
81
82static int
83_efl_suite_build_and_run(int argc, const char **argv, const char *suite_name, const Efl_Test_Case *etc)
84{
85 Suite *s;
86 SRunner *sr;
87 TCase *tc;
88 int i, failed_count;
89
90 s = suite_create(suite_name);
91 sr = srunner_create(s);
92
93 for (i = 0; etc[i].test_case; ++i)
94 {
95 if (!_efl_test_use(argc, argv, etc[i].test_case))
96 continue;
97
98 tc = tcase_create(etc[i].test_case);
99
100 if (_efl_test_fork_has(sr))
101 tcase_set_timeout(tc, 0);
102
103 etc[i].build(tc);
104 suite_add_tcase(s, tc);
105 }
106
107 srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml");
108 srunner_run_all(sr, CK_ENV);
109 failed_count = srunner_ntests_failed(sr);
110 srunner_free(sr);
111
112 return failed_count;
113}
114
115#endif