diff --git a/ridlbe/c++11/templates/cli/hdr/bitset.erb b/ridlbe/c++11/templates/cli/hdr/bitset.erb index 66d08f72..89a00047 100644 --- a/ridlbe/c++11/templates/cli/hdr/bitset.erb +++ b/ridlbe/c++11/templates/cli/hdr/bitset.erb @@ -27,6 +27,18 @@ public: % end %end +%# Add base class support + bool operator== (const <%= cxxname %> &rhs) const { return +%_ms = bitfields.dup.find_all {|bitf| !bitf.cxxname.empty? } +%unless _ms.empty? +% while !_ms.empty? +% _m = _ms.shift + (this->_taox11_<%= cxxname.downcase %>.<%= _m.cxxname %> == rhs._taox11_<%= cxxname.downcase %>.<%= _m.cxxname %>)<%= _ms.empty? ? ';' : '&&' %> +% end +%end + }; + bool operator!= (const <%= cxxname %> &rhs) const { return !this->operator== (rhs);}; + %bitfields.find_all {|bitf| !bitf.cxxname.empty? }.each do |_m| inline void <%= _m.cxxname %> (<%= _m.cxx_in_type %> _x11_<%= _m.cxxname %>) { this->_taox11_<%= cxxname.downcase %>.<%= _m.cxxname %> = _x11_<%= _m.cxxname %>; } inline <%= _m.cxx_in_type %> <%= _m.cxxname %> () const { return this->_taox11_<%= cxxname.downcase %>.<%= _m.cxxname %>; } @@ -40,7 +52,7 @@ private: { %bitfields.each do |bitfield| /// @copydoc <%= bitfield.doc_scoped_name %> - <%= bitfield.cxx_member_type %> <%= bitfield.cxxname %> : <%= bitfield.bits %>; + <%= bitfield.cxx_member_type %> <%= bitfield.cxxname %> : <%= bitfield.bits %><%= bitfield.cxxname.empty? ? '' : ' {}' %>; %end } _taox11_<%= cxxname.downcase %>; }; // <%= cxxname %> diff --git a/tests/idl4/bitset/client.cpp b/tests/idl4/bitset/client.cpp index 36565082..24c5ba2a 100644 --- a/tests/idl4/bitset/client.cpp +++ b/tests/idl4/bitset/client.cpp @@ -10,12 +10,76 @@ #include "testC.h" #include "testlib/taox11_testlog.h" -int main (int /*argc*/, char* /*argv*/[]) +int main (int argc, char* argv[]) { + int error_count = 0; + MyBitset1 mbs1; // Just compilation test TAOX11_TEST_INFO << "mbs1: " << mbs1 << std::endl; - return 0; + 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; + + MyBitset1 sin1 {}; + MyBitset1 sinout1 {}; + MyBitset1 sout1 {}; + + TAOX11_TEST_DEBUG << "Sending MyBitset1 sin: " << sin1 << " sinout: " << sinout1 << std::endl; + MyBitset1 const sret1 = foo->test_mybitset1 (sin1, sinout1, sout1); + if (sout1 != sin1) + { + TAOX11_TEST_ERROR << "ERROR: sout1<" << sout1 << "> != sin1<" << sin1 << ">" << std::endl; + ++error_count; + } + if (sinout1 != sin1) + { + TAOX11_TEST_ERROR << "ERROR: sinout1<" << sinout1 << "> != sin<" << sin1 << ">" << std::endl; + ++error_count; + } + TAOX11_TEST_DEBUG << "Received MyBitset1 sret1: " << sret1 << " sinout1: " << sinout1 << " sout1: " << sout1 << std::endl; + + 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; + ++error_count; + } + catch (const std::exception& e) + { + TAOX11_TEST_ERROR << "main - ERROR - Unexpected exception caught: " << e << std::endl; + ++error_count; + } + return error_count; } diff --git a/tests/idl4/bitset/foo.cpp b/tests/idl4/bitset/foo.cpp new file mode 100644 index 00000000..4c4d88d8 --- /dev/null +++ b/tests/idl4/bitset/foo.cpp @@ -0,0 +1,58 @@ +/** + * @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)) +{ +} + +MyBitset1 +Foo::test_mybitset1 (const MyBitset1 & sin, MyBitset1 & sinout, MyBitset1 & sout) +{ + sout = sin; + sinout = sin; + MyBitset1 sret = sin; + return sret; +} + +MyBitset2 +Foo::test_mybitset2 (const MyBitset2 & sin, MyBitset2 & sinout, MyBitset2 & sout) +{ + sout = sin; + sinout = sin; + MyBitset2 sret = sin; + return sret; +} + +MyBitset3 +Foo::test_mybitset3 (const MyBitset3 & sin, MyBitset3 & sinout, MyBitset3 & sout) +{ + sout = sin; + sinout = sin; + MyBitset3 sret = sin; + return sret; +} + +MyBitset4 +Foo::test_mybitset4 (const MyBitset4 & sin, MyBitset4 & sinout, MyBitset4 & sout) +{ + sout = sin; + sinout = sin; + MyBitset4 sret = sin; + return sret; +} + +void +Foo::shutdown () +{ + this->orb_->shutdown (false); +} diff --git a/tests/idl4/bitset/foo.h b/tests/idl4/bitset/foo.h new file mode 100644 index 00000000..aeb3ce59 --- /dev/null +++ b/tests/idl4/bitset/foo.h @@ -0,0 +1,36 @@ +/** + * @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 + MyBitset1 test_mybitset1 (const MyBitset1 & sin, MyBitset1 & sinout, MyBitset1 & sout) override; + MyBitset2 test_mybitset2 (const MyBitset2 & sin, MyBitset2 & sinout, MyBitset2 & sout) override; + MyBitset3 test_mybitset3 (const MyBitset3 & sin, MyBitset3 & sinout, MyBitset3 & sout) override; + MyBitset4 test_mybitset4 (const MyBitset4 & sin, MyBitset4 & sinout, MyBitset4 & 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/bitset/run_test.pl b/tests/idl4/bitset/run_test.pl index 1a1bcc10..4dce5db5 100755 --- a/tests/idl4/bitset/run_test.pl +++ b/tests/idl4/bitset/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/bitset/server.cpp b/tests/idl4/bitset/server.cpp new file mode 100644 index 00000000..c16ce17c --- /dev/null +++ b/tests/idl4/bitset/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/bitset/test.mpc b/tests/idl4/bitset/test.mpc index a68df472..e3af2857 100644 --- a/tests/idl4/bitset/test.mpc +++ b/tests/idl4/bitset/test.mpc @@ -18,3 +18,14 @@ project(*bitset_client): taox11_client { } } +project(*bitset_gen_server): taox11_server { + after += *bitset_gen_idl + Source_Files { + foo.cpp + server.cpp + } + Source_Files { + testC.cpp + testS.cpp + } +}