summaryrefslogtreecommitdiff
path: root/TAO/tests/RTCORBA/ORB_init/ORB_init.cpp
blob: 3bd37675c751afc76fbeb9bd3ad22b006d63ccf6 (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
// $Id$

#include "tao/RTCORBA/RTCORBA.h"
#include "tao/ORB.h"
#include "ace/Get_Opt.h"
#include "ace/OS_NS_stdio.h"
#include "ace/Argv_Type_Converter.h"

int
test_multiple_orbs (const char *test_name,
                    int argc,
                    char *argv[],
                    int iterations,
                    int rt_orb,
                    int destroy)
{
  CORBA::ORB_var *orbs =
    new CORBA::ORB_var[iterations];

  RTCORBA::RTORB_var *rt_orbs =
    new RTCORBA::RTORB_var[iterations];

  ACE_TRY_NEW_ENV
    {
      for (int i = 0;
           i < iterations;
           ++i)
        {
          char name[100];
          ACE_OS::sprintf (name, "%s %d", test_name, i);

          orbs[i] =
            CORBA::ORB_init (argc,
                             argv,
                             name
                             ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          if (rt_orb)
            {
              CORBA::Object_var object =
                orbs[i]->resolve_initial_references ("RTORB"
                                                     ACE_ENV_ARG_PARAMETER);
              ACE_TRY_CHECK;

              rt_orbs[i] =
                RTCORBA::RTORB::_narrow (object.in ()
                                         ACE_ENV_ARG_PARAMETER);
              ACE_TRY_CHECK;

              ACE_ASSERT (rt_orbs[i].in () != RTCORBA::RTORB::_nil ());
            }
        }

      if (destroy)
        {
          for (int i = 0;
               i < iterations;
               ++i)
            {
              orbs[i]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
              ACE_TRY_CHECK;
            }
        }
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "Unexpected exception caught in ORB_init");
      return -1;
    }
  ACE_ENDTRY;

  delete[] rt_orbs;
  delete[] orbs;

  return 0;
}

int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_Argv_Type_Converter convert (argc, argv);

  int iterations = 5;
  int rt_orb = 0;
  int destroy = 0;

  int result =
    test_multiple_orbs ("non-RT ORBs, disable destroy",
                        convert.get_argc(), convert.get_ASCII_argv(),
                        iterations,
                        rt_orb,
                        destroy);
  ACE_ASSERT (result == 0);

  destroy = 1;
  rt_orb = 0;

  result =
    test_multiple_orbs ("non-RT ORBs, enable destroy",
                        convert.get_argc(), convert.get_ASCII_argv(),
                        iterations,
                        rt_orb,
                        destroy);
  ACE_ASSERT (result == 0);

  destroy = 0;
  rt_orb = 1;

  result =
    test_multiple_orbs ("RT ORBs, disable destroy",
                        convert.get_argc(), convert.get_ASCII_argv(),
                        iterations,
                        rt_orb,
                        destroy);
  ACE_ASSERT (result == 0);

  destroy = 1;
  rt_orb = 1;

  result =
    test_multiple_orbs ("RT ORBs, enable destroy",
                        convert.get_argc(), convert.get_ASCII_argv(),
                        iterations,
                        rt_orb,
                        destroy);
  ACE_ASSERT (result == 0);

  return result;
}