zT.cc

Go to the documentation of this file.
00001 // zT.C
00002 
00003 #include <iostream>
00004 #include <fstream>
00005 
00006 using std::cerr ;
00007 using std::cout ;
00008 using std::endl ;
00009 using std::ifstream ;
00010 
00011 #include "zT.h"
00012 #include "BESUncompressZ.h"
00013 #include "BESCache.h"
00014 #include "BESException.h"
00015 #include <test_config.h>
00016 
00017 #define BES_CACHE_CHAR '#' 
00018 
00019 int
00020 zT::run(void)
00021 {
00022     cout << endl << "*****************************************" << endl;
00023     cout << "Entered zT::run" << endl;
00024     int retVal = 0;
00025 
00026     string cache_dir = (string)TEST_SRC_DIR + "/cache" ;
00027     string src_file = cache_dir + "/testfile.txt.Z" ;
00028 
00029     // we're not testing the caching mechanism, so just create it, but make
00030     // sure it gets created.
00031     string target ;
00032     try
00033     {
00034         BESCache cache( cache_dir, "z_cache", 1 ) ;
00035         // get the target name and make sure the target file doesn't exist
00036         if( cache.is_cached( src_file, target ) )
00037         {
00038             if( remove( target.c_str() ) != 0 )
00039             {
00040                 cerr << "Unable to remove target file " << target
00041                      << " , initializing test" << endl ;
00042                 return 1 ;
00043             }
00044         }
00045 
00046         cout << endl << "*****************************************" << endl;
00047         cout << "uncompress a test file" << endl;
00048         try
00049         {
00050             string result = BESUncompressZ::uncompress( src_file, target ) ;
00051             cout << "Uncompression succeeded" << endl ;
00052             if( result == target )
00053             {
00054                 cout << "result is correct" << endl ;
00055             }
00056             else
00057             {
00058                 cerr << "Resulting file " << result << " is not correct, "
00059                      << "should be " << target << endl ;
00060                 return 1 ;
00061             }
00062             ifstream strm( target.c_str() ) ;
00063             if( !strm )
00064             {
00065                 cerr << "Resulting file " << result << " doesn't exist" << endl;
00066                 return 1 ;
00067             }
00068             char line[80] ;
00069             strm.getline( (char *)line, 80 ) ;
00070             string sline = line ;
00071             if( sline != "This is a test of a compression method." )
00072             {
00073                 cerr << "Contents of file not correct" << endl ;
00074                 cerr << "Actual: " << sline << endl ;
00075                 cerr << "Should be: This is a test of a compression method."
00076                      << endl ;
00077                 return 1 ;
00078             }
00079             else
00080             {
00081                 cout << "Contents of file correct" << endl ;
00082             }
00083         }
00084         catch( BESException &e )
00085         {
00086             cerr << "Failed to uncompress the file" << endl ;
00087             cerr << e.get_message() << endl ;
00088             return 1 ;
00089         }
00090         catch( ... )
00091         {
00092             cerr << "Failed to uncompress the file" << endl ;
00093             cerr << "Unknown exception thrown" << endl ;
00094             return 1 ;
00095         }
00096 
00097         string tmp ;
00098         if( cache.is_cached( src_file, tmp ) )
00099         {
00100             cout << "File is now cached" << endl ;
00101         }
00102         else
00103         {
00104             cerr << "File should be cached" << endl ;
00105             return 1 ;
00106         }
00107 
00108         cout << endl << "*****************************************" << endl;
00109         cout << "uncompress a test file that is already cached" << endl;
00110         try
00111         {
00112             string result = BESUncompressZ::uncompress( src_file, target ) ;
00113             cout << "Uncompression succeeded" << endl ;
00114             if( result == target )
00115             {
00116                 cout << "result is correct" << endl ;
00117             }
00118             else
00119             {
00120                 cerr << "Resulting file " << result << " is not correct, "
00121                      << "should be " << target << endl ;
00122                 return 1 ;
00123             }
00124             ifstream strm( target.c_str() ) ;
00125             if( !strm )
00126             {
00127                 cerr << "Resulting file " << result << " doesn't exist" << endl;
00128                 return 1 ;
00129             }
00130             char line[80] ;
00131             strm.getline( (char *)line, 80 ) ;
00132             string sline = line ;
00133             if( sline != "This is a test of a compression method." )
00134             {
00135                 cerr << "Contents of file not correct" << endl ;
00136                 cerr << "Actual: " << sline << endl ;
00137                 cerr << "Should be: This is a test of a compression method."
00138                      << endl ;
00139                 return 1 ;
00140             }
00141             else
00142             {
00143                 cout << "Contents of file correct" << endl ;
00144             }
00145         }
00146         catch( BESException &e )
00147         {
00148             cerr << "Failed to uncompress the file" << endl ;
00149             cerr << e.get_message() << endl ;
00150             return 1 ;
00151         }
00152         catch( ... )
00153         {
00154             cerr << "Failed to uncompress the file" << endl ;
00155             cerr << "Unknown exception thrown" << endl ;
00156             return 1 ;
00157         }
00158 
00159         if( cache.is_cached( src_file, tmp ) )
00160         {
00161             cout << "File is still cached" << endl ;
00162         }
00163         else
00164         {
00165             cerr << "File should be cached" << endl ;
00166             return 1 ;
00167         }
00168 
00169     }
00170     catch( BESException &e )
00171     {
00172         cerr << "Unable to create the cache object" << endl ;
00173         cerr << e.get_message() << endl ;
00174         return 1 ;
00175     }
00176     catch( ... )
00177     {
00178         cerr << "Unable to create the cache object" << endl ;
00179         cerr << "Unknown exception thrown" << endl ;
00180         return 1 ;
00181     }
00182 
00183     cout << endl << "*****************************************" << endl;
00184     cout << "Returning from zT::run" << endl;
00185 
00186     return retVal;
00187 }
00188 
00189 int
00190 main(int argC, char **argV) {
00191     string env_var = (string)"BES_CONF=" + TEST_SRC_DIR + "/bes.conf" ;
00192     putenv( (char *)env_var.c_str() ) ;
00193     Application *app = new zT();
00194     return app->main(argC, argV);
00195 }
00196 

Generated on Wed Jan 2 06:01:19 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.4