summaryrefslogtreecommitdiff
path: root/TAO/tests/RTCORBA/Bug_3382_Regression/simple_client.cpp
blob: 0d433be115e0fc6bea0ac8c312b7d2d298a1956d (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
// $Id$

#include "tao/ORB_Core.h"
#include "tao/RTCORBA/RTCORBA.h"
#include "tao/RTCORBA/Priority_Mapping_Manager.h"
#include "ace/Get_Opt.h"

int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int result = 0;

   ACE_DEBUG ((LM_DEBUG, "Testing : "));

  for (int arg_i = 0; arg_i < argc; ++arg_i)
    {
      ACE_DEBUG ((LM_DEBUG, "%s ", argv[arg_i]));
    }

  ACE_DEBUG ((LM_DEBUG, "\n\n"));

  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var object =
        orb->resolve_initial_references ("RTCurrent");

      RTCORBA::Current_var current =
        RTCORBA::Current::_narrow (object.in ());

      object = orb->resolve_initial_references ("PriorityMappingManager");

      RTCORBA::PriorityMappingManager_var mapping_manager =
        RTCORBA::PriorityMappingManager::_narrow (object.in ());

      RTCORBA::PriorityMapping *pm =
        mapping_manager->mapping ();

      ACE_DEBUG ((LM_DEBUG, "Testing part #1\n\n"));

      // Check for this priority mapping that we are kosher
      RTCORBA::Priority i = RTCORBA::minPriority;
      do
        {
          CORBA::Short native1 = -1, corba1 = -1, native2 = -1, corba2 = -1;

          if (pm->to_native (i, native1))
            {
              if (! (pm->to_CORBA (native1, corba1) &&
                    pm->to_native (corba1, native2) &&
                    pm->to_CORBA (native2, corba2)))
                {
                  ACE_DEBUG ((LM_DEBUG, "ERROR : Mapping reported false during CORBA %d -> Native %d -> CORBA %d -> Native %d\n",
                                                    i,
                                                    native1,
                                                    corba1,
                                                    native2
                                                    ));
                }
              else if (! (corba2 == corba1 && native1 == native2))
                {
                  // titsup
                  ACE_DEBUG ((LM_DEBUG, "ERROR - Not idem-thingy. Mapping went: CORBA %d -> Native %d -> CORBA %d -> Native %d - CORBA %d\n",
                                                    i,
                                                    native1,
                                                    corba1,
                                                    native2,
                                                    corba2
                                                    ));
                  result = -1;
                }
              }
          i = i + 1; // There's a reason to not use unary increment
        }
      while (i != RTCORBA::minPriority);

      ACE_DEBUG ((LM_DEBUG, "\n\nTesting part #2\n\n"));

      // Accessing the priority when it hasn't been set should throw an exception
      try
        {
          i = current->the_priority ();
          ACE_DEBUG ((LM_DEBUG, "ERROR: Unexpectedly was able to access thread CORBA priority of %d when it hadn't been set\n", i));
          result = -1;
        }
      catch (const CORBA::INITIALIZE &)
        {
          // This is what should happen
        }
      catch (const CORBA::Exception & ex)
        {
          ex._tao_print_exception ("ERROR: Unexpected exception type accessing thread CORBA priority when it hadn't been set: ");
          result = -1;
        }
      catch (...)
        {
          ACE_DEBUG ((LM_DEBUG, "ERROR: Wildly unexpected exception type accessing thread CORBA priority when it hadn't been set\n", i));
          result = -1;
        }

      ACE_DEBUG ((LM_DEBUG, "\nTesting part #3\n\n"));

      // Setting an invalid CORBA priority should generate a BAD_PARAM if the mapping has rejected it
      try
        {
          current->the_priority (-1);
          ACE_DEBUG ((LM_DEBUG, "ERROR: Unexpectedly was able to set a thread CORBA priority\n"));
          result = -1;
        }
      catch (const CORBA::BAD_PARAM &)
        {
          // This is what should happen
        }
      catch (const CORBA::Exception & ex)
        {
          ex._tao_print_exception ("ERROR: Unexpected exception type setting an invalid CORBA priority");
          result = -1;
        }
      catch (...)
        {
          ACE_DEBUG ((LM_DEBUG, "ERROR: Wildly unexpected exception setting an invalid CORBA priority\n"));
          result = -1;
        }
    }
  catch (const CORBA::Exception & ex)
    {
      ex._tao_print_exception ("ERROR: Unexpected exception ");
      result = -1;
    }
  catch (...)
    {
      ACE_DEBUG ((LM_DEBUG, "ERROR: Unknown exception\n"));
      result = -1;
    }

  return result;
}