aboutsummaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2019-09-12 16:37:03 +0200
committerPali Rohár <pali.rohar@gmail.com>2019-09-12 16:37:03 +0200
commitab246dbf3a6682eb5f6544c0e6f384a72bbe7a98 (patch)
tree4045f300ca61cb6cea655c4418f0ffdb3df406fa /test.c
parent07ef52a5f199ae4fabeee9924c935d06f9e46aec (diff)
downloaddlfcn-win32-ab246dbf3a6682eb5f6544c0e6f384a72bbe7a98.tar.gz
dlfcn-win32-ab246dbf3a6682eb5f6544c0e6f384a72bbe7a98.tar.bz2
dlfcn-win32-ab246dbf3a6682eb5f6544c0e6f384a72bbe7a98.zip
Add test which check that dlopen() can open same files as open()
This ensures that dlopen() expects filenames encoded in same codepage as WinAPI's open() function.
Diffstat (limited to 'test.c')
-rw-r--r--test.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/test.c b/test.c
index aa0e0f1..c4aa81d 100644
--- a/test.c
+++ b/test.c
@@ -27,6 +27,10 @@
27#include <stdio.h> 27#include <stdio.h>
28#include <string.h> 28#include <string.h>
29#include <windows.h> 29#include <windows.h>
30#include <wchar.h>
31#include <io.h>
32#include <fcntl.h>
33#include <direct.h>
30#include "dlfcn.h" 34#include "dlfcn.h"
31 35
32/* If these dlclose's fails, we don't care as the handles are going to be 36/* If these dlclose's fails, we don't care as the handles are going to be
@@ -81,11 +85,14 @@ int main()
81 size_t (*fwrite_local) ( const void *, size_t, size_t, FILE * ); 85 size_t (*fwrite_local) ( const void *, size_t, size_t, FILE * );
82 size_t (*fputs_default) ( const char *, FILE * ); 86 size_t (*fputs_default) ( const char *, FILE * );
83 int (*nonexistentfunction)( void ); 87 int (*nonexistentfunction)( void );
88 int fd;
84 int ret; 89 int ret;
85 HMODULE library3; 90 HMODULE library3;
86 char toolongfile[32767]; 91 char toolongfile[32767];
87 DWORD code; 92 DWORD code;
88 char nonlibraryfile[MAX_PATH]; 93 char nonlibraryfile[MAX_PATH];
94 char bytename[sizeof("testdll2.dll")+4];
95 WCHAR widename[sizeof("testdll2.dll")+1];
89 DWORD length; 96 DWORD length;
90 HANDLE tempfile; 97 HANDLE tempfile;
91 DWORD dummy; 98 DWORD dummy;
@@ -210,6 +217,32 @@ int main()
210 else 217 else
211 printf( "SUCCESS\tCould not open file with too long file name via WINAPI: %lu\n", (unsigned long)code ); 218 printf( "SUCCESS\tCould not open file with too long file name via WINAPI: %lu\n", (unsigned long)code );
212 219
220 fd = _open( "testdll2.dll", _O_RDONLY | _O_BINARY );
221 if( fd < 0 )
222 {
223 if( _chdir( "Debug" ) == 0 )
224 {
225 fd = _open( "testdll2.dll", _O_RDONLY | _O_BINARY );
226 if( fd < 0 )
227 _chdir( ".." );
228 }
229 }
230 if( fd < 0 )
231 {
232 if( _chdir( "Release" ) == 0 )
233 {
234 fd = _open( "testdll2.dll", _O_RDONLY | _O_BINARY );
235 if( fd < 0 )
236 _chdir( ".." );
237 }
238 }
239 if( fd < 0 )
240 {
241 printf( "ERROR\tCould not open library2 file: %s\n", strerror( errno ) );
242 RETURN_ERROR;
243 }
244 _close( fd );
245
213 library2 = dlopen( "testdll2.dll", RTLD_GLOBAL ); 246 library2 = dlopen( "testdll2.dll", RTLD_GLOBAL );
214 if( !library2 ) 247 if( !library2 )
215 { 248 {
@@ -220,6 +253,66 @@ int main()
220 else 253 else
221 printf( "SUCCESS\tOpened library2 globally: %p\n", library2 ); 254 printf( "SUCCESS\tOpened library2 globally: %p\n", library2 );
222 255
256 widename[0] = 0xE1; /* wide non-ASCII character mappable to most ANSI codepages */
257 wcscpy( widename+1, L"testdll2.dll" );
258 if( !CopyFileW( L"testdll2.dll", widename, FALSE ))
259 {
260 printf( "ERROR\tCould not copy file testdll2.dll: %lu\n", (unsigned long)GetLastError( ) );
261 RETURN_ERROR;
262 }
263 else
264 printf( "SUCCESS\tCopied testdll2.dll to wide name %ls\n", widename );
265
266 ret = WideCharToMultiByte( CP_ACP, 0, widename, -1, bytename, sizeof( bytename ), NULL, NULL );
267 /* if we cannot convert widename to current codepage (used by _open() function), skip this test */
268 if( ret > 0 )
269 {
270 bytename[ret] = 0;
271
272 fd = _wopen( widename, _O_RDONLY | _O_BINARY );
273 if( fd < 0 )
274 {
275 printf( "ERROR\tCould not open copied wide library2 file %ls: %s\n", widename, strerror( errno ) );
276 DeleteFileW( widename );
277 RETURN_ERROR;
278 }
279 _close( fd );
280
281 fd = _open( bytename, _O_RDONLY | _O_BINARY );
282 if( fd < 0 )
283 {
284 printf( "ERROR\tCould not open copied wide library2 file %s: %s\n", bytename, strerror( errno ) );
285 DeleteFileW( widename );
286 RETURN_ERROR;
287 }
288 _close( fd );
289
290 dlclose( library2 );
291 library2 = dlopen( bytename, RTLD_GLOBAL );
292 if( !library2 )
293 {
294 error = dlerror( );
295 printf( "ERROR\tCould not open copied wide library2 file %s globally: %s\n", bytename, error ? error : "" );
296 DeleteFileW( widename );
297 RETURN_ERROR;
298 }
299 else
300 printf( "SUCCESS\tOpened copied wide library2 file %s globally: %p\n", bytename, library2 );
301
302 dlclose( library2 );
303 DeleteFileW( widename );
304
305 library2 = dlopen( "testdll2.dll", RTLD_GLOBAL );
306 if( !library2 )
307 {
308 error = dlerror( );
309 printf( "ERROR\tCould not open library2 globally: %s\n", error ? error : "" );
310 RETURN_ERROR;
311 }
312 else
313 printf( "SUCCESS\tOpened library2 globally: %p\n", library2 );
314 }
315
223 library = dlopen( "testdll.dll", RTLD_GLOBAL ); 316 library = dlopen( "testdll.dll", RTLD_GLOBAL );
224 if( !library ) 317 if( !library )
225 { 318 {