summaryrefslogtreecommitdiff
path: root/TAO/tests/ZIOP
diff options
context:
space:
mode:
authorJohnny Willemsen <jwillemsen@remedy.nl>2008-07-22 11:35:50 +0000
committerJohnny Willemsen <jwillemsen@remedy.nl>2008-07-22 11:35:50 +0000
commitf63fdaa4d9ee14de66129988fc5aa903fad0f541 (patch)
tree16b41d31e8a4d8c32b3baf76831616d8e606ac35 /TAO/tests/ZIOP
parent402b3a1ec291d92dd436c0248c9bb0f3ce62c82b (diff)
downloadATCD-f63fdaa4d9ee14de66129988fc5aa903fad0f541.tar.gz
Tue Jul 22 11:34:28 UTC 2008 Johnny Willemsen <jwillemsen@remedy.nl>
Diffstat (limited to 'TAO/tests/ZIOP')
-rw-r--r--TAO/tests/ZIOP/Hello.cpp24
-rw-r--r--TAO/tests/ZIOP/Hello.h31
-rw-r--r--TAO/tests/ZIOP/Test.idl20
-rw-r--r--TAO/tests/ZIOP/ZIOP.mpc35
-rw-r--r--TAO/tests/ZIOP/client.cpp117
-rwxr-xr-xTAO/tests/ZIOP/run_test.pl62
-rw-r--r--TAO/tests/ZIOP/server.cpp179
7 files changed, 468 insertions, 0 deletions
diff --git a/TAO/tests/ZIOP/Hello.cpp b/TAO/tests/ZIOP/Hello.cpp
new file mode 100644
index 00000000000..8d092e0a4f6
--- /dev/null
+++ b/TAO/tests/ZIOP/Hello.cpp
@@ -0,0 +1,24 @@
+//
+// $Id$
+//
+#include "Hello.h"
+
+ACE_RCSID(Hello, Hello, "$Id$")
+
+Hello::Hello (CORBA::ORB_ptr orb)
+ : orb_ (CORBA::ORB::_duplicate (orb))
+{
+}
+
+char *
+Hello::get_string (const char * mystring)
+{
+ ACE_DEBUG ((LM_DEBUG, "Received <%s>\n", mystring));
+ return CORBA::string_dup ("Hello there!Hello there!Hello there!Hello there!Hello there!Hello there!Hello there!Hello there!Hello there!\n");
+}
+
+void
+Hello::shutdown (void)
+{
+ this->orb_->shutdown (0);
+}
diff --git a/TAO/tests/ZIOP/Hello.h b/TAO/tests/ZIOP/Hello.h
new file mode 100644
index 00000000000..17f91192fe8
--- /dev/null
+++ b/TAO/tests/ZIOP/Hello.h
@@ -0,0 +1,31 @@
+//
+// $Id$
+//
+
+#ifndef HELLO_H
+#define HELLO_H
+#include /**/ "ace/pre.h"
+
+#include "TestS.h"
+
+/// Implement the Test::Hello interface
+class Hello
+ : public virtual POA_Test::Hello
+{
+public:
+ /// Constructor
+ Hello (CORBA::ORB_ptr orb);
+
+ // = The skeleton methods
+ virtual char * get_string (const char * mystring);
+
+ virtual void shutdown (void);
+
+private:
+ /// Use an ORB reference to conver strings to objects and shutdown
+ /// the application.
+ CORBA::ORB_var orb_;
+};
+
+#include /**/ "ace/post.h"
+#endif /* HELLO_H */
diff --git a/TAO/tests/ZIOP/Test.idl b/TAO/tests/ZIOP/Test.idl
new file mode 100644
index 00000000000..5d218fd76d2
--- /dev/null
+++ b/TAO/tests/ZIOP/Test.idl
@@ -0,0 +1,20 @@
+//
+// $Id$
+//
+
+/// Put the interfaces in a module, to avoid global namespace pollution
+module Test
+{
+ /// A very simple interface
+ interface Hello
+ {
+ /// Return a simple string
+ string get_string (in string mystring);
+
+ /// A method to shutdown the ORB
+ /**
+ * This method is used to simplify the test shutdown process
+ */
+ oneway void shutdown ();
+ };
+};
diff --git a/TAO/tests/ZIOP/ZIOP.mpc b/TAO/tests/ZIOP/ZIOP.mpc
new file mode 100644
index 00000000000..22fab2e866e
--- /dev/null
+++ b/TAO/tests/ZIOP/ZIOP.mpc
@@ -0,0 +1,35 @@
+// -*- MPC -*-
+// $Id$
+
+project(*idl): taoidldefaults {
+ IDL_Files {
+ Test.idl
+ }
+ custom_only = 1
+}
+
+project(*Server): taoserver, compression, ziop, codecfactory, zlibcompressor {
+ after += *idl
+ Source_Files {
+ Hello.cpp
+ server.cpp
+ }
+ Source_Files {
+ TestC.cpp
+ TestS.cpp
+ }
+ IDL_Files {
+ }
+}
+
+project(*Client): taoclient, compression, ziop, codecfactory, zlibcompressor {
+ after += *idl
+ Source_Files {
+ client.cpp
+ }
+ Source_Files {
+ TestC.cpp
+ }
+ IDL_Files {
+ }
+}
diff --git a/TAO/tests/ZIOP/client.cpp b/TAO/tests/ZIOP/client.cpp
new file mode 100644
index 00000000000..3b3a3ff5fcb
--- /dev/null
+++ b/TAO/tests/ZIOP/client.cpp
@@ -0,0 +1,117 @@
+// $Id$
+
+#include "TestC.h"
+#include "ace/Get_Opt.h"
+#include "tao/ZIOP/ZIOP.h"
+#include "tao/Compression/zlib/ZlibCompressor_Factory.h"
+
+ACE_RCSID(Hello, client, "$Id$")
+
+const char *ior = "file://test.ior";
+
+int
+parse_args (int argc, char *argv[])
+{
+ ACE_Get_Opt get_opts (argc, argv, "k:");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'k':
+ ior = get_opts.opt_arg ();
+ break;
+
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s "
+ "-k <ior> "
+ "\n",
+ argv [0]),
+ -1);
+ }
+ // Indicates sucessful parsing of the command line
+ return 0;
+}
+
+int
+ACE_TMAIN(int argc, ACE_TCHAR *argv[])
+{
+ try
+ {
+ CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
+
+ if (parse_args (argc, argv) != 0)
+ return 1;
+
+ CORBA::Object_var compression_manager =
+ orb->resolve_initial_references("CompressionManager");
+
+ Compression::CompressionManager_var manager =
+ Compression::CompressionManager::_narrow (compression_manager.in ());
+
+ if (CORBA::is_nil(manager.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Panic: nil compression manager\n"),
+ 1);
+
+ Compression::CompressorFactory_ptr compressor_factory;
+
+ ACE_NEW_RETURN (compressor_factory, TAO::Zlib_CompressorFactory (), 1);
+
+ Compression::CompressorFactory_var compr_fact = compressor_factory;
+ manager->register_factory(compr_fact.in ());
+
+ CORBA::Boolean comp_enables = true;
+ CORBA::ULong min_value = 0;
+ CORBA::Any compression_enabled;
+ CORBA::Any compmin;
+ Compression::CompressorIdLevelList compressor_id_list(2);
+ compressor_id_list.length(2);
+ Compression::CompressorIdLevel levelid;
+ levelid.compressor_id = Compression::COMPRESSORID_ZLIB;
+ levelid.compression_level = 9;
+ compressor_id_list[0] = levelid;
+ levelid.compressor_id = Compression::COMPRESSORID_BZIP2;
+ compressor_id_list[1] = levelid;
+ CORBA::Any compressor_id_any;
+ compressor_id_any <<= compressor_id_list;
+ compression_enabled <<= CORBA::Any::from_boolean (comp_enables);
+ compmin <<= min_value;
+ CORBA::PolicyList policies (3);
+ policies.length (3);
+ policies[0] = orb->create_policy (ZIOP::COMPRESSION_ENABLING_POLICY_ID, compression_enabled);
+ policies[1] = orb->create_policy (ZIOP::COMPRESSION_LOW_VALUE_POLICY_ID, compmin);
+ policies[2] = orb->create_policy(ZIOP::COMPRESSION_ID_LIST_POLICY_ID,compressor_id_any);
+ CORBA::Object_var tmp = orb->string_to_object(ior);
+ CORBA::Object_var tmp2 = tmp->_set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
+
+ Test::Hello_var hello = Test::Hello::_narrow(tmp2.in ());
+
+ if (CORBA::is_nil (hello.in ()))
+ {
+ ACE_ERROR_RETURN ((LM_DEBUG,
+ "Nil Test::Hello reference <%s>\n",
+ ior),
+ 1);
+ }
+
+ CORBA::String_var the_string = hello->get_string ("This is a test stringThis is a test stringThis is a test stringThis is a test stringThis is a test stringThis is a test stringThis is a test stringThis is a test stringThis is a test string\n");
+
+ ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%s>\n",
+ the_string.in ()));
+
+ hello->shutdown ();
+
+ orb->destroy ();
+ }
+ catch (const CORBA::Exception& ex)
+ {
+ ex._tao_print_exception ("Exception caught:");
+ return 1;
+ }
+
+ return 0;
+}
+
diff --git a/TAO/tests/ZIOP/run_test.pl b/TAO/tests/ZIOP/run_test.pl
new file mode 100755
index 00000000000..3c491cd2313
--- /dev/null
+++ b/TAO/tests/ZIOP/run_test.pl
@@ -0,0 +1,62 @@
+eval '(exit $?0)' && eval 'exec perl -S $0 ${1"$@"}'
+ & eval 'exec perl -S $0 $argv:q'
+ if 0;
+
+# $Id$
+# -*- perl -*-
+
+use lib "$ENV{ACE_ROOT}/bin";
+use PerlACE::Run_Test;
+
+$status = 0;
+$debug_level = '0';
+
+foreach $i (@ARGV) {
+ if ($i eq '-debug') {
+ $debug_level = '10';
+ }
+}
+
+$iorfile = PerlACE::LocalFile ("server.ior");
+unlink $iorfile;
+
+if (PerlACE::is_vxworks_test()) {
+ $SV = new PerlACE::ProcessVX ("server", "-ORBDebuglevel $debug_level -o server.ior");
+}
+else {
+ $SV = new PerlACE::Process ("server", "-ORBdebuglevel $debug_level -o $iorfile");
+}
+$CL = new PerlACE::Process ("client", " -k file://$iorfile -ORBdebuglevel $debug_level");
+
+$server = $SV->Spawn ();
+
+if ($server != 0) {
+ print STDERR "ERROR: server returned $server\n";
+ exit 1;
+}
+
+if (PerlACE::waitforfile_timed ($iorfile,
+ $PerlACE::wait_interval_for_process_creation) == -1) {
+ print STDERR "ERROR: cannot find file <$iorfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+
+$client = $CL->SpawnWaitKill (300);
+
+if ($client != 0) {
+ print STDERR "ERROR: client returned $client\n";
+ $status = 1;
+}
+
+$server = $SV->WaitKill (10);
+
+if ($server != 0) {
+ print STDERR "ERROR: server returned $server\n";
+ $status = 1;
+}
+
+#unlink $iorfile;
+
+exit $status;
+
diff --git a/TAO/tests/ZIOP/server.cpp b/TAO/tests/ZIOP/server.cpp
new file mode 100644
index 00000000000..d8248be4fa1
--- /dev/null
+++ b/TAO/tests/ZIOP/server.cpp
@@ -0,0 +1,179 @@
+// $Id$
+
+#include "Hello.h"
+#include "ace/Get_Opt.h"
+#include "ace/OS_NS_stdio.h"
+#include "tao/ZIOP/ZIOP.h"
+#include "tao/Compression/zlib/ZlibCompressor_Factory.h"
+#include "tao/Policy_ManagerC.h"
+#include "tao/Policy_CurrentC.h"
+
+ACE_RCSID (Hello,
+ server,
+ "$Id$")
+
+const char *ior_output_file = "test.ior";
+Compression::CompressionLevel level = 9;
+
+int
+parse_args (int argc, char *argv[])
+{
+ ACE_Get_Opt get_opts (argc, argv, "o:l:");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'o':
+ ior_output_file = get_opts.opt_arg ();
+ break;
+ case 'l':
+ level = ACE_OS::atoi (get_opts.opt_arg ());
+ break;
+
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s "
+ "-o <iorfile>"
+ "\n",
+ argv [0]),
+ -1);
+ }
+ // Indicates sucessful parsing of the command line
+ return 0;
+}
+
+int
+ACE_TMAIN(int argc, ACE_TCHAR *argv[])
+{
+ try
+ {
+ CORBA::ORB_var orb =
+ CORBA::ORB_init (argc, argv);
+
+ CORBA::Object_var compression_manager =
+ orb->resolve_initial_references("CompressionManager");
+
+ Compression::CompressionManager_var manager =
+ Compression::CompressionManager::_narrow (compression_manager.in ());
+
+ if (CORBA::is_nil(manager.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Panic: nil compression manager\n"),
+ 1);
+
+ Compression::CompressorFactory_ptr compressor_factory;
+
+ ACE_NEW_RETURN (compressor_factory, TAO::Zlib_CompressorFactory (), 1);
+
+ Compression::CompressorFactory_var compr_fact = compressor_factory;
+ manager->register_factory(compr_fact.in ());
+
+ CORBA::Object_var poa_object =
+ orb->resolve_initial_references("RootPOA");
+
+ PortableServer::POA_var root_poa =
+ PortableServer::POA::_narrow (poa_object.in ());
+
+ if (CORBA::is_nil (root_poa.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Panic: nil RootPOA\n"),
+ 1);
+
+ if (parse_args (argc, argv) != 0)
+ return 1;
+
+CORBA::Boolean compression_enabling = true;
+Compression::CompressorIdLevelList compressor_id_list(2);
+compressor_id_list.length(2);
+Compression::CompressorIdLevel levelid;
+levelid.compressor_id = Compression::COMPRESSORID_ZLIB;
+levelid.compression_level = 9;
+compressor_id_list[0] = levelid;
+levelid.compressor_id = Compression::COMPRESSORID_BZIP2;
+compressor_id_list[1] = levelid;
+//CORBA::ULong compression_low_value = 16384;
+//CORBA::ULong min_compression_ratio = 40;
+CORBA::Any compression_enabling_any;//, compressor_id_any, low_value_any;
+//CORBA::Any min_compression_ratio_any;
+compression_enabling_any <<= CORBA::Any::from_boolean(compression_enabling);
+CORBA::Any compressor_id_any;
+compressor_id_any <<= compressor_id_list;
+//low_value_any <<= compression_low_value;
+//min_compression_ratio_any <<= min_compression_ratio;
+PortableServer::POA_var my_compress_poa = NULL;
+CORBA::PolicyList policies(2);
+policies.length(2);
+try {
+policies[0] = orb->create_policy(ZIOP::COMPRESSION_ENABLING_POLICY_ID, compression_enabling_any);
+policies[1] = orb->create_policy(ZIOP::COMPRESSION_ID_LIST_POLICY_ID,compressor_id_any);
+//policies[2] = orb->create_policy(ZIOP::COMPRESSION_LOW_VALUE_POLICY_ID,compressor_id_any);
+//policies[3] = orb->create_policy(ZIOP::MIN_COMPRESSION_RATIO_POLICY_ID,min_compression_ratio);
+my_compress_poa = root_poa->create_POA("My_Compress_Poa", NULL, policies);
+} catch(const CORBA::PolicyError&) {
+policies.length(0);
+my_compress_poa = root_poa->create_POA("My_Compress_Poa", NULL, policies);
+}
+ CORBA::Object_var objectman =
+ orb->resolve_initial_references ("ORBPolicyManager");
+
+ CORBA::PolicyManager_var policy_manager =
+ CORBA::PolicyManager::_narrow (objectman.in ());
+
+ policy_manager->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
+
+ CORBA::Object_var pcobject =
+ orb->resolve_initial_references ("PolicyCurrent");
+
+ CORBA::PolicyCurrent_var policy_current =
+ CORBA::PolicyCurrent::_narrow (pcobject.in ());
+
+ policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
+
+ PortableServer::POAManager_var poa_manager = my_compress_poa->the_POAManager ();
+
+ Hello *hello_impl = 0;
+ ACE_NEW_RETURN (hello_impl,
+ Hello (orb.in ()),
+ 1);
+ PortableServer::ServantBase_var owner_transfer(hello_impl);
+
+ PortableServer::ObjectId_var id =
+ my_compress_poa->activate_object (hello_impl);
+
+ CORBA::Object_var object = my_compress_poa->id_to_reference (id.in ());
+
+ Test::Hello_var hello = Test::Hello::_narrow (object.in ());
+
+ CORBA::String_var ior = orb->object_to_string (hello.in ());
+
+ // Output the IOR to the <ior_output_file>
+ FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
+ if (output_file == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Cannot open output file for writing IOR: %s\n",
+ ior_output_file),
+ 1);
+ ACE_OS::fprintf (output_file, "%s", ior.in ());
+ ACE_OS::fclose (output_file);
+
+ poa_manager->activate ();
+
+ orb->run ();
+
+ ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
+
+ root_poa->destroy (1, 1);
+
+ orb->destroy ();
+ }
+ catch (const CORBA::Exception& ex)
+ {
+ ex._tao_print_exception ("Exception caught:");
+ return 1;
+ }
+
+ return 0;
+}
+