2 #include "FactoryC_impl.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
8 parse_args (int argc
, ACE_TCHAR
*argv
[])
10 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
13 while ((c
= get_opts ()) != -1)
17 ior
= get_opts
.optarg
;
22 ACE_ERROR_RETURN ((LM_ERROR
,
29 // Indicates successful parsing of the command line
34 no_factory (OBV_FactoryTest::Test_ptr test
)
39 // Calling this without a factory registred should give a marshal
40 // exception with minor code 1
41 OBV_FactoryTest::BaseValue_var base_value
=
42 test
->get_base_value ();
44 catch (const CORBA::MARSHAL
& ex
)
46 if ((ex
.minor() & 0xFFFU
) == 1)
51 catch (const CORBA::Exception
&)
58 "(%t) ERROR, no_factory failed\n"));
65 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
70 CORBA::ORB_init (argc
, argv
);
72 if (parse_args (argc
, argv
) != 0)
75 // Obtain reference to the object
76 CORBA::Object_var tmp
=
77 orb
->string_to_object(ior
);
79 OBV_FactoryTest::Test_var test
=
80 OBV_FactoryTest::Test::_narrow(tmp
.in ());
82 if (CORBA::is_nil (test
.in ()))
84 ACE_ERROR_RETURN ((LM_DEBUG
,
85 "Nil OBV_FactoryTest::Test reference <%s>\n",
90 // Check if we get the correct exception with minor code because no
91 // factory has been set.
92 if (!no_factory (test
.in ()))
96 OBV_FactoryTest::BaseValue_init
*base_factory
= 0;
97 ACE_NEW_RETURN (base_factory
,
98 OBV_FactoryTest::BaseValue_init
,
99 1); // supplied by mapping
101 orb
->register_value_factory (base_factory
->tao_repository_id (),
103 base_factory
->_remove_ref (); // release ownership
105 OBV_FactoryTest::Value1_init
*value1_factory
= 0;
106 ACE_NEW_RETURN (value1_factory
,
107 OBV_FactoryTest::Value1_init
,
108 1); // supplied by mapping
110 orb
->register_value_factory (value1_factory
->tao_repository_id (),
112 value1_factory
->_remove_ref ();
114 OBV_FactoryTest::Value2_init
*value2_factory
= 0;
115 ACE_NEW_RETURN (value2_factory
,
117 1); // custom implementation
119 orb
->register_value_factory (value2_factory
->tao_repository_id (),
121 value2_factory
->_remove_ref ();
123 // Now perform the test. I don't check return values.
124 // I just hope to get MARSHAL.
125 OBV_FactoryTest::BaseValue_var base_value
=
126 test
->get_base_value ();
128 OBV_FactoryTest::Value1_var value1
=
131 OBV_FactoryTest::Value2_var value2
=
136 value2
= value2_factory
->create_default (1);
138 OBV_FactoryTest::BaseValue::BV_Data data
;
141 value2
= value2_factory
->create (1, data
);
143 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - test finished\n"));
149 catch (const CORBA::Exception
& ex
)
151 ex
._tao_print_exception ("Exception caught:");