1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
19
#include "apr_general.h"
20
#include "apr_pools.h"
21
#include "apr_errno.h"
23
#include "apr_strings.h"
24
#include "apr_file_info.h"
33
# define MOD_NAME "mod_test.nlm"
35
# define MOD_NAME "mod_test.so"
37
# define MOD_NAME "mod_test.dll"
39
# define MOD_NAME ".libs/mod_test.so"
40
# define LIB_NAME ".libs/libmod_test.dylib"
41
#elif defined(__hpux__) || defined(__hpux)
42
# define MOD_NAME ".libs/mod_test.sl"
43
# define LIB_NAME ".libs/libmod_test.sl"
44
#elif defined(_AIX) || defined(__bsdi__)
45
# define MOD_NAME ".libs/libmod_test.so"
46
# define LIB_NAME ".libs/libmod_test.so"
47
#else /* Every other Unix */
48
# define MOD_NAME ".libs/mod_test.so"
49
# define LIB_NAME ".libs/libmod_test.so"
54
static void test_load_module(abts_case *tc, void *data)
56
apr_dso_handle_t *h = NULL;
60
status = apr_dso_load(&h, modname, p);
61
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
62
ABTS_PTR_NOTNULL(tc, h);
67
static void test_dso_sym(abts_case *tc, void *data)
69
apr_dso_handle_t *h = NULL;
70
apr_dso_handle_sym_t func1 = NULL;
72
void (*function)(char str[256]);
76
status = apr_dso_load(&h, modname, p);
77
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
78
ABTS_PTR_NOTNULL(tc, h);
80
status = apr_dso_sym(&func1, h, "print_hello");
81
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
82
ABTS_PTR_NOTNULL(tc, func1);
85
function = (void (*)(char *))func1;
87
ABTS_STR_EQUAL(tc, "Hello - I'm a DSO!\n", teststr);
93
static void test_dso_sym_return_value(abts_case *tc, void *data)
95
apr_dso_handle_t *h = NULL;
96
apr_dso_handle_sym_t func1 = NULL;
101
status = apr_dso_load(&h, modname, p);
102
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
103
ABTS_PTR_NOTNULL(tc, h);
105
status = apr_dso_sym(&func1, h, "count_reps");
106
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
107
ABTS_PTR_NOTNULL(tc, func1);
110
function = (int (*)(int))func1;
111
status = (*function)(5);
112
ABTS_INT_EQUAL(tc, 5, status);
118
static void test_unload_module(abts_case *tc, void *data)
120
apr_dso_handle_t *h = NULL;
123
apr_dso_handle_sym_t func1 = NULL;
125
status = apr_dso_load(&h, modname, p);
126
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
127
ABTS_PTR_NOTNULL(tc, h);
129
status = apr_dso_unload(h);
130
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
132
status = apr_dso_sym(&func1, h, "print_hello");
133
ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_ESYMNOTFOUND(status));
138
static char *libname;
140
static void test_load_library(abts_case *tc, void *data)
142
apr_dso_handle_t *h = NULL;
146
status = apr_dso_load(&h, libname, p);
147
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
148
ABTS_PTR_NOTNULL(tc, h);
153
static void test_dso_sym_library(abts_case *tc, void *data)
155
apr_dso_handle_t *h = NULL;
156
apr_dso_handle_sym_t func1 = NULL;
158
void (*function)(char str[256]);
162
status = apr_dso_load(&h, libname, p);
163
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
164
ABTS_PTR_NOTNULL(tc, h);
166
status = apr_dso_sym(&func1, h, "print_hello");
167
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
168
ABTS_PTR_NOTNULL(tc, func1);
171
function = (void (*)(char *))func1;
172
(*function)(teststr);
173
ABTS_STR_EQUAL(tc, "Hello - I'm a DSO!\n", teststr);
179
static void test_dso_sym_return_value_library(abts_case *tc, void *data)
181
apr_dso_handle_t *h = NULL;
182
apr_dso_handle_sym_t func1 = NULL;
184
int (*function)(int);
187
status = apr_dso_load(&h, libname, p);
188
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
189
ABTS_PTR_NOTNULL(tc, h);
191
status = apr_dso_sym(&func1, h, "count_reps");
192
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
193
ABTS_PTR_NOTNULL(tc, func1);
196
function = (int (*)(int))func1;
197
status = (*function)(5);
198
ABTS_INT_EQUAL(tc, 5, status);
204
static void test_unload_library(abts_case *tc, void *data)
206
apr_dso_handle_t *h = NULL;
209
apr_dso_handle_sym_t func1 = NULL;
211
status = apr_dso_load(&h, libname, p);
212
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
213
ABTS_PTR_NOTNULL(tc, h);
215
status = apr_dso_unload(h);
216
ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
218
status = apr_dso_sym(&func1, h, "print_hello");
219
ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_ESYMNOTFOUND(status));
222
#endif /* def(LIB_NAME) */
224
static void test_load_notthere(abts_case *tc, void *data)
226
apr_dso_handle_t *h = NULL;
229
status = apr_dso_load(&h, "No_File.so", p);
231
ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EDSOOPEN(status));
232
ABTS_PTR_NOTNULL(tc, h);
235
#endif /* APR_HAS_DSO */
237
abts_suite *testdso(abts_suite *suite)
239
suite = ADD_SUITE(suite)
242
apr_filepath_merge(&modname, NULL, MOD_NAME, 0, p);
244
abts_run_test(suite, test_load_module, NULL);
245
abts_run_test(suite, test_dso_sym, NULL);
246
abts_run_test(suite, test_dso_sym_return_value, NULL);
247
abts_run_test(suite, test_unload_module, NULL);
250
apr_filepath_merge(&libname, NULL, LIB_NAME, 0, p);
252
abts_run_test(suite, test_load_library, NULL);
253
abts_run_test(suite, test_dso_sym_library, NULL);
254
abts_run_test(suite, test_dso_sym_return_value_library, NULL);
255
abts_run_test(suite, test_unload_library, NULL);
258
abts_run_test(suite, test_load_notthere, NULL);
259
#endif /* APR_HAS_DSO */