Skip to content

Commit

Permalink
Merge pull request #304 from jwillemsen/jwi-idl4enumbitbound
Browse files Browse the repository at this point in the history
New IDL4 test for enum bit_bound
  • Loading branch information
jwillemsen authored Aug 6, 2023
2 parents aefebbc + d843760 commit 5d80389
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/taox11_tests.lst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ tests/idl4/bitset/run_test.pl:
tests/idl4/bitset/run_illegal_idl3_test.pl:
tests/idl4/bitmask/run_test.pl:
tests/idl4/bitmask/run_illegal_idl3_test.pl:
tests/idl4/enum/run_test.pl:
tests/idl4/explicit_ints/run_test.pl:
tests/idl4/explicit_ints/run_illegal_idl3_test.pl:
tests/idl4/illegal_idl/run_test.pl:
Expand Down
2 changes: 1 addition & 1 deletion ridlbe/c++11/templates/cli/hdr/enum.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// generated from <%= ridl_template_path %>
/// @copydoc <%= doc_scoped_name %>
enum class <%= cxxname %> : uint32_t
enum class <%= cxxname %> : <%= bitbound.cxx_type %>
{
<%= enumerators.collect {|e| "/// @copydoc #{doc_scoped_name}::#{e.name}\n #{e.cxxname}" }.join(",\n ") %>
};// <%= cxxname %>
Expand Down
6 changes: 6 additions & 0 deletions ridlbe/c++11/templates/cli/hdr/enum_idl_traits.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ template<>
struct traits <<%= scoped_cxxtype %>>
: IDL::common_byval_traits<<%= scoped_cxxtype %>>
{
/// Underlying type of the enum
using underlying_type = <%= bitbound.cxx_type %>;

/// bit_bound
using bit_bound = std::integral_constant<uint32_t, <%= bitbound_bits %>>;

template <typename OStrm_, typename Formatter = formatter<value_type, OStrm_>>
static inline OStrm_& write_on(OStrm_& os_, in_type val_, Formatter fmt_ = Formatter ())
{
Expand Down
4 changes: 2 additions & 2 deletions ridlbe/c++11/templates/cli/src/enum_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ TAO_CORBA::Boolean operator<< (
TAO_OutputCDR &strm,
const <%= scoped_cxxname %> &_tao_enumerator)
{
return strm << static_cast<uint32_t> (_tao_enumerator);
return strm << static_cast<<%= bitbound.cxx_type %>> (_tao_enumerator);
}

TAO_CORBA::Boolean operator>> (
TAO_InputCDR &strm,
<%= scoped_cxxname %> &_tao_enumerator)
{
uint32_t _tao_temp {};
<%= bitbound.cxx_type %> _tao_temp {};
bool const _tao_success = strm >> _tao_temp;

if (_tao_success)
Expand Down
3 changes: 3 additions & 0 deletions ridlbe/c++11/visitors/bitmask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def bitbound
node.bitbound
end

def bitbound_bits
node.bitbound_bits
end
# template mapping

map_template :bitmask, :bitmask
Expand Down
7 changes: 7 additions & 0 deletions ridlbe/c++11/visitors/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def enumerators
}
end

def bitbound
node.bitbound
end

def bitbound_bits
node.bitbound_bits
end
# template mapping

map_template :enum, :enum
Expand Down
56 changes: 56 additions & 0 deletions tests/idl4/enum/client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @file client.cpp
* @author Johnny Willemsen
*
* @brief CORBA C++11 client application
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

#include "testC.h"
#include "testlib/taox11_testlog.h"
#include <type_traits>

int main (int /*argc*/, char* /*argv*/[])
{
// Just compilation test

MyEnum my_bitenum;
X11_UNUSED_ARG(my_bitenum);

if (sizeof(uint8_t) != sizeof(MyEnumBound8))
{
TAOX11_TEST_ERROR << "Type of MyEnumBound8 is not uint8_t" << std::endl;
}
if (sizeof(uint16_t) != sizeof (MyEnumBound16))
{
TAOX11_TEST_ERROR << "Type of MyEnumBound16 is not uint16_t" << std::endl;
}
if (sizeof(uint32_t) != sizeof (MyEnumBound32))
{
TAOX11_TEST_ERROR << "Type of MyEnumBound32 is not uint32_t" << std::endl;
}
if (sizeof(uint32_t) != sizeof (MyEnum))
{
TAOX11_TEST_ERROR << "Type of MyEnum is not uint32_t" << std::endl;
}

if (IDL::traits<MyEnumBound8>::bit_bound::value != 8)
{
TAOX11_TEST_ERROR << "bit_bound traits MyEnumBound8 is 8" << std::endl;
}
if (IDL::traits<MyEnumBound16>::bit_bound::value != 16)
{
TAOX11_TEST_ERROR << "bit_bound traits MyEnumBound16 is 16" << std::endl;
}
if (IDL::traits<MyEnumBound32>::bit_bound::value != 32)
{
TAOX11_TEST_ERROR << "bit_bound traits MyEnumBound32 is 32" << std::endl;
}
if (IDL::traits<MyEnum>::bit_bound::value != 32)
{
TAOX11_TEST_ERROR << "bit_bound traits MyEnum is 32" << std::endl;
}

return 0;
}
31 changes: 31 additions & 0 deletions tests/idl4/enum/run_test.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#---------------------------------------------------------------------
# @file run_test.pl
# @author Marcel Smit
#
# @copyright Copyright (c) Remedy IT Expertise BV
#---------------------------------------------------------------------
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
& eval 'exec perl -S $0 $argv:q'
if 0;

# -*- perl -*-

use lib "$ENV{ACE_ROOT}/bin";
use PerlACE::TestTarget;

my $target = PerlACE::TestTarget::create_target(2) || die "Create target 2 failed\n";

$status = 0;

$SV = $target->CreateProcess ("client");

$server = $SV->SpawnWaitKill ($target->ProcessStartWaitInterval());

if ($server != 0) {
print STDERR "ERROR: const returned $server\n";
$status = 1;
}

$target->GetStderrLog();

exit $status;
33 changes: 33 additions & 0 deletions tests/idl4/enum/test.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @file test.idl
* @author Johnny Willemsen
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

enum MyEnum {
flag0,
flag1,
flag2
};

@bit_bound(8)
enum MyEnumBound8 {
flag8_1,
flag8_2,
flag8_3
};

@bit_bound(16)
enum MyEnumBound16 {
flag16_1,
flag16_2,
flag16_3
};

@bit_bound(32)
enum MyEnumBound32 {
flag32_1,
flag32_2,
flag32_3
};
20 changes: 20 additions & 0 deletions tests/idl4/enum/test.mpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// -*- MPC -*-

project(*idl4_enum_gen_idl): ridl_ostream_defaults {
IDL_Files {
test.idl
idlflags += --idl-version=4 -Scdr
}
custom_only = 1
}

project(*idl4_enum_client): taox11_client {
after += *idl4_enum_gen_idl
Source_Files {
client.cpp
}
Source_Files {
testC.cpp
}
}

15 changes: 15 additions & 0 deletions tests/idl4/illegal_idl/enum_bitbound_33.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @file enum_bitbound_33.idl
* @author Johnny Willemsen
*
* ridlc shall reject use of a enum with a bit_bound annotation with value 33
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

@bit_bound(33)
enum MyBitMask {
flag0,
flag1,
flag2
};
15 changes: 15 additions & 0 deletions tests/idl4/illegal_idl/enum_bitbound_missingvalue.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @file enum_bitbound_missingvalue.idl
* @author Johnny Willemsen
*
* ridlc shall reject use of a enum with a bit_bound annotation with no value
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

@bit_bound()
enum MyBitMask {
flag0,
flag1,
flag2
};
15 changes: 15 additions & 0 deletions tests/idl4/illegal_idl/enum_bitbound_negative.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @file enum_bitbound_negative.idl
* @author Johnny Willemsen
*
* ridlc shall reject use of a enum with a negative bit_bound value
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

@bit_bound(-1)
enum MyBitMask {
flag0,
flag1,
flag2
};
15 changes: 15 additions & 0 deletions tests/idl4/illegal_idl/enum_bitbound_zero.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @file enum_bitbound_zero.idl
* @author Johnny Willemsen
*
* ridlc shall reject use of a enum with a bit_bound annotation with value zero
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

@bit_bound(0)
enum MyBitMask {
flag0,
flag1,
flag2
};

0 comments on commit 5d80389

Please sign in to comment.