summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_2503_Regression/client.cpp
blob: 7d5423d2d455476ea9759216d8982260a6f4af16 (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
// $Id$

#include "test_i.h"
#include "common.h"
#include "ace/Get_Opt.h"

void parse_args(int argc, ACE_TCHAR * argv[]);
void test_remote_calls(CORBA::ORB_ptr orb);
void test_colocated_calls(CORBA::ORB_ptr orb);

int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
  {
    ACE_DEBUG ((LM_DEBUG, "Starting client\n"));
    CORBA::ORB_var orb = initialize_orb_and_poa(argc, argv);

    parse_args(argc, argv);

    ACE_DEBUG ((LM_DEBUG, "Testing remote\n"));
    test_remote_calls(orb.in());

    ACE_DEBUG ((LM_DEBUG, "Testing colocated\n"));
    test_colocated_calls(orb.in());

    ACE_DEBUG ((LM_DEBUG, "Testing ready\n"));
  }
  catch(...)
  {
    report_exception();
    return 1;
  }

  return 0;
}

const ACE_TCHAR *ior_argument = ACE_TEXT("file://test.ior");
int niterations = 100;

void
parse_args (int argc, ACE_TCHAR *argv[])
{
  ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:i:"));
  int c;

  while ((c = get_opts ()) != -1)
  {
    switch (c)
      {
      case 'k':
        ior_argument = get_opts.opt_arg ();
        break;

      case 'i':
        niterations = ACE_OS::atoi (get_opts.opt_arg ());
        break;

      case '?':
      default:
        throw "Usage: [-k ior] [-i iteration_count]";
      }
  }
}

void test_impl(
    CORBA::ORB_ptr orb,
    ACE_TCHAR const * ior,
    bool shutdown)
{
  CORBA::Object_var object = orb->string_to_object(ior);
  Test_var test = Test::_narrow(object.in());

  if(CORBA::is_nil(test.in()))
  {
    throw "Nil reference after narrow";
  }

  for(int i = 0; i != niterations; ++i)
  {
    test->sendc_the_operation(AMI_TestHandler::_nil());
  }

  ACE_Time_Value wait_for_responses_interval(1, 0);
  orb->run(wait_for_responses_interval);

  if (shutdown)
    test->shutdown ();
}

void test_remote_calls(CORBA::ORB_ptr orb)
{
  test_impl(orb, ior_argument, true);
}

void test_colocated_calls(CORBA::ORB_ptr orb)
{
  test_i servant (orb);
  CORBA::String_var ior =
    servant.create_and_activate_server();

  test_impl(orb, ACE_TEXT_CHAR_TO_TCHAR(ior.in()), false);
}