efl

Форк
0
/
evil_test_dlfcn.c 
131 строка · 2.9 Кб
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_private.h>
24

25
#include "evil_suite.h"
26

27

28
typedef int (*_evil_init)(void);
29
typedef int (*_evil_shutdwon)(void);
30

31

32
EFL_START_TEST(evil_dlfcn_dlopen_success)
33
{
34
   void *mod;
35
   int res;
36

37
   mod = dlopen("c:\\windows\\system32\\kernel32.dll", 0);
38
   fail_if(mod == NULL);
39

40
   res = dlclose(mod);
41
   fail_if(res != 0);
42
}
43
EFL_END_TEST
44

45
EFL_START_TEST(evil_dlfcn_dlopen_failure)
46
{
47
   void *mod;
48

49
   /* non existent DLL */
50
   mod = dlopen("c:\\windows\\system32\\kernel32.dl", 0);
51
   fail_if(mod != NULL);
52
}
53
EFL_END_TEST
54

55
EFL_START_TEST(evil_dlfcn_dlsym_success)
56
{
57
   _evil_init sym_init;
58
   _evil_shutdwon sym_shutdown;
59
   void *mod;
60
   int res;
61

62
   mod = dlopen("libevil-1.dll", 0);
63
   fail_if(mod == NULL);
64

65
   sym_init = dlsym(mod, "evil_init");
66
   fail_if(sym_init == NULL);
67
   fail_if(sym_init() != 2);
68

69
   sym_shutdown = dlsym(mod, "evil_shutdown");
70
   fail_if(sym_shutdown == NULL);
71
   fail_if(sym_shutdown() != 1);
72

73
   res = dlclose(mod);
74
   fail_if(res != 0);
75
}
76
EFL_END_TEST
77

78
EFL_START_TEST(evil_dlfcn_dlsym_failure)
79
{
80
   void *mod;
81
   void *sym;
82
   int res;
83

84
   mod = dlopen("libevil-1.dll", 0);
85
   fail_if(mod == NULL);
86

87
   /* non-existent symbol */
88
   sym = dlsym(mod, "evil_ini");
89
   fail_if(sym != NULL);
90

91
   res = dlclose(mod);
92
   fail_if(res != 0);
93
}
94
EFL_END_TEST
95

96
EFL_START_TEST(evil_dlfcn_dladdr)
97
{
98
   Dl_info info;
99
   void *mod;
100
   void *sym;
101
   char *dll;
102
   int res;
103

104
   mod = dlopen("libevil-1.dll", 0);
105
   fail_if(mod == NULL);
106

107
   sym = dlsym(mod, "evil_init");
108
   fail_if(sym == NULL);
109

110
   res = dladdr(sym, &info);
111
   fail_if(res == 0);
112

113
   fail_if(mod != info.dli_fbase);
114
   dll = strrchr(info.dli_fname, '\\') + 1;
115
   fail_if(strcmp("libevil-1.dll", dll) != 0);
116
   fail_if(sym != info.dli_saddr);
117
   fail_if(strcmp("evil_init", info.dli_sname) != 0);
118

119
   res = dlclose(mod);
120
   fail_if(res != 0);
121
}
122
EFL_END_TEST
123

124
void evil_test_dlfcn(TCase *tc)
125
{
126
   tcase_add_test(tc, evil_dlfcn_dlopen_success);
127
   tcase_add_test(tc, evil_dlfcn_dlopen_failure);
128
   tcase_add_test(tc, evil_dlfcn_dlsym_success);
129
   tcase_add_test(tc, evil_dlfcn_dlsym_failure);
130
   tcase_add_test(tc, evil_dlfcn_dladdr);
131
}
132

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.