// HbookFile_t.cxx #include "dataset_CBNT/HbookFile.h" #include #include #include "dataset_util/Text.h" #include "dataset_CBNT/HbookFile_t.h" using std::string; using std::cout; using std::endl; //********************************************************************** namespace { void msg(string txt) { cout << "*** "; cout << txt; cout << endl; } } // end unnamed namespace //********************************************************************** int HbookFile_t() { msg("Begin testing HbookFile"); msg("Find file"); string fname = find_file("cbnt.hbook"); assert( fname.size() ); assert( FileStatus(fname).is_readable() ); msg("Create invalid HbookFile"); { HbookFile badhfile; cout << badhfile << endl; assert( ! badhfile.is_valid() ); } msg("Create valid HbookFile"); HbookFile hfile(fname); cout << hfile << endl; assert( hfile.is_valid() ); assert( ! hfile.is_open() ); assert( ! hfile.is_open_for_reading() ); assert( ! hfile.is_open_for_writing() ); assert( ! hfile.is_open_for_paw() ); assert( hfile.full_filename() == fname ); assert( hfile.lun() == 0 ); assert( hfile.hbook_filename() == "" ); assert( hfile.paw_open_command() == "" ); assert( hfile.paw_close_command() == "" ); msg("Open file readonly"); hfile.open(); cout << hfile << endl; assert( hfile.is_valid() ); assert( hfile.is_open() ); assert( hfile.is_open_for_reading() ); assert( ! hfile.is_open_for_writing() ); assert( ! hfile.is_open_for_paw() ); assert( hfile.lun() > 0 ); assert( hfile.hbook_filename() != "" ); assert( hfile.paw_open_command() == "" ); assert( hfile.paw_close_command() == "" ); msg("Close"); assert( hfile.close() == 0 ); cout << hfile << endl; assert( hfile.is_valid() ); assert( ! hfile.is_open() ); assert( ! hfile.is_open_for_reading() ); assert( ! hfile.is_open_for_writing() ); assert( ! hfile.is_open_for_paw() ); assert( hfile.full_filename() == fname ); assert( hfile.lun() == 0 ); assert( hfile.hbook_filename() == "" ); assert( hfile.paw_open_command() == "" ); assert( hfile.paw_close_command() == "" ); msg("Open file for writing"); hfile.open(HbookFile::WRITE); cout << hfile << endl; assert( hfile.is_valid() ); assert( hfile.is_open() ); assert( hfile.is_open_for_reading() ); assert( hfile.is_open_for_writing() ); assert( ! hfile.is_open_for_paw() ); assert( hfile.lun() > 0 ); assert( hfile.hbook_filename() != "" ); assert( hfile.paw_open_command() == "" ); assert( hfile.paw_close_command() == "" ); msg("Close"); assert( hfile.close() == 0 ); cout << hfile << endl; assert( hfile.is_valid() ); assert( ! hfile.is_open() ); assert( ! hfile.is_open_for_reading() ); assert( ! hfile.is_open_for_writing() ); assert( ! hfile.is_open_for_paw() ); assert( hfile.full_filename() == fname ); assert( hfile.lun() == 0 ); assert( hfile.hbook_filename() == "" ); assert( hfile.paw_open_command() == "" ); assert( hfile.paw_close_command() == "" ); msg("Open file for PAW"); hfile.open(HbookFile::FORPAW); cout << hfile << endl; cout << hfile.paw_open_command() << endl; cout << hfile.paw_close_command() << endl; assert( hfile.is_valid() ); assert( hfile.is_open() ); assert( ! hfile.is_open_for_reading() ); assert( ! hfile.is_open_for_writing() ); assert( hfile.is_open_for_paw() ); assert( hfile.lun() > 0 ); assert( hfile.hbook_filename() != "" ); assert( hfile.paw_open_command() != "" ); assert( hfile.paw_close_command() != "" ); msg("Close"); assert( hfile.close() == 0 ); cout << hfile << endl; assert( hfile.is_valid() ); assert( ! hfile.is_open() ); assert( ! hfile.is_open_for_reading() ); assert( ! hfile.is_open_for_writing() ); assert( ! hfile.is_open_for_paw() ); assert( hfile.full_filename() == fname ); assert( hfile.lun() == 0 ); assert( hfile.hbook_filename() == "" ); assert( hfile.paw_open_command() == "" ); assert( hfile.paw_close_command() == "" ); msg("Generate code skeleton."); system("rm -f evcode.f"); assert( ! FileStatus("evcode.f").exists() ); assert( hfile.open() == 0 ); assert( hfile.cd("CBNT") == 0 ); assert( hfile.hrin() == 0 ); hfile.ls(" ", "T"); assert( hfile.evcode(3333) == 0 ); assert( FileStatus("evcode.f").is_readable() ); cout << Text("evcode.f") << endl; msg("End testing HbookFile"); return 0; } //********************************************************************** #ifdef CTEST_MAIN int main() { return HbookFile_t(); } #endif //**********************************************************************