summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_2543_Regression/bug_2543_regression.cpp
blob: ba1e926aa440d6700d78754b1a97bcc04ff58cc1 (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
// $Id$

#include "TestC.h"
#include "tao/CodecFactory/CodecFactory.h"

ACE_RCSID (Bug_2543_Regression,
           bug_2543_regression,
           "$Id$")

int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
       CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

       orb->register_value_factory(
               Base::_tao_obv_static_repository_id(),
               new Base_init);
       orb->register_value_factory(
               Value::_tao_obv_static_repository_id(),
               new Value_init);

       CORBA::Object_var object =
               orb->resolve_initial_references("CodecFactory");

       IOP::CodecFactory_var codec_factory =
               IOP::CodecFactory::_narrow(object.in ());
       IOP::Encoding e = {IOP::ENCODING_CDR_ENCAPS,1,2};

       IOP::Codec_var codec = codec_factory->create_codec(e);

       CORBA::Any any_o;
       BaseSeq values;
       values.length(1);
       values[0] = new OBV_Value(1,"An instance of Value");
       any_o <<= values;
       any_o.type(_tc_BaseSeq);

       CORBA::OctetSeq_var bin = codec->encode(any_o);
       CORBA::Any_var any_n = codec->decode(bin.in ());

       const BaseSeq * out = 0;
       if (!(any_n.in () >>= out))
         {
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Error: extract out of any failed\n"),
                               1);
         }
       if (ACE_OS::strcmp( (*out)[0]->_tao_obv_repository_id(),
                          Value::_tao_obv_static_repository_id()) != 0)
         {
            ACE_ERROR_RETURN ((LM_ERROR, "Error: wrong type!\n"), 1);
         }

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

  return 0;
}