ReactOS 0.4.15-dev-8102-g108db8f
atexit.c
Go to the documentation of this file.
1/*
2* PROJECT: ReactOS API tests
3* LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4* PURPOSE: Test for atexit
5* PROGRAMMER: Timo Kreuzer <timo.kreuzer@reactos.org>
6*/
7
8#include <apitest.h>
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <ntndk.h>
13
14int g_sequence = 0;
16
17void exitfunc1(void)
18{
20 g_sequence++;
22}
23
24void exitfunc2(void)
25{
27 g_sequence++;
29}
30
31void exitfunc3(void)
32{
34 g_sequence++;
36 printf("exitfunc3\n");
37}
38
40
42{
44 PFN_atexit patexit;
45
46 /* Open the named sempahore to count atexit callbacks */
47 g_hSemaphore = OpenSemaphoreA(SEMAPHORE_ALL_ACCESS, FALSE, "atext_apitest_sempahore");
48 ok(g_hSemaphore != NULL, "couldn't open semaphore.\n");
49
50 /* Load atexit from msvcrt.dll */
51 hmod = GetModuleHandleA("msvcrt.dll");
52 patexit = (PFN_atexit)GetProcAddress(hmod, "atexit");
53 ok(patexit != NULL, "failed to get atexit from msvcrt.dll\n");
54
55 /* Register 3 exit functions, the second one in msvcrt. */
57 if (patexit != NULL)
58 {
59 ok_int(patexit(exitfunc2), 0);
60 }
62}
63
65{
67 PSTR CommandLine;
68 int result;
69 HANDLE hSemaphore;
72
73 /* Check recursive call */
74 CommandLine = GetCommandLineA();
75 if (strstr(CommandLine, "-run") != NULL)
76 {
78 return;
79 }
80
81 /* Create a named semaphore to count atexit callbacks in remote process */
82 hSemaphore = CreateSemaphoreA(NULL, 1, 20, "atext_apitest_sempahore");
83
84 /* Run the actual test in a new process */
85 sprintf(Buffer, "%s -run", CommandLine);
87 ok_int(result, 0);
88
89 /* Check the new semaphore state */
90 Status = NtQuerySemaphore(hSemaphore, SemaphoreBasicInformation, &SemInfo, sizeof(SemInfo), NULL);
91 ok(NT_SUCCESS(Status), "NtQuerySemaphore failed: 0x%lx\n", Status);
92 ok_int(SemInfo.CurrentCount, 4);
93}
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define __cdecl
Definition: accygwin.h:79
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
LPSTR WINAPI GetCommandLineA(VOID)
Definition: proc.c:2003
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define printf
Definition: freeldr.h:97
Status
Definition: gdiplustypes.h:25
GLuint64EXT * result
Definition: glext.h:11304
int __cdecl atexit(void(__cdecl *)(void))
Definition: atonexit.c:97
int(__cdecl * PFN_atexit)(void(__cdecl *)(void))
Definition: atexit.c:39
void exitfunc2(void)
Definition: atexit.c:24
HANDLE g_hSemaphore
Definition: atexit.c:15
void Test_atexit()
Definition: atexit.c:41
void exitfunc1(void)
Definition: atexit.c:17
void exitfunc3(void)
Definition: atexit.c:31
int g_sequence
Definition: atexit.c:14
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:143
@ SemaphoreBasicInformation
Definition: extypes.h:349
int __cdecl system(_In_opt_z_ const char *_Command)
NTSTATUS NTAPI NtQuerySemaphore(IN HANDLE SemaphoreHandle, IN SEMAPHORE_INFORMATION_CLASS SemaphoreInformationClass, OUT PVOID SemaphoreInformation, IN ULONG SemaphoreInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: sem.c:222
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreA(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL, IN LONG lInitialCount, IN LONG lMaximumCount, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:430
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:542
HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
Definition: synch.c:516
char * PSTR
Definition: typedefs.h:51
#define SEMAPHORE_ALL_ACCESS
Definition: winbase.h:160
char CHAR
Definition: xmlstorage.h:175