Skip to content

Commit

Permalink
Merge pull request RemedyIT#362 from jwillemsen/jwi-splitostream
Browse files Browse the repository at this point in the history
Moved object and wstring/wchar ostream insertion to their own files a…
  • Loading branch information
jwillemsen authored Mar 26, 2024
2 parents 4750bd9 + fd0ad77 commit 0c0176e
Show file tree
Hide file tree
Showing 13 changed files with 440 additions and 21 deletions.
1 change: 1 addition & 0 deletions bin/taox11_tests.lst
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ tests/typecode_adapter/orb_create/run_test.pl: !CORBA_E_COMPACT !CORBA_E_MICRO
tests/typecode_adapter/resolve_ref/run_test.pl: !CORBA_E_COMPACT !CORBA_E_MICRO
tests/union/run_test.pl:
tests/union/run_cross_tao_server.pl:
tests/wchar/run_test.pl:
tests/write_traits/run_test.pl:
tests/wstring/run_cross_tao_client.pl:
tests/wstring/run_cross_tao_server.pl:
Expand Down
2 changes: 1 addition & 1 deletion ridlbe/c++11/writers/amistubheader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def initialize(output = STDOUT, opts = {})
end
end
@default_post_includes << 'tao/x11/anytypecode/typecode_constants.h' if params[:gen_typecodes]
@default_post_includes << 'tao/x11/corba_ostream.h' if params[:gen_ostream_operators]
@default_post_includes << 'tao/x11/object_ostream.h' if params[:gen_ostream_operators]
@default_post_includes << 'tao/x11/messaging/messaging.h'
@default_post_includes << 'tao/x11/amic_traits_t.h'
@default_post_includes << 'tao/x11/portable_server/servantbase.h'
Expand Down
12 changes: 10 additions & 2 deletions ridlbe/c++11/writers/stubheader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def initialize(output = STDOUT, opts = {})
end
end
@default_post_includes << 'tao/x11/anytypecode/typecode_constants.h' if params[:gen_typecodes]
@default_post_includes << 'tao/x11/corba_ostream.h' if params[:gen_ostream_operators]

@include_guard = "__RIDL_#{File.basename(params[:output] || '').to_random_include_guard}_INCLUDED__"

Expand Down Expand Up @@ -371,6 +370,8 @@ def declare_interface(node)
def enter_interface(node)
return if node.is_pseudo?

add_post_include('tao/x11/object_ostream.h')

unless node.is_abstract?
add_include('tao/x11/object.h')
add_include('tao/x11/system_exception.h')
Expand Down Expand Up @@ -433,6 +434,8 @@ def visit_typedef(node)

idl_type = node.idltype.resolved_type
case idl_type
when IDL::Type::WChar
check_idl_type(idl_type)
when IDL::Type::Fixed
add_include('tao/x11/fixed_t.h')
when IDL::Type::Sequence
Expand All @@ -447,9 +450,11 @@ def visit_typedef(node)
check_idl_type(idl_type.valuetype)
when IDL::Type::Array
check_idl_type(idl_type.basetype)
when IDL::Type::String, IDL::Type::WString
when IDL::Type::String,
IDL::Type::WString
add_include('tao/x11/bounded_string_t.h') if idl_type.size.to_i.positive?
add_include('tao/x11/bounded_type_traits_t.h') if idl_type.size.to_i.positive?
check_idl_type(idl_type)
end
end

Expand All @@ -468,6 +473,9 @@ def check_idl_type(idl_type)
add_include('tao/x11/portable_server/servant_forward.h')
when IDL::Type::AbstractBase
add_post_include('tao/x11/valuetype/abstract_base.h')
when IDL::Type::WString,
IDL::Type::WChar
add_post_include('tao/x11/wstringwchar_ostream.h') if params[:gen_ostream_operators]
end
end

Expand Down
26 changes: 26 additions & 0 deletions tao/x11/object_ostream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @file object_ostream.h
* @author Marijke Hengstmengel
*
* @brief CORBA C++11 Logging module
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

#ifndef TAOX11_OBJECT_OSTREAM_H
#define TAOX11_OBJECT_OSTREAM_H

#include "tao/x11/object_fwd.h"
#include <ostream>

namespace std
{
inline std::ostream&
operator<< (std::ostream& _os,
TAOX11_CORBA::object_reference<::TAOX11_NAMESPACE::CORBA::Object> /*_ve*/)
{
return _os << "CORBA:Object";
}
}

