// Environment_t.cxx #include "dataset_util/Environment.h" #include #include #include "dataset_util/XmlElement.h" using std::cout; using std::endl; void msg(const char* msg) { cout << "----- "; cout << msg; cout << " -----" << endl; } int Environment_t() { msg("Empty"); { Environment env; assert( env.size() == 0 ); } msg("System"); { Environment sysenv; sysenv.sysfill(); cout << sysenv << endl; } msg("Build environment"); { Environment env; assert( env.size() == 0 ); assert( ! env.has("BB") ); assert( env.value("BB") == "" ); env["A"] = "Avalue"; env["BB"] = "BB value"; env["CPATH"] = "Cval1:Cval2:Cval3"; cout << env << endl; assert( env.size() == 3 ); assert( env.has("BB") ); assert( env.value("BB") == "BB value" ); msg("Fetch env table"); { const char* const* cenv = env.env(); assert( cenv != 0 ); int ienv; for ( ienv=0; ienv<10; ++ienv ) { if ( cenv[ienv] == 0 ) break; cout << cenv[ienv] << endl; } assert( ienv == 3 ); msg("Create new environment from table"); Environment env2; env2.fill(cenv); cout << env2 << endl; assert( env2 == env ); } msg("Fetch unsafe env table"); { char* const* cenv = env.unsafe_env(); msg("Create new environment from table"); Environment env2; env2.fill(cenv); cout << env2 << endl; assert( env2 == env ); } msg("Write to XML"); const XmlElement* pele = env.xml(); cout << *pele << endl; assert( pele->name() == Environment::xml_name() ); msg("Read from xml"); Environment env3(*pele); cout << env3 << endl; assert( env3 == env ); } msg("Check system environment"); { Environment env; env.sysfill(); assert( env == Environment::initial() ); assert( env == Environment::current() ); } msg("All tests passed."); return 0; } #ifdef CTEST_MAIN int main() { return Environment_t(); } #endif