From c4096f670c7b3d43f8a5c1f65ef7e02033b0329d Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 14 Dec 2018 15:38:13 -0500 Subject: SL-10153: Review and rationalize fetching paths from environment. Use LLStringUtil::getenv() or getoptenv() whenever we fetch a string that will be used as a pathname. Use LLFile::tmpdir() instead of getenv("TEMP"). As an added extra-special bonus, finally clean up $TMP/llcontrol-test-zzzzzz directories that have been accumulating every time we run a local build! --- indra/llxml/tests/llcontrol_test.cpp | 39 ++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'indra/llxml') diff --git a/indra/llxml/tests/llcontrol_test.cpp b/indra/llxml/tests/llcontrol_test.cpp index 2b691ffbb1..f7e43d6def 100644 --- a/indra/llxml/tests/llcontrol_test.cpp +++ b/indra/llxml/tests/llcontrol_test.cpp @@ -27,43 +27,31 @@ #include "linden_common.h" #include "llsdserialize.h" +#include "llfile.h" +#include "stringize.h" #include "../llcontrol.h" #include "../test/lltut.h" +#include +#include namespace tut { - struct control_group { - LLControlGroup* mCG; + std::unique_ptr mCG; std::string mTestConfigDir; std::string mTestConfigFile; + std::vector mCleanups; static bool mListenerFired; control_group() { - mCG = new LLControlGroup("foo"); + mCG.reset(new LLControlGroup("foo")); LLUUID random; random.generate(); // generate temp dir - std::ostringstream oStr; - -#ifdef LL_WINDOWS - char* tmp_dir = getenv("TMP"); - if(tmp_dir) - { - oStr << tmp_dir << "/llcontrol-test-" << random << "/"; - } - else - { - oStr << "c:/tmp/llcontrol-test-" << random << "/"; - } -#else - oStr << "/tmp/llcontrol-test-" << random << "/"; -#endif - - mTestConfigDir = oStr.str(); + mTestConfigDir = STRINGIZE(LLFile::tmpdir() << "llcontrol-test-" << random << "/"); mTestConfigFile = mTestConfigDir + "settings.xml"; LLFile::mkdir(mTestConfigDir); LLSD config; @@ -76,7 +64,12 @@ namespace tut ~control_group() { //Remove test files - delete mCG; + for (auto filename : mCleanups) + { + LLFile::remove(filename); + } + LLFile::remove(mTestConfigFile); + LLFile::rmdir(mTestConfigDir); } void writeSettingsFile(const LLSD& config) { @@ -118,6 +111,7 @@ namespace tut ensure_equals("value of changed setting", mCG->getU32("TestSetting"), 13); LLControlGroup test_cg("foo2"); std::string temp_test_file = (mTestConfigDir + "setting_llsd_temp.xml"); + mCleanups.push_back(temp_test_file); mCG->saveToFile(temp_test_file.c_str(), TRUE); results = test_cg.loadFromFile(temp_test_file.c_str()); ensure("number of changed settings loaded", (results == 1)); @@ -139,6 +133,7 @@ namespace tut ensure_equals("value of changed setting", mCG->getU32("TestSetting"), 13); LLControlGroup test_cg("foo3"); std::string temp_test_file = (mTestConfigDir + "setting_llsd_persist_temp.xml"); + mCleanups.push_back(temp_test_file); mCG->saveToFile(temp_test_file.c_str(), TRUE); results = test_cg.loadFromFile(temp_test_file.c_str()); //If we haven't changed any settings, then we shouldn't have any settings to load @@ -153,7 +148,7 @@ namespace tut ensure("number of settings", (results == 1)); mCG->getControl("TestSetting")->getSignal()->connect(boost::bind(&this->handleListenerTest)); mCG->setU32("TestSetting", 13); - ensure("listener fired on changed setting", mListenerFired); + ensure("listener fired on changed setting", mListenerFired); } } -- cgit v1.2.3