// dataset_files_t.cxx #include #include #include "dataset_util/FileStatus.h" #include "dataset_xml/XmlParser.h" #include "dataset_base/Location.h" #include "dataset_base/Dataset.h" #include "dataset_base/Dataset_t.h" using std::string; using std::cout; using std::endl; using dset::LogicalFile; using dset::Location; using dset::Dataset; void msg(string txt) { cout << "----- "; cout << txt; cout << " -----" << endl; } int dataset_files_t() { system("rm -f dataset.dtd mydst.xml a.dat b.dat dstfiles.dat"); msg("Show help"); int stat = system("dataset_files -h"); assert( stat == 0 ); msg("Try with nonexistent file"); stat = system("dataset_files mydst.xml"); assert( stat != 0 ); msg("Create test files"); Text a0("a.dat"); a0.append("This is file a"); a0.append("A is for apple"); a0.write(); Text b0("b.dat"); b0.append("This is file b"); b0.append("B is for bumblebee"); b0.write(); msg("Create test dataset"); Location loc; loc.logical_files().push_back(LogicalFile("a.dat")); loc.logical_files().push_back(LogicalFile("b.dat")); TestDataset dst(loc, DatasetId(101,123)); dst.lock(); cout << dst << endl; msg("Write XML description of task"); assert( ! FileStatus("mydst.xml").exists() ); const XmlElement* pele = dst.xml(); assert( pele != 0 ); XmlParser xparser; stat = xparser.write("mydst.xml", *pele); if ( stat != 0 ) { cout << "Parser returned status " << stat << endl; } assert( stat == 0 ); assert( FileStatus("mydst.xml").exists() ); delete pele; msg("Try with this XML file"); stat = system("dataset_files mydst.xml"); assert( stat == 0 ); msg("Check file list"); assert( FileStatus("dstfiles.dat").is_readable() ); Text files("dstfiles.dat"); assert( files.size() == 2 ); string afile = files.line(0); string bfile = files.line(1); Text a1(afile); Text b1(bfile); assert( a1 == a0 ); assert( b1 == b0 ); return 0; } #ifdef CTEST_MAIN int main() { return dataset_files_t(); } #endif