TestClientMain.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include "TestClient.h"
00003 #include "networkApp.h"
00004 #ifdef _MSC_VER
00005 #include <io.h>
00006 #endif
00007 #include <iostream>
00008 #include <fstream>
00009 
00010 #define VersionString "Simple SOAP Test Client 2.1 build 0"
00011 
00027 /*
00028         History:
00029 
00030                 18-Aug-2003             GJPC    Intial Type in
00031 
00032         $Log: TestClientMain.cpp,v $
00033         Revision 1.1  2005/03/22 22:27:20  gjpc
00034         This is the intial check in of the Simple SOAP library.
00035         
00036         The code compiles and executes under MSVC .NET and GNU 3.3
00037         
00038         It has been run under Debian, SUSE, CYGWIN and WinXP
00039         
00040         Revision 1.3  2004/04/23 16:58:00  gjpc
00041         expanded the Simple SOAP package to allow RPC's within RPC's
00042         added Tree morphing primatives
00043         extended the test client to allow for programable validation
00044 */
00045 
00046 
00047 char *ServerObject = NULL;
00048 
00049 int networkAppMain( int argc, char* argv[] )
00050 {
00051     TestSOAPClient testSOAP;
00052 
00053         std::cout << VersionString << std::endl;
00054     if ( argc < 2 )
00055     {
00056                 std::cout       << "usage:  media.xml ServerObjectName TestListfile <IP Address> <port>" << std::endl 
00057                         << "Default IP 127.0.0.1 Default Port 8080" << std::endl ;
00058         return 1;
00059     }
00060 
00061         if ( access( argv[2], 4 ) != 0 )
00062     {
00063                 std::cout       << "Could not access file " << argv[2] ;
00064         return 1;
00065     }
00066 
00067         ServerObject = argv[1];                 // set the server object name
00068         std::string listFile = argv[2];
00069         std::ifstream inpList;
00070         inpList.open( listFile.c_str(), std::ios_base::in );
00071         if ( !inpList.is_open() )
00072         {
00073                 std::cout << "cannot open list file: " << listFile << std::endl;
00074                 return 1;
00075         }
00076 
00077         // setup the server address
00078         testSOAP.setEndPoint( argc < 4 ? std::string( "127.0.0.1" ) : std::string( argv[3] ), 
00079                                                 argc < 5 ? 8080 : atoi( argv[4] ) );
00080 
00081         std::string listPath = listFile;
00082         while ( listPath.end() != listPath.begin() )
00083         {
00084                 if ( ( *--listPath.end() == ':' ) ||
00085                                 ( *--listPath.end() == '/' ) ||
00086                                 ( *--listPath.end() == '\\')    )
00087                         break;
00088                 else
00089                         listPath.erase( --listPath.end() );
00090 
00091                 if ( ( *(listPath.end()-1) == ':' ) ||
00092                                 ( *(listPath.end()-1) == '/' ) ||
00093                                 ( *(listPath.end()-1) == '\\')  )
00094                         break;
00095                 else
00096                         listPath.erase(listPath.end()-1);
00097         }
00098         try
00099         {
00100                 std::string rpcFilename; 
00101                 while ( !inpList.eof() )
00102                 {
00103                         getline( inpList, rpcFilename );   //std::cout << rpcFilename << std::endl;
00104                         // allow empty lines and comments
00105                         if ( rpcFilename.empty() || ( rpcFilename[0] == '#' ) )
00106                                 continue;
00107 
00108                         // open the file with the RPC in it
00109                         std::ifstream inpRPC;
00110                         //rpcFilename = listPath + rpcFilename;
00111                         if ( rpcFilename[ rpcFilename.length()-1 ] == '\r' )
00112                                 rpcFilename[ rpcFilename.length()-1 ] = 0;
00113                         inpRPC.open( rpcFilename.c_str(), std::ios_base::in );
00114                         if ( !inpRPC.is_open() )
00115                         {
00116                                 std::cout << "cannot open RPC file: " << rpcFilename << std::endl;
00117                                 return 1;
00118                         }
00119 
00120                         // dump into a ostring
00121                         std::ostringstream rpcCall;
00122                         rpcCall << inpRPC.rdbuf();
00123 
00124                         // now mark the boudaries and process the calll to the server and its repsonse
00125                         std::cout << "\r\n\n===================== " << rpcFilename << " ============================\r\n\n";
00126                         std::cout << "\r\n\n--------------------- " << rpcFilename << " Return ---------------------\r\n\n" 
00127                                 << testSOAP.Generic( rpcCall.str() );
00128 
00129                         inpRPC.close();
00130                 }
00131     }
00132         catch ( std::exception& e )
00133         {
00134                 std::cerr << e.what() << std::endl;
00135                 return -1;
00136         }
00137 
00138         std::cout << std::endl << "Normal termination of test run" << std::endl;
00139         return 0;
00140 }
00141 
00142 
00143 int main( int argc, char* argv[] )
00144 {
00145         return NetworkStart( argc, argv, networkAppMain );
00146 }

Generated on Tue Mar 28 09:10:15 2006 for Simple SOAP by  doxygen 1.4.6