2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for GetModuleFileName
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
14 StartChild(char **argv
)
20 WCHAR CommandLine
[MAX_PATH
];
21 STARTUPINFOW StartupInfo
;
22 PROCESS_INFORMATION ProcessInfo
;
26 Length
= MultiByteToWideChar(CP_ACP
,
31 sizeof(Path
) / sizeof(WCHAR
));
32 ok(Length
> 0, "Length = %d\n", Length
);
34 FileName
= wcsrchr(Path
, '\\');
35 Slash
= wcsrchr(Path
, L
'/');
36 if (Slash
&& (!FileName
|| Slash
> FileName
))
41 /* It's an absolute path. Set it as current dir and get the file name */
45 Success
= SetCurrentDirectoryW(Path
);
46 ok(Success
== TRUE
, "SetCurrentDirectory failed for path '%ls'\n", Path
);
48 trace("Starting '%ls' in path '%ls'\n", FileName
, Path
);
53 trace("Starting '%ls', which is already relative\n", FileName
);
56 swprintf(CommandLine
, L
"\"%ls\" GetModuleFileName relative", FileName
);
58 RtlZeroMemory(&StartupInfo
, sizeof(StartupInfo
));
59 StartupInfo
.cb
= sizeof(StartupInfo
);
61 Success
= CreateProcessW(FileName
,
73 skip("CreateProcess failed with %lu\n", GetLastError());
76 CloseHandle(ProcessInfo
.hThread
);
77 Ret
= WaitForSingleObject(ProcessInfo
.hProcess
, 30 * 1000);
78 ok(Ret
== WAIT_OBJECT_0
, "WaitForSingleObject returns %lu\n", Ret
);
79 CloseHandle(ProcessInfo
.hProcess
);
84 TestGetModuleFileNameA(VOID
)
86 CHAR Buffer
[MAX_PATH
];
90 Length
= GetModuleFileNameA(NULL
, Buffer
, sizeof(Buffer
));
91 ok(Length
!= 0, "Length = %lu\n", Length
);
92 ok(Length
< sizeof(Buffer
), "Length = %lu\n", Length
);
93 ok(Buffer
[Length
] == 0, "Buffer not null terminated\n");
94 Relative
= PathIsRelativeA(Buffer
);
95 ok(Relative
== FALSE
, "GetModuleFileNameA returned relative path: %s\n", Buffer
);
100 TestGetModuleFileNameW(VOID
)
102 WCHAR Buffer
[MAX_PATH
];
106 Length
= GetModuleFileNameW(NULL
, Buffer
, sizeof(Buffer
) / sizeof(WCHAR
));
107 ok(Length
!= 0, "Length = %lu\n", Length
);
108 ok(Length
< sizeof(Buffer
) / sizeof(WCHAR
), "Length = %lu\n", Length
);
109 ok(Buffer
[Length
] == 0, "Buffer not null terminated\n");
110 Relative
= PathIsRelativeW(Buffer
);
111 ok(Relative
== FALSE
, "GetModuleFileNameW returned relative path: %ls\n", Buffer
);
114 START_TEST(GetModuleFileName
)
119 argc
= winetest_get_mainargs(&argv
);
124 TestGetModuleFileNameA();
125 TestGetModuleFileNameW();