ReactOS 0.4.15-dev-7842-g558ab78
GetModuleFileName.c File Reference
#include "precomp.h"
#include <shlwapi.h>
Include dependency graph for GetModuleFileName.c:

Go to the source code of this file.

Functions

static VOID StartChild (char **argv)
 
static VOID TestGetModuleFileNameA (VOID)
 
static VOID TestGetModuleFileNameW (VOID)
 
 START_TEST (GetModuleFileName)
 

Function Documentation

◆ START_TEST()

START_TEST ( GetModuleFileName  )

Definition at line 114 of file GetModuleFileName.c.

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)
static int argc
Definition: ServiceArgs.c:12
#define argv
Definition: mplay32.c:18
int winetest_get_mainargs(char ***pargv)

◆ StartChild()

static VOID StartChild ( char **  argv)
static

Definition at line 14 of file GetModuleFileName.c.

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}
PRTL_UNICODE_STRING_BUFFER Path
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#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
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
#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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
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
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ TestGetModuleFileNameA()

static VOID TestGetModuleFileNameA ( VOID  )
static

Definition at line 84 of file GetModuleFileName.c.

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}
Definition: bufpool.h:45
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539
BOOL WINAPI PathIsRelativeA(LPCSTR lpszPath)
Definition: path.c:1563
char CHAR
Definition: xmlstorage.h:175

Referenced by START_TEST().

◆ TestGetModuleFileNameW()

static VOID TestGetModuleFileNameW ( VOID  )
static

Definition at line 100 of file GetModuleFileName.c.

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}
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
BOOL WINAPI PathIsRelativeW(LPCWSTR lpszPath)
Definition: path.c:1579

Referenced by START_TEST().