00001
00002
00003 #include <iostream>
00004
00005 using std::cerr ;
00006 using std::cout ;
00007 using std::endl ;
00008
00009 #include "pvolT.h"
00010 #include "BESContainerStorageVolatile.h"
00011 #include "BESContainer.h"
00012 #include "TheBESKeys.h"
00013 #include "BESException.h"
00014 #include "BESTextInfo.h"
00015 #include <test_config.h>
00016
00017 int pvolT::
00018 run(void)
00019 {
00020 cout << endl << "*****************************************" << endl;
00021 cout << "Entered pvolT::run" << endl;
00022 int retVal = 0;
00023
00024 cout << endl << "*****************************************" << endl;
00025 cout << "Create volatile and add five elements" << endl;
00026 BESContainerStorageVolatile cpv( "volatile" ) ;
00027 cpv.add_container( "sym1", "real1", "type1" ) ;
00028 cpv.add_container( "sym2", "real2", "type2" ) ;
00029 cpv.add_container( "sym3", "real3", "type3" ) ;
00030 cpv.add_container( "sym4", "real4", "type4" ) ;
00031 cpv.add_container( "sym5", "real5", "type5" ) ;
00032
00033 cout << endl << "*****************************************" << endl;
00034 cout << "show containers" << endl;
00035 BESTextInfo info ;
00036 cpv.show_containers( info ) ;
00037 info.print( stdout ) ;
00038
00039 cout << endl << "*****************************************" << endl;
00040 cout << "try to add sym1 again" << endl;
00041 try
00042 {
00043 cpv.add_container( "sym1", "real1", "type1" ) ;
00044 cerr << "succesfully added sym1 again, bad things man" << endl ;
00045 return 1 ;
00046 }
00047 catch( BESException &e )
00048 {
00049 cout << "unable to add sym1 again, good" << endl ;
00050 cout << e.get_message() << endl ;
00051 }
00052
00053 {
00054 char s[10] ;
00055 char r[10] ;
00056 char c[10] ;
00057 for( int i = 1; i < 6; i++ )
00058 {
00059 sprintf( s, "sym%d", i ) ;
00060 sprintf( r, "./real%d", i ) ;
00061 sprintf( c, "type%d", i ) ;
00062 cout << endl << "*****************************************" << endl;
00063 cout << "Looking for " << s << endl;
00064 BESContainer d( s ) ;
00065 cpv.look_for( d ) ;
00066 if( d.is_valid() )
00067 {
00068 if( d.get_real_name() == r && d.get_container_type() == c )
00069 {
00070 cout << "found " << s << endl ;
00071 }
00072 else
00073 {
00074 cerr << "found " << s << " but:" << endl ;
00075 cerr << "real = " << r << ", should be " << d.get_real_name() << endl ;
00076 cerr << "type = " << c << ", should be " << d.get_container_type() << endl ;
00077 return 1 ;
00078 }
00079 }
00080 else
00081 {
00082 cerr << "couldn't find " << s << endl ;
00083 return 1 ;
00084 }
00085 }
00086 }
00087
00088 cout << endl << "*****************************************" << endl;
00089 cout << "remove sym1" << endl;
00090 bool rem = cpv.del_container( "sym1" ) ;
00091 if( rem )
00092 {
00093 cout << "successfully removed sym1" << endl ;
00094 }
00095
00096 {
00097 cout << endl << "*****************************************" << endl;
00098 cout << "find sym1" << endl;
00099 BESContainer d( "sym1" ) ;
00100 cpv.look_for( d ) ;
00101 if( d.is_valid() == true )
00102 {
00103 cerr << "found " << d.get_symbolic_name() << " with "
00104 << "real = " << d.get_real_name() << " and "
00105 << "type = " << d.get_container_type() << endl ;
00106 return 1 ;
00107 }
00108 else
00109 {
00110 cout << "didn't remove it, good" << endl ;
00111 }
00112 }
00113
00114 cout << endl << "*****************************************" << endl;
00115 cout << "remove sym5" << endl;
00116 rem = cpv.del_container( "sym5" ) ;
00117 if( rem )
00118 {
00119 cout << "successfully removed sym5" << endl ;
00120 }
00121
00122 {
00123 cout << endl << "*****************************************" << endl;
00124 cout << "find sym5" << endl;
00125 BESContainer d( "sym5" ) ;
00126 cpv.look_for( d ) ;
00127 if( d.is_valid() == true )
00128 {
00129 cerr << "found " << d.get_symbolic_name() << " with "
00130 << "real = " << d.get_real_name() << " and "
00131 << "type = " << d.get_container_type() << endl ;
00132 return 1 ;
00133 }
00134 else
00135 {
00136 cout << "didn't remove it, good" << endl ;
00137 }
00138 }
00139
00140 cout << endl << "*****************************************" << endl;
00141 cout << "remove nosym" << endl;
00142 rem = cpv.del_container( "nosym" ) ;
00143 if( !rem )
00144 {
00145 cout << "didn't find nosym, good" << endl ;
00146 }
00147 else
00148 {
00149 cerr << "removed a container, bad things man" << endl ;
00150 return 1 ;
00151 }
00152
00153 {
00154 char s[10] ;
00155 char r[10] ;
00156 char c[10] ;
00157 for( int i = 2; i < 5; i++ )
00158 {
00159 sprintf( s, "sym%d", i ) ;
00160 sprintf( r, "./real%d", i ) ;
00161 sprintf( c, "type%d", i ) ;
00162 cout << endl << "*****************************************" << endl;
00163 cout << "Looking for " << s << endl;
00164 BESContainer d( s ) ;
00165 cpv.look_for( d ) ;
00166 if( d.is_valid() )
00167 {
00168 if( d.get_real_name() == r && d.get_container_type() == c )
00169 {
00170 cout << "found " << s << endl ;
00171 }
00172 else
00173 {
00174 cerr << "found " << s << " but real = " << r
00175 << " and container = " << c << endl ;
00176 return 1 ;
00177 }
00178 }
00179 else
00180 {
00181 cerr << "couldn't find " << s << endl ;
00182 return 1 ;
00183 }
00184 }
00185 }
00186
00187 cout << endl << "*****************************************" << endl;
00188 cout << "show containers" << endl;
00189 BESTextInfo info2 ;
00190 cpv.show_containers( info2 ) ;
00191 info2.print( stdout ) ;
00192
00193 cout << endl << "*****************************************" << endl;
00194 cout << "Returning from pvolT::run" << endl;
00195 return retVal;
00196 }
00197
00198 int
00199 main(int argC, char **argV) {
00200 string env_var = (string)"BES_CONF=" + TEST_SRC_DIR
00201 + "/persistence_cgi_test.ini" ;
00202 putenv( (char *)env_var.c_str() ) ;
00203 Application *app = new pvolT();
00204 return app->main(argC, argV);
00205 }
00206