summaryrefslogtreecommitdiff
path: root/CIAO/tests/IDL3/Events/Any/main.cpp
blob: 77551725735cf61ec814909dcb14becdc0243443 (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
// $Id$

#include "EventAnyC.h"
#include "ace/Get_Opt.h"

void
insert_into_any (CORBA::Any& any, Components::EventBase* vb)
{
  any <<= vb;
}

void
debug_msg (const char *msg)
{
  ACE_ERROR ((LM_ERROR, "Error: %s\n", msg));
}

int
main (int argc, char *argv[])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "");
      StringMsg_init *StringMsg_factory = new StringMsg_init;

      orb->register_value_factory (StringMsg_factory->tao_repository_id (),
                                   StringMsg_factory);
      StringMsg_factory->_remove_ref (); // release ownership

      const char *test_str = "a message";

      StringMsg_var ev = new OBV_StringMsg;
      ev->str_msg (test_str);

      CORBA::Any in_any;
      insert_into_any (in_any, ev.in ());

      TAO_OutputCDR out;
      CORBA::Boolean good = out << in_any;

      if (!good)
        {
          debug_msg ("Any marshaling failed");
          return -1;
        }

      TAO_InputCDR in (out);
      CORBA::Any out_any;
      good = in >> out_any;

      if (!good)
        {
          debug_msg ("Any demarshaling failed");
          return -1;
        }

      StringMsg *ev_out = 0;
      good = out_any >>= ev_out;

      if (!good)
        {
          debug_msg ("Any extraction failed");
          return -1;
        }

      const char *result_str = ev_out->str_msg ();

      if (result_str == 0 || ACE_OS::strcmp (result_str, test_str) != 0)
        {
          debug_msg ("Extracted member string null or incorrect");
          return -1;
        }

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

  return 0;
}