00001
00002
00003 #include <iostream>
00004
00005 using std::cerr ;
00006 using std::cout ;
00007 using std::endl ;
00008
00009 #include "TestRequestHandler.h"
00010
00011 TestRequestHandler *trh = 0 ;
00012
00013 TestRequestHandler::TestRequestHandler( string name )
00014 : BESRequestHandler( name ),
00015 _resp_num( 0 )
00016 {
00017 trh = this ;
00018 add_handler( "resp1", TestRequestHandler::test_build_resp1 ) ;
00019 add_handler( "resp2", TestRequestHandler::test_build_resp2 ) ;
00020 add_handler( "resp3", TestRequestHandler::test_build_resp3 ) ;
00021 add_handler( "resp4", TestRequestHandler::test_build_resp4 ) ;
00022 }
00023
00024 TestRequestHandler::~TestRequestHandler()
00025 {
00026 }
00027
00028 bool
00029 TestRequestHandler::test_build_resp1( BESDataHandlerInterface &r )
00030 {
00031 trh->_resp_num = 1 ;
00032 return true ;
00033 }
00034
00035 bool
00036 TestRequestHandler::test_build_resp2( BESDataHandlerInterface &r )
00037 {
00038 trh->_resp_num = 2 ;
00039 return true ;
00040 }
00041
00042 bool
00043 TestRequestHandler::test_build_resp3( BESDataHandlerInterface &r )
00044 {
00045 trh->_resp_num = 3 ;
00046 return true ;
00047 }
00048
00049 bool
00050 TestRequestHandler::test_build_resp4( BESDataHandlerInterface &r )
00051 {
00052 trh->_resp_num = 4 ;
00053 return true ;
00054 }
00055
00056 int
00057 TestRequestHandler::test()
00058 {
00059 cout << endl << "*****************************************" << endl;
00060 cout << "finding the handlers" << endl ;
00061 BESDataHandlerInterface r ;
00062 p_request_handler p = find_handler( "resp1" ) ;
00063 if( p )
00064 {
00065 p( r ) ;
00066 if( _resp_num == 1 )
00067 {
00068 cout << "found resp1" << endl ;
00069 }
00070 else
00071 {
00072 cerr << "looking for resp1, found " << _resp_num << endl ;
00073 return 1 ;
00074 }
00075 }
00076 else
00077 {
00078 cerr << "coundn't find resp1" << endl ;
00079 return 1 ;
00080 }
00081
00082 p = find_handler( "resp2" ) ;
00083 if( p )
00084 {
00085 p( r ) ;
00086 if( _resp_num == 2 )
00087 {
00088 cout << "found resp2" << endl ;
00089 }
00090 else
00091 {
00092 cerr << "looking for resp2, found " << _resp_num << endl ;
00093 return 1 ;
00094 }
00095 }
00096 else
00097 {
00098 cerr << "coundn't find resp2" << endl ;
00099 return 1 ;
00100 }
00101
00102 p = find_handler( "resp3" ) ;
00103 if( p )
00104 {
00105 p( r ) ;
00106 if( _resp_num == 3 )
00107 {
00108 cout << "found resp3" << endl ;
00109 }
00110 else
00111 {
00112 cerr << "looking for resp3, found " << _resp_num << endl ;
00113 return 1 ;
00114 }
00115 }
00116 else
00117 {
00118 cerr << "coundn't find resp3" << endl ;
00119 return 1 ;
00120 }
00121
00122 p = find_handler( "resp4" ) ;
00123 if( p )
00124 {
00125 p( r ) ;
00126 if( _resp_num == 4 )
00127 {
00128 cout << "found resp4" << endl ;
00129 }
00130 else
00131 {
00132 cerr << "looking for resp4, found " << _resp_num << endl ;
00133 return 1 ;
00134 }
00135 }
00136 else
00137 {
00138 cerr << "coundn't find resp4" << endl ;
00139 return 1 ;
00140 }
00141
00142 p = find_handler( "thingy" ) ;
00143 if( p )
00144 {
00145 p( r ) ;
00146 cerr << "found the response handler " << _resp_num << endl ;
00147 return 1 ;
00148 }
00149 else
00150 {
00151 cout << "didn't find thingy, good" << endl ;
00152 }
00153
00154 cout << endl << "*****************************************" << endl;
00155 cout << "try to add resp3 again" << endl ;
00156 bool ret = add_handler( "resp3", TestRequestHandler::test_build_resp3 ) ;
00157 if( ret == true )
00158 {
00159 cerr << "successfully added resp3 again" << endl ;
00160 return 1 ;
00161 }
00162 else
00163 {
00164 cout << "failed to add resp3 again, good" << endl ;
00165 }
00166
00167 cout << endl << "*****************************************" << endl;
00168 cout << "removing resp2" << endl ;
00169 ret = remove_handler( "resp2" ) ;
00170 if( ret == true )
00171 {
00172 p = find_handler( "resp2" ) ;
00173 if( p )
00174 {
00175 p( r ) ;
00176 cerr << "found resp2, execution = " << _resp_num << endl ;
00177 return 1 ;
00178 }
00179 else
00180 {
00181 cout << "successfully removed resp2" << endl ;
00182 }
00183 }
00184 else
00185 {
00186 cerr << "failed to remove resp2" << endl ;
00187 return 1 ;
00188 }
00189
00190 if( add_handler( "resp2", TestRequestHandler::test_build_resp2 ) == true )
00191 {
00192 cout << "successfully added resp2 back" << endl ;
00193 }
00194 else
00195 {
00196 cerr << "failed to add resp2 back" << endl ;
00197 return 1 ;
00198 }
00199
00200 p = find_handler( "resp2" ) ;
00201 if( p )
00202 {
00203 p( r ) ;
00204 if( _resp_num == 2 )
00205 {
00206 cout << "found resp2" << endl ;
00207 }
00208 else
00209 {
00210 cerr << "looking for resp2, found " << _resp_num << endl ;
00211 return 1 ;
00212 }
00213 }
00214 else
00215 {
00216 cerr << "coundn't find resp2" << endl ;
00217 return 1 ;
00218 }
00219
00220 return 0 ;
00221 }
00222