pfileT.cc

Go to the documentation of this file.
00001 // pfileT.C
00002 
00003 #include <iostream>
00004 
00005 using std::cerr ;
00006 using std::cout ;
00007 using std::endl ;
00008 
00009 #include "pfileT.h"
00010 #include "BESContainerStorageFile.h"
00011 #include "BESContainer.h"
00012 #include "BESException.h"
00013 #include "BESTextInfo.h"
00014 #include "TheBESKeys.h"
00015 #include <test_config.h>
00016 
00017 int pfileT::
00018 run(void)
00019 {
00020     BESKeys *keys = TheBESKeys::TheKeys() ;
00021     keys->set_key( (string)"BES.Container.Persistence.File.FileTooMany=" + TEST_SRC_DIR + "/persistence_file3.txt" ) ;
00022     keys->set_key( (string)"BES.Container.Persistence.File.FileTooFew=" + TEST_SRC_DIR + "/persistence_file4.txt" ) ;
00023     keys->set_key( (string)"BES.Container.Persistence.File.File1=" + TEST_SRC_DIR + "/persistence_file1.txt" ) ;
00024     keys->set_key( (string)"BES.Container.Persistence.File.File2=" + TEST_SRC_DIR + "/persistence_file2.txt" ) ;
00025 
00026     cout << endl << "*****************************************" << endl;
00027     cout << "Entered pfileT::run" << endl;
00028     int retVal = 0;
00029 
00030     cout << endl << "*****************************************" << endl;
00031     cout << "Try to get one called File" << endl;
00032     try
00033     {
00034         BESContainerStorageFile cpf( "File" ) ;
00035         cerr << "opened file File, shouldn't have" << endl ;
00036         return 1 ;
00037     }
00038     catch( BESException &ex )
00039     {
00040         cout << "couldn't get File, good, because" << endl ;
00041         cout << ex.get_message() << endl ;
00042     }
00043 
00044     cout << endl << "*****************************************" << endl;
00045     cout << "Try to get one called FileNot" << endl;
00046     try
00047     {
00048         BESContainerStorageFile cpf( "FileNot" ) ;
00049         cerr << "opened file FileNot, shouldn't have" << endl ;
00050         return 1 ;
00051     }
00052     catch( BESException &ex )
00053     {
00054         cout << "couldn't get FileNot, good, because" << endl ;
00055         cout << ex.get_message() << endl ;
00056     }
00057 
00058     cout << endl << "*****************************************" << endl;
00059     cout << "Try to get one called FileTooMany" << endl;
00060     try
00061     {
00062         BESContainerStorageFile cpf( "FileTooMany" ) ;
00063         cerr << "opened file FileTooMany, shouldn't have" << endl ;
00064         return 1 ;
00065     }
00066     catch( BESException &ex )
00067     {
00068         cout << "couldn't get FileTooMany, good, because" << endl ;
00069         cout << ex.get_message() << endl ;
00070     }
00071 
00072     cout << endl << "*****************************************" << endl;
00073     cout << "Try to get one called FileTooFew" << endl;
00074     try
00075     {
00076         BESContainerStorageFile cpf( "FileTooFew" ) ;
00077         cerr << "opened file FileTooFew, shouldn't have" << endl ;
00078         return 1 ;
00079     }
00080     catch( BESException &ex )
00081     {
00082         cout << "couldn't get FileTooFew, good, because" << endl ;
00083         cout << ex.get_message() << endl ;
00084     }
00085 
00086     cout << endl << "*****************************************" << endl;
00087     cout << "Get one called File1" << endl;
00088     try
00089     {
00090         BESContainerStorageFile cpf( "File1" ) ;
00091         cout << "opened file File1, good" << endl ;
00092     }
00093     catch( BESException &ex )
00094     {
00095         cerr << "couldn't get File1 because" << endl ;
00096         cerr << ex.get_message() << endl ;
00097         return 1 ;
00098     }
00099 
00100     BESContainerStorageFile cpf( "File1" ) ;
00101     char s[10] ;
00102     char r[10] ;
00103     char c[10] ;
00104     for( int i = 1; i < 6; i++ )
00105     {
00106         sprintf( s, "sym%d", i ) ;
00107         sprintf( r, "real%d", i ) ;
00108         sprintf( c, "type%d", i ) ;
00109         cout << endl << "*****************************************" << endl;
00110         cout << "Looking for " << s << endl;
00111         BESContainer *d = cpf.look_for( s ) ;
00112         if( d )
00113         {
00114             if( d->get_real_name() == r && d->get_container_type() == c )
00115             {
00116                 cout << "found " << s << endl ;
00117             }
00118             else
00119             {
00120                 cerr << "found " << s << " but real = " << r
00121                      << " and container = " << c << endl ;
00122                 return 1 ;
00123             }
00124         }
00125         else
00126         {
00127             cerr << "couldn't find " << s << endl ;
00128             return 1 ;
00129         }
00130     }
00131 
00132     cout << endl << "*****************************************" << endl;
00133     cout << "Looking for thingy" << endl;
00134     BESContainer *d = cpf.look_for( "thingy" ) ;
00135     if( d )
00136     {
00137         cerr << "found thingy" << endl ;
00138         return 1 ;
00139     }
00140     else
00141     {
00142         cout << "didn't find thingy, good" << endl ;
00143     }
00144 
00145     cout << endl << "*****************************************" << endl;
00146     cout << "show containers" << endl;
00147     BESTextInfo info ;
00148     cpf.show_containers( info ) ;
00149     info.print( cout ) ;
00150 
00151     cout << endl << "*****************************************" << endl;
00152     cout << "Returning from pfileT::run" << endl;
00153 
00154     return retVal;
00155 }
00156 
00157 int
00158 main(int argC, char **argV) {
00159     string env_var = (string)"BES_CONF=" + TEST_SRC_DIR
00160                      + "/persistence_file_test.ini" ;
00161     putenv( (char *)env_var.c_str() ) ;
00162     Application *app = new pfileT();
00163     return app->main(argC, argV);
00164 }
00165 

Generated on Fri Nov 30 12:06:48 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.1