ReactOS 0.4.15-dev-7918-g2a2556c
GetModuleFileName.c
Go to the documentation of this file.
1/*
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>
6 */
7
8#include "precomp.h"
9
10#include <shlwapi.h>
11
12static
13VOID
15{
19 PWSTR Slash;
20 WCHAR CommandLine[MAX_PATH];
21 STARTUPINFOW StartupInfo;
22 PROCESS_INFORMATION ProcessInfo;
23 DWORD Ret;
24 int Length;
25
27 0,
28 argv[0],
29 -1,
30 Path,
31 sizeof(Path) / sizeof(WCHAR));
32 ok(Length > 0, "Length = %d\n", Length);
33
34 FileName = wcsrchr(Path, '\\');
35 Slash = wcsrchr(Path, L'/');
36 if (Slash && (!FileName || Slash > FileName))
37 FileName = Slash;
38
39 if (FileName)
40 {
41 /* It's an absolute path. Set it as current dir and get the file name */
42 FileName++;
43 FileName[-1] = L'\0';
44
46 ok(Success == TRUE, "SetCurrentDirectory failed for path '%ls'\n", Path);
47
48 trace("Starting '%ls' in path '%ls'\n", FileName, Path);
49 }
50 else
51 {
52 FileName = Path;
53 trace("Starting '%ls', which is already relative\n", FileName);
54 }
55
56 swprintf(CommandLine, L"\"%ls\" GetModuleFileName relative", FileName);
57
58 RtlZeroMemory(&StartupInfo, sizeof(StartupInfo));
59 StartupInfo.cb = sizeof(StartupInfo);
60
62 CommandLine,
63 NULL,
64 NULL,
65 FALSE,
66 0,
67 NULL,
68 NULL,
69 &StartupInfo,
70 &ProcessInfo);
71 if (!Success)
72 {
73 skip("CreateProcess failed with %lu\n", GetLastError());
74 return;
75 }
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);
80}
81
82static
83VOID
85{
88 BOOL Relative;
89
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);
96}
97
98static
99VOID
101{
104 BOOL Relative;
105
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);
112}
113
115{
116 int argc;
117 char **argv;
118
120 if (argc < 3)
122 else
123 {
126 }
127}
static VOID StartChild(char **argv)
static VOID TestGetModuleFileNameW(VOID)
static VOID TestGetModuleFileNameA(VOID)
PRTL_UNICODE_STRING_BUFFER Path
static int argc
Definition: ServiceArgs.c:12
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define wcsrchr
Definition: compat.h:16
#define CP_ACP
Definition: compat.h:109
#define MAX_PATH
Definition: compat.h:34
#define MultiByteToWideChar
Definition: compat.h:110
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2249
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4592
BOOL WINAPI PathIsRelativeA(LPCSTR lpszPath)
Definition: path.c:1563
BOOL WINAPI PathIsRelativeW(LPCWSTR lpszPath)
Definition: path.c:1579
#define swprintf
Definition: precomp.h:40
@ Success
Definition: eventcreate.c:712
struct _FileName FileName
Definition: fatprocs.h:896
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define argv
Definition: mplay32.c:18
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
int winetest_get_mainargs(char ***pargv)
DWORD cb
Definition: winbase.h:852
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
uint16_t * PWSTR
Definition: typedefs.h:56
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define GetModuleFileName
Definition: winbase.h:3831
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175