summaryrefslogtreecommitdiff
path: root/ACE/tests/Bug_3673_Regression_Test.cpp
blob: c074edbd1c9510535eab045c44cdda6d660703fd (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
/**
 * @file Bug_3673_Regression_Test.cpp
 *
 * $Id$
 *
 * Reproduces the problems reported in bug 3673
 *   http://deuce.doc.wustl.edu/bugzilla/show_bug.cgi?id=3673
 */

#include "test_config.h"
#include "ace/ACE.h"
#include "ace/OS_NS_stdio.h"

ACE_RCSID (tests,
           Bug_3673_Regression_Test,
           "$Id$")

#if defined (ACE_HAS_EXCEPTIONS)
static bool construct_alpha = false;
static bool destruct_alpha = false;
static bool construct_beta = false;
static bool destruct_beta = false;

template <typename T>
struct Alpha
{
  Alpha() { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("construct alpha\n"))); construct_alpha = true;}
  ~Alpha() { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("destruct alpha\n"))); destruct_alpha = true;}
};

struct Beta
{
  Beta() { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("construct beta\n"))); construct_beta = true;}
  ~Beta() { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("destruct bepha\n"))); destruct_beta = true;}
};

struct Test
{
  Alpha<int> a;
  Beta b;

  Test() { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("throw oops\n"))); throw "oops"; }
};
#endif

int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Bug_3673_Regression_Test"));
  int result = 0;

#if defined (ACE_HAS_EXCEPTIONS)
  bool caught_excep = false;
  try
  {
    Test test;
  }
  catch (...)
  {
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Caugt exception!\n")));
    caught_excep = true;
  }

  if (!caught_excep)
  {
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Not caugt exception\n")));
    ++result;
  }
  if (!construct_alpha)
  {
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Constructor alpha not called\n")));
    ++result;
  }
  if (!construct_beta)
  {
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Constructor beta not called\n")));
    ++result;
  }
  if (!destruct_alpha)
  {
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Destructor alpha not called\n")));
    ++result;
  }
  if (!destruct_beta)
  {
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Destructor beta not called\n")));
    ++result;
  }
#else
  ACE_ERROR ((LM_INFO,
              ACE_TEXT ("C++ exception support not enabled on this platform\n")));
#endif /* ACE_HAS_EXCEPTIONS */

  ACE_END_TEST;

  return result;
}