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( s ) ;
00112         cpf.look_for( d ) ;
00113         if( d.is_valid() )
00114         {
00115             if( d.get_real_name() == r && d.get_container_type() == c )
00116             {
00117                 cout << "found " << s << endl ;
00118             }
00119             else
00120             {
00121                 cerr << "found " << s << " but real = " << r
00122                      << " and container = " << c << endl ;
00123                 return 1 ;
00124             }
00125         }
00126         else
00127         {
00128             cerr << "couldn't find " << s << endl ;
00129             return 1 ;
00130         }
00131     }
00132 
00133     cout << endl << "*****************************************" << endl;
00134     cout << "Looking for thingy" << endl;
00135     BESContainer d( "thingy" ) ;
00136     cpf.look_for( d ) ;
00137     if( d.is_valid() )
00138     {
00139         cerr << "found thingy" << endl ;
00140         return 1 ;
00141     }
00142     else
00143     {
00144         cout << "didn't find thingy, good" << endl ;
00145     }
00146 
00147     cout << endl << "*****************************************" << endl;
00148     cout << "show containers" << endl;
00149     BESTextInfo info ;
00150     cpf.show_containers( info ) ;
00151     info.print( stdout ) ;
00152 
00153     cout << endl << "*****************************************" << endl;
00154     cout << "Returning from pfileT::run" << endl;
00155 
00156     return retVal;
00157 }
00158 
00159 int
00160 main(int argC, char **argV) {
00161     string env_var = (string)"BES_CONF=" + TEST_SRC_DIR
00162                      + "/persistence_file_test.ini" ;
00163     putenv( (char *)env_var.c_str() ) ;
00164     Application *app = new pfileT();
00165     return app->main(argC, argV);
00166 }
00167 

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