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

test-client.cc

00001 /*
00002 *  Name:      test-client.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Test for CORBAL (client)
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 <cstdio>
00027 #include <fstream>
00028 #include <iostream>
00029 #include <mpcl/net/corba/client_application.hh>
00030 #include <mpcl/net/corba/orb.hh>
00031 #include <mpcl/test.h>
00032 #include "test-sample_producer.hh"
00033 
00034 
00035 using mpcl::net::corba::TClientApplication;
00036 using mpcl::net::corba::TOrb;
00037 using mpcl::text::TString;
00038 
00039 
00040 //
00041 //  L O C A L   V A R I A B L E S
00042 //
00043 
00044 static const char*   _pkcIorFileName = "test-server.ior.txt";
00045 
00046 
00047 class TConsumerApplication :
00048   public virtual TClientApplication<TOrb>
00049 {
00050 
00051   private:
00052 
00054     typedef
00055       mpcl::TSampleProducer_var
00056       QTSampleProducer;
00057 
00059     QTSampleProducer   qtNamedSampleProducer1;
00060 
00062     QTSampleProducer   qtNamedSampleProducer2;
00063 
00065     QTSampleProducer   qtSampleProducer;
00066 
00067 
00068   public:
00069     
00070     TConsumerApplication ( const char* pkcNAME    ,
00071                            const char* pkcRELEASE ,
00072                            TOrb&       rtORB      )         :
00073       TClientApplication<TOrb> (pkcNAME, pkcRELEASE, rtORB) {}
00074 
00075     void initialize (void);
00076 
00077     int start (void);
00078 
00079 
00080   public:
00081 
00082     TString programFileName (void) const
00083     {
00084       return "test-client";
00085     }
00086 
00087 };  // class TConsumerApplication
00088 
00089 
00090 //
00091 //  C O N S T R U C T O R S
00092 //
00093 
00094 void TConsumerApplication::initialize (void)
00095 {
00096 
00097   std::string     yIor;
00098   std::ifstream   tIfstream (_pkcIorFileName);
00099 
00100   tIfstream >> yIor;
00101   tIfstream.close();
00102   std::remove (_pkcIorFileName);
00103   qtNamedSampleProducer1 =
00104     rtOrb.request<mpcl::TSampleProducer, QTSampleProducer> ("corbaname:rir:#mpcl/test-server/sample_producer_1.object");
00105   qtNamedSampleProducer2 =
00106     rtOrb.request<mpcl::TSampleProducer, QTSampleProducer> ("corbaname:rir:#mpcl/test-server/sample_producer_2.object");
00107   qtSampleProducer =
00108     rtOrb.request<mpcl::TSampleProducer, QTSampleProducer> (yIor.c_str());
00109 
00110 }  // initialize()
00111 
00112 
00113 int TConsumerApplication::start (void)
00114 { 
00115 
00116   TEST_INIT ("tests for class 'TConsumerApplication'");
00117 
00118   //
00119   //  Instance qtSampleProducer starts its internal counter at 0.
00120   //
00121   TEST_NUMBERS (0, qtSampleProducer->get());
00122   TEST_NUMBERS (1, qtSampleProducer->get());
00123   TEST_NUMBERS (2, qtSampleProducer->get());
00124   TEST_NUMBERS (3, qtSampleProducer->get());
00125 
00126   //
00127   //  Instance qtNamedSampleProducer1 starts its internal counter at 10.
00128   //
00129   TEST_NUMBERS (10, qtNamedSampleProducer1->get());
00130   TEST_NUMBERS (11, qtNamedSampleProducer1->get());
00131   TEST_NUMBERS (12, qtNamedSampleProducer1->get());
00132   TEST_NUMBERS (13, qtNamedSampleProducer1->get());
00133 
00134   //
00135   //  Instance qtNamedSampleProducer2 starts its internal counter at 20.
00136   //
00137   TEST_NUMBERS (20, qtNamedSampleProducer2->get());
00138   TEST_NUMBERS (21, qtNamedSampleProducer2->get());
00139   TEST_NUMBERS (22, qtNamedSampleProducer2->get());
00140   TEST_NUMBERS (23, qtNamedSampleProducer2->get());
00141 
00142   //
00143   //  Finishes ORB.
00144   //
00145   qtNamedSampleProducer1->finish();
00146 
00147   TEST_MEMORY_STATUS;
00148   TEST_RETURN_CODE;
00149 
00150 }  // start()
00151 
00152 
00154 int main (int argc, const char** argv)
00155 {
00156 
00157   TEST_INIT ("tests for CORBA as client");
00158   try
00159   {
00160     TOrb                   tOrb (argc, argv);
00161     TConsumerApplication   tApplication ("test-client", "0.0.0", tOrb);
00162     
00163     tApplication.initialize();
00164     TEST_FUNCTION (tApplication.start());
00165   }
00166   catch (CORBA::SystemException&)
00167   {
00168     std::cerr << "ORB; caught CORBA::SystemException" << std::endl;
00169     TEST_FAIL;
00170   }
00171   catch (CORBA::Exception&)
00172   {
00173     std::cerr << "ORB; caught CORBA::Exception" << std::endl;
00174     TEST_FAIL;
00175   }
00176   catch (const mpcl::TException& rktEXCEPTION)
00177   {
00178     std::cerr << rktEXCEPTION;
00179     TEST_FAIL;
00180   }
00181   catch (std::exception& rktEXCEPTION)
00182   {
00183     std::cerr << rktEXCEPTION.what();
00184     TEST_FAIL;
00185   }
00186   catch (...)
00187   {
00188     std::cerr << "caught unknown exception" << std::endl;
00189     TEST_FAIL;
00190   }
00191   TEST_MEMORY_STATUS;
00192   TEST_RETURN_CODE;
00193 
00194 }  // main()

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