Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_3942_Regression / Bug_3942_Regression.cpp
blobb32ae1e6d27fdfa47a70ab56a3215f248194988b
1 #include "FooS.h"
2 #include "tao/LocalObject.h"
3 #include "tao/Version.h"
5 #if TAO_MAJOR_VERSION < 2 && TAO_MINOR_VERSION < 6
6 # define RV refcount_.value
7 #else
8 # define RV _refcount_value
9 #endif
11 #define ASSERT_REFCOUNT(count, message) \
12 if (ximpl->RV () != count) \
13 { \
14 ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%l %C: expected %d actual %d\n"), \
15 message, count, ximpl->RV ()), -1); \
18 struct XImpl
19 #ifdef LOCAL
20 : X
21 # if TAO_MAJOR_VERSION < 2 && TAO_MINOR_VERSION < 6
22 // FUZZ: disable check_for_TAO_Local_RefCounted_Object
23 , TAO_Local_RefCounted_Object
24 # endif
25 #else
26 : POA_X
27 #endif
29 #if defined LOCAL && (TAO_MAJOR_VERSION < 2 && TAO_MINOR_VERSION < 6)
30 unsigned long _refcount_value () const { return refcount_.value (); }
31 #endif
33 void op () {}
36 int ACE_TMAIN (int, ACE_TCHAR *[])
38 #ifdef LOCAL
39 XImpl* ximpl = new XImpl;
40 X_var x = ximpl;
41 #else
42 int zero_args = 0;
43 CORBA::ORB_var orb = CORBA::ORB_init (zero_args,
44 static_cast<ACE_TCHAR **> (0));
45 CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
46 PortableServer::POA_var poa = PortableServer::POA::_narrow (obj);
47 XImpl* x_servant = new XImpl;
48 PortableServer::ServantBase_var sbv (x_servant);
49 X_var x = x_servant->_this ();
50 X* ximpl = x;
51 #endif
53 ASSERT_REFCOUNT (1, "baseline");
56 Y y;
57 y.theX = x;
58 ASSERT_REFCOUNT (2, "in struct");
59 X_var x2 = y.theX;
60 ASSERT_REFCOUNT (3, "from struct");
63 ASSERT_REFCOUNT (1, "baseline reestablished");
66 XSeq xseq (1);
67 xseq.length (1);
68 xseq[0] = x;
69 ASSERT_REFCOUNT (2, "in sequence");
70 #ifdef _MSC_VER
71 // For now, only attempt to compile this on MSVC -- it doesn't compile
72 // on GCC (and possibly others) due to:
73 // error: conversion from 'TAO::details::object_reference_sequence_element<TAO::details::object_reference_traits<X, TAO_Objref_Var_T<X>, true> >' to non-scalar type 'X_var' requested
74 // When the bug is fixed, the #ifdef should be removed. Until then, the
75 // test will appear to pass on other compilers, but the MSVC failures should
76 // be enough to notice that the bug needs fixing.
77 X_var x2 = xseq[0];
78 if (ximpl->RV () < 3) x2._retn (); // avoid a crash
79 ASSERT_REFCOUNT (3, "from sequence");
80 #endif
83 return 0;