diff --git a/ridlbe/c++11/templates/cli/src/enum_cdr.erb b/ridlbe/c++11/templates/cli/src/enum_cdr.erb index 1331512a..c5e6f606 100644 --- a/ridlbe/c++11/templates/cli/src/enum_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/enum_cdr.erb @@ -3,9 +3,11 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> &_tao_enumerator) { #if defined (ACE_HAS_CPP23) - return strm << std::to_underlying (_tao_enumerator); +% _arg = "std::underlying_type_t<#{scoped_cxxname}::_flags>(_tao_enumerator)" + return strm << <%= bitbound.cdr_from_fmt % _arg %>; #else - return strm << static_cast<<%= bitbound.cxx_type %>> (_tao_enumerator); +% _arg = "static_cast<#{bitbound.cxx_type}> (_tao_enumerator)" + return strm << <%= bitbound.cdr_from_fmt % _arg %>; #endif } diff --git a/tests/idl4/enum/client.cpp b/tests/idl4/enum/client.cpp index 9446f1bd..7e1514b2 100644 --- a/tests/idl4/enum/client.cpp +++ b/tests/idl4/enum/client.cpp @@ -11,7 +11,7 @@ #include "testlib/taox11_testlog.h" #include -int main (int /*argc*/, char* /*argv*/[]) +int main (int argc, char* argv[]) { // Just compilation test int retval {}; @@ -78,5 +78,165 @@ int main (int /*argc*/, char* /*argv*/[]) TAOX11_TEST_ERROR << "myValueEnum::myv6 is not 6 but " << static_cast(MyValueEnum::myv6) << std::endl; } + try + { + IDL::traits::ref_type _orb = CORBA::ORB_init (argc, argv); + + if (!_orb) + { + TAOX11_TEST_ERROR << "ERROR: CORBA::ORB_init (argc, argv) returned null ORB." << std::endl; + return 1; + } + + IDL::traits::ref_type obj = _orb->string_to_object ("file://test.ior"); + + if (!obj) + { + TAOX11_TEST_ERROR << "ERROR: string_to_object() returned null reference." << std::endl; + return 1; + } + + TAOX11_TEST_DEBUG << "retrieved object reference" << std::endl; + + IDL::traits::ref_type foo = IDL::traits::narrow (obj); + + if (!foo) + { + TAOX11_TEST_ERROR << "ERROR: IDL::traits::narrow (obj) returned null object." << std::endl; + return 1; + } + TAOX11_TEST_DEBUG << "narrowed Foo interface" << std::endl; + + MyEnum sin {MyEnum::flag0}; + MyEnum sinout {MyEnum::flag1}; + MyEnum sout {}; + + TAOX11_TEST_DEBUG << "Sending MyEnum sin: " << sin << " sinout: " << sinout << std::endl; + MyEnum const sret = foo->test_myenum (sin, sinout, sout); + if (sret != MyEnum::flag2) + { + TAOX11_TEST_ERROR << "ERROR: sret<" << sret << "> != sin<" << sin << ">" << std::endl; + ++retval; + } + if (sout != sin) + { + TAOX11_TEST_ERROR << "ERROR: sout<" << sout << "> != sin<" << sin << ">" << std::endl; + ++retval; + } + if (sinout != sin) + { + TAOX11_TEST_ERROR << "ERROR: sinout<" << sinout << "> != sin<" << sin << ">" << std::endl; + ++retval; + } + TAOX11_TEST_DEBUG << "Received MyEnum sret: " << sret << " sinout: " << sinout << " sout: " << sout << std::endl; + + MyEnumBound8 sin8 {MyEnumBound8::flag8_2}; + MyEnumBound8 sinout8 {}; + MyEnumBound8 sout8 {}; + + TAOX11_TEST_DEBUG << "Sending MyEnumBound8 sin: " << sin8 << " sinout: " << sinout8 << std::endl; + MyEnumBound8 const sret8 = foo->test_myenumbound8 (sin8, sinout8, sout8); + TAOX11_TEST_DEBUG << "Received MyEnumBound8 sret: " << sret8 << " sinout: " << sinout8 << " sout: " << sout8 << std::endl; + if (sret8 != sin8) + { + TAOX11_TEST_ERROR << "ERROR: sret8<" << sret8 << "> != sin8<" << sin8 << ">" << std::endl; + ++retval; + } + if (sout8 != sin8) + { + TAOX11_TEST_ERROR << "ERROR: sout<" << sout << "> != sin8<" << sin8 << ">" << std::endl; + ++retval; + } + if (sinout8 != sin8) + { + TAOX11_TEST_ERROR << "ERROR: sinout8<" << sinout8 << "> != sin8<" << sin8 << ">" << std::endl; + ++retval; + } + + MyEnumBound16 sin16 {MyEnumBound16::flag16_2}; + MyEnumBound16 sinout16 {}; + MyEnumBound16 sout16 {}; + + TAOX11_TEST_DEBUG << "Sending MyEnumBound16 sin: " << sin16 << " sinout: " << sinout16 << std::endl; + MyEnumBound16 const sret16 = foo->test_myenumbound16 (sin16, sinout16, sout16); + TAOX11_TEST_DEBUG << "Received MyEnumBound16 sret: " << sret16 << " sinout: " << sinout16 << " sout: " << sout16 << std::endl; + if (sret16 != sin16) + { + TAOX11_TEST_ERROR << "ERROR: sret16<" << sret16 << "> != sin16<" << sin16 << ">" << std::endl; + ++retval; + } + if (sout16 != sin16) + { + TAOX11_TEST_ERROR << "ERROR: sout<" << sout << "> != sin16<" << sin16 << ">" << std::endl; + ++retval; + } + if (sinout16 != sin16) + { + TAOX11_TEST_ERROR << "ERROR: sinout16<" << sinout16 << "> != sin16<" << sin16 << ">" << std::endl; + ++retval; + } + + MyEnumBound32 sin32 {MyEnumBound32::flag32_2}; + MyEnumBound32 sinout32 {}; + MyEnumBound32 sout32 {}; + + TAOX11_TEST_DEBUG << "Sending MyEnumBound32 sin: " << sin32 << " sinout: " << sinout32 << std::endl; + MyEnumBound32 const sret32 = foo->test_myenumbound32 (sin32, sinout32, sout32); + TAOX11_TEST_DEBUG << "Received MyEnumBound32 sret: " << sret32 << " sinout: " << sinout32 << " sout: " << sout32 << std::endl; + if (sret32 != sin32) + { + TAOX11_TEST_ERROR << "ERROR: sret32<" << sret32 << "> != sin32<" << sin32 << ">" << std::endl; + ++retval; + } + if (sout32 != sin32) + { + TAOX11_TEST_ERROR << "ERROR: sout<" << sout << "> != sin32<" << sin32 << ">" << std::endl; + ++retval; + } + if (sinout32 != sin32) + { + TAOX11_TEST_ERROR << "ERROR: sinout32<" << sinout32 << "> != sin32<" << sin32 << ">" << std::endl; + ++retval; + } + + MyValueEnum sinve {MyValueEnum::myv4}; + MyValueEnum sinoutve {}; + MyValueEnum soutve {}; + + TAOX11_TEST_DEBUG << "Sending MyValueEnum sin: " << sinve << " sinout: " << sinoutve << std::endl; + MyValueEnum const sretve = foo->test_myvalueenum (sinve, sinoutve, soutve); + TAOX11_TEST_DEBUG << "Received MyValueEnum sret: " << sretve << " sinout: " << sinoutve << " sout: " << soutve << std::endl; + if (sretve != sinve) + { + TAOX11_TEST_ERROR << "ERROR: sretve<" << sretve << "> != sinve<" << sinve << ">" << std::endl; + ++retval; + } + if (soutve != sinve) + { + TAOX11_TEST_ERROR << "ERROR: sout<" << sout << "> != sinve<" << sinve << ">" << std::endl; + ++retval; + } + if (sinoutve != sinve) + { + TAOX11_TEST_ERROR << "ERROR: sinoutve<" << sinoutve << "> != sinve<" << sinve << ">" << std::endl; + ++retval; + } + + TAOX11_TEST_DEBUG << "shutting down..." << std::endl; + foo->shutdown (); + _orb->destroy (); + } + catch (const CORBA::BAD_PARAM& e) + { + TAOX11_TEST_ERROR << "main - ERROR - Unexpected CORBA::BAD_PARAM exception caught" + << e << std::endl; + ++retval; + } + catch (const std::exception& e) + { + TAOX11_TEST_ERROR << "main - ERROR - Unexpected exception caught: " << e << std::endl; + ++retval; + } + return retval; } diff --git a/tests/idl4/enum/foo.cpp b/tests/idl4/enum/foo.cpp new file mode 100644 index 00000000..834f8da0 --- /dev/null +++ b/tests/idl4/enum/foo.cpp @@ -0,0 +1,112 @@ +/** + * @file foo.cpp + * @author Johnny Willemsen + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ +#include "foo.h" + +#include "testlib/taox11_testlog.h" + +Foo::Foo (IDL::traits::ref_type orb, + IDL::traits::ref_type poa) + : orb_ (std::move(orb)) + , poa_ (std::move(poa)) +{ +} + +MyEnum +Foo::test_myenum (MyEnum sin, + MyEnum & sinout, + MyEnum & sout) +{ + if (sin != MyEnum::flag0) + { + TAOX11_TEST_ERROR << "ERROR: test_myenum: Received incorrect sin<" << sin << ">" << std::endl; + } + else + { + TAOX11_TEST_DEBUG << "test_myenum: Received sin<" << sin << ">" << std::endl; + } + if (sinout != MyEnum::flag1) + { + TAOX11_TEST_ERROR << "ERROR: test_myenum: Received incorrect sinout<" << sinout << ">" << std::endl; + } + else + { + TAOX11_TEST_DEBUG << "test_myenum: Received sinout<" << sinout << ">" << std::endl; + } + sout = sin; + if (sout != MyEnum::flag0) + { + TAOX11_TEST_ERROR << "ERROR: test_myenum: Setting sout failed <" << sout << ">" << std::endl; + } + sinout = sin; + return MyEnum::flag2; +} + +MyEnumBound8 +Foo::test_myenumbound8 (MyEnumBound8 sin, + MyEnumBound8 & sinout, + MyEnumBound8 & sout) +{ + if (sin != MyEnumBound8::flag8_2) + { + TAOX11_TEST_ERROR << "ERROR: MyEnumBound8: Received incorrect sin<" << sin << ">" << std::endl; + } + sout = sin; + sinout = sin; + MyEnumBound8 sret = sin; + return sret; +} + +MyEnumBound16 +Foo::test_myenumbound16 (MyEnumBound16 sin, + MyEnumBound16 & sinout, + MyEnumBound16 & sout) +{ + if (sin != MyEnumBound16::flag16_2) + { + TAOX11_TEST_ERROR << "ERROR: MyEnumBound16: Received incorrect sin<" << sin << ">" << std::endl; + } + sout = sin; + sinout = sin; + MyEnumBound16 sret = sin; + return sret; +} + +MyEnumBound32 +Foo::test_myenumbound32 (MyEnumBound32 sin, + MyEnumBound32 & sinout, + MyEnumBound32 & sout) +{ + if (sin != MyEnumBound32::flag32_2) + { + TAOX11_TEST_ERROR << "ERROR: MyEnumBound32: Received incorrect sin<" << sin << ">" << std::endl; + } + sout = sin; + sinout = sin; + MyEnumBound32 sret = sin; + return sret; +} + +MyValueEnum +Foo::test_myvalueenum (MyValueEnum sin, + MyValueEnum & sinout, + MyValueEnum & sout) +{ + if (sin != MyValueEnum::myv4) + { + TAOX11_TEST_ERROR << "ERROR: MyValueEnum: Received incorrect sin<" << sin << ">" << std::endl; + } + sout = sin; + sinout = sin; + MyValueEnum sret = sin; + return sret; +} + +void +Foo::shutdown () +{ + this->orb_->shutdown (false); +} diff --git a/tests/idl4/enum/foo.h b/tests/idl4/enum/foo.h new file mode 100644 index 00000000..2c31844a --- /dev/null +++ b/tests/idl4/enum/foo.h @@ -0,0 +1,37 @@ +/** + * @file foo.h + * @author Johnny Willemsen + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ +#ifndef FOO_H +#define FOO_H + +#include "testS.h" + +class Foo final + : public virtual CORBA::servant_traits::base_type +{ +public: + /// Constructor + Foo (IDL::traits::ref_type orb, + IDL::traits::ref_type poa); + + // = The skeleton methods + MyEnum test_myenum (MyEnum sin, MyEnum & sinout, MyEnum & sout) override; + MyEnumBound8 test_myenumbound8 (MyEnumBound8 sin, MyEnumBound8 & sinout, MyEnumBound8 & sout) override; + MyEnumBound16 test_myenumbound16 (MyEnumBound16 sin, MyEnumBound16 & sinout, MyEnumBound16 & sout) override; + MyEnumBound32 test_myenumbound32 (MyEnumBound32 sin, MyEnumBound32 & sinout, MyEnumBound32 & sout) override; + MyValueEnum test_myvalueenum (const MyValueEnum sin, MyValueEnum & sinout, MyValueEnum & sout) override; + + void shutdown () override; + +private: + /// Use an ORB reference shutdown the server. + IDL::traits::ref_type orb_; + /// Use a POA reference to activate the references to + // the template module interface. + IDL::traits::ref_type poa_; +}; + +#endif /* FOO_H */ diff --git a/tests/idl4/enum/run_test.pl b/tests/idl4/enum/run_test.pl index 1a1bcc10..4dce5db5 100755 --- a/tests/idl4/enum/run_test.pl +++ b/tests/idl4/enum/run_test.pl @@ -1,6 +1,6 @@ #--------------------------------------------------------------------- # @file run_test.pl -# @author Marcel Smit +# @author Johnny Willemsen # # @copyright Copyright (c) Remedy IT Expertise BV #--------------------------------------------------------------------- @@ -13,19 +13,66 @@ use lib "$ENV{ACE_ROOT}/bin"; use PerlACE::TestTarget; -my $target = PerlACE::TestTarget::create_target(2) || die "Create target 2 failed\n"; +my $status = 0; +my $debug_level = '0'; -$status = 0; +foreach $i (@ARGV) { + if ($i eq '-debug') { + $debug_level = '10'; + } +} + +my $server = PerlACE::TestTarget::create_target(2) || die "Create target 2 failed\n"; +my $client = PerlACE::TestTarget::create_target(3) || die "Create target 3 failed\n"; + +my $iorbase = "test.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +my $client_iorfile = $client->LocalFile ($iorbase); +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +my $SV = $server->CreateProcess ("server", "-ORBdebuglevel $debug_level -o $server_iorfile"); +my $CL = $client->CreateProcess ("client", "-ORBdebuglevel $debug_level -k file://$client_iorfile"); +my $server_status = $SV->Spawn (); + +if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; +} + +if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +if ($server->GetFile ($iorbase) == -1) { + print STDERR "ERROR: cannot retrieve file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} +if ($client->PutFile ($iorbase) == -1) { + print STDERR "ERROR: cannot set file <$client_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} -$SV = $target->CreateProcess ("client"); +my $client_status = $CL->SpawnWaitKill ($client->ProcessStartWaitInterval()); + +if ($client_status != 0) { + print STDERR "ERROR: client returned $client_status\n"; + $status = 1; +} -$server = $SV->SpawnWaitKill ($target->ProcessStartWaitInterval()); +$server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); -if ($server != 0) { - print STDERR "ERROR: client returned $server\n"; +if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; $status = 1; } -$target->GetStderrLog(); +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); exit $status; diff --git a/tests/idl4/enum/server.cpp b/tests/idl4/enum/server.cpp new file mode 100644 index 00000000..c16ce17c --- /dev/null +++ b/tests/idl4/enum/server.cpp @@ -0,0 +1,110 @@ +/** + * @file server.cpp + * @author Johnny Willemsen + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ + +#include "foo.h" +#include "testlib/taox11_testlog.h" +#include + +int +main(int argc, ACE_TCHAR *argv[]) +{ + try + { + IDL::traits::ref_type _orb = CORBA::ORB_init (argc, argv); + + if (_orb == nullptr) + { + TAOX11_TEST_ERROR << "ERROR: CORBA::ORB_init (argc, argv) returned null ORB." << std::endl; + return 1; + } + + IDL::traits::ref_type obj = _orb->resolve_initial_references ("RootPOA"); + + if (!obj) + { + TAOX11_TEST_ERROR << "ERROR: resolve_initial_references (\"RootPOA\") returned null reference." << std::endl; + return 1; + } + + TAOX11_TEST_DEBUG << "retrieved RootPOA object reference" << std::endl; + + IDL::traits::ref_type root_poa = IDL::traits::narrow (obj); + + if (!root_poa) + { + TAOX11_TEST_ERROR << "ERROR: IDL::traits::narrow (obj) returned null object." << std::endl; + return 1; + } + + TAOX11_TEST_DEBUG << "narrowed POA interface" << std::endl; + + IDL::traits::ref_type poaman = root_poa->the_POAManager (); + + if (!poaman) + { + TAOX11_TEST_ERROR << "ERROR: root_poa->the_POAManager () returned null object." << std::endl; + return 1; + } + + CORBA::servant_traits::ref_type foo_impl = CORBA::make_reference (_orb, root_poa); + + TAOX11_TEST_DEBUG << "created Foo servant" << std::endl; + + PortableServer::ObjectId id = root_poa->activate_object (foo_impl); + + TAOX11_TEST_DEBUG << "activated Foo servant" << std::endl; + + IDL::traits::ref_type foo_obj = root_poa->id_to_reference (id); + + if (foo_obj == nullptr) + { + TAOX11_TEST_ERROR << "ERROR: root_poa->id_to_reference (id) returned null reference." << std::endl; + return 1; + } + + IDL::traits::ref_type foo = IDL::traits::narrow (foo_obj); + + if (foo == nullptr) + { + TAOX11_TEST_ERROR << "ERROR: IDL::traits::narrow (foo_obj) returned null reference." << std::endl; + return 1; + } + + std::string ior = _orb->object_to_string (foo); + + // Output the IOR to the + std::ofstream fos("test.ior"); + if (!fos) + { + TAOX11_TEST_ERROR << "ERROR: failed to open file 'test.ior'" << std::endl; + return 1; + } + fos << ior; + fos.close (); + + TAOX11_TEST_DEBUG << "IOR for Foo servant written to 'test.ior' : " << ior << std::endl; + + poaman->activate (); + + TAOX11_TEST_DEBUG << "starting event loop" << std::endl; + + _orb->run (); + + TAOX11_TEST_DEBUG << "event loop finished" << std::endl; + + root_poa->destroy (true, true); + + _orb->destroy (); + } + catch (const std::exception& e) + { + TAOX11_TEST_ERROR << "exception caught: " << e << std::endl; + return 1; + } + + return 0; +} diff --git a/tests/idl4/enum/test.idl b/tests/idl4/enum/test.idl index 91d24d07..9f179092 100644 --- a/tests/idl4/enum/test.idl +++ b/tests/idl4/enum/test.idl @@ -37,3 +37,18 @@ enum MyValueEnum { @value(5) myv5, @value(6) myv6 }; + +module Test +{ + interface Foo + { + MyEnum test_myenum (in MyEnum sin, inout MyEnum sinout, out MyEnum sout); + MyEnumBound8 test_myenumbound8 (in MyEnumBound8 sin, inout MyEnumBound8 sinout, out MyEnumBound8 sout); + MyEnumBound16 test_myenumbound16 (in MyEnumBound16 sin, inout MyEnumBound16 sinout, out MyEnumBound16 sout); + MyEnumBound32 test_myenumbound32 (in MyEnumBound32 sin, inout MyEnumBound32 sinout, out MyEnumBound32 sout); + MyValueEnum test_myvalueenum (in MyValueEnum sin, inout MyValueEnum sinout, out MyValueEnum sout); + + /// A method to shutdown the ORB + oneway void shutdown (); + }; +}; diff --git a/tests/idl4/enum/test.mpc b/tests/idl4/enum/test.mpc index 336b600d..54831951 100644 --- a/tests/idl4/enum/test.mpc +++ b/tests/idl4/enum/test.mpc @@ -18,3 +18,14 @@ project(*idl4_enum_client): taox11_client { } } +project(*idl4_enum_gen_server): taox11_server { + after += *idl4_enum_gen_idl + Source_Files { + foo.cpp + server.cpp + } + Source_Files { + testC.cpp + testS.cpp + } +}