diff options
author | Timothy Gu <timothygu99@gmail.com> | 2014-02-10 03:46:33 +0000 |
---|---|---|
committer | Timothy Gu <timothygu99@gmail.com> | 2014-02-10 03:46:33 +0000 |
commit | e16a6e8eb4f81144a14d31b66774c65e900caa7d (patch) | |
tree | e332fb49b4966895f753603ed508f677dabb3a8c | |
parent | 043b3358a91a5e9bef707fd3720f60552e0b9569 (diff) | |
download | dlfcn-win32-e16a6e8eb4f81144a14d31b66774c65e900caa7d.tar.gz dlfcn-win32-e16a6e8eb4f81144a14d31b66774c65e900caa7d.tar.bz2 dlfcn-win32-e16a6e8eb4f81144a14d31b66774c65e900caa7d.zip |
test: add trying to load nonexistent symbols test
-rw-r--r-- | test.c | 83 |
1 files changed, 82 insertions, 1 deletions
@@ -42,15 +42,20 @@ | |||
42 | * - Get global object | 42 | * - Get global object |
43 | * - Get symbol from library through library object <- works | 43 | * - Get symbol from library through library object <- works |
44 | * - Run function if it worked | 44 | * - Run function if it worked |
45 | * - Get nonexistent symbol from library through library object <- fails | ||
45 | * - Get symbol from library through global object <- works | 46 | * - Get symbol from library through global object <- works |
46 | * - Run function if it worked | 47 | * - Run function if it worked |
48 | * - Get nonexistent symbol from library through global object <- fails | ||
47 | * - Close library | 49 | * - Close library |
48 | * - Open library with RTLD_LOCAL | 50 | * - Open library with RTLD_LOCAL |
49 | * - Get symbol from library through library object <- works | 51 | * - Get symbol from library through library object <- works |
50 | * - Run function if it worked | 52 | * - Run function if it worked |
51 | * - Get symbol from library through global object <- fails | 53 | * - Get nonexistent symbol from library through library object <- fails |
54 | * - Get local symbol from library through global object <- fails | ||
55 | * - Get nonexistent local symbol from library through global object <- fails | ||
52 | * - Open library again (without closing it first) with RTLD_GLOBAL | 56 | * - Open library again (without closing it first) with RTLD_GLOBAL |
53 | * - Get symbol from library through global object <- works | 57 | * - Get symbol from library through global object <- works |
58 | * - Get nonexistent symbol from library through global object <- fails | ||
54 | * - Close library | 59 | * - Close library |
55 | * - Close global object | 60 | * - Close global object |
56 | * | 61 | * |
@@ -63,6 +68,7 @@ int main() | |||
63 | void *library; | 68 | void *library; |
64 | char *error; | 69 | char *error; |
65 | int (*function)( void ); | 70 | int (*function)( void ); |
71 | int (*nonexistentfunction)( void ); | ||
66 | int ret; | 72 | int ret; |
67 | 73 | ||
68 | library = dlopen( "testdll.dll", RTLD_GLOBAL ); | 74 | library = dlopen( "testdll.dll", RTLD_GLOBAL ); |
@@ -101,6 +107,21 @@ int main() | |||
101 | 107 | ||
102 | RUNFUNC; | 108 | RUNFUNC; |
103 | 109 | ||
110 | nonexistentfunction = dlsym( library, "nonexistentfunction" ); | ||
111 | if( nonexistentfunction ) | ||
112 | { | ||
113 | error = dlerror( ); | ||
114 | printf( "ERROR\tGot nonexistent symbol from library handle: %p\n", nonexistentfunction ); | ||
115 | CLOSE_LIB; | ||
116 | CLOSE_GLOBAL; | ||
117 | RETURN_ERROR; | ||
118 | } | ||
119 | else { | ||
120 | error = dlerror( ); | ||
121 | printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", | ||
122 | error ? error : "" ); | ||
123 | } | ||
124 | |||
104 | function = dlsym( global, "function" ); | 125 | function = dlsym( global, "function" ); |
105 | if( !function ) | 126 | if( !function ) |
106 | { | 127 | { |
@@ -116,6 +137,21 @@ int main() | |||
116 | 137 | ||
117 | RUNFUNC; | 138 | RUNFUNC; |
118 | 139 | ||
140 | nonexistentfunction = dlsym( global, "nonexistentfunction" ); | ||
141 | if( nonexistentfunction ) | ||
142 | { | ||
143 | error = dlerror( ); | ||
144 | printf( "ERROR\tGot nonexistent symbol from global handle: %p\n", nonexistentfunction ); | ||
145 | CLOSE_LIB; | ||
146 | CLOSE_GLOBAL; | ||
147 | RETURN_ERROR; | ||
148 | } | ||
149 | else { | ||
150 | error = dlerror( ); | ||
151 | printf( "SUCCESS\tCould not get nonexistent symbol from global handle: %s\n", | ||
152 | error ? error : "" ); | ||
153 | } | ||
154 | |||
119 | ret = dlclose( library ); | 155 | ret = dlclose( library ); |
120 | if( ret ) | 156 | if( ret ) |
121 | { | 157 | { |
@@ -153,6 +189,21 @@ int main() | |||
153 | 189 | ||
154 | RUNFUNC; | 190 | RUNFUNC; |
155 | 191 | ||
192 | nonexistentfunction = dlsym( library, "nonexistentfunction" ); | ||
193 | if( nonexistentfunction ) | ||
194 | { | ||
195 | error = dlerror( ); | ||
196 | printf( "ERROR\tGot nonexistent symbol from library handle: %p\n", nonexistentfunction ); | ||
197 | CLOSE_LIB; | ||
198 | CLOSE_GLOBAL; | ||
199 | RETURN_ERROR; | ||
200 | } | ||
201 | else { | ||
202 | error = dlerror( ); | ||
203 | printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", | ||
204 | error ? error : "" ); | ||
205 | } | ||
206 | |||
156 | function = dlsym( global, "function" ); | 207 | function = dlsym( global, "function" ); |
157 | if( function ) | 208 | if( function ) |
158 | { | 209 | { |
@@ -166,6 +217,21 @@ int main() | |||
166 | else | 217 | else |
167 | printf( "SUCCESS\tDid not get local symbol from global handle.\n" ); | 218 | printf( "SUCCESS\tDid not get local symbol from global handle.\n" ); |
168 | 219 | ||
220 | nonexistentfunction = dlsym( global, "nonexistentfunction" ); | ||
221 | if( nonexistentfunction ) | ||
222 | { | ||
223 | error = dlerror( ); | ||
224 | printf( "ERROR\tGot nonexistent local symbol from global handle: %p\n", nonexistentfunction ); | ||
225 | CLOSE_LIB; | ||
226 | CLOSE_GLOBAL; | ||
227 | RETURN_ERROR; | ||
228 | } | ||
229 | else { | ||
230 | error = dlerror( ); | ||
231 | printf( "SUCCESS\tDid not get nonexistent local symbol from global handle: %s\n", | ||
232 | error ? error : "" ); | ||
233 | } | ||
234 | |||
169 | library = dlopen( "testdll.dll", RTLD_GLOBAL ); | 235 | library = dlopen( "testdll.dll", RTLD_GLOBAL ); |
170 | if( !library ) | 236 | if( !library ) |
171 | { | 237 | { |
@@ -193,6 +259,21 @@ int main() | |||
193 | 259 | ||
194 | RUNFUNC; | 260 | RUNFUNC; |
195 | 261 | ||
262 | nonexistentfunction = dlsym( global, "nonexistentfunction" ); | ||
263 | if( nonexistentfunction ) | ||
264 | { | ||
265 | error = dlerror( ); | ||
266 | printf( "ERROR\tGot nonexistent symbol from global handle: %p\n", nonexistentfunction ); | ||
267 | CLOSE_LIB; | ||
268 | CLOSE_GLOBAL; | ||
269 | RETURN_ERROR; | ||
270 | } | ||
271 | else { | ||
272 | error = dlerror( ); | ||
273 | printf( "SUCCESS\tCould not get nonexistent symbol from global handle: %s\n", | ||
274 | error ? error : "" ); | ||
275 | } | ||
276 | |||
196 | ret = dlclose( library ); | 277 | ret = dlclose( library ); |
197 | if( ret ) | 278 | if( ret ) |
198 | { | 279 | { |