Skip to content

Commit

Permalink
Extend bitset support and test
Browse files Browse the repository at this point in the history
    * tests/idl4/bitset/foo.cpp:
    * tests/idl4/bitset/foo.h:
    * tests/idl4/bitset/server.cpp:
      Added.

    * ridlbe/c++11/templates/cli/hdr/bitset.erb:
    * tests/idl4/bitset/client.cpp:
    * tests/idl4/bitset/run_test.pl:
    * tests/idl4/bitset/test.mpc:
  • Loading branch information
jwillemsen committed Nov 22, 2024
1 parent 5f0d3ff commit 0ca98e5
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 11 deletions.
14 changes: 13 additions & 1 deletion ridlbe/c++11/templates/cli/hdr/bitset.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>; }
Expand All @@ -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 %>
Expand Down
68 changes: 66 additions & 2 deletions tests/idl4/bitset/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CORBA::ORB>::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;

Check warning on line 29 in tests/idl4/bitset/client.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/client.cpp#L28-L29

Added lines #L28 - L29 were not covered by tests
}

IDL::traits<CORBA::Object>::ref_type obj = _orb->string_to_object ("file://test.ior");

if (!obj)
{
TAOX11_TEST_ERROR << "ERROR: string_to_object(<ior>) returned null reference." << std::endl;
return 1;

Check warning on line 37 in tests/idl4/bitset/client.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/client.cpp#L36-L37

Added lines #L36 - L37 were not covered by tests
}

TAOX11_TEST_DEBUG << "retrieved object reference" << std::endl;

IDL::traits<Test::Foo>::ref_type foo = IDL::traits<Test::Foo>::narrow (obj);

if (!foo)
{
TAOX11_TEST_ERROR << "ERROR: IDL::traits<Test::Foo>::narrow (obj) returned null object." << std::endl;
return 1;

Check warning on line 47 in tests/idl4/bitset/client.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/client.cpp#L46-L47

Added lines #L46 - L47 were not covered by tests
}
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;

Check warning on line 60 in tests/idl4/bitset/client.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/client.cpp#L59-L60

Added lines #L59 - L60 were not covered by tests
}
if (sinout1 != sin1)
{
TAOX11_TEST_ERROR << "ERROR: sinout1<" << sinout1 << "> != sin<" << sin1 << ">" << std::endl;
++error_count;

Check warning on line 65 in tests/idl4/bitset/client.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/client.cpp#L64-L65

Added lines #L64 - L65 were not covered by tests
}
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)

Check warning on line 73 in tests/idl4/bitset/client.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/client.cpp#L73

Added line #L73 was not covered by tests
{
TAOX11_TEST_ERROR << "main - ERROR - Unexpected CORBA::BAD_PARAM exception caught"
<< e << std::endl;
++error_count;

Check warning on line 77 in tests/idl4/bitset/client.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/client.cpp#L75-L77

Added lines #L75 - L77 were not covered by tests
}
catch (const std::exception& e)

Check warning on line 79 in tests/idl4/bitset/client.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/client.cpp#L79

Added line #L79 was not covered by tests
{
TAOX11_TEST_ERROR << "main - ERROR - Unexpected exception caught: " << e << std::endl;
++error_count;

Check warning on line 82 in tests/idl4/bitset/client.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/client.cpp#L81-L82

Added lines #L81 - L82 were not covered by tests
}
return error_count;
}
58 changes: 58 additions & 0 deletions tests/idl4/bitset/foo.cpp
Original file line number Diff line number Diff line change
@@ -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<CORBA::ORB>::ref_type orb,
IDL::traits<PortableServer::POA>::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)

Check warning on line 28 in tests/idl4/bitset/foo.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/foo.cpp#L28

Added line #L28 was not covered by tests
{
sout = sin;
sinout = sin;
MyBitset2 sret = sin;
return sret;

Check warning on line 33 in tests/idl4/bitset/foo.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/foo.cpp#L30-L33

Added lines #L30 - L33 were not covered by tests
}

MyBitset3
Foo::test_mybitset3 (const MyBitset3 & sin, MyBitset3 & sinout, MyBitset3 & sout)

Check warning on line 37 in tests/idl4/bitset/foo.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/foo.cpp#L37

Added line #L37 was not covered by tests
{
sout = sin;
sinout = sin;
MyBitset3 sret = sin;
return sret;

Check warning on line 42 in tests/idl4/bitset/foo.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/foo.cpp#L39-L42

Added lines #L39 - L42 were not covered by tests
}

MyBitset4
Foo::test_mybitset4 (const MyBitset4 & sin, MyBitset4 & sinout, MyBitset4 & sout)

