aboutsummaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test.c')
-rw-r--r--test.c168
1 files changed, 148 insertions, 20 deletions
diff --git a/test.c b/test.c
index 814aca1..0070f8c 100644
--- a/test.c
+++ b/test.c
@@ -83,6 +83,11 @@ int main()
83 int (*nonexistentfunction)( void ); 83 int (*nonexistentfunction)( void );
84 int ret; 84 int ret;
85 HMODULE library3; 85 HMODULE library3;
86 char toolongfile[32767];
87 DWORD code;
88 char nonlibraryfile[MAX_PATH];
89 HANDLE tempfile;
90 DWORD dummy;
86 91
87#ifdef _DEBUG 92#ifdef _DEBUG
88 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); 93 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
@@ -93,6 +98,112 @@ int main()
93 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT); 98 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
94#endif 99#endif
95 100
101 ret = GetTempPathA( sizeof( nonlibraryfile ) - sizeof( "temp.dll" ), nonlibraryfile );
102 if( ret == 0 || ret > sizeof( nonlibraryfile ) - sizeof( "temp.dll" ) )
103 {
104 printf( "ERROR\tGetTempPath failed\n" );
105 RETURN_ERROR;
106 }
107
108 memcpy( nonlibraryfile + ret, "temp.dll", sizeof( "temp.dll" ) );
109
110 tempfile = CreateFileA( (LPCSTR) nonlibraryfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
111 if( tempfile == INVALID_HANDLE_VALUE )
112 {
113 printf( "ERROR\tCannot create temporary file %s: %lu\n", nonlibraryfile, (unsigned long)GetLastError( ) );
114 RETURN_ERROR;
115 }
116
117 WriteFile( tempfile, "test content", 12, &dummy, NULL );
118
119 CloseHandle( tempfile );
120
121 library3 = LoadLibraryA( nonlibraryfile );
122 code = GetLastError( );
123 if( library3 )
124 {
125 printf( "ERROR\tNon-library file %s was opened via WINAPI\n", nonlibraryfile );
126 CloseHandle( library3 );
127 DeleteFileA( nonlibraryfile );
128 RETURN_ERROR;
129 }
130 else if( code != ERROR_BAD_EXE_FORMAT )
131 {
132 printf( "ERROR\tNon-library file %s was processed via WINAPI: %lu\n", nonlibraryfile, (unsigned long)code );
133 DeleteFileA( nonlibraryfile );
134 RETURN_ERROR;
135 }
136 else
137 printf( "SUCCESS\tCould not open non-library file %s via WINAPI: %lu\n", nonlibraryfile, (unsigned long)code );
138
139 library = dlopen( nonlibraryfile, RTLD_GLOBAL );
140 if( library )
141 {
142 printf( "ERROR\tNon-library file %s was opened via dlopen\n", nonlibraryfile );
143 dlclose( library );
144 DeleteFileA( nonlibraryfile );
145 RETURN_ERROR;
146 }
147 error = dlerror( );
148 if( !error )
149 {
150 printf( "ERROR\tNo error from dlopen for non-library file\n" );
151 DeleteFileA( nonlibraryfile );
152 RETURN_ERROR;
153 }
154 else
155 printf( "SUCCESS\tCould not open non-library file %s: %s\n", nonlibraryfile, error );
156
157 DeleteFileA( nonlibraryfile );
158
159 library = dlopen( "nonexistentfile.dll", RTLD_GLOBAL );
160 if( library )
161 {
162 printf( "ERROR\tNon-existent file nonexistentfile.dll was opened via dlopen\n" );
163 RETURN_ERROR;
164 }
165 error = dlerror( );
166 if( !error )
167 {
168 printf( "ERROR\tNo error from dlopen for non-existent file\n" );
169 RETURN_ERROR;
170 }
171 else
172 printf( "SUCCESS\tCould not open non-existent file nonexistentfile.dll: %s\n", error );
173
174 memset( toolongfile, 'X', sizeof( toolongfile ) - 5 );
175 memcpy( toolongfile + sizeof( toolongfile ) - 5, ".dll", 5 );
176
177 library = dlopen( toolongfile, RTLD_GLOBAL );
178 if( library )
179 {
180 printf( "ERROR\tFile with too long file name was opened via dlopen\n" );
181 RETURN_ERROR;
182 }
183 error = dlerror( );
184 if( !error )
185 {
186 printf( "ERROR\tNo error from dlopen for file with too long file name\n" );
187 RETURN_ERROR;
188 }
189 else
190 printf( "SUCCESS\tCould not open file with too long file name: %s\n", error );
191
192 library3 = LoadLibraryA( toolongfile );
193 code = GetLastError( );
194 if( library3 )
195 {
196 printf( "ERROR\tFile with too long file name was opened via WINAPI\n" );
197 RETURN_ERROR;
198 }
199 else if( code != ERROR_FILENAME_EXCED_RANGE )
200 {
201 printf( "ERROR\tFile with too long file name was processed via WINAPI: %lu\n", (unsigned long)code );
202 RETURN_ERROR;
203 }
204 else
205 printf( "SUCCESS\tCould not open file with too long file name via WINAPI: %lu\n", (unsigned long)code );
206
96 library2 = dlopen( "testdll2.dll", RTLD_GLOBAL ); 207 library2 = dlopen( "testdll2.dll", RTLD_GLOBAL );
97 if( !library2 ) 208 if( !library2 )
98 { 209 {
@@ -201,11 +312,14 @@ int main()
201 CLOSE_GLOBAL; 312 CLOSE_GLOBAL;
202 RETURN_ERROR; 313 RETURN_ERROR;
203 } 314 }
204 else { 315 error = dlerror( );
205 error = dlerror( ); 316 if( !error )
206 printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", 317 {
207 error ? error : "" ); 318 printf( "ERROR\tNo error from dlsym for nonexistent symbol\n" );
319 RETURN_ERROR;
208 } 320 }
321 else
322 printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", error );
209 323
210 function = dlsym( global, "function" ); 324 function = dlsym( global, "function" );
211 if( !function ) 325 if( !function )
@@ -231,11 +345,14 @@ int main()
231 CLOSE_GLOBAL; 345 CLOSE_GLOBAL;
232 RETURN_ERROR; 346 RETURN_ERROR;
233 } 347 }
234 else { 348 error = dlerror( );
235 error = dlerror( ); 349 if( !error )
236 printf( "SUCCESS\tCould not get nonexistent symbol from global handle: %s\n", 350 {
237 error ? error : "" ); 351 printf( "ERROR\tNo error from dlsym for nonexistent symbol\n" );
352 RETURN_ERROR;
238 } 353 }
354 else
355 printf( "SUCCESS\tCould not get nonexistent symbol from global handle: %s\n", error );
239 356
240 ret = dlclose( library ); 357 ret = dlclose( library );
241 if( ret ) 358 if( ret )
@@ -293,11 +410,14 @@ int main()
293 CLOSE_GLOBAL; 410 CLOSE_GLOBAL;
294 RETURN_ERROR; 411 RETURN_ERROR;
295 } 412 }
296 else { 413 error = dlerror( );
297 error = dlerror( ); 414 if( !error )
298 printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", 415 {
299 error ? error : "" ); 416 printf( "ERROR\tNo error from dlsym for nonexistent symbol\n" );
417 RETURN_ERROR;
300 } 418 }
419 else
420 printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", error );
301 421
302 function = dlsym( global, "function" ); 422 function = dlsym( global, "function" );
303 if( function ) 423 if( function )
@@ -321,11 +441,14 @@ int main()
321 CLOSE_GLOBAL; 441 CLOSE_GLOBAL;
322 RETURN_ERROR; 442 RETURN_ERROR;
323 } 443 }
324 else { 444 error = dlerror( );
325 error = dlerror( ); 445 if( !error )
326 printf( "SUCCESS\tDid not get nonexistent local symbol from global handle: %s\n", 446 {
327 error ? error : "" ); 447 printf( "ERROR\tNo error from dlsym for nonexistent symbol\n" );
448 RETURN_ERROR;
328 } 449 }
450 else
451 printf( "SUCCESS\tDid not get nonexistent local symbol from global handle: %s\n", error );
329 452
330 library = dlopen( "testdll.dll", RTLD_GLOBAL ); 453 library = dlopen( "testdll.dll", RTLD_GLOBAL );
331 if( !library ) 454 if( !library )
@@ -363,10 +486,15 @@ int main()
363 CLOSE_GLOBAL; 486 CLOSE_GLOBAL;
364 RETURN_ERROR; 487 RETURN_ERROR;
365 } 488 }
366 else { 489 error = dlerror( );
367 error = dlerror( ); 490 if( !error )
368 printf( "SUCCESS\tCould not get nonexistent symbol from global handle: %s\n", 491 {
369 error ? error : "" ); 492 printf( "ERROR\tNo error from dlsym for nonexistent symbol\n" );
493 RETURN_ERROR;
494 }
495 else
496 {
497 printf( "SUCCESS\tCould not get nonexistent symbol from global handle: %s\n", error );
370 498
371 /* Test that the second call to dlerror() returns null as in the specs 499 /* Test that the second call to dlerror() returns null as in the specs
372 See https://github.com/dlfcn-win32/dlfcn-win32/issues/34 */ 500 See https://github.com/dlfcn-win32/dlfcn-win32/issues/34 */