summaryrefslogtreecommitdiff
path: root/ACE/tests/Bug_2368_Regression_Test.cpp
blob: 3606c24e8f115c6b26f696130467ec1d62aecc7c (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
 * @file Bug_2368_Regression_Test.cpp
 *
 * $Id$
 *
 * Reproduces the problems reported in bug 2368:
 *   http://deuce.doc.wustl.edu/bugzilla/show_bug.cgi?id=2368
 *
 * @author Johnny Willemsen  <jwillemsen@remedy.nl>
 */

#include "test_config.h"
#include "ace/Service_Config.h"
#include "ace/Reactor.h"
#include "ace/Log_Msg.h"
#include "ace/Signal.h"

static bool handleA_close_called = false;
static bool handleB_close_called = false;

class My_HandlerA : public ACE_Event_Handler
{
public:
  virtual int handle_close (ACE_HANDLE,
                            ACE_Reactor_Mask)
  {
    ACE_DEBUG ((LM_DEBUG,
                "Handle close called\n"));
    handleA_close_called = true;

    return 0;
  }

  virtual int handle_signal (int,
                             siginfo_t *,
                             ucontext_t *)
  {
    ACE_DEBUG ((LM_DEBUG,
                "Handle signal called\n"));

    return 0;
  }
};

class My_HandlerB : public ACE_Event_Handler
{
public:
  virtual int handle_close (ACE_HANDLE,
                            ACE_Reactor_Mask)
  {
    ACE_DEBUG ((LM_DEBUG,
                "Handle close called\n"));
    handleB_close_called = true;

    return 0;
  }

  virtual int handle_signal (int,
                             siginfo_t *,
                             ucontext_t *)
  {
    ACE_DEBUG ((LM_DEBUG,
                "Handle signal called\n"));

    return 0;
  }
};

int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Bug_2368_Regression_Test"));

  My_HandlerA my_handlerA;
  My_HandlerB my_handlerB;

  // Set up an ACE signal handler.
  if (ACE_Reactor::instance ()->register_handler
      (SIGINT,
       &my_handlerA) == -1)
    ACE_ERROR_RETURN ((LM_DEBUG,
                       "%p\n",
                       "register_handlerA"),
                      -1);

  if (ACE_Reactor::instance ()->register_handler
      (SIGINT,
       &my_handlerB) == -1)
    ACE_ERROR_RETURN ((LM_DEBUG,
                       "%p\n",
                       "register_handlerB"),
                      -1);

  ACE_Sig_Action *new_disp = 0;
  if (ACE_Reactor::instance ()->remove_handler
      (SIGINT,
       new_disp) == -1)
    ACE_ERROR_RETURN ((LM_DEBUG,
                       "%p\n",
                       "remove_handlerB"),
                      -1);

  if (ACE_Reactor::instance ()->close () == -1)
    ACE_ERROR ((LM_ERROR,
                "%p\n",
                "close"));

  if (!handleA_close_called)
    ACE_ERROR ((LM_ERROR,
                "Handle close hasn't been called for A. "
                "This test failure caused by the unresolved bug is EXPECTED!\n"));

  if (!handleB_close_called)
    ACE_ERROR ((LM_ERROR,
                "Handle close hasn't been called for B. "
                "This test failure caused by the unresolved bug is EXPECTED!\n"));

  ACE_END_TEST;

  return 0;
}