00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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/all.hh>
00032 #include <mpcl/test.h>
00033
00034 #include <unistd.h>
00035
00036 #include "test-sample_producer.hh"
00037
00038
00039 using mpcl::net::corba::TOrb;
00040 using mpcl::net::corba::TServerApplication;
00041 using mpcl::system::GetErrorMessage;
00042 using mpcl::system::tSystem;
00043 using mpcl::text::TString;
00044
00045
00046
00047
00048
00049
00050 static const char* _pkcIorFileName = "test-server.ior.txt";
00051
00052
00057 template <typename TOrb>
00058 class TSampleProducer :
00059 public POA_mpcl::TSampleProducer ,
00060 public PortableServer::RefCountServantBase
00061 {
00062
00063 private:
00064
00066 long int liValue;
00067
00069 TOrb& rtOrb;
00070
00071
00072 public:
00073
00074 TSampleProducer (TOrb& rtORB, long int liSTART_VALUE = 0) :
00075 POA_mpcl::TSampleProducer () ,
00076 PortableServer::RefCountServantBase () ,
00077 liValue (liSTART_VALUE) ,
00078 rtOrb (rtORB) {}
00079
00081 CORBA::Long get (void)
00082 {
00083 return liValue++;
00084 }
00085
00087 void finish (void)
00088 {
00089 rtOrb.finish();
00090 }
00091
00092 };
00093
00094
00096 class TProducerApplication :
00097 public TServerApplication<TOrb>
00098 {
00099
00100 private:
00101
00103 typedef
00104 TSampleProducer<TOrb>
00105 TCorbaSampleProducer;
00106
00108 typedef
00109 mpcl::TSampleProducer_var
00110 QTCorbaSampleProducer;
00111
00112
00113 public:
00114
00115 TProducerApplication ( const char* pkcNAME ,
00116 const char* pkcRELEASE ,
00117 TOrb& rtORB ) :
00118 TServerApplication<TOrb> (pkcNAME, pkcRELEASE, rtORB) {}
00119
00120 void initialize (void)
00121 {
00122 TCorbaSampleProducer* ptNamedSampleProducer1;
00123 TCorbaSampleProducer* ptNamedSampleProducer2;
00124 TCorbaSampleProducer* ptSampleProducer;
00125 QTCorbaSampleProducer qtNamedSampleProducer1;
00126 QTCorbaSampleProducer qtNamedSampleProducer2;
00127 QTCorbaSampleProducer qtSampleProducer;
00128 std::ofstream tOfstream (_pkcIorFileName);
00129
00130 ptNamedSampleProducer1 = new TCorbaSampleProducer (rtOrb, 10);
00131 ptNamedSampleProducer2 = new TCorbaSampleProducer (rtOrb, 20);
00132 ptSampleProducer = new TCorbaSampleProducer (rtOrb);
00133 qtNamedSampleProducer1 =
00134 rtOrb.enrol<TCorbaSampleProducer, QTCorbaSampleProducer> (ptNamedSampleProducer1, "/mpcl/test-server/sample_producer_1.object");
00135 qtNamedSampleProducer2 =
00136 rtOrb.enrol<TCorbaSampleProducer, QTCorbaSampleProducer> (ptNamedSampleProducer2, "/mpcl/test-server/sample_producer_2.object");
00137 qtSampleProducer =
00138 rtOrb.enrol<TCorbaSampleProducer, QTCorbaSampleProducer> (ptSampleProducer);
00139 tOfstream << rtOrb.name (qtSampleProducer) << std::endl;
00140 }
00141
00142
00143 public:
00144
00145 TString programFileName (void) const
00146 {
00147 return "test-server";
00148 }
00149
00150 };
00151
00152
00154 int main (int argc, const char** argv)
00155 {
00156
00157 using std::basic_ifstream;
00158
00159 TEST_INIT ("tests for CORBA (server)");
00160
00161 try
00162 {
00163 switch (fork())
00164 {
00165 case 0:
00166 {
00167
00168
00169
00170 TOrb tOrb (argc, argv);
00171 TProducerApplication tApplication ("test-server", "0.0.0", tOrb);
00172
00173 tApplication.initialize();
00174 TEST_FUNCTION (tApplication.start());
00175 break;
00176 }
00177 case -1:
00178 {
00179 throw mpcl::TException ("test-server", GetErrorMessage(), __FILE__, __LINE__);
00180 break;
00181 }
00182 default:
00183 {
00184 basic_ifstream<char> tIfstream;
00185 int I = 0;
00186
00187
00188
00189
00190
00191 TEST_FAIL_WITH_CODE (77);
00192 do
00193 {
00194
00195
00196
00197 tSystem.sleep (2);
00198 tIfstream.clear();
00199 tIfstream.open (_pkcIorFileName);
00200 } while ( !tIfstream.is_open() && ( I++ < 10 ) );
00201 break;
00202 }
00203 }
00204 }
00205 catch (CORBA::SystemException&)
00206 {
00207 std::cerr << "ORB; caught CORBA::SystemException" << std::endl;
00208 TEST_FAIL;
00209 }
00210 catch (CORBA::Exception&)
00211 {
00212 std::cerr << "ORB; caught CORBA::Exception" << std::endl;
00213 TEST_FAIL;
00214 }
00215 catch (const mpcl::TException& rktEXCEPTION)
00216 {
00217 std::cerr << rktEXCEPTION;
00218 TEST_FAIL;
00219 }
00220 catch (std::exception& rktEXCEPTION)
00221 {
00222 std::cerr << rktEXCEPTION.what();
00223 TEST_FAIL;
00224 }
00225 catch (...)
00226 {
00227 std::cerr << "caught unknown exception" << std::endl;
00228 TEST_FAIL;
00229 }
00230 TEST_MEMORY_STATUS;
00231 TEST_RETURN_CODE;
00232
00233 }