Skip to content

Commit

Permalink
Merge pull request #404 from jwillemsen/jwi-idl4enumtest
Browse files Browse the repository at this point in the history
Test and fix enum bit_bound/value annotations
  • Loading branch information
jwillemsen authored Oct 21, 2024
2 parents 8cded67 + 0db04ec commit cfe7abc
Show file tree
Hide file tree
Showing 8 changed files with 505 additions and 11 deletions.
6 changes: 4 additions & 2 deletions ridlbe/c++11/templates/cli/src/enum_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
162 changes: 161 additions & 1 deletion tests/idl4/enum/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "testlib/taox11_testlog.h"
#include <type_traits>

int main (int /*argc*/, char* /*argv*/[])
int main (int argc, char* argv[])
{
// Just compilation test
int retval {};
Expand Down Expand Up @@ -78,5 +78,165 @@ int main (int /*argc*/, char* /*argv*/[])
TAOX11_TEST_ERROR << "myValueEnum::myv6 is not 6 but " << static_cast<int32_t>(MyValueEnum::myv6) << std::endl;
}

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;
}

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;
}

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;
}
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;
}
112 changes: 112 additions & 0 deletions tests/idl4/enum/foo.cpp
Original file line number Diff line number Diff line change
@@ -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<CORBA::ORB>::ref_type orb,
IDL::traits<PortableServer::POA>::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);
}
37 changes: 37 additions & 0 deletions tests/idl4/enum/foo.h
Original file line number Diff line number Diff line change
@@ -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<Test::Foo>::base_type
{
public:
/// Constructor
Foo (IDL::traits<CORBA::ORB>::ref_type orb,
IDL::traits<PortableServer::POA>::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<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 */
Loading

0 comments on commit cfe7abc

Please sign in to comment.