ReactOS 0.4.15-dev-7953-g1f49173
static_construct.cpp File Reference
#include <apitest.h>
#include <strsafe.h>
#include "dll_startup.h"
Include dependency graph for static_construct.cpp:

Go to the source code of this file.

Classes

struct  init_static
 
struct  shared_memory
 
struct  shared_mem_static
 

Macros

#define MAPPING_NAME   L"crt_apitest_static_construct"
 

Functions

static VOID TestInitStatic (VOID)
 
static VOID TestDllStartup (VOID)
 
static void map_memory ()
 
static void unmap_memory ()
 
static VOID TestStaticDestruct (VOID)
 
 START_TEST (static_construct)
 

Variables

int static_init_counter
 
static int static_init_counter_at_startup
 
static int static_construct_counter_at_startup
 
static int m_uninit_at_startup
 
int static_construct_counter = 789
 
static struct init_static init_static
 
static HANDLE g_FileMapping = NULL
 
static BOOL g_CreatedFileMapping = FALSE
 
static shared_memoryg_Memory = NULL
 
static struct shared_mem_static shared_mem_static
 

Macro Definition Documentation

◆ MAPPING_NAME

#define MAPPING_NAME   L"crt_apitest_static_construct"

Definition at line 119 of file static_construct.cpp.

Function Documentation

◆ map_memory()

static void map_memory ( )
static

Definition at line 121 of file static_construct.cpp.

122{
123 if (g_FileMapping)
124 return;
125
127 if (g_FileMapping)
128 {
130 }
131 else
132 {
135 }
136 if (g_FileMapping == NULL)
137 {
138 skip("Could not map shared memory\n");
139 return;
140 }
142 if (g_Memory == NULL)
143 {
144 skip("Could not map view of shared memory\n");
147 }
150}
#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 INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define MapViewOfFile
Definition: compat.h:745
HANDLE NTAPI OpenFileMappingW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: filemap.c:297
#define PAGE_READWRITE
Definition: nt_native.h:1304
static HANDLE g_FileMapping
static BOOL g_CreatedFileMapping
static shared_memory * g_Memory
#define MAPPING_NAME
#define ZeroMemory
Definition: winbase.h:1712
#define FILE_MAP_ALL_ACCESS
Definition: winbase.h:156

Referenced by shared_mem_static::shared_mem_static().

◆ START_TEST()

START_TEST ( static_construct  )

Definition at line 216 of file static_construct.cpp.

217{
218 char **argv;
220
221 if (argc >= 3)
222 {
223 // we are just here to increment the reference count in the shared section!
224 ok(g_Memory != NULL, "Expected the shared memory to be mapped!\n");
225 ok(g_CreatedFileMapping == FALSE, "Expected the shared memory to be created by my parent!\n");
226 return;
227 }
228
232}
static int argc
Definition: ServiceArgs.c:12
#define ok(value,...)
Definition: atltest.h:57
#define argv
Definition: mplay32.c:18
int winetest_get_mainargs(char ***pargv)
static VOID TestInitStatic(VOID)
static VOID TestStaticDestruct(VOID)
static VOID TestDllStartup(VOID)

◆ TestDllStartup()

static VOID TestDllStartup ( VOID  )
static

Definition at line 61 of file static_construct.cpp.

62{
63#if defined(TEST_MSVCRT)
64 const PCWSTR DllName = L"msvcrt_crt_dll_startup.dll";
65#elif defined(TEST_STATIC_CRT)
66 const PCWSTR DllName = L"static_crt_dll_startup.dll";
67#else
68#error This test only makes sense for static CRT and msvcrt.dll
69#endif
72 wcsrchr(DllPath, L'\\')[1] = UNICODE_NULL;
74
76 if (hDll == NULL)
77 {
78 skip("Helper dll not found\n");
79 return;
80 }
81 SET_COUNTER_VALUES_POINTER *pSetCounterValuesPointer = reinterpret_cast<SET_COUNTER_VALUES_POINTER*>(GetProcAddress(hDll, "SetCounterValuesPointer"));
82 if (pSetCounterValuesPointer == NULL)
83 {
84 skip("Helper function not found\n");
85 FreeLibrary(hDll);
86 return;
87 }
89 pSetCounterValuesPointer(&values);
90 ok(values.m_uninit_at_startup == 0, "m_uninit_at_startup = %d\n", values.m_uninit_at_startup);
91 ok(values.m_uninit == 1, "m_uninit = %d\n", values.m_uninit);
92 ok(values.m_counter == 2, "m_counter = %d\n", values.m_counter);
93 ok(values.static_construct_counter_at_startup == 5656, "static_construct_counter_at_startup = %d\n", values.static_construct_counter_at_startup);
94 ok(values.static_construct_counter == 5657, "static_construct_counter = %d\n", values.static_construct_counter);
95 ok(values.dtor_counter_at_detach == 0, "dtor_counter_at_detach = %d\n", values.dtor_counter_at_detach);
96 ok(values.dtor_counter == 0, "dtor_counter = %d\n", values.dtor_counter);
97 values.dtor_counter_at_detach = 78789;
98 values.dtor_counter = 7878;
99 FreeLibrary(hDll);
100 ok(values.m_uninit_at_startup == 0, "m_uninit_at_startup = %d\n", values.m_uninit_at_startup);
101 ok(values.m_uninit == 1, "m_uninit = %d\n", values.m_uninit);
102 ok(values.m_counter == 2, "m_counter = %d\n", values.m_counter);
103 ok(values.static_construct_counter_at_startup == 5656, "static_construct_counter_at_startup = %d\n", values.static_construct_counter_at_startup);
104 ok(values.static_construct_counter == 5657, "static_construct_counter = %d\n", values.static_construct_counter);
105 ok(values.dtor_counter_at_detach == 7878, "dtor_counter_at_detach = %d\n", values.dtor_counter_at_detach);
106 ok(values.dtor_counter == 7879, "dtor_counter = %d\n", values.dtor_counter);
107}
#define wcsrchr
Definition: compat.h:16
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define LoadLibraryW(x)
Definition: compat.h:747
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
void WINAPI SET_COUNTER_VALUES_POINTER(_Out_ struct counter_values *pcv)
Definition: dll_startup.h:24
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:5666
static const char const char * DllPath
Definition: image.c:34
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
const uint16_t * PCWSTR
Definition: typedefs.h:57
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ TestInitStatic()

