summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_2669_Regression/client.cpp
blob: f840ef82b8b07825396e4b761088c6686cb10a78 (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

//=============================================================================
/**
 *  $Id$
 */
//=============================================================================


#include "ace/Get_Opt.h"
#include "ace/Task.h"
#include "ace/OS_NS_string.h"

#include "ChildS.h"

int
parse_args (int argc, char *argv[])
{
  ACE_Get_Opt get_opts (argc, argv, "");
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case '?':
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           "usage:  %s "
                           "\n",
                           argv [0]),
                          -1);
      }
  // Indicates sucessful parsing of the command line
  return 0;
}

class ChildHandler : public POA_ChildModule::AMI_ChildInterfaceHandler
{
public:
  ChildHandler (void) {};
  ~ChildHandler (void) {};
};

class NonRelatedChildHandler : public POA_AMI_ChildInterfaceHandler
{
public:
  NonRelatedChildHandler (void) {};
  ~NonRelatedChildHandler (void) {};
};

int
main (int argc, char *argv[])
{
  int result = 0;

  ACE_DECLARE_NEW_CORBA_ENV;

  ACE_TRY
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv, "");
      ACE_TRY_CHECK;

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

      PortableServer::POA_var poa_var =
        PortableServer::POA::_narrow (object_var.in ());
      ACE_TRY_CHECK;

      PortableServer::POAManager_var poa_manager_var =
        poa_var->the_POAManager ();
      ACE_TRY_CHECK;

      poa_manager_var->activate ();
      ACE_TRY_CHECK;

      if (parse_args (argc, argv) != 0)
        return 1;

      // Create two handlers
      ChildHandler child_handler;
      NonRelatedChildHandler non_related_child_handler;

      ChildModule::AMI_ChildInterfaceHandler_var the_child_handler_var =
        child_handler._this ();

      const char * expectedid = "IDL:child.pragma.prefix/ChildModule/AMI_ChildInterfaceHandler:1.0";
      if (ACE_OS::strcmp (the_child_handler_var->_interface_repository_id (), expectedid) != 0)
        {
          ACE_ERROR ((LM_ERROR, "Error: REGRESSION - ChildModule::repository id is "
                                "incorrectly generated, received %s\n",
                                the_child_handler_var->_interface_repository_id ()));
          result = 1;
        }

      // This handler has no relationship with the above in IDL.
      AMI_ChildInterfaceHandler_var the_non_related_child_handler_var =
        non_related_child_handler._this ();

      // Check that both handler objects narrow successfully to their parent
      // handler types...
      ParentModule::AMI_ParentInterfaceHandler_var the_parent_handler_var =
        ParentModule::AMI_ParentInterfaceHandler::_narrow (the_child_handler_var.in ());

      if (CORBA::is_nil (the_parent_handler_var.in ()))
        {
          ACE_ERROR ((LM_ERROR, "Error: REGRESSION - Cannot narrow ChildModule::ChildInterface "
                                "reply handler to its parent handler type.\n"));
          result = 1;
        }

      AMI_ParentInterfaceHandler_var the_non_related_parent_handler_var =
        AMI_ParentInterfaceHandler::_narrow (the_non_related_child_handler_var.in ());

      if (CORBA::is_nil (the_non_related_parent_handler_var.in ()))
        {
          ACE_ERROR ((LM_ERROR, "Error: REGRESSION - Cannot narrow ChildInterface "
                                "reply handler to its parent handler type.\n"));
          result = 1;
        }

      // Check that both handler objects *won't* narrow to each other's parent
      // handler types...
      the_parent_handler_var =
        ParentModule::AMI_ParentInterfaceHandler::_narrow (the_non_related_child_handler_var.in ());

      if (! CORBA::is_nil (the_parent_handler_var.in ()))
        {
          ACE_ERROR ((LM_ERROR, "Error: REGRESSION - ChildModule::ChildInterface reply handler "
                                "narrows to unrelated type.\n"));
          result = 1;
        }

      the_non_related_parent_handler_var =
        AMI_ParentInterfaceHandler::_narrow (the_child_handler_var.in ());

      if (! CORBA::is_nil (the_non_related_parent_handler_var.in ()))
        {
          ACE_ERROR ((LM_ERROR, "Error: REGRESSION - ChildModule::ChildInterface reply handler "
                                "narrows to unrelated type.\n"));
          result = 1;
        }

      poa_var->destroy (1,0);

      orb->destroy ();

    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "Caught exception:");
      return 1;
    }
  ACE_ENDTRY;
  ACE_CHECK_RETURN (-1);

  return result;
}