summaryrefslogtreecommitdiff
path: root/src/bin/evil/evil_test_dlfcn.c
blob: b84a9eb2387a511b97ae4dfcc598b86266a95f45 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */

#include <string.h>
#include <dlfcn.h>

#include <Evil.h>

#include "evil_suite.h"
#include "evil_test_dlfcn.h"


typedef int (*_evil_init)(void);
typedef int (*_evil_shutdwon)(void);


static int
test_dlfcn_test_dlopen(void)
{
   void *handle;

   handle = dlopen("libevil-1.dll", 0);
   if (!handle)
     return 0;

   if (dlclose(handle))
     return 0;

   return 1;
}

static int
test_dlfcn_test_dlsym(void)
{
   void          *handle;
   _evil_init     sym_init;
   _evil_shutdwon sym_shutdown;

   handle = dlopen("libevil-1.dll", 0);
   if (!handle)
     return 0;

   sym_init = dlsym(handle, "evil_init");
   if (!sym_init)
     {
        dlclose(handle);
        return 0;
     }

   sym_shutdown = dlsym(handle, "evil_shutdown");
   if (!sym_shutdown)
     {
        dlclose(handle);
        return 0;
     }

   if (dlclose(handle))
     return 0;

   return 1;
}

static int
test_dlfcn_tests_run(suite *s)
{
   int res;

   res  = test_dlfcn_test_dlopen();
   res &= test_dlfcn_test_dlsym();

   return res;
}

int
test_dlfcn(suite *s)
{

   return test_dlfcn_tests_run(s);
}