2006-06-14 06:51:13 +02:00
|
|
|
/*
|
|
|
|
* Tests msvcrt/data.c
|
|
|
|
*
|
|
|
|
* Copyright 2006 Andrew Ziem
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <winnls.h>
|
|
|
|
#include <process.h>
|
|
|
|
#include <errno.h>
|
2012-12-14 10:35:36 +01:00
|
|
|
#include <direct.h>
|
|
|
|
|
|
|
|
static int* (__cdecl *p___p___argc)(void);
|
|
|
|
static char*** (__cdecl *p___p___argv)(void);
|
2006-06-14 06:51:13 +02:00
|
|
|
|
2009-05-23 11:21:28 +02:00
|
|
|
typedef void (__cdecl *_INITTERMFUN)(void);
|
|
|
|
static void (__cdecl *p_initterm)(_INITTERMFUN *start, _INITTERMFUN *end);
|
2006-06-14 06:51:13 +02:00
|
|
|
|
2011-07-02 06:43:57 +02:00
|
|
|
static int (__cdecl *p_get_pgmptr)(char **p);
|
|
|
|
|
2006-06-14 06:51:13 +02:00
|
|
|
static int callbacked;
|
|
|
|
|
2009-05-23 11:21:28 +02:00
|
|
|
static void __cdecl initcallback(void)
|
2006-06-14 06:51:13 +02:00
|
|
|
{
|
|
|
|
callbacked++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define initterm_test(start, end, expected) \
|
|
|
|
callbacked = 0; \
|
2007-03-14 12:26:43 +01:00
|
|
|
p_initterm(start, end); \
|
2006-06-14 06:51:13 +02:00
|
|
|
ok(expected == callbacked,"_initterm: callbacks count mismatch: got %i, expected %i\n", callbacked, expected);
|
|
|
|
|
2006-12-10 16:51:26 +01:00
|
|
|
static void test_initterm(void)
|
2006-06-14 06:51:13 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
static _INITTERMFUN callbacks[4];
|
|
|
|
|
2006-11-23 21:38:51 +01:00
|
|
|
if (!p_initterm)
|
|
|
|
return;
|
|
|
|
|
2006-06-14 06:51:13 +02:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
callbacks[i] = initcallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
initterm_test(&callbacks[0], &callbacks[1], 1);
|
|
|
|
initterm_test(&callbacks[0], &callbacks[2], 2);
|
|
|
|
initterm_test(&callbacks[0], &callbacks[3], 3);
|
|
|
|
|
|
|
|
callbacks[1] = NULL;
|
|
|
|
initterm_test(&callbacks[0], &callbacks[3], 2);
|
|
|
|
}
|
|
|
|
|
2009-04-16 09:10:28 +02:00
|
|
|
static void test_initvar( HMODULE hmsvcrt )
|
|
|
|
{
|
2013-11-05 05:30:56 +01:00
|
|
|
OSVERSIONINFOA osvi = { sizeof(OSVERSIONINFOA) };
|
2009-05-20 17:47:43 +02:00
|
|
|
int *pp_winver = (int*)GetProcAddress(hmsvcrt, "_winver");
|
|
|
|
int *pp_winmajor = (int*)GetProcAddress(hmsvcrt, "_winmajor");
|
|
|
|
int *pp_winminor = (int*)GetProcAddress(hmsvcrt, "_winminor");
|
|
|
|
int *pp_osver = (int*)GetProcAddress(hmsvcrt, "_osver");
|
2010-05-05 13:36:58 +02:00
|
|
|
int *pp_osplatform = (int*)GetProcAddress(hmsvcrt, "_osplatform");
|
|
|
|
unsigned int winver, winmajor, winminor, osver, osplatform;
|
2009-04-16 09:10:28 +02:00
|
|
|
|
|
|
|
if( !( pp_winmajor && pp_winminor && pp_winver)) {
|
|
|
|
win_skip("_winver variables are not available\n");
|
|
|
|
return;
|
|
|
|
}
|
2009-05-20 17:47:43 +02:00
|
|
|
winver = *pp_winver;
|
|
|
|
winminor = *pp_winminor;
|
|
|
|
winmajor = *pp_winmajor;
|
2013-11-05 05:30:56 +01:00
|
|
|
GetVersionExA( &osvi);
|
2009-04-16 09:10:28 +02:00
|
|
|
ok( winminor == osvi.dwMinorVersion, "Wrong value for _winminor %02x expected %02x\n",
|
|
|
|
winminor, osvi.dwMinorVersion);
|
|
|
|
ok( winmajor == osvi.dwMajorVersion, "Wrong value for _winmajor %02x expected %02x\n",
|
|
|
|
winmajor, osvi.dwMajorVersion);
|
|
|
|
ok( winver == ((osvi.dwMajorVersion << 8) | osvi.dwMinorVersion),
|
|
|
|
"Wrong value for _winver %02x expected %02x\n",
|
|
|
|
winver, ((osvi.dwMajorVersion << 8) | osvi.dwMinorVersion));
|
2010-05-05 13:36:58 +02:00
|
|
|
if( !pp_osver || !pp_osplatform ) {
|
2009-04-16 09:10:28 +02:00
|
|
|
win_skip("_osver variables are not available\n");
|
|
|
|
return;
|
|
|
|
}
|
2009-05-20 17:47:43 +02:00
|
|
|
osver = *pp_osver;
|
2010-05-05 13:36:58 +02:00
|
|
|
osplatform = *pp_osplatform;
|
2009-04-16 09:10:28 +02:00
|
|
|
ok( osver == (osvi.dwBuildNumber & 0xffff) ||
|
|
|
|
((osvi.dwBuildNumber >> 24) == osvi.dwMajorVersion &&
|
|
|
|
((osvi.dwBuildNumber >> 16) & 0xff) == osvi.dwMinorVersion), /* 95/98/ME */
|
|
|
|
"Wrong value for _osver %04x expected %04x\n",
|
|
|
|
osver, osvi.dwBuildNumber);
|
2010-05-05 13:36:58 +02:00
|
|
|
ok(osplatform == osvi.dwPlatformId,
|
2015-08-31 12:24:53 +02:00
|
|
|
"Wrong value for _osplatform %x expected %x\n",
|
2010-05-05 13:36:58 +02:00
|
|
|
osplatform, osvi.dwPlatformId);
|
2009-04-16 09:10:28 +02:00
|
|
|
}
|
|
|
|
|
2011-07-02 06:43:57 +02:00
|
|
|
static void test_get_pgmptr(void)
|
|
|
|
{
|
|
|
|
char *pgm = NULL;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (!p_get_pgmptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
res = p_get_pgmptr(&pgm);
|
|
|
|
|
|
|
|
ok( res == 0, "Wrong _get_pgmptr return value %d expected 0\n", res);
|
|
|
|
ok( pgm != NULL, "_get_pgmptr returned a NULL pointer\n" );
|
|
|
|
}
|
|
|
|
|
2012-12-14 10:35:36 +01:00
|
|
|
static void test___getmainargs(void)
|
|
|
|
{
|
|
|
|
int argc, new_argc, mode;
|
|
|
|
char **argv, **new_argv, **envp;
|
2020-02-11 19:09:34 +01:00
|
|
|
char tmppath[MAX_PATH], filepath[MAX_PATH + 14];
|
2012-12-14 10:35:36 +01:00
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
ok(GetTempPathA(MAX_PATH, tmppath) != 0, "GetTempPath failed\n");
|
|
|
|
|
|
|
|
mode = 0;
|
|
|
|
__getmainargs(&argc, &argv, &envp, 0, &mode);
|
|
|
|
ok(argc == 4, "argc = %d\n", argc);
|
|
|
|
ok(!strcmp(argv[1], "data"), "argv[1] = %s\n", argv[1]);
|
|
|
|
sprintf(filepath, "%s*\\*", tmppath);
|
|
|
|
ok(!strcmp(argv[2], filepath), "argv[2] = %s\n", argv[2]);
|
|
|
|
sprintf(filepath, "%swine_test/*", tmppath);
|
|
|
|
ok(!strcmp(argv[3], filepath), "argv[3] = %s\n", argv[3]);
|
2012-12-26 13:28:14 +01:00
|
|
|
ok(!argv[4], "argv[4] != NULL\n");
|
2012-12-14 10:35:36 +01:00
|
|
|
|
|
|
|
if(p___p___argc && p___p___argv) {
|
|
|
|
new_argc = *p___p___argc();
|
|
|
|
new_argv = *p___p___argv();
|
|
|
|
ok(new_argc == 4, "*__p___argc() = %d\n", new_argc);
|
2015-08-31 12:24:53 +02:00
|
|
|
ok(new_argv == argv, "*__p___argv() = %p, expected %p\n", new_argv, argv);
|
2012-12-14 10:35:36 +01:00
|
|
|
}
|
2019-05-30 12:01:55 +02:00
|
|
|
else skip("__p___argc or __p___argv is not available\n");
|
2012-12-14 10:35:36 +01:00
|
|
|
|
|
|
|
mode = 0;
|
|
|
|
__getmainargs(&argc, &argv, &envp, 1, &mode);
|
|
|
|
ok(argc == 5, "argc = %d\n", argc);
|
|
|
|
ok(!strcmp(argv[1], "data"), "argv[1] = %s\n", argv[1]);
|
|
|
|
sprintf(filepath, "%s*\\*", tmppath);
|
|
|
|
ok(!strcmp(argv[2], filepath), "argv[2] = %s\n", argv[2]);
|
|
|
|
sprintf(filepath, "%swine_test/a", tmppath);
|
|
|
|
if(argv[3][strlen(argv[3])-1] == 'a') {
|
|
|
|
ok(!strcmp(argv[3], filepath), "argv[3] = %s\n", argv[3]);
|
|
|
|
sprintf(filepath, "%swine_test/test", tmppath);
|
|
|
|
ok(!strcmp(argv[4], filepath), "argv[4] = %s\n", argv[4]);
|
|
|
|
}else {
|
|
|
|
ok(!strcmp(argv[4], filepath), "argv[4] = %s\n", argv[4]);
|
|
|
|
sprintf(filepath, "%swine_test/test", tmppath);
|
|
|
|
ok(!strcmp(argv[3], filepath), "argv[3] = %s\n", argv[3]);
|
|
|
|
}
|
2012-12-26 13:28:14 +01:00
|
|
|
ok(!argv[5], "argv[5] != NULL\n");
|
2012-12-14 10:35:36 +01:00
|
|
|
|
|
|
|
if(p___p___argc && p___p___argv) {
|
|
|
|
new_argc = *p___p___argc();
|
|
|
|
new_argv = *p___p___argv();
|
|
|
|
ok(new_argc == argc, "*__p___argc() = %d, expected %d\n", new_argc, argc);
|
2015-08-31 12:24:53 +02:00
|
|
|
ok(new_argv == argv, "*__p___argv() = %p, expected %p\n", new_argv, argv);
|
2012-12-14 10:35:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(filepath, "%swine_test/b", tmppath);
|
|
|
|
f = fopen(filepath, "w");
|
|
|
|
ok(f != NULL, "fopen(%s) failed: %d\n", filepath, errno);
|
|
|
|
fclose(f);
|
|
|
|
mode = 0;
|
|
|
|
__getmainargs(&new_argc, &new_argv, &envp, 1, &mode);
|
|
|
|
ok(new_argc == argc+1, "new_argc = %d, expected %d\n", new_argc, argc+1);
|
|
|
|
_unlink(filepath);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test___getmainargs_parent(char *name)
|
|
|
|
{
|
|
|
|
char cmdline[3*MAX_PATH];
|
2020-02-11 19:09:34 +01:00
|
|
|
char tmppath[MAX_PATH], filepath[MAX_PATH + 14];
|
2013-11-05 05:30:56 +01:00
|
|
|
STARTUPINFOA startup;
|
2012-12-14 10:35:36 +01:00
|
|
|
PROCESS_INFORMATION proc;
|
|
|
|
FILE *f;
|
2012-12-19 20:33:23 +01:00
|
|
|
int ret;
|
2012-12-14 10:35:36 +01:00
|
|
|
|
|
|
|
ok(GetTempPathA(MAX_PATH, tmppath) != 0, "GetTempPath failed\n");
|
|
|
|
sprintf(cmdline, "%s data %s*\\* %swine_test/*", name, tmppath, tmppath);
|
|
|
|
|
|
|
|
sprintf(filepath, "%swine_test", tmppath);
|
2012-12-19 20:33:23 +01:00
|
|
|
ret = _mkdir(filepath);
|
|
|
|
ok(!ret, "_mkdir failed: %d\n", errno);
|
2012-12-14 10:35:36 +01:00
|
|
|
sprintf(filepath, "%swine_test\\a", tmppath);
|
|
|
|
f = fopen(filepath, "w");
|
|
|
|
ok(f != NULL, "fopen(%s) failed: %d\n", filepath, errno);
|
|
|
|
fclose(f);
|
|
|
|
sprintf(filepath, "%swine_test\\test", tmppath);
|
|
|
|
f = fopen(filepath, "w");
|
|
|
|
ok(f != NULL, "fopen(%s) failed: %d\n", filepath, errno);
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE|NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &proc);
|
2020-03-16 23:52:21 +01:00
|
|
|
wait_child_process(proc.hProcess);
|
2012-12-14 10:35:36 +01:00
|
|
|
|
|
|
|
_unlink(filepath);
|
|
|
|
sprintf(filepath, "%swine_test\\a", tmppath);
|
|
|
|
_unlink(filepath);
|
|
|
|
sprintf(filepath, "%swine_test", tmppath);
|
|
|
|
_rmdir(filepath);
|
|
|
|
}
|
|
|
|
|
2006-06-14 06:51:13 +02:00
|
|
|
START_TEST(data)
|
|
|
|
{
|
2006-11-23 21:38:51 +01:00
|
|
|
HMODULE hmsvcrt;
|
2012-12-14 10:35:36 +01:00
|
|
|
int arg_c;
|
|
|
|
char** arg_v;
|
2009-04-16 09:10:28 +02:00
|
|
|
|
2006-11-23 21:38:51 +01:00
|
|
|
hmsvcrt = GetModuleHandleA("msvcrt.dll");
|
|
|
|
if (!hmsvcrt)
|
|
|
|
hmsvcrt = GetModuleHandleA("msvcrtd.dll");
|
|
|
|
if (hmsvcrt)
|
2011-07-02 06:43:57 +02:00
|
|
|
{
|
2006-11-23 21:38:51 +01:00
|
|
|
p_initterm=(void*)GetProcAddress(hmsvcrt, "_initterm");
|
2011-07-02 06:43:57 +02:00
|
|
|
p_get_pgmptr=(void*)GetProcAddress(hmsvcrt, "_get_pgmptr");
|
2012-12-14 10:35:36 +01:00
|
|
|
p___p___argc=(void*)GetProcAddress(hmsvcrt, "__p___argc");
|
|
|
|
p___p___argv=(void*)GetProcAddress(hmsvcrt, "__p___argv");
|
2011-07-02 06:43:57 +02:00
|
|
|
}
|
2012-12-14 10:35:36 +01:00
|
|
|
|
|
|
|
arg_c = winetest_get_mainargs(&arg_v);
|
|
|
|
if(arg_c >= 3) {
|
|
|
|
test___getmainargs();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-06-14 06:51:13 +02:00
|
|
|
test_initterm();
|
2009-04-16 09:10:28 +02:00
|
|
|
test_initvar(hmsvcrt);
|
2011-07-02 06:43:57 +02:00
|
|
|
test_get_pgmptr();
|
2012-12-14 10:35:36 +01:00
|
|
|
test___getmainargs_parent(arg_v[0]);
|
2006-06-14 06:51:13 +02:00
|
|
|
}
|