static VOID TestInitStatic ( VOID  )
static

Definition at line 46 of file static_construct.cpp.

47{
48 ok(static_init_counter_at_startup == 123, "static_init_counter at startup: %d\n", static_init_counter_at_startup);
49 ok(static_construct_counter_at_startup == 789, "static_construct_counter at startup: %d\n", static_construct_counter_at_startup);
50 ok(m_uninit_at_startup == 0, "init_static.m_uninit at startup: %d\n", m_uninit_at_startup);
51
52 ok(static_init_counter == 123, "static_init_counter: %d\n", static_init_counter);
53
54 ok(static_construct_counter == 790, "static_construct_counter: %d\n", static_construct_counter);
55 ok(init_static.m_counter == 2, "init_static.m_counter: %d\n", init_static.m_counter);
56 ok(init_static.m_uninit == 1, "init_static.m_uninit: %d\n", init_static.m_uninit);
57}
int static_init_counter
Definition: static_init.c:12
int static_construct_counter
static int m_uninit_at_startup
static int static_init_counter_at_startup
static int static_construct_counter_at_startup

Referenced by START_TEST().

◆ TestStaticDestruct()

static VOID TestStaticDestruct ( VOID  )
static

Definition at line 184 of file static_construct.cpp.

185{
186 ok(g_Memory != NULL, "Expected the mapping to be in place\n");
187 ok(g_CreatedFileMapping == TRUE, "Expected to create a new shared section!\n");
188 if (g_Memory == NULL)
189 {
190 skip("Can't proceed without file mapping\n");
191 return;
192 }
193 ok(g_Memory->init_count == 1, "Expected init_count to be 1, was: %d\n", g_Memory->init_count);
194 ok(g_Memory->uninit_count == 0, "Expected uninit_count to be 0, was: %d\n", g_Memory->uninit_count);
195
197 // we just need an extra argument to tell the test it's only running to increment the dtor count :)
199 WCHAR buf[MAX_PATH+40];
200 StringCchPrintfW(buf, _countof(buf), L"\"%ls\" static_construct dummy", path);
201
202 STARTUPINFOW si = { sizeof(si) };
204 BOOL created = CreateProcessW(NULL, buf, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
205 ok(created, "Expected CreateProcess to succeed\n");
206 if (created)
207 {
209 CloseHandle(pi.hThread);
210 CloseHandle(pi.hProcess);
211 ok(g_Memory->init_count == 2, "Expected init_count to be 2, was: %d\n", g_Memory->init_count);
212 ok(g_Memory->uninit_count == 1, "Expected uninit_count to be 1, was: %d\n", g_Memory->uninit_count);
213 }
214}
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
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static refpint_t pi[]
Definition: server.c:96
void winetest_wait_child_process(HANDLE process)
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530

Referenced by START_TEST().

◆ unmap_memory()

static void unmap_memory ( )
static

Definition at line 152 of file static_construct.cpp.

153{
154 // we do not clean the mapping in the child, since we want to count all dtor's!
156 {
159 g_Memory = NULL;
161 }
162}
#define UnmapViewOfFile
Definition: compat.h:746

Referenced by shared_mem_static::~shared_mem_static().

Variable Documentation

◆ g_CreatedFileMapping

BOOL g_CreatedFileMapping = FALSE
static

Definition at line 116 of file static_construct.cpp.

Referenced by map_memory(), START_TEST(), TestStaticDestruct(), and unmap_memory().

◆ g_FileMapping

HANDLE g_FileMapping = NULL
static

Definition at line 115 of file static_construct.cpp.

Referenced by map_memory(), and unmap_memory().

◆ g_Memory

◆ init_static

◆ m_uninit_at_startup

int m_uninit_at_startup
static

Definition at line 23 of file static_construct.cpp.

Referenced by init_static::init_static(), and TestInitStatic().

◆ shared_mem_static

◆ static_construct_counter

int static_construct_counter = 789

Definition at line 25 of file static_construct.cpp.

Referenced by init_static::init_static(), START_TEST(), and TestInitStatic().

◆ static_construct_counter_at_startup

int static_construct_counter_at_startup
static

Definition at line 22 of file static_construct.cpp.

Referenced by init_static::init_static(), and TestInitStatic().

◆ static_init_counter

int static_init_counter
extern

Definition at line 12 of file static_init.c.

Referenced by init_static::init_static(), START_TEST(), and TestInitStatic().

◆ static_init_counter_at_startup

int static_init_counter_at_startup
static

Definition at line 21 of file static_construct.cpp.

Referenced by init_static::init_static(), and TestInitStatic().