summaryrefslogtreecommitdiff
path: root/TAO/tests/Collocation_Exception_Test/Client_Task.cpp
blob: 52ce918d1286601530587e145918ef082a0a3189 (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

#include "Client_Task.h"

Client_Task::Client_Task (const ACE_TCHAR *ior,
                          CORBA::ORB_ptr corb,
                          ACE_Thread_Manager *thr_mgr)
  : ACE_Task_Base (thr_mgr)
    , input_ (ior)
    , corb_ (CORBA::ORB::_duplicate (corb))
{
}

void
Client_Task::test_system_exception (
  Test::Hello_ptr hello_ptr)
{
  try
    {
      hello_ptr->system_exception_test ();
    }
  catch (const CORBA::INTERNAL& )
    {
      ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Caught internal exception as expected\n"));
      // ignore
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "Unexpected exception caught in test_system_exception:");
      throw;
    }
}

void
Client_Task::test_user_exception_expected (
  Test::Hello_ptr hello_ptr)
{
  try
    {
      hello_ptr->user_exception_expected ();
    }
  catch (const ::Test::Hello::A& )
    {
      ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Caught user A exception as expected\n"));
      // ignore
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "Unexpected exception caught in test_user_exception_expected:");
      throw;
    }
}

void
Client_Task::test_user_exception_not_expected (
  Test::Hello_ptr hello_ptr)
{
  try
    {
      hello_ptr->user_exception_not_expected ();
    }
  catch (const CORBA::UNKNOWN& ex)
    {
      if ((ex.minor() & 0xFFFU) == 1)
        {
          ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Caught unknown exception as expected\n"));
        }
      else
        {
          ex._tao_print_exception (
            "Unexpected exception caught in user_exception_not_expected:");
          throw;
        }
      // ignore
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "Unexpected exception caught in user_exception_not_expected:");
      throw;
    }
}

int
Client_Task::svc (void)
{
  try
    {
      CORBA::Object_var tmp = this->corb_->string_to_object (input_);

      Test::Hello_var hello = Test::Hello::_narrow(tmp.in ());

      if (CORBA::is_nil (hello.in ()))
        {
          ACE_ERROR_RETURN ((LM_DEBUG,
                             "Nil Test::Hello reference <%s>\n",
                             input_),
                             1);
        }

      CORBA::String_var the_string = hello->get_string ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n",
                  the_string.in ()));

      this->test_system_exception (hello.in ());

      this->test_user_exception_expected (hello.in ());

      this->test_user_exception_not_expected (hello.in ());

      hello->shutdown ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;

}