Apache HTTPD
testdso.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17
18#include "apr.h"
19#include "testutil.h"
20#include "apr_general.h"
21#include "apr_pools.h"
22#include "apr_errno.h"
23#include "apr_dso.h"
24#include "apr_strings.h"
25#include "apr_file_info.h"
26#if APR_HAVE_UNISTD_H
27#include <unistd.h>
28#endif
29
30#if APR_HAS_DSO
31
32#ifdef NETWARE
33# define MOD_NAME "mod_test.nlm"
34#elif defined(BEOS) || defined(__MVS__)
35# define MOD_NAME "mod_test.so"
36#elif defined(WIN32)
37# define MOD_NAME TESTBINPATH "mod_test.dll"
38#elif defined(DARWIN)
39# define MOD_NAME ".libs/mod_test.so"
40# define LIB_NAME ".libs/libmod_test.dylib"
41#elif (defined(__hpux__) || defined(__hpux)) && !defined(__ia64)
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"
50#endif
51
52static char *modname;
53
54static void test_load_module(abts_case *tc, void *data)
55{
58 char errstr[256];
59
61 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
63
65}
66
67static void test_dso_sym(abts_case *tc, void *data)
68{
72 void (*function)(char str[256]);
73 char teststr[256];
74 char errstr[256];
75
77 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
79
80 status = apr_dso_sym(&func1, h, "print_hello");
81 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
83
84 if (!tc->failed) {
85 function = (void (*)(char *))func1;
86 (*function)(teststr);
87 ABTS_STR_EQUAL(tc, "Hello - I'm a DSO!\n", teststr);
88 }
89
91}
92
93static void test_dso_sym_return_value(abts_case *tc, void *data)
94{
98 int (*function)(int);
99 char errstr[256];
100
102 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
103 ABTS_PTR_NOTNULL(tc, h);
104
105 status = apr_dso_sym(&func1, h, "count_reps");
106 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
108
109 if (!tc->failed) {
110 function = (int (*)(int))func1;
111 status = (*function)(5);
112 ABTS_INT_EQUAL(tc, 5, status);
113 }
114
116}
117
118static void test_unload_module(abts_case *tc, void *data)
119{
122 char errstr[256];
124
126 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
127 ABTS_PTR_NOTNULL(tc, h);
128
130 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
131
132 status = apr_dso_sym(&func1, h, "print_hello");
134}
135
136
137#ifdef LIB_NAME
138static char *libname;
139
140static void test_load_library(abts_case *tc, void *data)
141{
144 char errstr[256];
145
147 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
148 ABTS_PTR_NOTNULL(tc, h);
149
151}
152
153static void test_dso_sym_library(abts_case *tc, void *data)
154{
158 void (*function)(char str[256]);
159 char teststr[256];
160 char errstr[256];
161
163 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
164 ABTS_PTR_NOTNULL(tc, h);
165
166 status = apr_dso_sym(&func1, h, "print_hello");
167 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
169
170 if (!tc->failed) {
171 function = (void (*)(char *))func1;
172 (*function)(teststr);
173 ABTS_STR_EQUAL(tc, "Hello - I'm a DSO!\n", teststr);
174 }
175
177}
178
180{
184 int (*function)(int);
185 char errstr[256];
186
188 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
189 ABTS_PTR_NOTNULL(tc, h);
190
191 status = apr_dso_sym(&func1, h, "count_reps");
192 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
194
195 if (!tc->failed) {
196 function = (int (*)(int))func1;
197 status = (*function)(5);
198 ABTS_INT_EQUAL(tc, 5, status);
199 }
200
202}
203
204static void test_unload_library(abts_case *tc, void *data)
205{
208 char errstr[256];
210
212 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
213 ABTS_PTR_NOTNULL(tc, h);
214
216 ABTS_ASSERT(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
217
218 status = apr_dso_sym(&func1, h, "print_hello");
220}
221
222#endif /* def(LIB_NAME) */
223
224static void test_load_notthere(abts_case *tc, void *data)
225{
228
229 status = apr_dso_load(&h, "No_File.so", p);
230
232 ABTS_PTR_NOTNULL(tc, h);
233}
234
235#endif /* APR_HAS_DSO */
236
238{
239 suite = ADD_SUITE(suite)
240
241#if APR_HAS_DSO
243
248
249#ifdef LIB_NAME
251
256#endif
257
259#endif /* APR_HAS_DSO */
260
261 return suite;
262}
263
void abts_run_test(abts_suite *ts, test_func f, void *value)
Definition abts.c:175
#define ADD_SUITE(suite)
Definition abts.h:67
#define ABTS_PTR_NOTNULL(a, b)
Definition abts.h:125
#define ABTS_STR_EQUAL(a, b, c)
Definition abts.h:123
#define ABTS_ASSERT(a, b, c)
Definition abts.h:130
#define ABTS_INT_EQUAL(a, b, c)
Definition abts.h:109
APR Dynamic Object Handling Routines.
APR Error Codes.
APR File Information.
APR Miscellaneous library routines.
APR memory allocation.
APR Strings library.
#define APR_STATUS_IS_EDSOOPEN(s)
Definition apr_errno.h:403
#define APR_STATUS_IS_ESYMNOTFOUND(s)
Definition apr_errno.h:424
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
const apr_hash_t * h
Definition apr_hash.h:97
int int status
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
int failed
Definition abts.h:59
abts_suite * testdso(abts_suite *suite)
Definition testdso.c:237
abts_suite * teststr(abts_suite *suite)
Definition teststr.c:411
#define str
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray