reqlistT.cc

Go to the documentation of this file.
00001 // reqlistT.C
00002 
00003 #include <iostream>
00004 
00005 using std::cerr ;
00006 using std::cout ;
00007 using std::endl ;
00008 
00009 #include "reqlistT.h"
00010 #include "BESRequestHandlerList.h"
00011 #include "TestRequestHandler.h"
00012 
00013 int reqlistT::
00014 run(void) {
00015     cout << endl << "*****************************************" << endl;
00016     cout << "Entered reqlistT::run" << endl;
00017     int retVal = 0;
00018 
00019     cout << endl << "*****************************************" << endl;
00020     cout << "add the 5 request handlers" << endl ;
00021     BESRequestHandlerList *rhl = BESRequestHandlerList::TheList() ;
00022     char num[10] ;
00023     for( int i = 0; i < 5; i++ )
00024     {
00025         sprintf( num, "req%d", i ) ;
00026         if( rhl->add_handler( num, new TestRequestHandler( num ) ) == true )
00027         {
00028             cout << "successfully added " << num << endl ;
00029         }
00030         else
00031         {
00032             cerr << "failed to add " << num << endl ;
00033             return 1 ;
00034         }
00035     }
00036 
00037     cout << endl << "*****************************************" << endl;
00038     cout << "try to add req3 again" << endl ;
00039     BESRequestHandler *rh = new TestRequestHandler( "req3" ) ;
00040     if( rhl->add_handler( "req3", rh ) == true )
00041     {
00042         cerr << "successfully added req3 again" << endl ;
00043         return 1 ;
00044     }
00045     else
00046     {
00047         cout << "failed to add req3 again, good" << endl ;
00048         delete rh ;
00049     }
00050 
00051     cout << endl << "*****************************************" << endl;
00052     cout << "finding the handlers" << endl ;
00053     for( int i = 4; i >=0; i-- )
00054     {
00055         sprintf( num, "req%d", i ) ;
00056         rh = rhl->find_handler( num ) ;
00057         if( rh )
00058         {
00059             if( rh->get_name() == num )
00060             {
00061                 cout << "found " << num << endl ;
00062             }
00063             else
00064             {
00065                 cerr << "looking for " << num
00066                      << ", found " << rh->get_name() << endl ;
00067                 return 1 ;
00068             }
00069         }
00070         else
00071         {
00072             cerr << "coundn't find " << num << endl ;
00073             return 1 ;
00074         }
00075     }
00076     rh = rhl->find_handler( "thingy" ) ;
00077     if( rh )
00078     {
00079         if( rh->get_name() == "thingy" )
00080         {
00081             cerr << "found thingy" << endl ;
00082             return 1 ;
00083         }
00084         else
00085         {
00086             cerr << "looking for thingy, found " << rh->get_name() << endl ;
00087             return 1 ;
00088         }
00089     }
00090     else
00091     {
00092         cout << "coundn't find thingy" << endl ;
00093     }
00094 
00095     cout << endl << "*****************************************" << endl;
00096     cout << "removing req2" << endl ;
00097     rh = rhl->remove_handler( "req2" ) ;
00098     if( rh )
00099     {
00100         string name = rh->get_name() ;
00101         if( name == "req2" )
00102         {
00103             cout << "successfully removed req2" << endl ;
00104             delete rh ;
00105         }
00106         else
00107         {
00108             cerr << "trying to remove req2, but removed " << name << endl ;
00109             return 1 ;
00110         }
00111     }
00112     else
00113     {
00114         cerr << "failed to remove req2" << endl ;
00115         return 1 ;
00116     }
00117 
00118     rh = rhl->find_handler( "req2" ) ;
00119     if( rh )
00120     {
00121         if( rh->get_name() == "req2" )
00122         {
00123             cerr << "found req2, should have been removed" << endl ;
00124             return 1 ;
00125         }
00126         else
00127         {
00128             cerr << "found " << rh->get_name() << " when looking for req2"
00129                  << endl ;
00130             return 1 ;
00131         }
00132     }
00133     else
00134     {
00135         cout << "couldn't find req2, good" << endl ;
00136     }
00137 
00138     if( rhl->add_handler( "req2", new TestRequestHandler( "req2" ) ) == true )
00139     {
00140         cout << "successfully added req2 back" << endl ;
00141     }
00142     else
00143     {
00144         cerr << "failed to add req2 back" << endl ;
00145         return 1 ;
00146     }
00147 
00148     rh = rhl->find_handler( "req2" ) ;
00149     if( rh )
00150     {
00151         if( rh->get_name() == "req2" )
00152         {
00153             cout << "found req2" << endl ;
00154         }
00155         else
00156         {
00157             cerr << "looking for req2, found " << rh->get_name() << endl ;
00158             return 1 ;
00159         }
00160     }
00161     else
00162     {
00163         cerr << "coundn't find req2" << endl ;
00164         return 1 ;
00165     }
00166 
00167     cout << endl << "*****************************************" << endl;
00168     cout << "Iterating through handler list" << endl ;
00169     BESRequestHandlerList::Handler_citer h = rhl->get_first_handler() ;
00170     BESRequestHandlerList::Handler_citer hl = rhl->get_last_handler() ;
00171     int count = 0 ;
00172     for( ; h != hl; h++ )
00173     {
00174         rh = (*h).second ;
00175         char sb[10] ;
00176         sprintf( sb, "req%d", count ) ;
00177         string n = rh->get_name() ;
00178         if( n == sb )
00179         {
00180             cout << "found " << n << endl ;
00181         }
00182         else
00183         {
00184             cerr << "found " << n << ", looking for " << sb << endl ;
00185             return 1 ;
00186         }
00187         count++ ;
00188     }
00189     if( count == 5 )
00190     {
00191         cout << "found right number of handlers" << endl ;
00192     }
00193     else
00194     {
00195         cerr << "wrong number of handlers, found " << count << endl ;
00196         return 1 ;
00197     }
00198 
00199     cout << endl << "*****************************************" << endl;
00200     cout << "Returning from reqlistT::run" << endl;
00201 
00202     return retVal;
00203 }
00204 
00205 int
00206 main(int argC, char **argV) {
00207     Application *app = new reqlistT();
00208     return app->main(argC, argV);
00209 }
00210 

Generated on Wed Aug 29 03:24:05 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.2