Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / CodeSets / simple / client.cpp
blob6fdc8a8c1b007e7edd4681c98f431c8722f221af
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file client.cpp
7 * A simple client to demonstrate the use of codeset translation
9 * @author Phil Mesnier <mesnier_p@ociweb.com>
11 //=============================================================================
13 // IDL generated headers
14 #include "simpleC.h"
15 #include "ace/ace_wchar.h"
17 // FUZZ: disable check_for_streams_include
18 #include "ace/streams.h"
20 #include "ace/OS_NS_string.h"
21 #include "ace/Log_Msg.h"
22 #include "ace/Get_Opt.h"
24 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
26 int
27 parse_args (int argc, ACE_TCHAR *argv[])
29 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
30 int c;
32 while ((c = get_opts ()) != -1)
33 switch (c)
35 case 'k':
36 ior = get_opts.opt_arg ();
37 break;
39 case '?':
40 default:
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "usage: %s "
43 "-k <ior> "
44 "\n",
45 argv [0]),
46 -1);
48 // Indicates successful parsing of the command line
49 return 0;
52 wchar_t *
53 make_wstring (const char *str)
55 // Short circuit null pointer case
56 if (str == 0)
57 return 0;
59 size_t len = ACE_OS::strlen (str) + 1;
60 wchar_t *wstr = new wchar_t[len];
61 ACE_DEBUG ((LM_DEBUG,
62 "make_wstring: str = %C\n", str));
63 for (size_t i = 0; i < len; i++)
65 char *t = const_cast<char *> (str);
66 wstr[i] = static_cast<wchar_t> (*(t + i));
67 ACE_DEBUG ((LM_DEBUG,
68 "wstr[%d] = %d\n", i, (short)wstr[i]));
70 return wstr;
73 // ------------------------------------------------------------
74 // Client
75 // ------------------------------------------------------------
76 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
78 int error_count = 0;
80 try
82 // Init the orb
83 CORBA::ORB_var orb= CORBA::ORB_init (argc, argv);
85 // Get IOR from command line (or file)
86 if (parse_args (argc, argv) != 0)
87 return 1;
89 // The first arg should be the IOR
90 CORBA::Object_var object =
91 orb->string_to_object (ior);
93 // Get the server
94 simple_var server = simple::_narrow (object.in ());
96 const char *bare_string = "Hello World";
98 const char *any_string = "Any World";
99 CORBA::Any inarg;
100 inarg <<= any_string;
101 CORBA::Any_var outarg;
103 // Invoke the call.
104 CORBA::String_var reply =
105 server->op1 (bare_string,
106 inarg,
107 outarg.out ());
109 const char *any_reply;
110 outarg >>= any_reply;
112 ACE_DEBUG ((LM_DEBUG,
113 "Client sent %C, got %C\n", bare_string, reply.in ()) );
115 if (ACE_OS::strcmp (bare_string, reply.in ()) != 0)
117 ++error_count;
120 ACE_DEBUG ((LM_DEBUG,
121 "Client sent %C, got %C\n", any_string, any_reply) );
123 if (ACE_OS::strcmp (any_string, any_reply) != 0)
125 ++error_count;
127 #if defined (ACE_HAS_WCHAR)
128 wchar_t *wide_string = ACE_OS::strdup(ACE_TEXT_ALWAYS_WCHAR(ACE_TEXT ("Wide String")));
129 wchar_t *wide_reply = server->op2 (wide_string);
130 ACE_DEBUG ((LM_DEBUG,
131 "sent %W, got %W\n", wide_string, wide_reply));
133 ACE_OS::free (wide_string);
134 CORBA::wstring_free (wide_reply);
135 #endif /* ACE_HAS_WCHAR */
137 server->shutdown ();
139 orb->destroy ();
141 catch (const CORBA::Exception& ex)
143 ex._tao_print_exception ("Exception caught in client:");
144 return 1;
147 return error_count;