summaryrefslogtreecommitdiff
path: root/trunk/TAO/tests/Bug_2826_Regression/bug_2826_regression.cpp
blob: 71742bbd4eb89e83ae4f614489bf8778db6c6cd3 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// $Id$

#include "tao/ORB_Core.h"
#include "tao/PortableServer/PortableServer.h"
#include "fooS.h"

ACE_RCSID (Bug_2826_Regression,
           bug_2826_regression,
           "$Id$")
namespace
{
class Foo_i : public virtual POA_foo
{
public:
  virtual void check ()
  {
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) checking \n"));
  }
};

int vc_check(foo_ptr ff, bool active=true)
{
  try
  {
    CORBA::PolicyList_var policies;
    CORBA::Boolean rv=ff->_validate_connection (policies.out());
    if (!rv)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) got false from _validate_connection\n"),
                          1);
    }
  }
  catch (const CORBA::INV_POLICY&)
  {
    if (!active)
      ACE_ERROR_RETURN ((LM_ERROR,
                             " (%P|%t) unexpect inlaid policies\n"),
                              2);
  }
  catch (const CORBA::OBJECT_NOT_EXIST&)
  {
    if (active)
      ACE_ERROR_RETURN ((LM_ERROR,
                             " (%P|%t) unexpect object not exists\n"),
                              3);
  }
  catch (const CORBA::Exception&)
  {
    ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) unexpect exception\n"),
                          4);
  }
  return 0;
}
}

int main (int argc, char *argv[])
{
  CORBA::ORB_var orb;
  try
  {
    orb= CORBA::ORB_init (argc, argv, 0);

    CORBA::Object_var root_poa_o =
      orb->resolve_initial_references ("RootPOA");

    PortableServer::POA_var rootPOA =
      PortableServer::POA::_narrow (root_poa_o.in ());

    if (CORBA::is_nil (rootPOA.in ()))
      {
        ACE_ERROR_RETURN ((LM_ERROR,
        " (%P|%t) Panic: nil RootPOA\n"), 1);
      }

    PortableServer::POAManager_var poaMgr = rootPOA->the_POAManager ();

    poaMgr->activate ();

    CORBA::PolicyList policies;
    policies.length (3);
    policies[0] = rootPOA->create_id_assignment_policy (
      PortableServer::SYSTEM_ID);
    policies[1] = rootPOA->create_implicit_activation_policy (
      PortableServer::NO_IMPLICIT_ACTIVATION);
    policies[2] = rootPOA->create_lifespan_policy (
      PortableServer::TRANSIENT);

    PortableServer::POA_var fooPoa = rootPOA->create_POA (
      "FOO_POA", poaMgr.in (), policies );

    for (CORBA::ULong i = 0; i < policies.length (); ++i)
    {
      policies[i]->destroy ();
    }

    Foo_i servant;
    PortableServer::ObjectId_var oid = fooPoa->activate_object( &servant );

    CORBA::Object_var obj = fooPoa->id_to_reference (oid.in ());

    foo_var client = foo::_narrow (obj.in());

    client->check();

    if (vc_check(client.in()))
    {
      orb->destroy();
      return 1;
    }

    fooPoa->deactivate_object (oid.in () );  //servant is gone

    if (vc_check(client.in(), false))  //exception expected
    {
      orb->destroy();
      return 2;
    }
  }
  catch(...)
  {
    return 3;
  }
  return 0;
}