diff --git a/testing/unittests/espapicmdtests.cpp b/testing/unittests/espapicmdtests.cpp index 01474298e33..e115db64737 100644 --- a/testing/unittests/espapicmdtests.cpp +++ b/testing/unittests/espapicmdtests.cpp @@ -258,9 +258,6 @@ class EspApiCmdTest : public CppUnit::TestFixture sasha(createIFile("/tmp/hpcctest/sasha.xml")) { try{ - InitModuleObjects(); - queryStderrLogMsgHandler()->setMessageFields(0); - queryLogMsgManager()->removeMonitor(queryStderrLogMsgHandler()); dir->createDirectory(); Owned ioCommon = common->open(IFOcreate); @@ -317,7 +314,7 @@ class EspApiCmdTest : public CppUnit::TestFixture "/tmp/hpcctest/common.xml\n" "/tmp/hpcctest/store.xml\n"; - for(Owned& myfile: env.files) + for(Owned& myfile: queryEnvironment().files) { fileStr.append(myfile->queryFilename()); fileStr.append("\n"); @@ -333,7 +330,7 @@ class EspApiCmdTest : public CppUnit::TestFixture string refStr = "WSSasha\n" "wsstore\n"; - vector services = env.esdlDefObj.getAllServices(); + vector services = queryEnvironment().esdlDefObj.getAllServices(); for(const char* service : services) { serviceStr.append(service); @@ -351,7 +348,7 @@ class EspApiCmdTest : public CppUnit::TestFixture ostringstream oss; string res; - env.esdlDefObj.describeAllServices(oss); + queryEnvironment().esdlDefObj.describeAllServices(oss); res = oss.str(); sortAndWriteBack(res); @@ -368,7 +365,7 @@ class EspApiCmdTest : public CppUnit::TestFixture "Ping\n" "RestoreWU\n"; - vector methods = env.esdlDefObj.getAllMethods(); + vector methods = queryEnvironment().esdlDefObj.getAllMethods(); for(const char* &method:methods) { methodStr.append(method); @@ -388,7 +385,7 @@ class EspApiCmdTest : public CppUnit::TestFixture ostringstream oss; string res; - env.esdlDefObj.describeAllMethods("WSSasha",oss); + queryEnvironment().esdlDefObj.describeAllMethods("WSSasha",oss); res = oss.str(); sortAndWriteBack(res); @@ -399,22 +396,22 @@ class EspApiCmdTest : public CppUnit::TestFixture } void testCheckValidService() { - bool validCheck = env.esdlDefObj.checkValidService("WSSasha"); - bool invalidCheck = env.esdlDefObj.checkValidService("InvalidService"); + bool validCheck = queryEnvironment().esdlDefObj.checkValidService("WSSasha"); + bool invalidCheck = queryEnvironment().esdlDefObj.checkValidService("InvalidService"); CPPUNIT_ASSERT_EQUAL(validCheck, true); CPPUNIT_ASSERT_EQUAL(invalidCheck, false); } void testCheckValidMethod() { - bool validCheck = env.esdlDefObj.checkValidMethod("GetVersion", "WSSasha"); - bool invalidCheck = env.esdlDefObj.checkValidMethod("InvalidMethod", "WSSasha"); + bool validCheck = queryEnvironment().esdlDefObj.checkValidMethod("GetVersion", "WSSasha"); + bool invalidCheck = queryEnvironment().esdlDefObj.checkValidMethod("InvalidMethod", "WSSasha"); CPPUNIT_ASSERT_EQUAL(validCheck, true); CPPUNIT_ASSERT_EQUAL(invalidCheck, false); } void testDescribe() { - env.esdlDefObj.loadAllMethods("wsstore"); + queryEnvironment().esdlDefObj.loadAllMethods("wsstore"); string refString = "ListStoresRequest\n" "string NameFilter\n" @@ -438,19 +435,19 @@ class EspApiCmdTest : public CppUnit::TestFixture ostringstream oss; string res; - env.esdlDefObj.describe("wsstore","ListStores", oss); + queryEnvironment().esdlDefObj.describe("wsstore","ListStores", oss); res = oss.str(); oss.str(""); oss.clear(); string invalidServiceRes; - env.esdlDefObj.describe("bad_name","ListStores", oss); + queryEnvironment().esdlDefObj.describe("bad_name","ListStores", oss); invalidServiceRes = oss.str(); oss.str(""); oss.clear(); string invalidMethodRes; - env.esdlDefObj.describe("wsstore","bad_name", oss); + queryEnvironment().esdlDefObj.describe("wsstore","bad_name", oss); invalidMethodRes = oss.str(); CPPUNIT_ASSERT_EQUAL(refString, res); @@ -459,7 +456,12 @@ class EspApiCmdTest : public CppUnit::TestFixture } private: - static Environment env; + Environment & queryEnvironment() + { + //Avoid creating this object until it is first used - otherwise any calls to the logging will crash + static Environment env; + return env; + } void sortAndWriteBack(string& input) { @@ -485,8 +487,6 @@ class EspApiCmdTest : public CppUnit::TestFixture } }; -EspApiCmdTest::Environment EspApiCmdTest::env; - CPPUNIT_TEST_SUITE_REGISTRATION( EspApiCmdTest ); CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EspApiCmdTest, "EspApiCmdTest" );