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; 63 signal(SIGSEGV, sighandler); 64 res = raise(SIGSEGV); 65 ok(res == 0, "failed to raise SIGSEGV\n"); 66 ok(*ret == (void*)0xdeadbeef, "*ret = %p\n", *ret); 67 68 signal(SIGABRT, sighandler); 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 76 START_TEST(signal) 77 { 78 test_signal(); 79 test___pxcptinfoptrs(); 80 } 81