#endif /* TAOX11_OBJECT_OSTREAM_H */
3 changes: 2 additions & 1 deletion tao/x11/taox11.mpc
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ project(taox11) : taox11_defaults, taolib {
bounded_vector_t.h
cdr_long_double.h
corba.h
corba_ostream.h
dynamic_adapter.h
exception.h
exception_macros.h
Expand All @@ -310,6 +309,7 @@ project(taox11) : taox11_defaults, taolib {
object.h
object_fwd.h
object_loader.h
object_ostream.h
object_traits_t.h
objproxy.h
orb.h
Expand Down Expand Up @@ -339,6 +339,7 @@ project(taox11) : taox11_defaults, taolib {
valuetype_adapter.h
versioned_x11_namespace.h
versionx11.h
wstringwchar_ostream.h
}

Header_Files {
Expand Down
26 changes: 9 additions & 17 deletions tao/x11/corba_ostream.h → tao/x11/wstringwchar_ostream.h
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
/**
* @file corba_ostream.h
* @file wstringwchar_ostream.h
* @author Marijke Hengstmengel
*
* @brief CORBA C++11 Logging module
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

#ifndef TAOX11_CORBA_OSTREAM_H
#define TAOX11_CORBA_OSTREAM_H
#ifndef TAOX11_WTRINGWCHAR_OSTREAM_H
#define TAOX11_WTRINGWCHAR_OSTREAM_H

#include "tao/x11/taox11_export.h"
#include "tao/x11/corba.h"

#include <sstream>
#include <ostream>
#include <cstdlib>
#include "iostream"
#include <codecvt>
#include <locale>

namespace std
{
inline std::ostream&
operator<< (std::ostream& _os,
TAOX11_CORBA::object_reference<::TAOX11_NAMESPACE::CORBA::Object> /*_ve*/)
{
return _os << "CORBA:Object";
}

/// std::wstring to ostream insertion
inline std::ostream&
operator<< (std::ostream& _os, const std::wstring& _v)
{
return _os << "\"" << ACE_Wide_To_Ascii (_v.c_str ()).char_rep () << "\"";
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> conv;
return _os << "\"" << conv.to_bytes(_v) << "\"";
}

/// wchar_t to ostream insertion
Expand All @@ -52,4 +44,4 @@ namespace std
}
}

#endif /* TAOX11_CORBA_OSTREAM_H */
#endif /* TAOX11_WTRINGWCHAR_OSTREAM_H */
74 changes: 74 additions & 0 deletions tests/wchar/client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @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"

int main(int argc, char* argv[])
{
int result = 0;
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;
}

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::Hello>::ref_type hello = IDL::traits<Test::Hello>::narrow (obj);

if (!hello)
{
TAOX11_TEST_ERROR << "ERROR: IDL::traits<Test::Hello>::narrow (obj) returned null object."
<< std::endl;
return 1;
}
TAOX11_TEST_DEBUG << "narrowed Hello interface" << std::endl;

// Test
{
TAOX11_TEST_DEBUG << "Test wchar get and set." << std::endl;
wchar_t const text = hello->getset_wchar (L'H');
if (text != L'H')
{
TAOX11_TEST_ERROR_W << L"ERROR: hello->get_string() returned an unexpected value. "
<< L"expected <H>, received <" << text << L">" << std::endl;
++result;
}
TAOX11_TEST_DEBUG_W << L"ostream test wchar: " << text << std::endl;
}

TAOX11_TEST_DEBUG << "shutting down...";
hello->shutdown();
TAOX11_TEST_DEBUG << std::endl;

orb->destroy ();
}
catch (const std::exception& e)
{
TAOX11_TEST_ERROR << "exception caught: " << e << std::endl;
++result;
}

return result;
}
35 changes: 35 additions & 0 deletions tests/wchar/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file hello.cpp
* @author Mark Drijver
*
* @brief CORBA C++11 server application
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/


#include "hello.h"
#include "testlib/taox11_testlog.h"

Hello::Hello(IDL::traits<CORBA::ORB>::ref_type orb, int& result)
: orb_ (std::move(orb))
, result_ (result)
{
}

wchar_t
Hello::getset_wchar (wchar_t text)
{
if (text != L'H')
{
TAOX11_TEST_ERROR_W << L"ERROR: Hello::getset_wchar received an unexpected value. "
<< L"expected <H>, received <" << text << L">" << std::endl;
++this->result_;
}
return L'H';
}

void Hello::shutdown ()
{
this->orb_->shutdown (false);
}
37 changes: 37 additions & 0 deletions tests/wchar/hello.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file hello.h
* @author Johnny Willemsen
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/
#ifndef HELLO_H
#define HELLO_H

#include "testS.h"

/// Implement the Test::Hello interface
class Hello final
: public virtual CORBA::servant_traits<Test::Hello>::base_type
{
public:
/// Constructor
Hello(IDL::traits<CORBA::ORB>::ref_type orb, int& result);

// = The skeleton methods
wchar_t getset_wchar(wchar_t text) override;

void shutdown() override;

private:
/// Use an ORB reference to convert strings to objects and shutdown
/// the application.
IDL::traits<CORBA::ORB>::ref_type orb_;
int &result_;

Hello (const Hello&) = delete;
Hello (Hello&&) = delete;
Hello& operator= (const Hello&) = delete;
Hello& operator= (Hello&&) = delete;
};

#endif /* HELLO_H */
78 changes: 78 additions & 0 deletions tests/wchar/run_test.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#---------------------------------------------------------------------
# @file run_test.pl
# @author Mark Drijver
#
# @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;

$status = 0;
$debug_level = '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);

$SV = $server->CreateProcess ("server", "-ORBdebuglevel $debug_level -o $server_iorfile");
$CL = $client->CreateProcess ("client", "-k file://$client_iorfile");
$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;
}

$client_status = $CL->SpawnWaitKill ($client->ProcessStartWaitInterval());

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

$server_status = $SV->WaitKill ($server->ProcessStopWaitInterval());

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

$server->DeleteFile($iorbase);
$client->DeleteFile($iorbase);

exit $status;
Loading

0 comments on commit 0c0176e

Please sign in to comment.