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>
10 #define WIN32_NO_STATUS
12 #define COM_NO_WINDOWS_H
20 StartChild(char **argv
)
26 WCHAR CommandLine
[MAX_PATH
];
27 STARTUPINFOW StartupInfo
;
28 PROCESS_INFORMATION ProcessInfo
;
32 Length
= MultiByteToWideChar(CP_ACP
,
37 sizeof(Path
) / sizeof(WCHAR
));
38 ok(Length
> 0, "Length = %d\n", Length
);
40 FileName
= wcsrchr(Path
, '\\');
41 Slash
= wcsrchr(Path
, L
'/');
42 if (Slash
&& (!FileName
|| Slash
> FileName
))
47 /* It's an absolute path. Set it as current dir and get the file name */
51 Success
= SetCurrentDirectoryW(Path
);
52 ok(Success
== TRUE
, "SetCurrentDirectory failed for path '%ls'\n", Path
);
54 trace("Starting '%ls' in path '%ls'\n", FileName
, Path
);
59 trace("Starting '%ls', which is already relative\n", FileName
);
62 swprintf(CommandLine
, L
"\"%ls\" GetModuleFileName relative", FileName
);
64 RtlZeroMemory(&StartupInfo
, sizeof(StartupInfo
));
65 StartupInfo
.cb
= sizeof(StartupInfo
);
67 Success
= CreateProcessW(FileName
,
79 skip("CreateProcess failed with %lu\n", GetLastError());
82 CloseHandle(ProcessInfo
.hThread
);
83 Ret
= WaitForSingleObject(ProcessInfo
.hProcess
, 30 * 1000);
84 ok(Ret
== WAIT_OBJECT_0
, "WaitForSingleObject returns %lu\n", Ret
);
85 CloseHandle(ProcessInfo
.hProcess
);
90 TestGetModuleFileNameA(VOID
)
92 CHAR Buffer
[MAX_PATH
];
96 Length
= GetModuleFileNameA(NULL
, Buffer
, sizeof(Buffer
));
97 ok(Length
!= 0, "Length = %lu\n", Length
);
98 ok(Length
< sizeof(Buffer
), "Length = %lu\n", Length
);
99 ok(Buffer
[Length
] == 0, "Buffer not null terminated\n");
100 Relative
= PathIsRelativeA(Buffer
);
101 ok(Relative
== FALSE
, "GetModuleFileNameA returned relative path: %s\n", Buffer
);
106 TestGetModuleFileNameW(VOID
)
108 WCHAR Buffer
[MAX_PATH
];
112 Length
= GetModuleFileNameW(NULL
, Buffer
, sizeof(Buffer
) / sizeof(WCHAR
));
113 ok(Length
!= 0, "Length = %lu\n", Length
);
114 ok(Length
< sizeof(Buffer
) / sizeof(WCHAR
), "Length = %lu\n", Length
);
115 ok(Buffer
[Length
] == 0, "Buffer not null terminated\n");
116 Relative
= PathIsRelativeW(Buffer
);
117 ok(Relative
== FALSE
, "GetModuleFileNameW returned relative path: %ls\n", Buffer
);
120 START_TEST(GetModuleFileName
)
125 argc
= winetest_get_mainargs(&argv
);
130 TestGetModuleFileNameA();
131 TestGetModuleFileNameW();