debugT.cc

Go to the documentation of this file.
00001 // debugT.C
00002 
00003 #include <unistd.h>
00004 
00005 #include <iostream>
00006 #include <sstream>
00007 
00008 using std::cerr ;
00009 using std::cout ;
00010 using std::endl ;
00011 using std::ostringstream ;
00012 
00013 #include "debugT.h"
00014 #include "BESDebug.h"
00015 #include "BESException.h"
00016 #include "test_config.h"
00017 
00018 int
00019 debugT::run(void)
00020 {
00021     cout << endl << "*****************************************" << endl;
00022     cout << "Entered debugT::run" << endl;
00023     int retVal = 0;
00024 
00025     if( !_tryme.empty() )
00026     {
00027         cout << endl << "*****************************************" << endl;
00028         cout << "trying " << _tryme << endl;
00029     }
00030     else
00031     {
00032         try
00033         {
00034             cout << endl << "*****************************************" << endl;
00035             cout << "Setting up with bad file name /bad/dir/debug" << endl;
00036             BESDebug::SetUp( "/bad/dir/debug,nc" ) ;
00037             cerr << "Successfully set up, shouldn't have" << endl ;
00038             return 1 ;
00039         }
00040         catch( BESException &e )
00041         {
00042             cout << "Unable to set up debug ... good" << endl ;
00043         }
00044 
00045         try
00046         {
00047             cout << endl << "*****************************************" << endl;
00048             cout << "Setting up myfile.debug,nc,cdf,hdf4" << endl;
00049             BESDebug::SetUp( "myfile.debug,nc,cdf,hdf4" ) ;
00050             cout << "successfully set up" << endl ;
00051             int result = access( "myfile.debug", W_OK|R_OK ) ;
00052             if( result == -1 )
00053             {
00054                 cerr << "File not created" << endl ;
00055                 return 1 ;
00056             }
00057             BESDebug::SetStrm( 0, false ) ;
00058             result = remove( "myfile.debug" ) ;
00059             if( result == -1 )
00060             {
00061                 cerr << "Unable to remove the debug file" << endl ;
00062                 return 1 ;
00063             }
00064         }
00065         catch( BESException &e )
00066         {
00067             cerr << "Unable to set up debug ... should have worked" << endl ;
00068             return 1 ;
00069         }
00070 
00071         try
00072         {
00073             cout << endl << "*****************************************" << endl;
00074             cout << "Setting up cerr,ff" << endl;
00075             BESDebug::SetUp( "cerr,ff,-cdf" ) ;
00076             cout << "Successfully set up" << endl ;
00077         }
00078         catch( BESException &e )
00079         {
00080             cerr << "Unable to set up debug ... should have worked" << endl ;
00081             return 1 ;
00082         }
00083 
00084         cout << endl << "*****************************************" << endl;
00085         cout << "try debugging to nc" << endl;
00086         ostringstream nc ;
00087         BESDebug::SetStrm( &nc, false ) ;
00088         string debug_str = "Testing nc debug" ;
00089         BESDEBUG( "nc", debug_str ) ;
00090         if( nc.str() != debug_str )
00091         {
00092             cerr << "incorrect debug information: " << nc.str() << endl ;
00093             return 1 ;
00094         }
00095 
00096         cout << endl << "*****************************************" << endl;
00097         cout << "try debugging to hdf4" << endl;
00098         ostringstream hdf4 ;
00099         BESDebug::SetStrm( &hdf4, false ) ;
00100         debug_str = "Testing hdf4 debug" ;
00101         BESDEBUG( "hdf4", debug_str ) ;
00102         if( hdf4.str() != debug_str )
00103         {
00104             cerr << "incorrect debug information: " << hdf4.str() << endl ;
00105             return 1 ;
00106         }
00107 
00108         cout << endl << "*****************************************" << endl;
00109         cout << "try debugging to ff" << endl;
00110         ostringstream ff ;
00111         BESDebug::SetStrm( &ff, false ) ;
00112         debug_str = "Testing ff debug" ;
00113         BESDEBUG( "ff", debug_str ) ;
00114         if( ff.str() != debug_str )
00115         {
00116             cerr << "incorrect debug information: " << ff.str() << endl ;
00117             return 1 ;
00118         }
00119 
00120         cout << endl << "*****************************************" << endl;
00121         cout << "turn off ff and try debugging to ff again" << endl;
00122         BESDebug::Set( "ff", false ) ;
00123         ostringstream ff2 ;
00124         BESDebug::SetStrm( &ff2, false ) ;
00125         debug_str = "" ;
00126         BESDEBUG( "ff", debug_str ) ;
00127         if( ff2.str() != debug_str )
00128         {
00129             cerr << "incorrect debug information: " << ff2.str() << endl ;
00130             return 1 ;
00131         }
00132 
00133         cout << endl << "*****************************************" << endl;
00134         cout << "try debugging to cdf" << endl;
00135         ostringstream cdf ;
00136         BESDebug::SetStrm( &cdf, false ) ;
00137         debug_str = "" ;
00138         BESDEBUG( "cdf", debug_str ) ;
00139         if( cdf.str() != debug_str )
00140         {
00141             cerr << "incorrect debug information: " << cdf.str() << endl ;
00142             return 1 ;
00143         }
00144     }
00145 
00146     cout << endl << "*****************************************" << endl;
00147     cout << "display debug help" << endl;
00148     BESDebug::Help( cout ) ;
00149 
00150     cout << endl << "*****************************************" << endl;
00151     cout << "Returning from debugT::run" << endl;
00152 
00153     return retVal;
00154 }
00155 
00156 int
00157 main(int argC, char **argV) {
00158     int c = 0 ;
00159     string tryme ;
00160     while( ( c = getopt( argC, argV, "d:" ) ) != EOF )
00161     {
00162         switch( c )
00163         {
00164             case 'd':
00165                 tryme = optarg ;
00166                 break ;
00167             default:
00168                 cerr << "bad option to debugT" << endl ;
00169                 cerr << "debugT -d string" << endl ;
00170                 return 1 ;
00171                 break ;
00172         }
00173     }
00174     string env_var = (string)"BES_CONF=" + TEST_SRC_DIR + "/bes.conf" ;
00175     putenv( (char *)env_var.c_str() ) ;
00176 
00177     Application *app = new debugT( tryme );
00178     return app->main(argC, argV);
00179 }
00180 

Generated on Fri Nov 30 12:06:48 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.1