signal.c 2.19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * Unit test suite for signal function.
 *
 * Copyright 2009 Peter Rosin
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "wine/test.h"
#include <winbase.h>
#include <signal.h>

static int test_value = 0;

27
static void __cdecl sighandler(int signum)
28
{
29 30 31 32 33 34 35
    void **ret = __pxcptinfoptrs();

    ok(ret != NULL, "ret = NULL\n");
    if(signum == SIGABRT)
        ok(*ret == (void*)0xdeadbeef, "*ret = %p\n", *ret);
    else if(signum == SIGSEGV)
        ok(*ret == NULL, "*ret = %p\n", *ret);
36 37 38 39 40
    ++test_value;
}

static void test_signal(void)
{
41
    void (__cdecl *old)(int);
42 43 44
    int res;

    old = signal(SIGBREAK, sighandler);
45
    ok(old != SIG_ERR, "Failed to install signal handler for SIGBREAK\n");
46 47
    test_value = 0;
    res = raise(SIGBREAK);
48 49
    ok(res == 0, "Failed to raise SIGBREAK\n");
    ok(test_value == 1, "SIGBREAK handler not invoked\n");
50 51
}

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
static void test___pxcptinfoptrs(void)
{
    void **ret = __pxcptinfoptrs();
    int res;

    ok(ret != NULL, "ret == NULL\n");
    ok(*ret == NULL, "*ret != NULL\n");

    test_value = 0;

    *ret = (void*)0xdeadbeef;
    signal(SIGSEGV, sighandler);
    res = raise(SIGSEGV);
    ok(res == 0, "failed to raise SIGSEGV\n");
    ok(*ret == (void*)0xdeadbeef, "*ret = %p\n", *ret);

    signal(SIGABRT, sighandler);
    res = raise(SIGABRT);
    ok(res == 0, "failed to raise SIGBREAK\n");
    ok(*ret == (void*)0xdeadbeef, "*ret = %p\n", *ret);

    ok(test_value == 2, "test_value = %d\n", test_value);
}

76 77 78
START_TEST(signal)
{
    test_signal();
79
    test___pxcptinfoptrs();
80
}