summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/FaultTolerance/IOGRManipulation/IOGRTest.cpp
blob: 72014970c1d9a1e0b62920ca498aec7ce10378f1 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// $Id$

//========================================================================
//
// = LIBRARY
//   tests/FaultTolerance/IOGRManipulation
//
//
// = FILENAME
//     IOGRTest.cpp
//
// = DESCRIPTION
//   This program tests the basic functionality FT IOGR implementation
//
// = AUTHOR
//     Bala Natarajan <bala@cs.wustl.edu>
//
//=========================================================================

#include "tao/ORB.h"
#include "orbsvcs/FT_CORBA_ORBC.h"
#include "orbsvcs/FaultTolerance/FT_IOGR_Property.h"

ACE_RCSID(IOGRManipluation,
          IOGRTest,
          "$Id$")

int
main (int argc, char *argv[])
{

  ACE_DEBUG ((LM_DEBUG, "---------------------------------------------\n"));
  ACE_DEBUG ((LM_DEBUG, "Running the IOGRManipulation Tests.\n"));

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      // Retrieve the ORB.
      CORBA::ORB_var orb_ = CORBA::ORB_init (argc,
                                             argv,
                                             0
                                             ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
      // **********************************************************************

      // Get an object reference for the ORBs IORManipulation object!
      CORBA::Object_var IORM =
        orb_->resolve_initial_references (TAO_OBJID_IORMANIPULATION,
                                          0
                                          ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      TAO_IOP::TAO_IOR_Manipulation_var iorm =
               TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM.in ()
                                                       ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
      // **********************************************************************

      // Create a few fictitious IORs
      CORBA::Object_var name1 =
        orb_->string_to_object ("iiop://acme.cs.wustl.edu:6060/xyz"
                                ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
      CORBA::Object_var name2 =
        orb_->string_to_object ("iiop://tango.cs.wustl.edu:7070/xyz"
                                ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // **********************************************************************
      // Create IOR list for use with merge_iors.
      TAO_IOP::TAO_IOR_Manipulation::IORList iors (2);
      iors.length (2);
      iors [0] = name1;
      iors [1] = name2;
      // **********************************************************************

      CORBA::Object_var merged =
        iorm->merge_iors (iors ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // Check for set and get primaries
      // Make a dummy property set
      FT::TagFTGroupTaggedComponent ft_tag_component;
      TAO_FT_IOGR_Property prop (ft_tag_component);

      CORBA::Boolean retval =
        iorm->set_primary (&prop, name2.in (), merged.in () ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if (retval != 0)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("\tThe primary has been set\n")));
      else
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("\tError in setting primary\n")));
          return -1;
        }

      // Check whether a primary has been set
      retval = iorm->is_primary_set (&prop,
                                     merged.in ()
                                     ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if (retval)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("\tis_primary_set () returned true\n")));
      else
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("\tis_primary_set () returned false\n")));

          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("\tSo Exiting\n")));
          return -1;
        }

      // Get the primary
      CORBA::Object_var prim =
        iorm->get_primary (&prop,
                           merged.in ()
                           ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // Check whether we got back the right primary
      if (prim->_is_equivalent (name2.in ()))
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("\tWe got the right primary back\n")));
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("\tWe have a problem in getting the right primary\n")));
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("\tSo exiting\n")));
          return -1;
        }
      // **********************************************************************
      // Set properties
      // Property values

      // Major and Minor revision numbers
      ft_tag_component.component_version.major = (CORBA::Octet) 1;
      ft_tag_component.component_version.minor = (CORBA::Octet) 0;

      // Domain id
      const char *id = "iogr_regression";
      ft_tag_component.group_domain_id = id;

      // Object group id
      ft_tag_component.object_group_id =
        (CORBA::ULongLong) 10;

      // Version
      ft_tag_component.object_group_ref_version =
        (CORBA::ULong) 5;

      // Set the property
      retval = iorm->set_property (&prop,
                                   merged.in ()
                                   ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      /// Extract the property
      FT::TagFTGroupTaggedComponent ftc;
      TAO_FT_IOGR_Property tmp_prop;

      retval =
        tmp_prop.get_tagged_component (merged.in (),
                                       ftc
                                       ACE_ENV_ARG_PARAMETER);

      ACE_TRY_CHECK;

      ACE_DEBUG ((LM_DEBUG,
                  "(%P|%t) Testing for tagged component \n"));


      if ((ftc.object_group_ref_version != 5) &&
          (ftc.object_group_id != 10))
        ACE_ERROR ((LM_ERROR,
                    "%P|%t) Not working right \n"));




      if (retval)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("\tWe have set the property\n")));
    }
  ACE_CATCH (TAO_IOP::NotFound, userex)
    {
      ACE_PRINT_EXCEPTION (userex,
                           ACE_TEXT ("Unexpected NotFound Exception!\n"));
      return -1;
    }
  ACE_CATCH (TAO_IOP::Duplicate, userex)
    {
      ACE_PRINT_EXCEPTION (userex,
                           "Unexpected Duplicate Exception!\n");
      return -1;
    }
  ACE_CATCH (TAO_IOP::Invalid_IOR, userex)
    {
      ACE_PRINT_EXCEPTION (userex,
                           "Unexpected Invalid_IOR Exception!\n");
      return -1;
    }
  ACE_CATCH (CORBA::SystemException, sysex)
    {
      ACE_PRINT_EXCEPTION (sysex,
                           "Unexpected system Exception!!\n");
      return -1;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "Unexpected ACE_CATCHANY Exception!\n");
      return -1;
    }
  ACE_ENDTRY;

  ACE_DEBUG ((LM_DEBUG, "IORManipulation Tests Successfully Completed!\n"));
  ACE_DEBUG ((LM_DEBUG, "---------------------------------------------\n"));

  return 0;
}