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( s ) ;
00088             cpl->look_for( d ) ;
00089             if( d.is_valid() )
00090             {
00091                 if( d.get_real_name() == r && d.get_container_type() == c )
00092                 {
00093                     cout << "found " << s << endl ;
00094                 }
00095                 else
00096                 {
00097                     cerr << "found " << s << " but real = " << d.get_real_name()
00098                          << " and container = " << d.get_container_type() << endl;
00099                     return 1 ;
00100                 }
00101             }
00102             else
00103             {
00104                 cerr << "couldn't find " << s << endl ;
00105                 return 1 ;
00106             }
00107         }
00108         catch( BESException &e )
00109         {
00110             cerr << "couldn't find " << s << endl ;
00111             return 1 ;
00112         }
00113     }
00114 
00115     cout << endl << "*****************************************" << endl;
00116     cout << "looking for non-existant thingy" << endl;
00117     try
00118     {
00119         BESContainer dnot( "thingy" ) ;
00120         cpl->look_for( dnot ) ;
00121         if( dnot.is_valid() )
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( stdout ) ;
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( "sym2" ) ;
00159         cpl->look_for( d2 ) ;
00160         if( d2.is_valid() )
00161         {
00162             cerr << "found sym2 with real = " << d2.get_real_name()
00163                  << " and container = " << d2.get_container_type() << endl ;
00164             return 1 ;
00165         }
00166         else
00167         {
00168             cout << "couldn't find sym2, good" << endl ;
00169         }
00170     }
00171     catch( BESException &e )
00172     {
00173         cout << "couldn't find sym2, good" << endl ;
00174     }
00175 
00176     cout << endl << "*****************************************" << endl;
00177     cout << "looking for sym7" << endl;
00178     try
00179     {
00180         BESContainer d7( "sym7" ) ;
00181         cpl->look_for( d7 ) ;
00182         if( d7.is_valid() )
00183         {
00184             if( d7.get_real_name() == "real7" &&
00185                 d7.get_container_type() == "type7" )
00186             {
00187                 cout << "found sym7" << endl ;
00188             }
00189             else
00190             {
00191                 cerr << "found sym7 but real = " << d7.get_real_name()
00192                      << " and container = " << d7.get_container_type() << endl ;
00193                 return 1 ;
00194             }
00195         }
00196         else
00197         {
00198             cerr << "couldn't find sym7, should have" << endl ;
00199             return 1 ;
00200         }
00201     }
00202     catch( BESException &e )
00203     {
00204         cerr << "couldn't find sym7, should have" << endl ;
00205         return 1 ;
00206     }
00207 
00208     cout << endl << "*****************************************" << endl;
00209     cout << "Returning from plistT::run" << endl;
00210 
00211     return retVal;
00212 }
00213 
00214 int
00215 main(int argC, char **argV) {
00216     Application *app = new plistT();
00217     string env_var = (string)"BES_CONF=" + TEST_SRC_DIR
00218                      + "/persistence_file_test.ini" ;
00219     putenv( (char *)env_var.c_str() ) ;
00220     return app->main(argC, argV);
00221 }
00222 

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