plistT.cc

Go to the documentation of this file.
00001 // plistT.C
00002 
00003 #include <iostream>
00004 
00005 using std::cerr ;
00006 using std::cout ;
00007 using std::endl ;
00008 
00009 #include "plistT.h"
00010 #include "BESContainerStorageList.h"
00011 #include "BESContainerStorageFile.h"
00012 #include "BESContainer.h"
00013 #include "BESException.h"
00014 #include "BESTextInfo.h"
00015 #include "TheBESKeys.h"
00016 #include <test_config.h>
00017 
00018 int plistT::
00019 run(void)
00020 {
00021     BESKeys *keys = TheBESKeys::TheKeys() ;
00022     keys->set_key( (string)"BES.Container.Persistence.File.FileTooMany=" + TEST_SRC_DIR + "/persistence_file3.txt" ) ;
00023     keys->set_key( (string)"BES.Container.Persistence.File.FileTooFew=" + TEST_SRC_DIR + "/persistence_file4.txt" ) ;
00024     keys->set_key( (string)"BES.Container.Persistence.File.File1=" + TEST_SRC_DIR + "/persistence_file1.txt" ) ;
00025     keys->set_key( (string)"BES.Container.Persistence.File.File2=" + TEST_SRC_DIR + "/persistence_file2.txt" ) ;
00026 
00027     cout << endl << "*****************************************" << endl;
00028     cout << "Entered plistT::run" << endl;
00029     int retVal = 0;
00030 
00031     cout << endl << "*****************************************" << endl;
00032     cout << "Create the BESContainerPersistentList" << endl;
00033     BESContainerStorageList *cpl = BESContainerStorageList::TheList() ;
00034 
00035     cout << endl << "*****************************************" << endl;
00036     cout << "Add BESContainerStorageFile for File1 and File2" << endl;
00037     BESContainerStorageFile *cpf ;
00038     cpf = new BESContainerStorageFile( "File1" ) ;
00039     if( cpl->add_persistence( cpf ) == true )
00040     {
00041         cout << "successfully added File1" << endl ;
00042     }
00043     else
00044     {
00045         cerr << "unable to add File1" << endl ;
00046         return 1 ;
00047     }
00048 
00049     cpf = new BESContainerStorageFile( "File2" ) ;
00050     if( cpl->add_persistence( cpf ) == true )
00051     {
00052         cout << "successfully added File2" << endl ;
00053     }
00054     else
00055     {
00056         cerr << "unable to add File2" << endl ;
00057         return 1 ;
00058     }
00059 
00060     cout << endl << "*****************************************" << endl;
00061     cout << "Try to add File2 again" << endl;
00062     cpf = new BESContainerStorageFile( "File2" ) ;
00063     if( cpl->add_persistence( cpf ) == true )
00064     {
00065         cerr << "successfully added File2 again" << endl ;
00066         delete cpf ;
00067         return 1 ;
00068     }
00069     else
00070     {
00071         cout << "unable to add File2, good" << endl ;
00072         delete cpf ;
00073     }
00074 
00075     char s[10] ;
00076     char r[10] ;
00077     char c[10] ;
00078     for( int i = 1; i < 11; i++ )
00079     {
00080         sprintf( s, "sym%d", i ) ;
00081         sprintf( r, "real%d", i ) ;
00082         sprintf( c, "type%d", i ) ;
00083         cout << endl << "*****************************************" << endl;
00084         cout << "looking for " << s << endl;
00085         try
00086         {
00087             BESContainer *d = cpl->look_for( s ) ;
00088             if( d )
00089             {
00090                 if( d->get_real_name() == r && d->get_container_type() == c )
00091                 {
00092                     cout << "found " << s << endl ;
00093                 }
00094                 else
00095                 {
00096                     cerr << "found " << s << " but real = "
00097                          << d->get_real_name()
00098                          << " and container = "
00099                          << d->get_container_type() << endl;
00100                     return 1 ;
00101                 }
00102             }
00103             else
00104             {
00105                 cerr << "couldn't find " << s << endl ;
00106                 return 1 ;
00107             }
00108         }
00109         catch( BESException &e )
00110         {
00111             cerr << "couldn't find " << s << endl ;
00112             return 1 ;
00113         }
00114     }
00115 
00116     cout << endl << "*****************************************" << endl;
00117     cout << "looking for non-existant thingy" << endl;
00118     try
00119     {
00120         BESContainer *dnot = cpl->look_for( "thingy" ) ;
00121         if( dnot )
00122         {
00123             cerr << "found thingy, shouldn't have" << endl ;
00124             return 1 ;
00125         }
00126         else
00127         {
00128             cout << "didn't find thingy, good" << endl ;
00129         }
00130     }
00131     catch( BESException &e )
00132     {
00133         cout << "didn't find thingy, good" << endl ;
00134     }
00135 
00136     cout << endl << "*****************************************" << endl;
00137     cout << "show containers" << endl;
00138     BESTextInfo info ;
00139     cpl->show_containers( info ) ;
00140     info.print( cout ) ;
00141 
00142     cout << endl << "*****************************************" << endl;
00143     cout << "remove File1" << endl;
00144     if( cpl->del_persistence( "File1" ) == true )
00145     {
00146         cout << "successfully removed File1" << endl ;
00147     }
00148     else
00149     {
00150         cerr << "unable to remove File1" << endl ;
00151         return 1 ;
00152     }
00153 
00154     cout << endl << "*****************************************" << endl;
00155     cout << "looking for sym2" << endl;
00156     try
00157     {
00158         BESContainer *d2 = cpl->look_for( "sym2" ) ;
00159         if( d2 )
00160         {
00161             cerr << "found sym2 with real = " << d2->get_real_name()
00162                  << " and container = " << d2->get_container_type() << endl ;
00163             return 1 ;
00164         }
00165         else
00166         {
00167             cout << "couldn't find sym2, good" << endl ;
00168         }
00169     }
00170     catch( BESException &e )
00171     {
00172         cout << "couldn't find sym2, good" << endl ;
00173     }
00174 
00175     cout << endl << "*****************************************" << endl;
00176     cout << "looking for sym7" << endl;
00177     try
00178     {
00179         BESContainer *d7 = cpl->look_for( "sym7" ) ;
00180         if( d7 )
00181         {
00182             if( d7->get_real_name() == "real7" &&
00183                 d7->get_container_type() == "type7" )
00184             {
00185                 cout << "found sym7" << endl ;
00186             }
00187             else
00188             {
00189                 cerr << "found sym7 but real = " << d7->get_real_name()
00190                      << " and container = " << d7->get_container_type()
00191                      << endl ;
00192                 return 1 ;
00193             }
00194         }
00195         else
00196         {
00197             cerr << "couldn't find sym7, should have" << endl ;
00198             return 1 ;
00199         }
00200     }
00201     catch( BESException &e )
00202     {
00203         cerr << "couldn't find sym7, should have" << endl ;
00204         return 1 ;
00205     }
00206 
00207     cout << endl << "*****************************************" << endl;
00208     cout << "Returning from plistT::run" << endl;
00209 
00210     return retVal;
00211 }
00212 
00213 int
00214 main(int argC, char **argV) {
00215     Application *app = new plistT();
00216     string env_var = (string)"BES_CONF=" + TEST_SRC_DIR
00217                      + "/persistence_file_test.ini" ;
00218     putenv( (char *)env_var.c_str() ) ;
00219     return app->main(argC, argV);
00220 }
00221 

Generated on Sat Jan 19 04:05:37 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.4