Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / ImplRepo / servers_interact_on_startup / client.cpp
blobd33667ecc5bd8c6a6c3a353f599b07afdc95f645
1 #include "TestC.h"
2 #include <iostream>
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_unistd.h"
6 int client_num = 0;
7 ACE_TCHAR *server_ior = 0;
8 bool expect_transient = false;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("ek:n:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'e':
20 expect_transient = true;
21 break;
23 case 'k':
24 server_ior = get_opts.opt_arg ();
25 break;
27 case 'n':
28 client_num = ACE_OS::atoi (get_opts.opt_arg ());
29 break;
31 case '?':
32 default:
33 ACE_ERROR_RETURN ((LM_ERROR,
34 ACE_TEXT ("usage: %s ")
35 ACE_TEXT ("-e ")
36 ACE_TEXT ("-k <server-ior> ")
37 ACE_TEXT ("\n"),
38 argv [0]),
39 -1);
41 // Indicates successful parsing of the command line
42 return 0;
45 int
46 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
48 try
50 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
52 if (parse_args (argc, argv) != 0)
53 return 1;
55 ACE_DEBUG ((LM_DEBUG,
56 ACE_TEXT ("(%P|%t|%T) Client %d sending request to %C\n"),
57 client_num, server_ior));
58 try
60 CORBA::Object_var obj =
61 orb->string_to_object (server_ior);
62 ACE_ASSERT (!CORBA::is_nil (obj.in ()));
63 Test_var test = Test::_narrow (obj.in());
64 ACE_ASSERT (!CORBA::is_nil (test.in()));
65 CORBA::Short n = test->get_server_num ();
66 ACE_DEBUG ((LM_DEBUG,
67 ACE_TEXT ("(%P|%t|%T) Client %d received reply from server %d\n"),
68 client_num, n));
70 catch (const CORBA::TRANSIENT &)
72 if (expect_transient)
74 ACE_DEBUG ((LM_DEBUG,
75 ACE_TEXT ("(%P|%t|%T) Client %d got expected transient exception\n"),
76 client_num));
78 else
80 ACE_DEBUG ((LM_DEBUG,
81 ACE_TEXT ("(%P|%t|%T) Client %d caught unexpected transent\n"),
82 client_num));
83 return -1;
86 return 0;
88 catch(const CORBA::Exception& ex)
90 ex._tao_print_exception (ACE_TEXT ("client:"));
93 return -1;