summaryrefslogtreecommitdiff
path: root/src/tests/evil
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2015-04-29 10:50:11 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-05-07 09:53:12 +0200
commit92ff90ecca98f9e8e66a1f7a3ecf4e46f65913d4 (patch)
tree3da7d8cbc50d35dd472c3e8cc5fddb5b17602ac8 /src/tests/evil
parent00a3de5c1f3268c9b7c98e5be39c3947b105ee6e (diff)
evil: fix dladdr() implementation, add 2 unit tests for evil.
@fix Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/tests/evil')
-rw-r--r--src/tests/evil/evil_suite.c138
-rw-r--r--src/tests/evil/evil_suite.h41
-rw-r--r--src/tests/evil/evil_test_dlfcn.c132
-rw-r--r--src/tests/evil/evil_test_main.c37
4 files changed, 348 insertions, 0 deletions
diff --git a/src/tests/evil/evil_suite.c b/src/tests/evil/evil_suite.c
new file mode 100644
index 0000000000..2699bee32a
--- /dev/null
+++ b/src/tests/evil/evil_suite.c
@@ -0,0 +1,138 @@
1/* EVIL - EFL library for Windows port
2 * Copyright (C) 2015 Vincent Torri
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <stdio.h>
24#include <string.h>
25
26#include <Evil.h>
27
28#include "evil_suite.h"
29
30typedef struct _Evil_Test_Case Evil_Test_Case;
31struct _Evil_Test_Case
32{
33 const char *test_case;
34 void (*build)(TCase *tc);
35};
36
37static const Evil_Test_Case etc[] = {
38 /* { "Dirent", evil_test_dirent }, */
39 { "Dlfcn", evil_test_dlfcn },
40 /* { "Fcntl", evil_test_fcntl }, */
41 /* { "Fnmatch", evil_test_fnmatch }, */
42 /* { "Inet", evil_test_inet }, */
43 /* { "Langinfo", evil_test_langinfo }, */
44 /* { "Link", evil_test_link }, */
45 { "Main", evil_test_main },
46 /* { "Mman", evil_test_mman }, */
47 /* { "Pwd", evil_test_pwd }, */
48 /* { "Stdio", evil_test_stdio }, */
49 /* { "Stdlib", evil_test_stdlib }, */
50 /* { "String", evil_test_string }, */
51 /* { "Time", evil_test_time }, */
52 /* { "Unistd", evil_test_unistd }, */
53 /* { "Util", evil_test_util }, */
54 { NULL, NULL }
55};
56
57static void
58_list_tests(void)
59{
60 const Evil_Test_Case *itr = etc;
61 fputs("Available Test Cases:\n", stderr);
62 for (; itr->test_case; itr++)
63 fprintf(stderr, "\t%s\n", itr->test_case);
64}
65
66static unsigned char
67_use_test(int argc, const char **argv, const char *test_case)
68{
69 if (argc < 1)
70 return 1;
71
72 for (; argc > 0; argc--, argv++)
73 if (strcmp(test_case, *argv) == 0)
74 return 1;
75
76 return 0;
77}
78
79Suite *
80evil_build_suite(int argc, const char **argv)
81{
82 TCase *tc;
83 Suite *s;
84 int i;
85
86 s = suite_create("Evil");
87
88 for (i = 0; etc[i].test_case; ++i)
89 {
90 if (!_use_test(argc, argv, etc[i].test_case))
91 continue;
92
93 tc = tcase_create(etc[i].test_case);
94#ifndef _WIN32
95 tcase_set_timeout(tc, 0);
96#endif
97
98 etc[i].build(tc);
99 suite_add_tcase(s, tc);
100 }
101
102 return s;
103}
104
105int
106main(int argc, char **argv)
107{
108 Suite *s;
109 SRunner *sr;
110 int i, failed_count;
111
112 for (i = 1; i < argc; i++)
113 if ((strcmp(argv[i], "-h") == 0) ||
114 (strcmp(argv[i], "--help") == 0))
115 {
116 fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
117 argv[0]);
118 _list_tests();
119 return 0;
120 }
121 else if ((strcmp(argv[i], "-l") == 0) ||
122 (strcmp(argv[i], "--list") == 0))
123 {
124 _list_tests();
125 return 0;
126 }
127
128 putenv("EFL_RUN_IN_TREE=1");
129
130 s = evil_build_suite(argc - 1, (const char **)argv + 1);
131 sr = srunner_create(s);
132 srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml");
133 srunner_run_all(sr, CK_ENV);
134 failed_count = srunner_ntests_failed(sr);
135 srunner_free(sr);
136
137 return (failed_count == 0) ? 0 : 255;
138}
diff --git a/src/tests/evil/evil_suite.h b/src/tests/evil/evil_suite.h
new file mode 100644
index 0000000000..17222fcfec
--- /dev/null
+++ b/src/tests/evil/evil_suite.h
@@ -0,0 +1,41 @@
1/* EVIL - EFL library for Windows port
2 * Copyright (C) 2015 Vincent Torri
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef EVIL_SUITE_H_
20#define EVIL_SUITE_H_
21
22#include <check.h>
23
24/* void evil_test_dirent(TCase *tc); */
25void evil_test_dlfcn(TCase *tc);
26/* void evil_test_fcntl(TCase *tc); */
27/* void evil_test_fnmatch(TCase *tc); */
28/* void evil_test_inet(TCase *tc); */
29/* void evil_test_langinfo(TCase *tc); */
30/* void evil_test_link(TCase *tc); */
31void evil_test_main(TCase *tc);
32/* void evil_test_mman(TCase *tc); */
33/* void evil_test_pwd(TCase *tc); */
34/* void evil_test_stdio(TCase *tc); */
35/* void evil_test_stdlib(TCase *tc); */
36/* void evil_test_string(TCase *tc); */
37/* void evil_test_time(TCase *tc); */
38/* void evil_test_unistd(TCase *tc); */
39/* void evil_test_util(TCase *tc); */
40
41#endif /* EVIL_SUITE_H_ */
diff --git a/src/tests/evil/evil_test_dlfcn.c b/src/tests/evil/evil_test_dlfcn.c
new file mode 100644
index 0000000000..28ee5b528e
--- /dev/null
+++ b/src/tests/evil/evil_test_dlfcn.c
@@ -0,0 +1,132 @@
1/* EVIL - EFL library for Windows port
2 * Copyright (C) 2015 Vincent Torri
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <dlfcn.h>
24#include <Evil.h>
25
26#include "evil_suite.h"
27
28
29typedef int (*_evil_init)(void);
30typedef int (*_evil_shutdwon)(void);
31
32
33START_TEST(evil_dlfcn_dlopen_success)
34{
35 void *mod;
36 int res;
37
38 mod = dlopen("c:\\windows\\system32\\kernel32.dll", 0);
39 fail_if(mod == NULL);
40
41 res = dlclose(mod);
42 fail_if(res != 0);
43}
44END_TEST
45
46START_TEST(evil_dlfcn_dlopen_failure)
47{
48 void *mod;
49
50 /* non existent DLL */
51 mod = dlopen("c:\\windows\\system32\\kernel32.dl", 0);
52 fail_if(mod != NULL);
53}
54END_TEST
55
56START_TEST(evil_dlfcn_dlsym_success)
57{
58 _evil_init sym_init;
59 _evil_shutdwon sym_shutdown;
60 void *mod;
61 int res;
62
63 mod = dlopen("libevil-1.dll", 0);
64 fail_if(mod == NULL);
65
66 sym_init = dlsym(mod, "evil_init");
67 fail_if(sym_init == NULL);
68 fail_if(sym_init() != 1);
69
70 sym_shutdown = dlsym(mod, "evil_shutdown");
71 fail_if(sym_shutdown == NULL);
72 fail_if(sym_shutdown() != 0);
73
74 res = dlclose(mod);
75 fail_if(res != 0);
76}
77END_TEST
78
79START_TEST(evil_dlfcn_dlsym_failure)
80{
81 void *mod;
82 void *sym;
83 int res;
84
85 mod = dlopen("libevil-1.dll", 0);
86 fail_if(mod == NULL);
87
88 /* non-existent symbol */
89 sym = dlsym(mod, "evil_ini");
90 fail_if(sym != NULL);
91
92 res = dlclose(mod);
93 fail_if(res != 0);
94}
95END_TEST
96
97START_TEST(evil_dlfcn_dladdr)
98{
99 Dl_info info;
100 void *mod;
101 void *sym;
102 char *dll;
103 int res;
104
105 mod = dlopen("libevil-1.dll", 0);
106 fail_if(mod == NULL);
107
108 sym = dlsym(mod, "evil_init");
109 fail_if(sym == NULL);
110
111 res = dladdr(sym, &info);
112 fail_if(res == 0);
113
114 fail_if(mod != info.dli_fbase);
115 dll = strrchr(info.dli_fname, '\\') + 1;
116 fail_if(strcmp("libevil-1.dll", dll) != 0);
117 fail_if(sym != info.dli_saddr);
118 fail_if(strcmp("evil_init", info.dli_sname) != 0);
119
120 res = dlclose(mod);
121 fail_if(res != 0);
122}
123END_TEST
124
125void evil_test_dlfcn(TCase *tc)
126{
127 tcase_add_test(tc, evil_dlfcn_dlopen_success);
128 tcase_add_test(tc, evil_dlfcn_dlopen_failure);
129 tcase_add_test(tc, evil_dlfcn_dlsym_success);
130 tcase_add_test(tc, evil_dlfcn_dlsym_failure);
131 tcase_add_test(tc, evil_dlfcn_dladdr);
132}
diff --git a/src/tests/evil/evil_test_main.c b/src/tests/evil/evil_test_main.c
new file mode 100644
index 0000000000..d116aef166
--- /dev/null
+++ b/src/tests/evil/evil_test_main.c
@@ -0,0 +1,37 @@
1/* EVIL - EFL library for Windows port
2 * Copyright (C) 2015 Vincent Torri
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <Evil.h>
24
25#include "evil_suite.h"
26
27START_TEST(evil_main_simple)
28{
29 fail_if(evil_init() != 1);
30 fail_if(evil_shutdown() != 0);
31}
32END_TEST
33
34void evil_test_main(TCase *tc)
35{
36 tcase_add_test(tc, evil_main_simple);
37}