ReactOS  0.4.15-dev-1152-g6c94e4f
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)
121  StartChild(argv);
122  else
123  {
126  }
127 }
static VOID StartChild(char **argv)
static int argc
Definition: ServiceArgs.c:12
static VOID TestGetModuleFileNameA(VOID)
#define argv
Definition: mplay32.c:18
int winetest_get_mainargs(char ***pargv)
static VOID TestGetModuleFileNameW(VOID)

◆ StartChild()

static VOID StartChild ( char **  argv)
static

Definition at line 14 of file GetModuleFileName.c.

15 {
16  BOOL Success;
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 }
#define CloseHandle
Definition: compat.h:487
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:56
#define CP_ACP
Definition: compat.h:109
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define argv
Definition: mplay32.c:18
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
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:4595
#define WAIT_OBJECT_0
Definition: winbase.h:387
#define trace
Definition: atltest.h:70
DWORD cb
Definition: winbase.h:830
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
#define swprintf(buf, format,...)
Definition: sprintf.c:56
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static const WCHAR L[]
Definition: oid.c:1250
#define wcsrchr
Definition: compat.h:16
struct _FileName FileName
Definition: fatprocs.h:893
PRTL_UNICODE_STRING_BUFFER Path
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2248
#define ok(value,...)
Definition: atltest.h:57
#define MultiByteToWideChar
Definition: compat.h:110
#define skip(...)
Definition: atltest.h:64
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by START_TEST().

◆ TestGetModuleFileNameA()

static VOID TestGetModuleFileNameA ( VOID  )
static

Definition at line 84 of file GetModuleFileName.c.

85 {
87  DWORD Length;
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 }
char CHAR
Definition: xmlstorage.h:175
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
BOOL WINAPI PathIsRelativeA(LPCSTR lpszPath)
Definition: path.c:1542
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().

◆ TestGetModuleFileNameW()

static VOID TestGetModuleFileNameW ( VOID  )
static

Definition at line 100 of file GetModuleFileName.c.

101 {
103  DWORD Length;
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:1558
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().