Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

test-colocated.cc

00001 /*
00002 *  Name:      test-colocated.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Test for CORBA (colocated)
00005 *  Date:      $Date: 2003/10/06 12:45:11 $
00006 *  Revision:  $Revision: 1.2 $
00007 *
00008 *  Copyright (C) 2001-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #include <cstdlib>
00027 #include <fstream>
00028 #include <iostream>
00029 #include <mpcl/net/corba/orb.hh>
00030 #include <mpcl/net/corba/server_application.hh>
00031 #include <mpcl/system/system.hh>
00032 #include <mpcl/test.h>
00033 #include "test-sample_producer.hh"
00034 
00035 
00036 using mpcl::net::corba::TOrb;
00037 using mpcl::net::corba::TServerApplication;
00038 
00039 
00040 //
00041 //  L O C A L   V A R I A B L E S
00042 //
00043 
00048 template <typename TOrb>
00049 class TSampleProducer                        :
00050   public POA_mpcl::TSampleProducer           ,
00051   public PortableServer::RefCountServantBase
00052 {
00053 
00054   private:
00055 
00057     long int   liValue;
00058 
00060     TOrb&   rtOrb;
00061 
00062 
00063   public:
00064 
00065     TSampleProducer (TOrb& rtORB)                 :
00066       POA_mpcl::TSampleProducer           ()      ,
00067       PortableServer::RefCountServantBase ()      ,
00068       liValue                             (0)     ,
00069       rtOrb                               (rtORB) {}
00070 
00072     CORBA::Long get (void)
00073     {
00074       return liValue++;
00075     }
00076 
00078     void finish (void)
00079     {
00080       rtOrb.finish();
00081     }
00082 
00083 };  // class TSampleProducer
00084 
00085 
00087 class TColocatedApplication :
00088   public TServerApplication<TOrb>
00089 {
00090 
00091   private:
00092 
00094     typedef
00095       TSampleProducer<TOrb>
00096       TCorbaSampleProducer;
00097 
00099     typedef
00100       mpcl::TSampleProducer_var
00101       QTCorbaSampleProducer;
00102 
00104     QTCorbaSampleProducer   qtSampleProducer;
00105 
00106 
00107   public:
00108 
00109     TColocatedApplication ( const char* pkcNAME    ,
00110                             const char* pkcRELEASE ,
00111                             TOrb&       rtORB      )        :
00112       TServerApplication<TOrb> (pkcNAME, pkcRELEASE, rtORB) {}
00113 
00114     void initialize (void)
00115     {
00116       TCorbaSampleProducer*   ptSampleProducer;
00117 
00118       ptSampleProducer = new TCorbaSampleProducer (rtOrb);
00119       qtSampleProducer =
00120         rtOrb.enrol<TCorbaSampleProducer, QTCorbaSampleProducer> (ptSampleProducer);
00121     }
00122 
00123     int start (void)
00124     {
00125       TEST_INIT ("tests for class 'TClientApplication'");
00126 
00127       TServerApplication<TOrb>::start();
00128       TEST_NUMBERS (0, qtSampleProducer->get());
00129       TEST_NUMBERS (1, qtSampleProducer->get());
00130       TEST_NUMBERS (2, qtSampleProducer->get());
00131       TEST_NUMBERS (3, qtSampleProducer->get());
00132 
00133       TEST_MEMORY_STATUS;
00134       TEST_RETURN_CODE;
00135     }
00136     
00137 
00138   public:
00139 
00140     mpcl::TString programFileName (void) const
00141     {
00142       return "test-colocated";
00143     }
00144 
00145 };  // class TColocatedApplication
00146 
00147 
00149 int main (int argc, const char** argv)
00150 {
00151 
00152   TEST_INIT ("tests for CORBA (colocated)");
00153 
00154   try
00155   {
00156     TOrb                    tOrb (argc, argv);
00157     TColocatedApplication   tApplication ("test-colocated", "0.0.0", tOrb);
00158 
00159     tOrb.setColocated (true);
00160     tApplication.initialize();
00161     TEST_FUNCTION (tApplication.start());
00162   }
00163   catch (CORBA::SystemException&)
00164   {
00165     std::cerr << "ORB; caught CORBA::SystemException" << std::endl;
00166     TEST_FAIL;
00167   }
00168   catch (CORBA::Exception&)
00169   {
00170     std::cerr << "ORB; caught CORBA::Exception" << std::endl;
00171     TEST_FAIL;
00172   }
00173   catch (const mpcl::TException& rktEXCEPTION)
00174   {
00175     std::cerr << rktEXCEPTION;
00176     TEST_FAIL;
00177   }
00178   catch (std::exception& rktEXCEPTION)
00179   {
00180     std::cerr << rktEXCEPTION.what();
00181     TEST_FAIL;
00182   }
00183   catch (...)
00184   {
00185     std::cerr << "caught unknown exception" << std::endl;
00186     TEST_FAIL;
00187   }
00188   TEST_MEMORY_STATUS;
00189   TEST_RETURN_CODE;
00190 
00191 }  // main()

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18