00001
00002
00003 #include <iostream>
00004
00005 using std::cerr ;
00006 using std::cout ;
00007 using std::endl ;
00008
00009 #include "infoT.h"
00010 #include "TheBESKeys.h"
00011 #include "BESTextInfo.h"
00012 #include "BESHTMLInfo.h"
00013 #include "BESXMLInfo.h"
00014 #include "BESInfoList.h"
00015 #include "BESInfoNames.h"
00016 #include <test_config.h>
00017
00018 int infoT::
00019 run(void)
00020 {
00021 cout << endl << "*****************************************" << endl;
00022 cout << "Entered infoT::run" << endl;
00023 int retVal = 0;
00024
00025 cout << endl << "*****************************************" << endl;
00026 cout << "add info builders to info list ... " ;
00027 BESInfoList::TheList()->add_info_builder( BES_TEXT_INFO,
00028 BESTextInfo::BuildTextInfo ) ;
00029 BESInfoList::TheList()->add_info_builder( BES_HTML_INFO,
00030 BESHTMLInfo::BuildHTMLInfo ) ;
00031 BESInfoList::TheList()->add_info_builder( BES_XML_INFO,
00032 BESXMLInfo::BuildXMLInfo ) ;
00033 cout << "OK" << endl ;
00034
00035 map<string,string> attrs ;
00036 attrs["attr_name"] = "\"attr_val\"" ;
00037
00038 cout << endl << "*****************************************" << endl;
00039 cout << "Set Info type to txt ... " ;
00040 TheBESKeys::TheKeys()->set_key( "BES.Info.Type", "txt" ) ;
00041 BESInfo *info = BESInfoList::TheList()->build_info() ;
00042 BESTextInfo *t_info = dynamic_cast<BESTextInfo *>(info) ;
00043 if( t_info )
00044 {
00045 cout << "OK" << endl ;
00046 }
00047 else
00048 {
00049 cout << "FAIL" << endl ;
00050 return 1 ;
00051 }
00052 t_info->begin_response( "testTextResponse" ) ;
00053 t_info->add_tag( "tag1", "tag1 data" ) ;
00054 t_info->begin_tag( "tag2" ) ;
00055 t_info->add_tag( "tag3", "tag3 data", &attrs ) ;
00056 t_info->end_tag( "tag2" ) ;
00057 t_info->end_response() ;
00058 t_info->print( stdout ) ;
00059
00060 cout << endl << "*****************************************" << endl;
00061 cout << "Set Info type to html ... " << endl ;
00062 TheBESKeys::TheKeys()->set_key( "BES.Info.Type", "html" ) ;
00063 info = BESInfoList::TheList()->build_info() ;
00064 BESHTMLInfo *h_info = dynamic_cast<BESHTMLInfo *>(info) ;
00065 if( h_info )
00066 {
00067 cout << "OK" << endl ;
00068 }
00069 else
00070 {
00071 cout << "FAIL" << endl ;
00072 return 1 ;
00073 }
00074 h_info->begin_response( "testHTMLResponse" ) ;
00075 h_info->add_tag( "tag1", "tag1 data" ) ;
00076 h_info->begin_tag( "tag2" ) ;
00077 h_info->add_tag( "tag3", "tag3 data", &attrs ) ;
00078 h_info->end_tag( "tag2" ) ;
00079 h_info->end_response() ;
00080 h_info->print( stdout ) ;
00081
00082 cout << endl << "*****************************************" << endl;
00083 cout << "Set Info type to xml ... " << endl ;
00084 TheBESKeys::TheKeys()->set_key( "BES.Info.Type", "xml" ) ;
00085 info = BESInfoList::TheList()->build_info() ;
00086 BESXMLInfo *x_info = dynamic_cast<BESXMLInfo *>(info) ;
00087 if( x_info )
00088 {
00089 cout << "OK" << endl ;
00090 }
00091 else
00092 {
00093 cout << "FAIL" << endl ;
00094 return 1 ;
00095 }
00096 x_info->begin_response( "testXMLResponse" ) ;
00097 x_info->add_tag( "tag1", "tag1 data" ) ;
00098 x_info->begin_tag( "tag2" ) ;
00099 x_info->add_tag( "tag3", "tag3 data", &attrs ) ;
00100 x_info->end_tag( "tag2" ) ;
00101 x_info->end_response() ;
00102 x_info->print( stdout ) ;
00103
00104 cout << endl << "*****************************************" << endl;
00105 cout << "Returning from infoT::run" << endl;
00106
00107 return retVal;
00108 }
00109
00110 int
00111 main(int argC, char **argV) {
00112 string env_var = (string)"BES_CONF=" + TEST_SRC_DIR
00113 + "/info_test.ini" ;
00114 putenv( (char *)env_var.c_str() ) ;
00115 Application *app = new infoT();
00116 return app->main(argC, argV);
00117 }
00118