2004-04-06 00:54:03 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 Stefan Leichter
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2005-01-04 21:35:46 +01:00
|
|
|
#include <stdio.h>
|
2004-04-06 00:54:03 +02:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winver.h"
|
|
|
|
|
2004-11-09 21:11:07 +01:00
|
|
|
#define MY_LAST_ERROR -1L
|
|
|
|
#define EXPECT_BAD_PATH__NOT_FOUND \
|
|
|
|
ok( (ERROR_PATH_NOT_FOUND == GetLastError()) || \
|
|
|
|
(ERROR_RESOURCE_DATA_NOT_FOUND == GetLastError()) || \
|
2004-12-16 15:34:18 +01:00
|
|
|
(ERROR_FILE_NOT_FOUND == GetLastError()) || \
|
2004-11-09 21:11:07 +01:00
|
|
|
(ERROR_BAD_PATHNAME == GetLastError()), \
|
|
|
|
"Last error wrong! ERROR_RESOURCE_DATA_NOT_FOUND/ERROR_BAD_PATHNAME (98)/" \
|
2004-12-16 15:34:18 +01:00
|
|
|
"ERROR_PATH_NOT_FOUND (NT4)/ERROR_FILE_NOT_FOUND (2k3)" \
|
|
|
|
"expected, got 0x%08lx\n", GetLastError());
|
2004-11-09 21:11:07 +01:00
|
|
|
#define EXPECT_INVALID__NOT_FOUND \
|
|
|
|
ok( (ERROR_PATH_NOT_FOUND == GetLastError()) || \
|
|
|
|
(ERROR_RESOURCE_DATA_NOT_FOUND == GetLastError()) || \
|
2004-12-16 15:34:18 +01:00
|
|
|
(ERROR_FILE_NOT_FOUND == GetLastError()) || \
|
2004-11-09 21:11:07 +01:00
|
|
|
(ERROR_INVALID_PARAMETER == GetLastError()), \
|
|
|
|
"Last error wrong! ERROR_RESOURCE_DATA_NOT_FOUND/ERROR_INVALID_PARAMETER (98)/" \
|
2004-12-16 15:34:18 +01:00
|
|
|
"ERROR_PATH_NOT_FOUND (NT4)/ERROR_FILE_NOT_FOUND (2k3)" \
|
|
|
|
"expected, got 0x%08lx\n", GetLastError());
|
2004-11-09 21:11:07 +01:00
|
|
|
|
2004-04-06 00:54:03 +02:00
|
|
|
static void test_info_size(void)
|
|
|
|
{ DWORD hdl, retval;
|
2005-05-31 11:33:59 +02:00
|
|
|
char mypath[MAX_PATH] = "";
|
2004-04-06 00:54:03 +02:00
|
|
|
|
2004-11-09 21:11:07 +01:00
|
|
|
SetLastError(MY_LAST_ERROR);
|
2004-04-06 00:54:03 +02:00
|
|
|
retval = GetFileVersionInfoSizeA( NULL, NULL);
|
|
|
|
ok( !retval,
|
|
|
|
"GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
|
|
|
|
retval);
|
2004-11-09 21:11:07 +01:00
|
|
|
EXPECT_INVALID__NOT_FOUND;
|
2004-04-06 00:54:03 +02:00
|
|
|
|
|
|
|
hdl = 0x55555555;
|
2004-11-09 21:11:07 +01:00
|
|
|
SetLastError(MY_LAST_ERROR);
|
2004-04-06 00:54:03 +02:00
|
|
|
retval = GetFileVersionInfoSizeA( NULL, &hdl);
|
|
|
|
ok( !retval,
|
|
|
|
"GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
|
|
|
|
retval);
|
2004-11-09 21:11:07 +01:00
|
|
|
EXPECT_INVALID__NOT_FOUND;
|
2004-04-06 00:54:03 +02:00
|
|
|
ok( hdl == 0L,
|
|
|
|
"Handle wrong! 0L expected, got 0x%08lx\n", hdl);
|
|
|
|
|
2004-11-09 21:11:07 +01:00
|
|
|
SetLastError(MY_LAST_ERROR);
|
2004-04-06 00:54:03 +02:00
|
|
|
retval = GetFileVersionInfoSizeA( "", NULL);
|
|
|
|
ok( !retval,
|
|
|
|
"GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
|
|
|
|
retval);
|
2004-11-09 21:11:07 +01:00
|
|
|
EXPECT_BAD_PATH__NOT_FOUND;
|
2004-04-06 00:54:03 +02:00
|
|
|
|
|
|
|
hdl = 0x55555555;
|
2004-11-09 21:11:07 +01:00
|
|
|
SetLastError(MY_LAST_ERROR);
|
2004-04-06 00:54:03 +02:00
|
|
|
retval = GetFileVersionInfoSizeA( "", &hdl);
|
|
|
|
ok( !retval,
|
|
|
|
"GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
|
|
|
|
retval);
|
2004-11-09 21:11:07 +01:00
|
|
|
EXPECT_BAD_PATH__NOT_FOUND;
|
2004-04-06 00:54:03 +02:00
|
|
|
ok( hdl == 0L,
|
|
|
|
"Handle wrong! 0L expected, got 0x%08lx\n", hdl);
|
|
|
|
|
2004-11-09 21:11:07 +01:00
|
|
|
SetLastError(MY_LAST_ERROR);
|
2004-04-06 00:54:03 +02:00
|
|
|
retval = GetFileVersionInfoSizeA( "kernel32.dll", NULL);
|
|
|
|
ok( retval,
|
|
|
|
"GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
|
|
|
|
retval);
|
2004-11-19 19:19:31 +01:00
|
|
|
ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
|
|
|
|
"Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
|
|
|
|
MY_LAST_ERROR, GetLastError());
|
2004-04-06 00:54:03 +02:00
|
|
|
|
|
|
|
hdl = 0x55555555;
|
2004-11-09 21:11:07 +01:00
|
|
|
SetLastError(MY_LAST_ERROR);
|
2004-04-06 00:54:03 +02:00
|
|
|
retval = GetFileVersionInfoSizeA( "kernel32.dll", &hdl);
|
|
|
|
ok( retval,
|
|
|
|
"GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
|
|
|
|
retval);
|
2004-11-09 21:11:07 +01:00
|
|
|
ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
|
|
|
|
"Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
|
|
|
|
MY_LAST_ERROR, GetLastError());
|
2004-04-06 00:54:03 +02:00
|
|
|
ok( hdl == 0L,
|
|
|
|
"Handle wrong! 0L expected, got 0x%08lx\n", hdl);
|
|
|
|
|
2004-11-09 21:11:07 +01:00
|
|
|
SetLastError(MY_LAST_ERROR);
|
2004-04-06 00:54:03 +02:00
|
|
|
retval = GetFileVersionInfoSizeA( "notexist.dll", NULL);
|
|
|
|
ok( !retval,
|
|
|
|
"GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
|
|
|
|
retval);
|
2005-01-04 21:35:46 +01:00
|
|
|
ok( (ERROR_FILE_NOT_FOUND == GetLastError()) ||
|
2004-11-09 21:11:07 +01:00
|
|
|
(ERROR_RESOURCE_DATA_NOT_FOUND == GetLastError()) ||
|
|
|
|
(MY_LAST_ERROR == GetLastError()),
|
2004-06-29 01:51:35 +02:00
|
|
|
"Last error wrong! ERROR_FILE_NOT_FOUND/ERROR_RESOURCE_DATA_NOT_FOUND "
|
2004-11-09 21:11:07 +01:00
|
|
|
"(XP)/0x%08lx (NT4) expected, got 0x%08lx\n", MY_LAST_ERROR, GetLastError());
|
2005-05-31 11:33:59 +02:00
|
|
|
|
|
|
|
/* test a currently loaded executable */
|
|
|
|
if(GetModuleFileNameA(NULL, mypath, MAX_PATH)) {
|
|
|
|
hdl = 0x55555555;
|
|
|
|
SetLastError(MY_LAST_ERROR);
|
|
|
|
retval = GetFileVersionInfoSizeA( mypath, &hdl);
|
|
|
|
ok( retval,
|
|
|
|
"GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
|
|
|
|
retval);
|
|
|
|
ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
|
|
|
|
"Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
|
|
|
|
MY_LAST_ERROR, GetLastError());
|
|
|
|
ok( hdl == 0L,
|
|
|
|
"Handle wrong! 0L expected, got 0x%08lx\n", hdl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
trace("skipping GetModuleFileNameA(NULL,..) failed\n");
|
|
|
|
|
|
|
|
/* test a not loaded executable */
|
|
|
|
if(GetSystemDirectoryA(mypath, MAX_PATH)) {
|
|
|
|
lstrcatA(mypath, "\\regsvr32.exe");
|
|
|
|
|
|
|
|
if(INVALID_FILE_ATTRIBUTES == GetFileAttributesA(mypath))
|
|
|
|
trace("GetFileAttributesA(%s) failed\n", mypath);
|
|
|
|
else {
|
|
|
|
hdl = 0x55555555;
|
|
|
|
SetLastError(MY_LAST_ERROR);
|
|
|
|
retval = GetFileVersionInfoSizeA( mypath, &hdl);
|
|
|
|
ok( retval,
|
|
|
|
"GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
|
|
|
|
retval);
|
|
|
|
ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
|
|
|
|
"Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
|
|
|
|
MY_LAST_ERROR, GetLastError());
|
|
|
|
ok( hdl == 0L,
|
|
|
|
"Handle wrong! 0L expected, got 0x%08lx\n", hdl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
trace("skipping GetModuleFileNameA(NULL,..) failed\n");
|
2004-04-06 00:54:03 +02:00
|
|
|
}
|
|
|
|
|
2005-01-04 21:35:46 +01:00
|
|
|
static void VersionDwordLong2String(DWORDLONG Version, LPSTR lpszVerString)
|
|
|
|
{
|
|
|
|
WORD a, b, c, d;
|
|
|
|
|
|
|
|
a = (WORD)(Version >> 48);
|
|
|
|
b = (WORD)((Version >> 32) & 0xffff);
|
|
|
|
c = (WORD)((Version >> 16) & 0xffff);
|
|
|
|
d = (WORD)(Version & 0xffff);
|
|
|
|
|
|
|
|
sprintf(lpszVerString, "%d.%d.%d.%d", a, b, c, d);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_info(void)
|
|
|
|
{
|
|
|
|
DWORD hdl, retval;
|
|
|
|
PVOID pVersionInfo = NULL;
|
|
|
|
BOOL boolret;
|
|
|
|
VS_FIXEDFILEINFO *pFixedVersionInfo;
|
|
|
|
UINT uiLength;
|
|
|
|
char VersionString[MAX_PATH];
|
|
|
|
DWORDLONG dwlVersion;
|
|
|
|
|
|
|
|
hdl = 0x55555555;
|
|
|
|
SetLastError(MY_LAST_ERROR);
|
|
|
|
retval = GetFileVersionInfoSizeA( "kernel32.dll", &hdl);
|
|
|
|
ok( retval,
|
|
|
|
"GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
|
|
|
|
retval);
|
|
|
|
ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
|
|
|
|
"Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
|
|
|
|
MY_LAST_ERROR, GetLastError());
|
|
|
|
ok( hdl == 0L,
|
|
|
|
"Handle wrong! 0L expected, got 0x%08lx\n", hdl);
|
|
|
|
|
|
|
|
if ( retval == 0 || hdl != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pVersionInfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retval );
|
|
|
|
ok(pVersionInfo != 0, "HeapAlloc failed\n" );
|
|
|
|
if (pVersionInfo == 0)
|
|
|
|
return;
|
|
|
|
|
2005-02-25 17:19:19 +01:00
|
|
|
#if 0
|
|
|
|
/* this test crashes on WinNT4
|
|
|
|
*/
|
2005-01-04 21:35:46 +01:00
|
|
|
boolret = GetFileVersionInfoA( "kernel32.dll", 0, retval, 0);
|
|
|
|
ok (!boolret, "GetFileVersionInfoA should have failed: GetLastError = 0x%08lx\n", GetLastError());
|
2005-02-08 14:43:41 +01:00
|
|
|
ok ((GetLastError() == ERROR_INVALID_DATA) || (GetLastError() == ERROR_BAD_PATHNAME) ||
|
|
|
|
(GetLastError() == NO_ERROR),
|
|
|
|
"Last error wrong! ERROR_INVALID_DATA/ERROR_BAD_PATHNAME (ME)/"
|
|
|
|
"NO_ERROR (95) expected, got 0x%08lx\n",
|
2005-01-04 21:35:46 +01:00
|
|
|
GetLastError());
|
2005-02-25 17:19:19 +01:00
|
|
|
#endif
|
2005-01-04 21:35:46 +01:00
|
|
|
|
|
|
|
boolret = GetFileVersionInfoA( "kernel32.dll", 0, retval, pVersionInfo );
|
|
|
|
ok (boolret, "GetFileVersionInfoA failed: GetLastError = 0x%08lx\n", GetLastError());
|
|
|
|
if (!boolret)
|
|
|
|
return;
|
|
|
|
|
|
|
|
boolret = VerQueryValueA( pVersionInfo, "\\", (LPVOID *)&pFixedVersionInfo, &uiLength );
|
|
|
|
ok (boolret, "VerQueryValueA failed: GetLastError = 0x%08lx\n", GetLastError());
|
|
|
|
if (!boolret)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dwlVersion = (((DWORDLONG)pFixedVersionInfo->dwFileVersionMS) << 32) +
|
|
|
|
pFixedVersionInfo->dwFileVersionLS;
|
|
|
|
|
|
|
|
VersionDwordLong2String(dwlVersion, VersionString);
|
|
|
|
|
|
|
|
trace("kernel32.dll version: %s\n", VersionString);
|
|
|
|
|
2005-02-25 17:19:19 +01:00
|
|
|
#if 0
|
|
|
|
/* this test crashes on WinNT4
|
|
|
|
*/
|
2005-01-04 21:35:46 +01:00
|
|
|
boolret = VerQueryValueA( pVersionInfo, "\\", (LPVOID *)&pFixedVersionInfo, 0);
|
|
|
|
ok (boolret, "VerQueryValue failed: GetLastError = 0x%08lx\n", GetLastError());
|
2005-02-25 17:19:19 +01:00
|
|
|
#endif
|
2005-01-04 21:35:46 +01:00
|
|
|
}
|
|
|
|
|
2004-04-06 00:54:03 +02:00
|
|
|
START_TEST(info)
|
|
|
|
{
|
|
|
|
test_info_size();
|
2005-01-04 21:35:46 +01:00
|
|
|
test_info();
|
2004-04-06 00:54:03 +02:00
|
|
|
}
|