// Location_t.cxx #include "dataset_base/Location.h" #include #include "dataset_util/Text.h" #include "dataset_util/XmlElement.h" using std::cout; using std::endl; using dset::Url; using dset::Location; void msg(const char* msg) { cout << "----- "; cout << msg; cout << " -----" << endl; } int Location_t() { msg("Invalid location"); Location badloc(123); cout << badloc << endl; assert( ! badloc.is_valid() ); assert( badloc.error() == 123 ); assert( ! badloc.is_empty() ); system("rm -f myfile1.dat myfile2.dat myfile3.dat myfile4.dat"); msg("Create empty location"); Location loc1; cout << loc1 << endl; assert( loc1.is_valid() ); assert( loc1.error() == 0 ); assert( loc1.is_empty() ); msg("Fill location"); system("touch myfile1.dat"); system("touch myfile2.dat"); system("touch myfile3.dat"); Url url1("file:myfile1.dat"); Url url2("file:myfile2.dat"); Url url3("file:myfile3.dat"); loc1.files().push_back(url1); loc1.files().push_back(url2); loc1.files().push_back(url3); cout << loc1 << endl; assert( ! loc1.is_empty() ); assert( loc1.files().size() == 3 ); msg("Write to XML"); const XmlElement* pele = loc1.xml(); assert( pele != 0 ); cout << *pele << endl; msg("Reconstruct from XML"); Location loc2(*pele); cout << loc2 << endl; assert( loc2.files().size() == 3 ); assert( loc2.files() == loc1.files() ); msg("Check DTD"); const Text& dtd = Location::dtd(); assert( dtd.size() != 0 ); cout << dtd << endl; msg("Create new location"); Location loc3; system("touch myfile4.dat"); loc3.files().push_back(Url("file:myfile1.dat")); loc3.files().push_back(Url("file:myfile4.dat")); cout << loc3 << endl; assert( loc3.files().size() == 2 ); msg("Add first to the new location"); loc3.add(loc1); cout << loc3 << endl; assert( loc3.files().size() == 4 ); msg("Check equality"); assert( loc1 == loc2 ); assert( loc1 != loc3 ); delete pele; return 0; } #ifdef CTEST_MAIN int main() { return Location_t(); } #endif