summaryrefslogtreecommitdiff
path: root/TAO/tests/Portable_Interceptors/Register_Initial_References/server.cpp
blob: efac5ba2c36d5ebdd448a94ec692d39916e97fe0 (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
// $Id$

#include "Server_ORBInitializer.h"
#include "tao/ORBInitializer_Registry.h"
#include "test_i.h"

ACE_RCSID(Recursive_ORBInitializer,
          server,
          "$Id$")


int test_orb (CORBA::ORB_ptr orb ACE_ENV_ARG_DECL)
{
  int errors = 0;

  POA_TestModule::test* test = 0;
  ACE_NEW_RETURN (test,
                  test_i, 1);

  CORBA::Object_ptr object = test->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (1);

  orb->register_initial_reference ("ORBMyService",
                                    object
                                    ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (1);

  bool invalid_name = false;
  ACE_TRY
    {
      // Registering with an empty string should give an exception
      orb->register_initial_reference ("",
                                       object
                                       ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
    }
  ACE_CATCH (CORBA::ORB::InvalidName, ex)
    {
      invalid_name = true;
    }
  ACE_CATCHANY
    {
    }
  ACE_ENDTRY;

  if (!invalid_name)
    {
      errors++;
      ACE_ERROR ((LM_ERROR, "ERROR: Registering with an empty string with the ORB"
                            "doesn't throw an exception\n"));
    }

  bool duplicate_name = false;
  ACE_TRY_EX (duplicate)
    {
      // Registering with an duplicate string should give an exception
      orb->register_initial_reference ("ORBMyService",
                                        object
                                        ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK_EX (duplicate);
    }
  ACE_CATCH (CORBA::ORB::InvalidName, ex)
    {
      duplicate_name = true;
    }
  ACE_CATCHANY
    {
    }
  ACE_ENDTRY;

  if (!duplicate_name)
    {
      errors++;
      ACE_ERROR ((LM_ERROR, "ERROR: Registering with a duplicate with ORB "
                            "doesn't throw the expected exception\n"));
    }

  bool invalid_object = false;
  ACE_TRY_EX (invalid)
    {
      // Registering with a nil object
      orb->register_initial_reference ("ORBNilServer",
                                       CORBA::Object::_nil()
                                       ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK_EX (invalid);
    }
  ACE_CATCH (CORBA::BAD_PARAM , ex)
    {
      if ((ex.minor() & 0xFFFU) == 27)
        {
          invalid_object = true;
        }
    }
  ACE_CATCHANY
    {
    }
  ACE_ENDTRY;

  if (!invalid_object)
    {
      errors++;
      ACE_ERROR ((LM_ERROR, "ERROR: Registering with a nil object to ORB "
                            "doesn't throw bad param with minor code 27\n"));
    }

  return errors;
}

int
main (int argc, char *argv[])
{
  Server_ORBInitializer *initializer = 0;
  int retval = 0;

  ACE_NEW_RETURN (initializer,
                  Server_ORBInitializer,
                  -1);  // No exceptions yet!

  PortableInterceptor::ORBInitializer_var initializer_var =
    initializer;

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

      retval = test_orb (orb.in () ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      PortableInterceptor::register_orb_initializer (initializer_var.in ()
                                                     ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      CORBA::ORB_var second_orb =
        CORBA::ORB_init (argc, argv, "SecondORB" ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "Caught exception in server:");
      return 1;
    }
  ACE_ENDTRY;

  return retval;
}