#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <glib.h>

static void
test_sigbus (void)
{
  if (g_test_subprocess())
    raise (SIGBUS);

  g_test_trap_subprocess (NULL, 0, 0);
  /* this will fail */
  g_test_trap_assert_passed ();
}

static void
test_sigalrm (void)
{
  if (g_test_subprocess())
    raise (SIGALRM);

  g_test_trap_subprocess (NULL, 0, 0);
  /* this will fail */
  g_test_trap_assert_passed ();
}

static void
test_exit0 (void)
{
  if (g_test_subprocess())
    {
      printf ("I am going to exit 0\n");
      fprintf (stderr, "I am going to exit 0 and this is stderr\n");
      exit (0);
    }

  g_test_trap_subprocess (NULL, 0, 0);
  /* this will fail */
  g_test_trap_assert_failed ();
}

static void
test_exit23 (void)
{
  if (g_test_subprocess())
    exit (23);

  g_test_trap_subprocess (NULL, 0, 0);
  /* this will fail */
  g_test_trap_assert_passed ();
}

int
main (int argc,
    char *argv[])
{
  g_test_init (&argc, &argv, NULL);
  g_test_set_nonfatal_assertions ();
  g_test_add_func ("/exit0", test_exit0);
  g_test_add_func ("/exit23", test_exit23);
  g_test_add_func ("/sigbus", test_sigbus);
  g_test_add_func ("/sigalrm", test_sigalrm);

  return g_test_run ();
}
