aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2019-05-23 20:24:17 +0200
committerPali Rohár <pali.rohar@gmail.com>2019-05-23 20:24:17 +0200
commite646c9ab005d6a4480fa3728ebe9c34182bfedc6 (patch)
tree3984a9c029036cc902a08b91056d4a8a7cd62a01
parent27319bfc884c2817c7c5f4fd1046903dc2e419e0 (diff)
downloaddlfcn-win32-e646c9ab005d6a4480fa3728ebe9c34182bfedc6.tar.gz
dlfcn-win32-e646c9ab005d6a4480fa3728ebe9c34182bfedc6.tar.bz2
dlfcn-win32-e646c9ab005d6a4480fa3728ebe9c34182bfedc6.zip
Add test for non-library file
-rw-r--r--test.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/test.c b/test.c
index f7a20d7..0070f8c 100644
--- a/test.c
+++ b/test.c
@@ -85,6 +85,9 @@ int main()
85 HMODULE library3; 85 HMODULE library3;
86 char toolongfile[32767]; 86 char toolongfile[32767];
87 DWORD code; 87 DWORD code;
88 char nonlibraryfile[MAX_PATH];
89 HANDLE tempfile;
90 DWORD dummy;
88 91
89#ifdef _DEBUG 92#ifdef _DEBUG
90 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); 93 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
@@ -95,6 +98,64 @@ int main()
95 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT); 98 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
96#endif 99#endif
97 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
98 library = dlopen( "nonexistentfile.dll", RTLD_GLOBAL ); 159 library = dlopen( "nonexistentfile.dll", RTLD_GLOBAL );
99 if( library ) 160 if( library )
100 { 161 {