ReactOS  0.4.14-dev-49-gfb4591c
signal.c
Go to the documentation of this file.
1 /*
2  * Unit test suite for signal function.
3  *
4  * Copyright 2009 Peter Rosin
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #include "wine/test.h"
22 #include <winbase.h>
23 #include <signal.h>
24 
25 static int test_value = 0;
26 
27 static void __cdecl sighandler(int signum)
28 {
29  void **ret = __pxcptinfoptrs();
30 
31  ok(ret != NULL, "ret = NULL\n");
32  if(signum == SIGABRT)
33  ok(*ret == (void*)0xdeadbeef, "*ret = %p\n", *ret);
34  else if(signum == SIGSEGV)
35  ok(*ret == NULL, "*ret = %p\n", *ret);
36  ++test_value;
37 }
38 
39 static void test_signal(void)
40 {
41  void (__cdecl *old)(int);
42  int res;
43 
44  old = signal(SIGBREAK, sighandler);
45  ok(old != SIG_ERR, "Failed to install signal handler for SIGBREAK\n");
46  test_value = 0;
47  res = raise(SIGBREAK);
48  ok(res == 0, "Failed to raise SIGBREAK\n");
49  ok(test_value == 1, "SIGBREAK handler not invoked\n");
50 }
51 
52 static void test___pxcptinfoptrs(void)
53 {
54  void **ret = __pxcptinfoptrs();
55  int res;
56 
57  ok(ret != NULL, "ret == NULL\n");
58  ok(*ret == NULL, "*ret != NULL\n");
59 
60  test_value = 0;
61 
62  *ret = (void*)0xdeadbeef;
64  res = raise(SIGSEGV);
65  ok(res == 0, "failed to raise SIGSEGV\n");
66  ok(*ret == (void*)0xdeadbeef, "*ret = %p\n", *ret);
67 
69  res = raise(SIGABRT);
70  ok(res == 0, "failed to raise SIGBREAK\n");
71  ok(*ret == (void*)0xdeadbeef, "*ret = %p\n", *ret);
72 
73  ok(test_value == 2, "test_value = %d\n", test_value);
74 }
75 
77 {
78  test_signal();
80 }
static int test_value
Definition: signal.c:25
#define SIGABRT
Definition: signal.h:28
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define __cdecl
Definition: accygwin.h:79
#define SIGBREAK
Definition: signal.h:40
static void __cdecl sighandler(int signum)
Definition: signal.c:27
#define SIG_ERR
Definition: signal.h:52
smooth NULL
Definition: ftsmooth.c:416
int ret
#define SIGSEGV
Definition: signal.h:33
static void test___pxcptinfoptrs(void)
Definition: signal.c:52
START_TEST(signal)
Definition: signal.c:76
void **__cdecl __pxcptinfoptrs(void)
Definition: xcptinfo.c:6
#define ok(value,...)
Definition: atltest.h:57
static void test_signal(void)
Definition: signal.c:39
GLuint res
Definition: glext.h:9613
__p_sig_fn_t signal(int sig, __p_sig_fn_t func)
Definition: signal.c:23
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31