Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / OBV / Factory / client.cpp
blob3a2c472c964f4ccd379bea81bac13763be489fb8
1 #include "FactoryC.h"
2 #include "FactoryC_impl.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'k':
17 ior = get_opts.optarg;
18 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-k <ior> "
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 bool
34 no_factory (OBV_FactoryTest::Test_ptr test)
36 bool succeed = false;
37 try
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)
48 succeed = true;
51 catch (const CORBA::Exception&)
55 if (!succeed)
57 ACE_ERROR ((LM_ERROR,
58 "(%t) ERROR, no_factory failed\n"));
61 return succeed;
64 int
65 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
67 try
69 CORBA::ORB_var orb =
70 CORBA::ORB_init (argc, argv);
72 if (parse_args (argc, argv) != 0)
73 return 1;
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",
86 ior),
87 1);
90 // Check if we get the correct exception with minor code because no
91 // factory has been set.
92 if (!no_factory (test.in ()))
93 return 1;
95 // Create factories.
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 (),
102 base_factory);
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 (),
111 value1_factory);
112 value1_factory->_remove_ref ();
114 OBV_FactoryTest::Value2_init *value2_factory = 0;
115 ACE_NEW_RETURN (value2_factory,
116 Value2_init_impl,
117 1); // custom implementation
119 orb->register_value_factory (value2_factory->tao_repository_id (),
120 value2_factory);
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 =
129 test->get_value1 ();
131 OBV_FactoryTest::Value2_var value2 =
132 test->get_value2 ();
134 // Test factories.
136 value2 = value2_factory->create_default (1);
138 OBV_FactoryTest::BaseValue::BV_Data data;
139 data.value = 2;
141 value2 = value2_factory->create (1, data);
143 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - test finished\n"));
145 test->shutdown ();
147 orb->destroy ();
149 catch (const CORBA::Exception& ex)
151 ex._tao_print_exception ("Exception caught:");
152 return 1;
155 return 0;