diff --git a/dlls/msvcrt/tests/data.c b/dlls/msvcrt/tests/data.c index c20be18df3e..07230938b4c 100644 --- a/dlls/msvcrt/tests/data.c +++ b/dlls/msvcrt/tests/data.c @@ -30,6 +30,11 @@ #include #include #include +#include + +void __cdecl __getmainargs(int *, char ***, char ***, int, int *); +static int* (__cdecl *p___p___argc)(void); +static char*** (__cdecl *p___p___argv)(void); typedef void (__cdecl *_INITTERMFUN)(void); static void (__cdecl *p_initterm)(_INITTERMFUN *start, _INITTERMFUN *end); @@ -124,9 +129,106 @@ static void test_get_pgmptr(void) ok( pgm != NULL, "_get_pgmptr returned a NULL pointer\n" ); } +static void test___getmainargs(void) +{ + int argc, new_argc, mode; + char **argv, **new_argv, **envp; + char tmppath[MAX_PATH], filepath[MAX_PATH]; + 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]); + + 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); + ok(new_argv == argv, "*__p___argv() = %p, epxected %p\n", new_argv, argv); + }else { + win_skip("__p___argc or __p___argv is not available\n"); + } + + 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]); + } + + 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); + ok(new_argv == argv, "*__p___argv() = %p, epxected %p\n", new_argv, argv); + } + + 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]; + char tmppath[MAX_PATH], filepath[MAX_PATH]; + STARTUPINFO startup; + PROCESS_INFORMATION proc; + FILE *f; + + ok(GetTempPathA(MAX_PATH, tmppath) != 0, "GetTempPath failed\n"); + sprintf(cmdline, "%s data %s*\\* %swine_test/*", name, tmppath, tmppath); + + sprintf(filepath, "%swine_test", tmppath); + ok(!_mkdir(filepath), "_mkdir failed: %d\n", errno); + 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); + winetest_wait_child_process(proc.hProcess); + + _unlink(filepath); + sprintf(filepath, "%swine_test\\a", tmppath); + _unlink(filepath); + sprintf(filepath, "%swine_test", tmppath); + _rmdir(filepath); +} + START_TEST(data) { HMODULE hmsvcrt; + int arg_c; + char** arg_v; hmsvcrt = GetModuleHandleA("msvcrt.dll"); if (!hmsvcrt) @@ -135,8 +237,18 @@ START_TEST(data) { p_initterm=(void*)GetProcAddress(hmsvcrt, "_initterm"); p_get_pgmptr=(void*)GetProcAddress(hmsvcrt, "_get_pgmptr"); + p___p___argc=(void*)GetProcAddress(hmsvcrt, "__p___argc"); + p___p___argv=(void*)GetProcAddress(hmsvcrt, "__p___argv"); } + + arg_c = winetest_get_mainargs(&arg_v); + if(arg_c >= 3) { + test___getmainargs(); + return; + } + test_initterm(); test_initvar(hmsvcrt); test_get_pgmptr(); + test___getmainargs_parent(arg_v[0]); }