Add test for non-library file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
diff --git a/test.c b/test.c
index f7a20d7..0070f8c 100644
--- a/test.c
+++ b/test.c
@@ -85,6 +85,9 @@ int main()
HMODULE library3;
char toolongfile[32767];
DWORD code;
+ char nonlibraryfile[MAX_PATH];
+ HANDLE tempfile;
+ DWORD dummy;
#ifdef _DEBUG
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
@@ -95,6 +98,64 @@ int main()
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
#endif
+ ret = GetTempPathA( sizeof( nonlibraryfile ) - sizeof( "temp.dll" ), nonlibraryfile );
+ if( ret == 0 || ret > sizeof( nonlibraryfile ) - sizeof( "temp.dll" ) )
+ {
+ printf( "ERROR\tGetTempPath failed\n" );
+ RETURN_ERROR;
+ }
+
+ memcpy( nonlibraryfile + ret, "temp.dll", sizeof( "temp.dll" ) );
+
+ tempfile = CreateFileA( (LPCSTR) nonlibraryfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
+ if( tempfile == INVALID_HANDLE_VALUE )
+ {
+ printf( "ERROR\tCannot create temporary file %s: %lu\n", nonlibraryfile, (unsigned long)GetLastError( ) );
+ RETURN_ERROR;
+ }
+
+ WriteFile( tempfile, "test content", 12, &dummy, NULL );
+
+ CloseHandle( tempfile );
+
+ library3 = LoadLibraryA( nonlibraryfile );
+ code = GetLastError( );
+ if( library3 )
+ {
+ printf( "ERROR\tNon-library file %s was opened via WINAPI\n", nonlibraryfile );
+ CloseHandle( library3 );
+ DeleteFileA( nonlibraryfile );
+ RETURN_ERROR;
+ }
+ else if( code != ERROR_BAD_EXE_FORMAT )
+ {
+ printf( "ERROR\tNon-library file %s was processed via WINAPI: %lu\n", nonlibraryfile, (unsigned long)code );
+ DeleteFileA( nonlibraryfile );
+ RETURN_ERROR;
+ }
+ else
+ printf( "SUCCESS\tCould not open non-library file %s via WINAPI: %lu\n", nonlibraryfile, (unsigned long)code );
+
+ library = dlopen( nonlibraryfile, RTLD_GLOBAL );
+ if( library )
+ {
+ printf( "ERROR\tNon-library file %s was opened via dlopen\n", nonlibraryfile );
+ dlclose( library );
+ DeleteFileA( nonlibraryfile );
+ RETURN_ERROR;
+ }
+ error = dlerror( );
+ if( !error )
+ {
+ printf( "ERROR\tNo error from dlopen for non-library file\n" );
+ DeleteFileA( nonlibraryfile );
+ RETURN_ERROR;
+ }
+ else
+ printf( "SUCCESS\tCould not open non-library file %s: %s\n", nonlibraryfile, error );
+
+ DeleteFileA( nonlibraryfile );
+
library = dlopen( "nonexistentfile.dll", RTLD_GLOBAL );
if( library )
{