|
| 1 | +#include "EchoC.h" |
| 2 | +#include "ace/Get_Opt.h" |
| 3 | +#include <cstring> |
| 4 | + |
| 5 | +const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior"); |
| 6 | + |
| 7 | +int parse_args (int argc, ACE_TCHAR *argv[]) |
| 8 | +{ |
| 9 | + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("f:")); |
| 10 | + int c; |
| 11 | + |
| 12 | + while ((c = get_opts ()) != -1) |
| 13 | + switch (c) |
| 14 | + { |
| 15 | + case 'f': |
| 16 | + ior = get_opts.opt_arg (); |
| 17 | + break; |
| 18 | + |
| 19 | + case '?': |
| 20 | + default: |
| 21 | + ACE_ERROR_RETURN ((LM_ERROR, |
| 22 | + "usage: %s " |
| 23 | + "-f <ior> " |
| 24 | + "\n", |
| 25 | + argv [0]), |
| 26 | + -1); |
| 27 | + } |
| 28 | + // Indicates successful parsing of the command line |
| 29 | + return 0; |
| 30 | +} |
| 31 | + |
| 32 | +int |
| 33 | +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) |
| 34 | +{ |
| 35 | + try |
| 36 | + { |
| 37 | + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); |
| 38 | + |
| 39 | + if (parse_args (argc, argv) != 0) |
| 40 | + return -1; |
| 41 | + |
| 42 | + CORBA::Object_var tmp = orb->string_to_object(ior); |
| 43 | + |
| 44 | + Echo_var echo = Echo::_narrow(tmp.in ()); |
| 45 | + |
| 46 | + if (CORBA::is_nil (echo.in ())) |
| 47 | + { |
| 48 | + ACE_ERROR_RETURN ((LM_ERROR, |
| 49 | + "Nil Echo reference <%s>\n", |
| 50 | + ior), |
| 51 | + -1); |
| 52 | + } |
| 53 | + |
| 54 | + Echo::List_var list = echo->return_list(); |
| 55 | + |
| 56 | + ACE_DEBUG ((LM_DEBUG, |
| 57 | + "Received list of length %u\n", |
| 58 | + list->length())); |
| 59 | + if (list->length() != 2) |
| 60 | + { |
| 61 | + ACE_ERROR_RETURN ((LM_ERROR, "Expected length 2\n"), -1); |
| 62 | + } |
| 63 | + const char* value = (*list)[0].in(); |
| 64 | + size_t length = std::strlen(value); |
| 65 | + ACE_DEBUG ((LM_DEBUG, |
| 66 | + "First element has length %u\n", |
| 67 | + length)); |
| 68 | + for (size_t n = 0; n < length; ++n) |
| 69 | + { |
| 70 | + if (value[n] != 'A') |
| 71 | + { |
| 72 | + ACE_ERROR_RETURN ((LM_ERROR, |
| 73 | + "Character at position %u should be 'A'," |
| 74 | + " but is '%c'\n", value[n]), -1); |
| 75 | + } |
| 76 | + } |
| 77 | + value = (*list)[1].in(); |
| 78 | + length = std::strlen(value); |
| 79 | + ACE_DEBUG ((LM_DEBUG, |
| 80 | + "Second element has length %u, value: <%C>\n", |
| 81 | + length, value)); |
| 82 | + if (strcmp(value, "Hello World") != 0) |
| 83 | + { |
| 84 | + ACE_ERROR_RETURN ((LM_ERROR, "Expected \"Hello World\""), -1); |
| 85 | + } |
| 86 | + |
| 87 | + Echo::WList_var wlist = echo->return_wlist(); |
| 88 | + |
| 89 | + ACE_DEBUG ((LM_DEBUG, |
| 90 | + "Received wide list of length %u\n", |
| 91 | + wlist->length())); |
| 92 | + if (wlist->length() != 2) |
| 93 | + { |
| 94 | + ACE_ERROR_RETURN ((LM_ERROR, "Expected length 2\n"), -1); |
| 95 | + } |
| 96 | + |
| 97 | + echo->shutdown (); |
| 98 | + orb->destroy (); |
| 99 | + } |
| 100 | + catch (const CORBA::Exception& ex) |
| 101 | + { |
| 102 | + ex._tao_print_exception ("Exception caught:"); |
| 103 | + return 1; |
| 104 | + } |
| 105 | + |
| 106 | + return 0; |
| 107 | +} |
0 commit comments