From 1b68f71348ecf3983b76b40d7940da8377f049b7 Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Mon, 29 Apr 2024 07:43:28 +0300 Subject: #824 Process source files in bulk: replace tabs with spaces, convert CRLF to LF, and trim trailing whitespaces as needed --- indra/test/test.cpp | 1096 +++++++++++++++++++++++++-------------------------- 1 file changed, 548 insertions(+), 548 deletions(-) (limited to 'indra/test/test.cpp') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index f1c5991330..21232e88f5 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -1,4 +1,4 @@ -/** +/** * @file test.cpp * @author Phoenix * @date 2005-09-26 @@ -7,26 +7,26 @@ * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2010, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -/** +/** * * You can add tests by creating a new cpp file in this directory, and * rebuilding. There are at most 50 tests per testgroup without a @@ -47,10 +47,10 @@ #include "apr_getopt.h" // the CTYPE_WORKAROUND is needed for linux dev stations that don't -// have the broken libc6 packages needed by our out-of-date static +// have the broken libc6 packages needed by our out-of-date static // libs (such as libcrypto and libcurl). -- Leviathan 20060113 #ifdef CTYPE_WORKAROUND -# include "ctype_workaround.h" +# include "ctype_workaround.h" #endif #ifndef LL_WINDOWS @@ -85,254 +85,254 @@ void wouldHaveCrashed(const std::string& message); namespace tut { - std::string sSourceDir; + std::string sSourceDir; - test_runner_singleton runner; + test_runner_singleton runner; } class LLReplayLog { public: - LLReplayLog() {} - virtual ~LLReplayLog() {} + LLReplayLog() {} + virtual ~LLReplayLog() {} - virtual void reset() {} - virtual void replay(std::ostream&) {} + virtual void reset() {} + virtual void replay(std::ostream&) {} }; class RecordToTempFile : public LLError::Recorder, public boost::noncopyable { public: - RecordToTempFile() - : LLError::Recorder(), - boost::noncopyable(), - mTempFile("log", ""), - mFile(mTempFile.getName().c_str()) - { - } - - virtual ~RecordToTempFile() - { - mFile.close(); - } - - virtual void recordMessage(LLError::ELevel level, const std::string& message) - { + RecordToTempFile() + : LLError::Recorder(), + boost::noncopyable(), + mTempFile("log", ""), + mFile(mTempFile.getName().c_str()) + { + } + + virtual ~RecordToTempFile() + { + mFile.close(); + } + + virtual void recordMessage(LLError::ELevel level, const std::string& message) + { LL_PROFILE_ZONE_SCOPED - mFile << message << std::endl; - } - - void reset() - { - mFile.close(); - mFile.open(mTempFile.getName().c_str()); - } - - void replay(std::ostream& out) - { - mFile.close(); - std::ifstream inf(mTempFile.getName().c_str()); - std::string line; - while (std::getline(inf, line)) - { - out << line << std::endl; - } - } + mFile << message << std::endl; + } + + void reset() + { + mFile.close(); + mFile.open(mTempFile.getName().c_str()); + } + + void replay(std::ostream& out) + { + mFile.close(); + std::ifstream inf(mTempFile.getName().c_str()); + std::string line; + while (std::getline(inf, line)) + { + out << line << std::endl; + } + } private: - NamedTempFile mTempFile; - llofstream mFile; + NamedTempFile mTempFile; + llofstream mFile; }; class LLReplayLogReal: public LLReplayLog, public boost::noncopyable { public: - LLReplayLogReal(LLError::ELevel level) - : LLReplayLog(), - boost::noncopyable(), - mOldSettings(LLError::saveAndResetSettings()), - mRecorder(new RecordToTempFile()) - { - LLError::setFatalFunction(wouldHaveCrashed); - LLError::setDefaultLevel(level); - LLError::addRecorder(mRecorder); - } - - virtual ~LLReplayLogReal() - { - LLError::removeRecorder(mRecorder); - LLError::restoreSettings(mOldSettings); - } - - virtual void reset() - { - std::dynamic_pointer_cast(mRecorder)->reset(); - } - - virtual void replay(std::ostream& out) - { - std::dynamic_pointer_cast(mRecorder)->replay(out); - } + LLReplayLogReal(LLError::ELevel level) + : LLReplayLog(), + boost::noncopyable(), + mOldSettings(LLError::saveAndResetSettings()), + mRecorder(new RecordToTempFile()) + { + LLError::setFatalFunction(wouldHaveCrashed); + LLError::setDefaultLevel(level); + LLError::addRecorder(mRecorder); + } + + virtual ~LLReplayLogReal() + { + LLError::removeRecorder(mRecorder); + LLError::restoreSettings(mOldSettings); + } + + virtual void reset() + { + std::dynamic_pointer_cast(mRecorder)->reset(); + } + + virtual void replay(std::ostream& out) + { + std::dynamic_pointer_cast(mRecorder)->replay(out); + } private: - LLError::SettingsStoragePtr mOldSettings; - LLError::RecorderPtr mRecorder; + LLError::SettingsStoragePtr mOldSettings; + LLError::RecorderPtr mRecorder; }; class LLTestCallback : public chained_callback { - typedef chained_callback super; + typedef chained_callback super; public: - LLTestCallback(bool verbose_mode, std::ostream *stream, - std::shared_ptr replayer) : - mVerboseMode(verbose_mode), - mTotalTests(0), - mPassedTests(0), - mFailedTests(0), - mSkippedTests(0), - // By default, capture a shared_ptr to std::cout, with a no-op "deleter" - // so that destroying the shared_ptr makes no attempt to delete std::cout. - mStream(std::shared_ptr(&std::cout, [](std::ostream*){})), - mReplayer(replayer) - { - if (stream) - { - // We want a boost::iostreams::tee_device that will stream to two - // std::ostreams. - typedef boost::iostreams::tee_device TeeDevice; - // More than that, though, we want an actual stream using that - // device. - typedef boost::iostreams::stream TeeStream; - // Allocate and assign in two separate steps, per Herb Sutter. - // (Until we turn on C++11 support, have to wrap *stream with - // boost::ref() due to lack of perfect forwarding.) - std::shared_ptr pstream(new TeeStream(std::cout, boost::ref(*stream))); - mStream = pstream; - } - } - - ~LLTestCallback() - { - } - - virtual void run_started() - { - //std::cout << "run_started" << std::endl; - LL_INFOS("TestRunner")<<"Test Started"<< LL_ENDL; - super::run_started(); - } - - virtual void group_started(const std::string& name) { - LL_INFOS("TestRunner")<<"Unit test group_started name=" << name << LL_ENDL; - *mStream << "Unit test group_started name=" << name << std::endl; - super::group_started(name); - } - - virtual void group_completed(const std::string& name) { - LL_INFOS("TestRunner")<<"Unit test group_completed name=" << name << LL_ENDL; - *mStream << "Unit test group_completed name=" << name << std::endl; - super::group_completed(name); - } - - virtual void test_completed(const tut::test_result& tr) - { - ++mTotalTests; - - // If this test failed, dump requested log messages BEFORE stating the - // test result. - if (tr.result != tut::test_result::ok && tr.result != tut::test_result::skip) - { - mReplayer->replay(*mStream); - } - // Either way, clear stored messages in preparation for next test. - mReplayer->reset(); - - std::ostringstream out; - out << "[" << tr.group << ", " << tr.test; - if (! tr.name.empty()) - out << ": " << tr.name; - out << "] "; - switch(tr.result) - { - case tut::test_result::ok: - ++mPassedTests; - out << "ok"; - break; - case tut::test_result::fail: - ++mFailedTests; - out << "fail"; - break; - case tut::test_result::ex: - ++mFailedTests; - out << "exception: " << LLError::Log::demangle(tr.exception_typeid.c_str()); - break; - case tut::test_result::warn: - ++mFailedTests; - out << "test destructor throw"; - break; - case tut::test_result::term: - ++mFailedTests; - out << "abnormal termination"; - break; - case tut::test_result::skip: - ++mSkippedTests; - out << "skipped known failure"; - break; - default: - ++mFailedTests; - out << "unknown (tr.result == " << tr.result << ")"; - } - if(mVerboseMode || (tr.result != tut::test_result::ok)) - { - *mStream << out.str(); - if(!tr.message.empty()) - { - *mStream << ": '" << tr.message << "'"; - LL_WARNS("TestRunner") << "not ok : "< 0) - { - *mStream << "\tSkipped known failures:\t" << mSkippedTests - << std::endl; - } - - if(mFailedTests > 0) - { - *mStream << "*********************************" << std::endl; - *mStream << "Failed Tests:\t" << mFailedTests << std::endl; - *mStream << "Please report or fix the problem." << std::endl; - *mStream << "*********************************" << std::endl; - } - super::run_completed(); - } + LLTestCallback(bool verbose_mode, std::ostream *stream, + std::shared_ptr replayer) : + mVerboseMode(verbose_mode), + mTotalTests(0), + mPassedTests(0), + mFailedTests(0), + mSkippedTests(0), + // By default, capture a shared_ptr to std::cout, with a no-op "deleter" + // so that destroying the shared_ptr makes no attempt to delete std::cout. + mStream(std::shared_ptr(&std::cout, [](std::ostream*){})), + mReplayer(replayer) + { + if (stream) + { + // We want a boost::iostreams::tee_device that will stream to two + // std::ostreams. + typedef boost::iostreams::tee_device TeeDevice; + // More than that, though, we want an actual stream using that + // device. + typedef boost::iostreams::stream TeeStream; + // Allocate and assign in two separate steps, per Herb Sutter. + // (Until we turn on C++11 support, have to wrap *stream with + // boost::ref() due to lack of perfect forwarding.) + std::shared_ptr pstream(new TeeStream(std::cout, boost::ref(*stream))); + mStream = pstream; + } + } + + ~LLTestCallback() + { + } + + virtual void run_started() + { + //std::cout << "run_started" << std::endl; + LL_INFOS("TestRunner")<<"Test Started"<< LL_ENDL; + super::run_started(); + } + + virtual void group_started(const std::string& name) { + LL_INFOS("TestRunner")<<"Unit test group_started name=" << name << LL_ENDL; + *mStream << "Unit test group_started name=" << name << std::endl; + super::group_started(name); + } + + virtual void group_completed(const std::string& name) { + LL_INFOS("TestRunner")<<"Unit test group_completed name=" << name << LL_ENDL; + *mStream << "Unit test group_completed name=" << name << std::endl; + super::group_completed(name); + } + + virtual void test_completed(const tut::test_result& tr) + { + ++mTotalTests; + + // If this test failed, dump requested log messages BEFORE stating the + // test result. + if (tr.result != tut::test_result::ok && tr.result != tut::test_result::skip) + { + mReplayer->replay(*mStream); + } + // Either way, clear stored messages in preparation for next test. + mReplayer->reset(); + + std::ostringstream out; + out << "[" << tr.group << ", " << tr.test; + if (! tr.name.empty()) + out << ": " << tr.name; + out << "] "; + switch(tr.result) + { + case tut::test_result::ok: + ++mPassedTests; + out << "ok"; + break; + case tut::test_result::fail: + ++mFailedTests; + out << "fail"; + break; + case tut::test_result::ex: + ++mFailedTests; + out << "exception: " << LLError::Log::demangle(tr.exception_typeid.c_str()); + break; + case tut::test_result::warn: + ++mFailedTests; + out << "test destructor throw"; + break; + case tut::test_result::term: + ++mFailedTests; + out << "abnormal termination"; + break; + case tut::test_result::skip: + ++mSkippedTests; + out << "skipped known failure"; + break; + default: + ++mFailedTests; + out << "unknown (tr.result == " << tr.result << ")"; + } + if(mVerboseMode || (tr.result != tut::test_result::ok)) + { + *mStream << out.str(); + if(!tr.message.empty()) + { + *mStream << ": '" << tr.message << "'"; + LL_WARNS("TestRunner") << "not ok : "< 0) + { + *mStream << "\tSkipped known failures:\t" << mSkippedTests + << std::endl; + } + + if(mFailedTests > 0) + { + *mStream << "*********************************" << std::endl; + *mStream << "Failed Tests:\t" << mFailedTests << std::endl; + *mStream << "Please report or fix the problem." << std::endl; + *mStream << "*********************************" << std::endl; + } + super::run_completed(); + } protected: - bool mVerboseMode; - int mTotalTests; - int mPassedTests; - int mFailedTests; - int mSkippedTests; - std::shared_ptr mStream; - std::shared_ptr mReplayer; + bool mVerboseMode; + int mTotalTests; + int mPassedTests; + int mFailedTests; + int mSkippedTests; + std::shared_ptr mStream; + std::shared_ptr mReplayer; }; // TeamCity specific class which emits service messages @@ -341,358 +341,358 @@ protected: class LLTCTestCallback : public LLTestCallback { public: - LLTCTestCallback(bool verbose_mode, std::ostream *stream, - std::shared_ptr replayer) : - LLTestCallback(verbose_mode, stream, replayer) - { - } - - ~LLTCTestCallback() - { - } - - virtual void group_started(const std::string& name) { - LLTestCallback::group_started(name); - std::cout << "\n##teamcity[testSuiteStarted name='" << escape(name) << "']" << std::endl; - } - - virtual void group_completed(const std::string& name) { - LLTestCallback::group_completed(name); - std::cout << "##teamcity[testSuiteFinished name='" << escape(name) << "']" << std::endl; - } - - virtual void test_completed(const tut::test_result& tr) - { - std::string testname(STRINGIZE(tr.group << "." << tr.test)); - if (! tr.name.empty()) - { - testname.append(":"); - testname.append(tr.name); - } - testname = escape(testname); - - // Sadly, tut::callback doesn't give us control at test start; have to - // backfill start message into TC output. - std::cout << "##teamcity[testStarted name='" << testname << "']" << std::endl; - - // now forward call to base class so any output produced there is in - // the right TC context - LLTestCallback::test_completed(tr); - - switch(tr.result) - { - case tut::test_result::ok: - break; - - case tut::test_result::fail: - case tut::test_result::ex: - case tut::test_result::warn: - case tut::test_result::term: - std::cout << "##teamcity[testFailed name='" << testname - << "' message='" << escape(tr.message) << "']" << std::endl; - break; - - case tut::test_result::skip: - std::cout << "##teamcity[testIgnored name='" << testname << "']" << std::endl; - break; - - default: - break; - } - - std::cout << "##teamcity[testFinished name='" << testname << "']" << std::endl; - } - - static std::string escape(const std::string& str) - { - // Per http://confluence.jetbrains.net/display/TCD65/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ServiceMessages - std::string result; - for (char c : str) - { - switch (c) - { - case '\'': - result.append("|'"); - break; - case '\n': - result.append("|n"); - break; - case '\r': - result.append("|r"); - break; + LLTCTestCallback(bool verbose_mode, std::ostream *stream, + std::shared_ptr replayer) : + LLTestCallback(verbose_mode, stream, replayer) + { + } + + ~LLTCTestCallback() + { + } + + virtual void group_started(const std::string& name) { + LLTestCallback::group_started(name); + std::cout << "\n##teamcity[testSuiteStarted name='" << escape(name) << "']" << std::endl; + } + + virtual void group_completed(const std::string& name) { + LLTestCallback::group_completed(name); + std::cout << "##teamcity[testSuiteFinished name='" << escape(name) << "']" << std::endl; + } + + virtual void test_completed(const tut::test_result& tr) + { + std::string testname(STRINGIZE(tr.group << "." << tr.test)); + if (! tr.name.empty()) + { + testname.append(":"); + testname.append(tr.name); + } + testname = escape(testname); + + // Sadly, tut::callback doesn't give us control at test start; have to + // backfill start message into TC output. + std::cout << "##teamcity[testStarted name='" << testname << "']" << std::endl; + + // now forward call to base class so any output produced there is in + // the right TC context + LLTestCallback::test_completed(tr); + + switch(tr.result) + { + case tut::test_result::ok: + break; + + case tut::test_result::fail: + case tut::test_result::ex: + case tut::test_result::warn: + case tut::test_result::term: + std::cout << "##teamcity[testFailed name='" << testname + << "' message='" << escape(tr.message) << "']" << std::endl; + break; + + case tut::test_result::skip: + std::cout << "##teamcity[testIgnored name='" << testname << "']" << std::endl; + break; + + default: + break; + } + + std::cout << "##teamcity[testFinished name='" << testname << "']" << std::endl; + } + + static std::string escape(const std::string& str) + { + // Per http://confluence.jetbrains.net/display/TCD65/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ServiceMessages + std::string result; + for (char c : str) + { + switch (c) + { + case '\'': + result.append("|'"); + break; + case '\n': + result.append("|n"); + break; + case '\r': + result.append("|r"); + break; /*==========================================================================*| - // These are not possible 'char' values from a std::string. - case '\u0085': // next line - result.append("|x"); - break; - case '\u2028': // line separator - result.append("|l"); - break; - case '\u2029': // paragraph separator - result.append("|p"); - break; + // These are not possible 'char' values from a std::string. + case '\u0085': // next line + result.append("|x"); + break; + case '\u2028': // line separator + result.append("|l"); + break; + case '\u2029': // paragraph separator + result.append("|p"); + break; |*==========================================================================*/ - case '|': - result.append("||"); - break; - case '[': - result.append("|["); - break; - case ']': - result.append("|]"); - break; - default: - result.push_back(c); - break; - } - } - return result; - } + case '|': + result.append("||"); + break; + case '[': + result.append("|["); + break; + case ']': + result.append("|]"); + break; + default: + result.push_back(c); + break; + } + } + return result; + } }; static const apr_getopt_option_t TEST_CL_OPTIONS[] = { - {"help", 'h', 0, "Print the help message."}, - {"list", 'l', 0, "List available test groups."}, - {"verbose", 'v', 0, "Verbose output."}, - {"group", 'g', 1, "Run test group specified by option argument."}, - {"output", 'o', 1, "Write output to the named file."}, - {"sourcedir", 's', 1, "Project source file directory from CMake."}, - {"touch", 't', 1, "Touch the given file if all tests succeed"}, - {"wait", 'w', 0, "Wait for input before exit."}, - {"debug", 'd', 0, "Emit full debug logs."}, - {"suitename", 'x', 1, "Run tests using this suitename"}, - {0, 0, 0, 0} + {"help", 'h', 0, "Print the help message."}, + {"list", 'l', 0, "List available test groups."}, + {"verbose", 'v', 0, "Verbose output."}, + {"group", 'g', 1, "Run test group specified by option argument."}, + {"output", 'o', 1, "Write output to the named file."}, + {"sourcedir", 's', 1, "Project source file directory from CMake."}, + {"touch", 't', 1, "Touch the given file if all tests succeed"}, + {"wait", 'w', 0, "Wait for input before exit."}, + {"debug", 'd', 0, "Emit full debug logs."}, + {"suitename", 'x', 1, "Run tests using this suitename"}, + {0, 0, 0, 0} }; void stream_usage(std::ostream& s, const char* app) { - s << "Usage: " << app << " [OPTIONS]" << std::endl - << std::endl; - - s << "This application runs the unit tests." << std::endl << std::endl; - - s << "Options: " << std::endl; - const apr_getopt_option_t* option = &TEST_CL_OPTIONS[0]; - while(option->name) - { - s << " "; - s << " -" << (char)option->optch << ", --" << option->name - << std::endl; - s << "\t" << option->description << std::endl << std::endl; - ++option; - } - - s << app << " is also sensitive to environment variables:\n" - << "LOGTEST=level : for all tests, emit log messages at level 'level'\n" - << "LOGFAIL=level : only for failed tests, emit log messages at level 'level'\n" - << "where 'level' is one of ALL, DEBUG, INFO, WARN, ERROR, NONE.\n" - << "--debug is like LOGTEST=DEBUG, but --debug overrides LOGTEST,\n" - << "while LOGTEST overrides LOGFAIL.\n\n"; - - s << "Examples:" << std::endl; - s << " " << app << " --verbose" << std::endl; - s << "\tRun all the tests and report all results." << std::endl; - s << " " << app << " --list" << std::endl; - s << "\tList all available test groups." << std::endl; - s << " " << app << " --group=uuid" << std::endl; - s << "\tRun the test group 'uuid'." << std::endl; - - s << "\n\n" - << "In any event, logs are recorded in the build directory by appending\n" - << "the suffix '.log' to the full path name of this application.\n" - << "If no level is specified as described above, these log files are at\n" - << "DEBUG level.\n" - ; + s << "Usage: " << app << " [OPTIONS]" << std::endl + << std::endl; + + s << "This application runs the unit tests." << std::endl << std::endl; + + s << "Options: " << std::endl; + const apr_getopt_option_t* option = &TEST_CL_OPTIONS[0]; + while(option->name) + { + s << " "; + s << " -" << (char)option->optch << ", --" << option->name + << std::endl; + s << "\t" << option->description << std::endl << std::endl; + ++option; + } + + s << app << " is also sensitive to environment variables:\n" + << "LOGTEST=level : for all tests, emit log messages at level 'level'\n" + << "LOGFAIL=level : only for failed tests, emit log messages at level 'level'\n" + << "where 'level' is one of ALL, DEBUG, INFO, WARN, ERROR, NONE.\n" + << "--debug is like LOGTEST=DEBUG, but --debug overrides LOGTEST,\n" + << "while LOGTEST overrides LOGFAIL.\n\n"; + + s << "Examples:" << std::endl; + s << " " << app << " --verbose" << std::endl; + s << "\tRun all the tests and report all results." << std::endl; + s << " " << app << " --list" << std::endl; + s << "\tList all available test groups." << std::endl; + s << " " << app << " --group=uuid" << std::endl; + s << "\tRun the test group 'uuid'." << std::endl; + + s << "\n\n" + << "In any event, logs are recorded in the build directory by appending\n" + << "the suffix '.log' to the full path name of this application.\n" + << "If no level is specified as described above, these log files are at\n" + << "DEBUG level.\n" + ; } void stream_groups(std::ostream& s, const char* app) { - s << "Registered test groups:" << std::endl; - tut::groupnames gl = tut::runner.get().list_groups(); - tut::groupnames::const_iterator it = gl.begin(); - tut::groupnames::const_iterator end = gl.end(); - for(; it != end; ++it) - { - s << " " << *(it) << std::endl; - } + s << "Registered test groups:" << std::endl; + tut::groupnames gl = tut::runner.get().list_groups(); + tut::groupnames::const_iterator it = gl.begin(); + tut::groupnames::const_iterator end = gl.end(); + for(; it != end; ++it) + { + s << " " << *(it) << std::endl; + } } void wouldHaveCrashed(const std::string& message) { - tut::fail("llerrs message: " + message); + tut::fail("llerrs message: " + message); } static LLTrace::ThreadRecorder* sMasterThreadRecorder = NULL; int main(int argc, char **argv) { - // The following line must be executed to initialize Google Mock - // (and Google Test) before running the tests. + // The following line must be executed to initialize Google Mock + // (and Google Test) before running the tests. #ifndef LL_WINDOWS - ::testing::InitGoogleMock(&argc, argv); + ::testing::InitGoogleMock(&argc, argv); #endif - ll_init_apr(); - apr_getopt_t* os = NULL; - if(APR_SUCCESS != apr_getopt_init(&os, gAPRPoolp, argc, argv)) - { - std::cerr << "apr_getopt_init() failed" << std::endl; - return 1; - } - - // values used for controlling application - bool verbose_mode = false; - bool wait_at_exit = false; - std::string test_group; - std::string suite_name; - - // LOGTEST overrides default, but can be overridden by --debug. - const char* LOGTEST = getenv("LOGTEST"); - - // values used for options parsing - apr_status_t apr_err; - const char* opt_arg = NULL; - int opt_id = 0; - std::unique_ptr output; - const char *touch = NULL; - - while(true) - { - apr_err = apr_getopt_long(os, TEST_CL_OPTIONS, &opt_id, &opt_arg); - if(APR_STATUS_IS_EOF(apr_err)) break; - if(apr_err) - { - char buf[255]; /* Flawfinder: ignore */ - std::cerr << "Error parsing options: " - << apr_strerror(apr_err, buf, 255) << std::endl; - return 1; - } - switch (opt_id) - { - case 'g': - test_group.assign(opt_arg); - break; - case 'h': - stream_usage(std::cout, argv[0]); - return 0; - break; - case 'l': - stream_groups(std::cout, argv[0]); - return 0; - case 'v': - verbose_mode = true; - break; - case 'o': - output.reset(new llofstream); - output->open(opt_arg); - break; - case 's': // --sourcedir - tut::sSourceDir = opt_arg; - // For convenience, so you can use tut::sSourceDir + "myfile" - tut::sSourceDir += '/'; - break; - case 't': - touch = opt_arg; - break; - case 'w': - wait_at_exit = true; - break; - case 'd': - LOGTEST = "DEBUG"; - break; - case 'x': - suite_name.assign(opt_arg); - break; - default: - stream_usage(std::cerr, argv[0]); - return 1; - break; - } - } - - // set up logging - const char* LOGFAIL = getenv("LOGFAIL"); - std::shared_ptr replayer{std::make_shared()}; - - // Testing environment variables for both 'set' and 'not empty' allows a - // user to suppress a pre-existing environment variable by forcing empty. - if (LOGTEST && *LOGTEST) - { - LLError::initForApplication(".", ".", true /* log to stderr */); - LLError::setDefaultLevel(LLError::decodeLevel(LOGTEST)); - } - else - { - LLError::initForApplication(".", ".", false /* do not log to stderr */); - LLError::setDefaultLevel(LLError::LEVEL_DEBUG); - if (LOGFAIL && *LOGFAIL) - { - LLError::ELevel level = LLError::decodeLevel(LOGFAIL); - replayer.reset(new LLReplayLogReal(level)); - } - } - LLError::setFatalFunction(wouldHaveCrashed); - std::string test_app_name(argv[0]); - std::string test_log = test_app_name + ".log"; - LLFile::remove(test_log); - LLError::logToFile(test_log); + ll_init_apr(); + apr_getopt_t* os = NULL; + if(APR_SUCCESS != apr_getopt_init(&os, gAPRPoolp, argc, argv)) + { + std::cerr << "apr_getopt_init() failed" << std::endl; + return 1; + } + + // values used for controlling application + bool verbose_mode = false; + bool wait_at_exit = false; + std::string test_group; + std::string suite_name; + + // LOGTEST overrides default, but can be overridden by --debug. + const char* LOGTEST = getenv("LOGTEST"); + + // values used for options parsing + apr_status_t apr_err; + const char* opt_arg = NULL; + int opt_id = 0; + std::unique_ptr output; + const char *touch = NULL; + + while(true) + { + apr_err = apr_getopt_long(os, TEST_CL_OPTIONS, &opt_id, &opt_arg); + if(APR_STATUS_IS_EOF(apr_err)) break; + if(apr_err) + { + char buf[255]; /* Flawfinder: ignore */ + std::cerr << "Error parsing options: " + << apr_strerror(apr_err, buf, 255) << std::endl; + return 1; + } + switch (opt_id) + { + case 'g': + test_group.assign(opt_arg); + break; + case 'h': + stream_usage(std::cout, argv[0]); + return 0; + break; + case 'l': + stream_groups(std::cout, argv[0]); + return 0; + case 'v': + verbose_mode = true; + break; + case 'o': + output.reset(new llofstream); + output->open(opt_arg); + break; + case 's': // --sourcedir + tut::sSourceDir = opt_arg; + // For convenience, so you can use tut::sSourceDir + "myfile" + tut::sSourceDir += '/'; + break; + case 't': + touch = opt_arg; + break; + case 'w': + wait_at_exit = true; + break; + case 'd': + LOGTEST = "DEBUG"; + break; + case 'x': + suite_name.assign(opt_arg); + break; + default: + stream_usage(std::cerr, argv[0]); + return 1; + break; + } + } + + // set up logging + const char* LOGFAIL = getenv("LOGFAIL"); + std::shared_ptr replayer{std::make_shared()}; + + // Testing environment variables for both 'set' and 'not empty' allows a + // user to suppress a pre-existing environment variable by forcing empty. + if (LOGTEST && *LOGTEST) + { + LLError::initForApplication(".", ".", true /* log to stderr */); + LLError::setDefaultLevel(LLError::decodeLevel(LOGTEST)); + } + else + { + LLError::initForApplication(".", ".", false /* do not log to stderr */); + LLError::setDefaultLevel(LLError::LEVEL_DEBUG); + if (LOGFAIL && *LOGFAIL) + { + LLError::ELevel level = LLError::decodeLevel(LOGFAIL); + replayer.reset(new LLReplayLogReal(level)); + } + } + LLError::setFatalFunction(wouldHaveCrashed); + std::string test_app_name(argv[0]); + std::string test_log = test_app_name + ".log"; + LLFile::remove(test_log); + LLError::logToFile(test_log); #ifdef CTYPE_WORKAROUND - ctype_workaround(); + ctype_workaround(); #endif - if (!sMasterThreadRecorder) - { - sMasterThreadRecorder = new LLTrace::ThreadRecorder(); - LLTrace::set_master_thread_recorder(sMasterThreadRecorder); - } - - // run the tests - - LLTestCallback* mycallback; - if (getenv("TEAMCITY_PROJECT_NAME")) - { - mycallback = new LLTCTestCallback(verbose_mode, output.get(), replayer); - } - else - { - mycallback = new LLTestCallback(verbose_mode, output.get(), replayer); - } - - // a chained_callback subclass must be linked with previous - mycallback->link(); - - if(test_group.empty()) - { - tut::runner.get().run_tests(); - } - else - { - tut::runner.get().run_tests(test_group); - } - - bool success = (mycallback->getFailedTests() == 0); - - if (wait_at_exit) - { - std::cerr << "Press return to exit..." << std::endl; - std::cin.get(); - } - - if (touch && success) - { - llofstream s; - s.open(touch); - s << "ok" << std::endl; - s.close(); - } - - ll_cleanup_apr(); - - int retval = (success ? 0 : 1); - return retval; - - //delete mycallback; + if (!sMasterThreadRecorder) + { + sMasterThreadRecorder = new LLTrace::ThreadRecorder(); + LLTrace::set_master_thread_recorder(sMasterThreadRecorder); + } + + // run the tests + + LLTestCallback* mycallback; + if (getenv("TEAMCITY_PROJECT_NAME")) + { + mycallback = new LLTCTestCallback(verbose_mode, output.get(), replayer); + } + else + { + mycallback = new LLTestCallback(verbose_mode, output.get(), replayer); + } + + // a chained_callback subclass must be linked with previous + mycallback->link(); + + if(test_group.empty()) + { + tut::runner.get().run_tests(); + } + else + { + tut::runner.get().run_tests(test_group); + } + + bool success = (mycallback->getFailedTests() == 0); + + if (wait_at_exit) + { + std::cerr << "Press return to exit..." << std::endl; + std::cin.get(); + } + + if (touch && success) + { + llofstream s; + s.open(touch); + s << "ok" << std::endl; + s.close(); + } + + ll_cleanup_apr(); + + int retval = (success ? 0 : 1); + return retval; + + //delete mycallback; } -- cgit v1.3 From 82d713782529074b03720833038cb0df2b8bcffd Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Tue, 14 May 2024 08:50:04 +0300 Subject: #1457 Fix the tests on mac --- build.sh | 1 + indra/llimage/tests/llimageworker_test.cpp | 3 ++- indra/test/test.cpp | 6 ------ 3 files changed, 3 insertions(+), 7 deletions(-) (limited to 'indra/test/test.cpp') diff --git a/build.sh b/build.sh index 46a287ea32..e025b73170 100755 --- a/build.sh +++ b/build.sh @@ -178,6 +178,7 @@ pre_build() "$autobuild" configure --quiet -c $variant \ ${eval_autobuild_configure_parameters:---} \ + -DLL_TESTS:BOOL=ON \ -DPACKAGE:BOOL=ON \ -DHAVOK:BOOL="$HAVOK" \ -DRELEASE_CRASH_REPORTING:BOOL="$RELEASE_CRASH_REPORTING" \ diff --git a/indra/llimage/tests/llimageworker_test.cpp b/indra/llimage/tests/llimageworker_test.cpp index 49fc1afd82..2568adf89e 100644 --- a/indra/llimage/tests/llimageworker_test.cpp +++ b/indra/llimage/tests/llimageworker_test.cpp @@ -68,6 +68,7 @@ U8* LLImageRaw::allocateData(S32 size) { return NULL; } U8* LLImageRaw::reallocateData(S32 size) { return NULL; } const U8* LLImageBase::getData() const { return NULL; } U8* LLImageBase::getData() { return NULL; } +const std::string& LLImage::getLastThreadError() { static std::string msg; return msg; } // End Stubbing // ------------------------------------------------------------------------------------------- @@ -98,7 +99,7 @@ namespace tut done = res; *done = false; } - virtual void completed(bool success, LLImageRaw* raw, LLImageRaw* aux, U32) + virtual void completed(bool success, const std::string& error_message, LLImageRaw* raw, LLImageRaw* aux, U32 request_id) { *done = true; } diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 21232e88f5..61a4eb07c5 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -54,12 +54,6 @@ #endif #ifndef LL_WINDOWS - -typedef struct { - void *re_pcre; - size_t re_nsub; - size_t re_erroffset; -} regex_t; #include #include #endif -- cgit v1.3 From 1ebf006b73c06d037e3d3ae4393136082195096d Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Wed, 27 Mar 2024 19:51:59 -0400 Subject: Remove dead googlemock dependency and related setup code --- autobuild.xml | 46 ---------------------- indra/cmake/CMakeLists.txt | 1 - indra/cmake/GoogleMock.cmake | 32 ---------------- indra/cmake/LLAddBuildTest.cmake | 7 ---- indra/llmessage/tests/llmockhttpclient.h | 66 -------------------------------- indra/test/CMakeLists.txt | 2 - indra/test/test.cpp | 11 ------ 7 files changed, 165 deletions(-) delete mode 100644 indra/cmake/GoogleMock.cmake delete mode 100644 indra/llmessage/tests/llmockhttpclient.h (limited to 'indra/test/test.cpp') diff --git a/autobuild.xml b/autobuild.xml index 8d0797ad82..e00b18c3c6 100644 --- a/autobuild.xml +++ b/autobuild.xml @@ -859,52 +859,6 @@ description glh - is a platform-indepenedent C++ OpenGL helper library - googlemock - - platforms - - darwin64 - - archive - - hash - dce3174b12136746f5f910e311e895c1b47bf8fb - hash_algorithm - sha1 - url - https://github.com/secondlife/3p-googlemock/releases/download/v1.7.0.2b109d4/googlemock-1.7.0.2b109d4-darwin64-2b109d4.tar.zst - - name - darwin64 - - windows64 - - archive - - hash - 265813f84b04c3b03f3d7d33e149b3d5e3cf31db - hash_algorithm - sha1 - url - https://github.com/secondlife/3p-googlemock/releases/download/v1.7.0.2b109d4/googlemock-1.7.0.2b109d4-windows64-2b109d4.tar.zst - - name - windows64 - - - license - BSD - license_file - LICENSES/gmock.txt - copyright - Copyright 2008, Google Inc. - version - 1.7.0.2b109d4 - name - googlemock - description - a library for writing and using C++ mock classes - gstreamer platforms diff --git a/indra/cmake/CMakeLists.txt b/indra/cmake/CMakeLists.txt index e1507bf6a0..df968144ed 100644 --- a/indra/cmake/CMakeLists.txt +++ b/indra/cmake/CMakeLists.txt @@ -26,7 +26,6 @@ set(cmake_SOURCE_FILES FreeType.cmake GLEXT.cmake GLH.cmake - GoogleMock.cmake Havok.cmake Hunspell.cmake JsonCpp.cmake diff --git a/indra/cmake/GoogleMock.cmake b/indra/cmake/GoogleMock.cmake deleted file mode 100644 index c3d195c37b..0000000000 --- a/indra/cmake/GoogleMock.cmake +++ /dev/null @@ -1,32 +0,0 @@ -# -*- cmake -*- -include(Prebuilt) -include(Linking) - -include_guard() - -add_library( ll::googlemock INTERFACE IMPORTED ) -if(USE_CONAN) - target_link_libraries( ll::googlemock INTERFACE CONAN_PKG::gtest ) - - #Not very nice, but for the moment we need this for tut.hpp - target_include_directories( ll::googlemock SYSTEM INTERFACE ${LIBS_PREBUILT_DIR}/include ) - return() -endif() - -use_prebuilt_binary(googlemock) - -target_include_directories( ll::googlemock SYSTEM INTERFACE ${LIBS_PREBUILT_DIR}/include ) - -if (LINUX) - # VWR-24366: gmock is underlinked, it needs gtest. - target_link_libraries( ll::googlemock INTERFACE gmock gtest) -elseif(WINDOWS) - target_link_libraries( ll::googlemock INTERFACE gmock) - target_include_directories( ll::googlemock SYSTEM INTERFACE - ${LIBS_PREBUILT_DIR}/include - ${LIBS_PREBUILT_DIR}/include/gmock) -elseif(DARWIN) - target_link_libraries( ll::googlemock INTERFACE gmock gtest) -endif(LINUX) - - diff --git a/indra/cmake/LLAddBuildTest.cmake b/indra/cmake/LLAddBuildTest.cmake index 6e948c2186..5d96a4398f 100644 --- a/indra/cmake/LLAddBuildTest.cmake +++ b/indra/cmake/LLAddBuildTest.cmake @@ -8,7 +8,6 @@ endif() include(00-Common) include(LLTestCommand) -include(GoogleMock) include(bugsplat) include(Tut) @@ -26,10 +25,6 @@ MACRO(LL_ADD_PROJECT_UNIT_TESTS project sources) # # More info and examples at: https://wiki.secondlife.com/wiki/How_to_add_unit_tests_to_indra_code - # This here looks weird, but is needed. It will inject GoogleMock into projects that forgot to include `this` (LLAddBuildTest.cmake) - # But through some other means have access to this macro - include(GoogleMock) - if(LL_TEST_VERBOSE) message("LL_ADD_PROJECT_UNIT_TESTS UNITTEST_PROJECT_${project} sources: ${sources}") endif() @@ -48,7 +43,6 @@ MACRO(LL_ADD_PROJECT_UNIT_TESTS project sources) set(alltest_LIBRARIES llcommon - ll::googlemock ) if(NOT "${project}" STREQUAL "llmath") # add llmath as a dep unless the tested module *is* llmath! @@ -211,7 +205,6 @@ FUNCTION(LL_ADD_INTEGRATION_TEST set(libraries ${library_dependencies} - ll::googlemock ) # Add test executable build target diff --git a/indra/llmessage/tests/llmockhttpclient.h b/indra/llmessage/tests/llmockhttpclient.h deleted file mode 100644 index 1611ab7bd8..0000000000 --- a/indra/llmessage/tests/llmockhttpclient.h +++ /dev/null @@ -1,66 +0,0 @@ -/** - * @file - * @brief - * - * $LicenseInfo:firstyear=2008&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -/* Macro Definitions */ -#ifndef LL_LLMOCKHTTPCLIENT_H -#define LL_LLMOCKHTTPCLIENT_H - -#include "linden_common.h" -#include "llhttpclientinterface.h" - -#include - -class LLMockHTTPClient : public LLHTTPClientInterface -{ -public: - MOCK_METHOD2(get, void(const std::string& url, LLCurl::ResponderPtr responder)); - MOCK_METHOD3(get, void(const std::string& url, LLCurl::ResponderPtr responder, const LLSD& headers)); - MOCK_METHOD3(put, void(const std::string& url, const LLSD& body, LLCurl::ResponderPtr responder)); -}; - -// A helper to match responder types -template -struct ResponderType -{ - bool operator()(LLCurl::ResponderPtr ptr) const - { - T* p = dynamic_cast(ptr.get()); - return p != NULL; - } -}; - -inline bool operator==(const LLSD& l, const LLSD& r) -{ - std::ostringstream ls, rs; - ls << l; - rs << r; - return ls.str() == rs.str(); - -} - - -#endif //LL_LLMOCKHTTPCLIENT_H - diff --git a/indra/test/CMakeLists.txt b/indra/test/CMakeLists.txt index 4a0a8716c4..3dcddf9dc2 100644 --- a/indra/test/CMakeLists.txt +++ b/indra/test/CMakeLists.txt @@ -9,7 +9,6 @@ include(Linking) include(Tut) include(LLAddBuildTest) include(bugsplat) -include(GoogleMock) set(test_SOURCE_FILES io.cpp @@ -65,7 +64,6 @@ target_link_libraries(lltest llxml llcommon llcorehttp - ll::googlemock ) if (WINDOWS) diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 61a4eb07c5..cbd1077306 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -53,11 +53,6 @@ # include "ctype_workaround.h" #endif -#ifndef LL_WINDOWS -#include -#include -#endif - #if LL_MSVC #pragma warning (push) #pragma warning (disable : 4702) // warning C4702: unreachable code @@ -522,12 +517,6 @@ static LLTrace::ThreadRecorder* sMasterThreadRecorder = NULL; int main(int argc, char **argv) { - // The following line must be executed to initialize Google Mock - // (and Google Test) before running the tests. -#ifndef LL_WINDOWS - ::testing::InitGoogleMock(&argc, argv); -#endif - ll_init_apr(); apr_getopt_t* os = NULL; if(APR_SUCCESS != apr_getopt_init(&os, gAPRPoolp, argc, argv)) -- cgit v1.3