Check warning on line 46 in tests/idl4/bitset/foo.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/foo.cpp#L46

Added line #L46 was not covered by tests
{
sout = sin;
sinout = sin;
MyBitset4 sret = sin;
return sret;

Check warning on line 51 in tests/idl4/bitset/foo.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/foo.cpp#L48-L51

Added lines #L48 - L51 were not covered by tests
}

void
Foo::shutdown ()
{
this->orb_->shutdown (false);
}
36 changes: 36 additions & 0 deletions tests/idl4/bitset/foo.h
Original file line number Diff line number Diff line change
@@ -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<Test::Foo>::base_type
{
public:
/// Constructor
Foo (IDL::traits<CORBA::ORB>::ref_type orb,
IDL::traits<PortableServer::POA>::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<CORBA::ORB>::ref_type orb_;
/// Use a POA reference to activate the references to
// the template module interface.
IDL::traits<PortableServer::POA>::ref_type poa_;
};

#endif /* FOO_H */
63 changes: 55 additions & 8 deletions tests/idl4/bitset/run_test.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#---------------------------------------------------------------------
# @file run_test.pl
# @author Marcel Smit
# @author Johnny Willemsen
#
# @copyright Copyright (c) Remedy IT Expertise BV
#---------------------------------------------------------------------
Expand All @@ -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;
110 changes: 110 additions & 0 deletions tests/idl4/bitset/server.cpp
Original file line number Diff line number Diff line change
@@ -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 <fstream>

int
main(int argc, ACE_TCHAR *argv[])
{
try
{
IDL::traits<CORBA::ORB>::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;

Check warning on line 22 in tests/idl4/bitset/server.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/server.cpp#L21-L22

Added lines #L21 - L22 were not covered by tests
}

IDL::traits<CORBA::Object>::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;

Check warning on line 30 in tests/idl4/bitset/server.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/server.cpp#L29-L30

Added lines #L29 - L30 were not covered by tests
}

TAOX11_TEST_DEBUG << "retrieved RootPOA object reference" << std::endl;

IDL::traits<PortableServer::POA>::ref_type root_poa = IDL::traits<PortableServer::POA>::narrow (obj);

if (!root_poa)
{
TAOX11_TEST_ERROR << "ERROR: IDL::traits<PortableServer::POA>::narrow (obj) returned null object." << std::endl;
return 1;

Check warning on line 40 in tests/idl4/bitset/server.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/server.cpp#L39-L40

Added lines #L39 - L40 were not covered by tests
}

TAOX11_TEST_DEBUG << "narrowed POA interface" << std::endl;

IDL::traits<PortableServer::POAManager>::ref_type poaman = root_poa->the_POAManager ();

if (!poaman)
{
TAOX11_TEST_ERROR << "ERROR: root_poa->the_POAManager () returned null object." << std::endl;
return 1;

Check warning on line 50 in tests/idl4/bitset/server.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/server.cpp#L49-L50

Added lines #L49 - L50 were not covered by tests
}

CORBA::servant_traits<Test::Foo>::ref_type foo_impl = CORBA::make_reference<Foo> (_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<CORBA::Object>::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;

Check warning on line 66 in tests/idl4/bitset/server.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/server.cpp#L65-L66

Added lines #L65 - L66 were not covered by tests
}

IDL::traits<Test::Foo>::ref_type foo = IDL::traits<Test::Foo>::narrow (foo_obj);

if (foo == nullptr)
{
TAOX11_TEST_ERROR << "ERROR: IDL::traits<Test::Foo>::narrow (foo_obj) returned null reference." << std::endl;
return 1;

Check warning on line 74 in tests/idl4/bitset/server.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/server.cpp#L73-L74

Added lines #L73 - L74 were not covered by tests
}

std::string ior = _orb->object_to_string (foo);

// Output the IOR to the <ior_output_file>
std::ofstream fos("test.ior");
if (!fos)
{
TAOX11_TEST_ERROR << "ERROR: failed to open file 'test.ior'" << std::endl;
return 1;

Check warning on line 84 in tests/idl4/bitset/server.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/server.cpp#L83-L84

Added lines #L83 - L84 were not covered by tests
}
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)

Check warning on line 103 in tests/idl4/bitset/server.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/server.cpp#L103

Added line #L103 was not covered by tests
{
TAOX11_TEST_ERROR << "exception caught: " << e << std::endl;
return 1;

Check warning on line 106 in tests/idl4/bitset/server.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/bitset/server.cpp#L105-L106

Added lines #L105 - L106 were not covered by tests
}

return 0;
}
Loading

0 comments on commit 0ca98e5

Please sign in to comment.