diff options
| author | Richard Linden <none@none> | 2014-04-07 19:09:40 -0700 | 
|---|---|---|
| committer | Richard Linden <none@none> | 2014-04-07 19:09:40 -0700 | 
| commit | 98aabdc176c23de9ba23f902dc2015f9c775d26e (patch) | |
| tree | 5ac6ffdb8e9be8d3c2a2f8b591c9971726c6b73c /indra/llcommon/tests | |
| parent | 7e966f28da79d2d24f93a2615c8807421300700c (diff) | |
| parent | e5bbdafdeda0f2e6bbe97d59a24ca398b54c31eb (diff) | |
merge with release
Diffstat (limited to 'indra/llcommon/tests')
| -rwxr-xr-x | indra/llcommon/tests/bitpack_test.cpp | 2 | ||||
| -rwxr-xr-x | indra/llcommon/tests/commonmisc_test.cpp | 10 | ||||
| -rw-r--r-- | indra/llcommon/tests/lldeadmantimer_test.cpp | 6 | ||||
| -rwxr-xr-x | indra/llcommon/tests/llerror_test.cpp | 90 | ||||
| -rwxr-xr-x | indra/llcommon/tests/lleventcoro_test.cpp | 8 | ||||
| -rwxr-xr-x | indra/llcommon/tests/lleventdispatcher_test.cpp | 2 | ||||
| -rwxr-xr-x | indra/llcommon/tests/lleventfilter_test.cpp | 4 | ||||
| -rwxr-xr-x | indra/llcommon/tests/llinstancetracker_test.cpp | 16 | ||||
| -rwxr-xr-x | indra/llcommon/tests/llleap_test.cpp | 3 | ||||
| -rwxr-xr-x | indra/llcommon/tests/llprocess_test.cpp | 13 | ||||
| -rwxr-xr-x | indra/llcommon/tests/llsdserialize_test.cpp | 6 | ||||
| -rw-r--r-- | indra/llcommon/tests/lltrace_test.cpp | 142 | ||||
| -rw-r--r-- | indra/llcommon/tests/llunits_test.cpp | 388 | ||||
| -rwxr-xr-x | indra/llcommon/tests/reflection_test.cpp | 220 | ||||
| -rwxr-xr-x | indra/llcommon/tests/wrapllerrs.h | 8 | 
15 files changed, 613 insertions, 305 deletions
| diff --git a/indra/llcommon/tests/bitpack_test.cpp b/indra/llcommon/tests/bitpack_test.cpp index afc0c18cd0..9bfd567068 100755 --- a/indra/llcommon/tests/bitpack_test.cpp +++ b/indra/llcommon/tests/bitpack_test.cpp @@ -28,7 +28,7 @@  #include "linden_common.h" -#include "../bitpack.h" +#include "../llbitpack.h"  #include "../test/lltut.h" diff --git a/indra/llcommon/tests/commonmisc_test.cpp b/indra/llcommon/tests/commonmisc_test.cpp index b115c153c1..4b3e07fa75 100755 --- a/indra/llcommon/tests/commonmisc_test.cpp +++ b/indra/llcommon/tests/commonmisc_test.cpp @@ -339,7 +339,7 @@ namespace tut  /*  			if(actual != expected)  			{ -				llwarns << "iteration " << i << llendl; +				LL_WARNS() << "iteration " << i << LL_ENDL;  				std::ostringstream e_str;  				std::string::iterator iter = expected.begin();  				std::string::iterator end = expected.end(); @@ -349,8 +349,8 @@ namespace tut  				}  				e_str << std::endl;  				llsd_serialize_string(e_str, expected); -				llwarns << "expected size: " << expected.size() << llendl; -				llwarns << "expected:      " << e_str.str() << llendl; +				LL_WARNS() << "expected size: " << expected.size() << LL_ENDL; +				LL_WARNS() << "expected:      " << e_str.str() << LL_ENDL;  				std::ostringstream a_str;  				iter = actual.begin(); @@ -361,8 +361,8 @@ namespace tut  				}  				a_str << std::endl;  				llsd_serialize_string(a_str, actual); -				llwarns << "actual size:   " << actual.size() << llendl; -				llwarns << "actual:      " << a_str.str() << llendl; +				LL_WARNS() << "actual size:   " << actual.size() << LL_ENDL; +				LL_WARNS() << "actual:      " << a_str.str() << LL_ENDL;  			}  */  			ensure_equals("string value", actual, expected); diff --git a/indra/llcommon/tests/lldeadmantimer_test.cpp b/indra/llcommon/tests/lldeadmantimer_test.cpp index 7fd2dde6e0..23167762c3 100644 --- a/indra/llcommon/tests/lldeadmantimer_test.cpp +++ b/indra/llcommon/tests/lldeadmantimer_test.cpp @@ -37,12 +37,12 @@  static LLDeadmanTimer::time_type float_time_to_u64(F64 delta)  { -	return LLDeadmanTimer::time_type(delta * gClockFrequency); +	return LLDeadmanTimer::time_type(delta * get_timer_info().mClockFrequency);  }  static F64 u64_time_to_float(LLDeadmanTimer::time_type delta)  { -	return delta * gClockFrequencyInv; +	return delta * get_timer_info().mClockFrequencyInv;  } @@ -54,7 +54,7 @@ struct deadmantimer_test  	deadmantimer_test()  		{  			// LLTimer internals updating -			update_clock_frequencies(); +			get_timer_info().update();  		}  }; diff --git a/indra/llcommon/tests/llerror_test.cpp b/indra/llcommon/tests/llerror_test.cpp index 279a90e51b..b28c5ba4b3 100755 --- a/indra/llcommon/tests/llerror_test.cpp +++ b/indra/llcommon/tests/llerror_test.cpp @@ -40,7 +40,7 @@ namespace  {  	void test_that_error_h_includes_enough_things_to_compile_a_message()  	{ -		llinfos << "!" << llendl; +		LL_INFOS() << "!" << LL_ENDL;  	}  } @@ -55,7 +55,7 @@ namespace tut  	class TestRecorder : public LLError::Recorder  	{  	public: -		TestRecorder() : mWantsTime(false) { } +		TestRecorder() { mWantsTime = false; }  		~TestRecorder() { LLError::removeRecorder(this); }  		void recordMessage(LLError::ELevel level, @@ -68,7 +68,6 @@ namespace tut  		void clearMessages()		{ mMessages.clear(); }  		void setWantsTime(bool t)	{ mWantsTime = t; } -		bool wantsTime()			{ return mWantsTime; }  		std::string message(int n)  		{ @@ -82,8 +81,6 @@ namespace tut  	private:  		typedef std::vector<std::string> MessageVector;  		MessageVector mMessages; - -		bool mWantsTime;  	};  	struct ErrorTestData @@ -144,8 +141,8 @@ namespace tut  	void ErrorTestObject::test<1>()  		// basic test of output  	{ -		llinfos << "test" << llendl; -		llinfos << "bob" << llendl; +		LL_INFOS() << "test" << LL_ENDL; +		LL_INFOS() << "bob" << LL_ENDL;  		ensure_message_contains(0, "test");  		ensure_message_contains(1, "bob"); @@ -156,11 +153,11 @@ namespace  {  	void writeSome()  	{ -		lldebugs << "one" << llendl; -		llinfos << "two" << llendl; -		llwarns << "three" << llendl; -		llerrs << "four" << llendl; -			// fatal messages write out and addtional "error" message +		LL_DEBUGS() << "one" << LL_ENDL; +		LL_INFOS() << "two" << LL_ENDL; +		LL_WARNS() << "three" << LL_ENDL; +		// fatal messages write out an additional "error" message +		LL_ERRS() << "four" << LL_ENDL;  	}  }; @@ -259,19 +256,20 @@ namespace  	std::string writeReturningLocation()  	{ -		llinfos << "apple" << llendl;	int this_line = __LINE__; +		LL_INFOS() << "apple" << LL_ENDL;	int this_line = __LINE__;  		return locationString(this_line);  	} -	std::string writeReturningLocationAndFunction() +	void writeReturningLocationAndFunction(std::string& location, std::string& function)  	{ -		llinfos << "apple" << llendl;	int this_line = __LINE__; -		return locationString(this_line) + __FUNCTION__; +		LL_INFOS() << "apple" << LL_ENDL;	int this_line = __LINE__; +		location = locationString(this_line); +		function = __FUNCTION__;  	}  	std::string errorReturningLocation()  	{ -		llerrs << "die" << llendl;	int this_line = __LINE__; +		LL_ERRS() << "die" << LL_ENDL;	int this_line = __LINE__;  		return locationString(this_line);  	}  } @@ -306,13 +304,13 @@ namespace tut  std::string logFromGlobal(bool id)  { -	llinfos << (id ? "logFromGlobal: " : "") << "hi" << llendl; +	LL_INFOS() << (id ? "logFromGlobal: " : "") << "hi" << LL_ENDL;  	return "logFromGlobal";  }  static std::string logFromStatic(bool id)  { -	llinfos << (id ? "logFromStatic: " : "") << "hi" << llendl; +	LL_INFOS() << (id ? "logFromStatic: " : "") << "hi" << LL_ENDL;  	return "logFromStatic";  } @@ -320,7 +318,7 @@ namespace  {  	std::string logFromAnon(bool id)  	{ -		llinfos << (id ? "logFromAnon: " : "") << "hi" << llendl; +		LL_INFOS() << (id ? "logFromAnon: " : "") << "hi" << LL_ENDL;  		return "logFromAnon";  	}  } @@ -328,7 +326,7 @@ namespace  namespace Foo {  	std::string logFromNamespace(bool id)  	{ -		llinfos << (id ? "Foo::logFromNamespace: " : "") << "hi" << llendl; +		LL_INFOS() << (id ? "Foo::logFromNamespace: " : "") << "hi" << LL_ENDL;  		//return "Foo::logFromNamespace";  			// there is no standard way to get the namespace name, hence  			// we won't be testing for it @@ -342,12 +340,12 @@ namespace  	public:  		std::string logFromMember(bool id)  		{ -			llinfos << (id ? "ClassWithNoLogType::logFromMember: " : "") << "hi" << llendl; +			LL_INFOS() << (id ? "ClassWithNoLogType::logFromMember: " : "") << "hi" << LL_ENDL;  			return "ClassWithNoLogType::logFromMember";  		}  		static std::string logFromStatic(bool id)  		{ -			llinfos << (id ? "ClassWithNoLogType::logFromStatic: " : "") << "hi" << llendl; +			LL_INFOS() << (id ? "ClassWithNoLogType::logFromStatic: " : "") << "hi" << LL_ENDL;  			return "ClassWithNoLogType::logFromStatic";  		}  	}; @@ -357,12 +355,12 @@ namespace  	public:  		std::string logFromMember(bool id)  		{ -			llinfos << (id ? "ClassWithLogType::logFromMember: " : "") << "hi" << llendl; +			LL_INFOS() << (id ? "ClassWithLogType::logFromMember: " : "") << "hi" << LL_ENDL;  			return "ClassWithLogType::logFromMember";  		}  		static std::string logFromStatic(bool id)  		{ -			llinfos << (id ? "ClassWithLogType::logFromStatic: " : "") << "hi" << llendl; +			LL_INFOS() << (id ? "ClassWithLogType::logFromStatic: " : "") << "hi" << LL_ENDL;  			return "ClassWithLogType::logFromStatic";  		}  	}; @@ -434,19 +432,19 @@ namespace  {  	std::string innerLogger()  	{ -		llinfos << "inside" << llendl; +		LL_INFOS() << "inside" << LL_ENDL;  		return "moo";  	}  	std::string outerLogger()  	{ -		llinfos << "outside(" << innerLogger() << ")" << llendl; +		LL_INFOS() << "outside(" << innerLogger() << ")" << LL_ENDL;  		return "bar";  	}  	void uberLogger()  	{ -		llinfos << "uber(" << outerLogger() << "," << innerLogger() << ")" << llendl; +		LL_INFOS() << "uber(" << outerLogger() << "," << innerLogger() << ")" << LL_ENDL;  	}  	class LogWhileLogging @@ -454,7 +452,7 @@ namespace  	public:  		void print(std::ostream& out) const  		{ -			llinfos << "logging" << llendl; +			LL_INFOS() << "logging" << LL_ENDL;  			out << "baz";  		}  	}; @@ -465,7 +463,7 @@ namespace  	void metaLogger()  	{  		LogWhileLogging l; -		llinfos << "meta(" << l << ")" << llendl; +		LL_INFOS() << "meta(" << l << ")" << LL_ENDL;  	}  } @@ -495,7 +493,7 @@ namespace tut  	}  	template<> template<> -		// special handling of llerrs calls +		// special handling of LL_ERRS() calls  	void ErrorTestObject::test<8>()  	{  		LLError::setPrintLocation(false); @@ -518,7 +516,7 @@ namespace  	void ufoSighting()  	{ -		llinfos << "ufo" << llendl; +		LL_INFOS() << "ufo" << LL_ENDL;  	}  } @@ -548,11 +546,13 @@ namespace tut  		LLError::setPrintLocation(true);  		LLError::setTimeFunction(roswell);  		mRecorder->setWantsTime(true); -		std::string locationAndFunction = writeReturningLocationAndFunction(); +		std::string location, +					function; +		writeReturningLocationAndFunction(location, function); -		ensure_equals("order is time type location function message", +		ensure_equals("order is location time type function message",  			mRecorder->message(0), -			roswell() + " INFO: " + locationAndFunction + ": apple"); +			location + roswell() + " INFO: " + function + ": apple");  	}  	template<> template<> @@ -562,7 +562,7 @@ namespace tut  		TestRecorder* altRecorder(new TestRecorder);  		LLError::addRecorder(altRecorder); -		llinfos << "boo" << llendl; +		LL_INFOS() << "boo" << LL_ENDL;  		ensure_message_contains(0, "boo");  		ensure_equals("alt recorder count", altRecorder->countMessages(), 1); @@ -574,7 +574,7 @@ namespace tut  		anotherRecorder->setWantsTime(true);  		LLError::addRecorder(anotherRecorder); -		llinfos << "baz" << llendl; +		LL_INFOS() << "baz" << LL_ENDL;  		std::string when = roswell(); @@ -590,10 +590,10 @@ class TestAlpha  {  	LOG_CLASS(TestAlpha);  public: -	static void doDebug()	{ lldebugs << "add dice" << llendl; } -	static void doInfo()	{ llinfos  << "any idea" << llendl; } -	static void doWarn()	{ llwarns  << "aim west" << llendl; } -	static void doError()	{ llerrs   << "ate eels" << llendl; } +	static void doDebug()	{ LL_DEBUGS() << "add dice" << LL_ENDL; } +	static void doInfo()	{ LL_INFOS()  << "any idea" << LL_ENDL; } +	static void doWarn()	{ LL_WARNS()  << "aim west" << LL_ENDL; } +	static void doError()	{ LL_ERRS()   << "ate eels" << LL_ENDL; }  	static void doAll() { doDebug(); doInfo(); doWarn(); doError(); }  }; @@ -601,10 +601,10 @@ class TestBeta  {  	LOG_CLASS(TestBeta);  public: -	static void doDebug()	{ lldebugs << "bed down" << llendl; } -	static void doInfo()	{ llinfos  << "buy iron" << llendl; } -	static void doWarn()	{ llwarns  << "bad word" << llendl; } -	static void doError()	{ llerrs   << "big easy" << llendl; } +	static void doDebug()	{ LL_DEBUGS() << "bed down" << LL_ENDL; } +	static void doInfo()	{ LL_INFOS()  << "buy iron" << LL_ENDL; } +	static void doWarn()	{ LL_WARNS()  << "bad word" << LL_ENDL; } +	static void doError()	{ LL_ERRS()   << "big easy" << LL_ENDL; }  	static void doAll() { doDebug(); doInfo(); doWarn(); doError(); }  }; diff --git a/indra/llcommon/tests/lleventcoro_test.cpp b/indra/llcommon/tests/lleventcoro_test.cpp index 5ebde1a31d..cb5e15eff2 100755 --- a/indra/llcommon/tests/lleventcoro_test.cpp +++ b/indra/llcommon/tests/lleventcoro_test.cpp @@ -346,13 +346,13 @@ namespace tut                  LLCoroEventPumps waiter;                  replyName = waiter.getName0();                  errorName = waiter.getName1(); -                WrapLL_ERRS capture; +                WrapLLErrs capture;                  try                  {                      result = waiter.waitWithLog(self);                      debug("no exception");                  } -                catch (const WrapLL_ERRS::FatalException& e) +                catch (const WrapLLErrs::FatalException& e)                  {                      debug(STRINGIZE("exception " << e.what()));                      threw = e.what(); @@ -436,7 +436,7 @@ namespace tut              BEGIN              {                  LLCoroEventPumps waiter; -                WrapLL_ERRS capture; +                WrapLLErrs capture;                  try                  {                      result = waiter.postAndWaitWithLog(self, @@ -444,7 +444,7 @@ namespace tut                          immediateAPI.getPump(), "reply", "error");                      debug("no exception");                  } -                catch (const WrapLL_ERRS::FatalException& e) +                catch (const WrapLLErrs::FatalException& e)                  {                      debug(STRINGIZE("exception " << e.what()));                      threw = e.what(); diff --git a/indra/llcommon/tests/lleventdispatcher_test.cpp b/indra/llcommon/tests/lleventdispatcher_test.cpp index 263c9b171f..5a4df81bf1 100755 --- a/indra/llcommon/tests/lleventdispatcher_test.cpp +++ b/indra/llcommon/tests/lleventdispatcher_test.cpp @@ -312,7 +312,7 @@ namespace tut  {      struct lleventdispatcher_data      { -        WrapLL_ERRS redirect; +        WrapLLErrs redirect;          Dispatcher work;          Vars v;          std::string name, desc; diff --git a/indra/llcommon/tests/lleventfilter_test.cpp b/indra/llcommon/tests/lleventfilter_test.cpp index ca05ef62a9..2cdfb52f2f 100755 --- a/indra/llcommon/tests/lleventfilter_test.cpp +++ b/indra/llcommon/tests/lleventfilter_test.cpp @@ -244,7 +244,7 @@ namespace tut      void filter_object::test<4>()      {          set_test_name("LLEventTimeout::errorAfter()"); -        WrapLL_ERRS capture; +        WrapLLErrs capture;          LLEventPump& driver(pumps.obtain("driver"));          TestEventTimeout filter(driver);          listener0.reset(0); @@ -274,7 +274,7 @@ namespace tut          {              mainloop.post(17);          } -        catch (const WrapLL_ERRS::FatalException& e) +        catch (const WrapLLErrs::FatalException& e)          {              threw = e.what();          } diff --git a/indra/llcommon/tests/llinstancetracker_test.cpp b/indra/llcommon/tests/llinstancetracker_test.cpp index e769c3e22c..c7d4b8a06b 100755 --- a/indra/llcommon/tests/llinstancetracker_test.cpp +++ b/indra/llcommon/tests/llinstancetracker_test.cpp @@ -194,15 +194,15 @@ namespace tut      {          set_test_name("delete Keyed with outstanding instance_iter");          std::string what; -        Keyed* keyed = new Keyed("one"); +        Keyed* keyed = new Keyed("delete Keyed with outstanding instance_iter");          { -            WrapLL_ERRS wrapper; +            WrapLLErrs wrapper;              Keyed::instance_iter i(Keyed::beginInstances());              try              {                  delete keyed;              } -            catch (const WrapLL_ERRS::FatalException& e) +            catch (const WrapLLErrs::FatalException& e)              {                  what = e.what();              } @@ -215,15 +215,15 @@ namespace tut      {          set_test_name("delete Keyed with outstanding key_iter");          std::string what; -        Keyed* keyed = new Keyed("one"); +        Keyed* keyed = new Keyed("delete Keyed with outstanding key_it");          { -            WrapLL_ERRS wrapper; +            WrapLLErrs wrapper;              Keyed::key_iter i(Keyed::beginKeys());              try              {                  delete keyed;              } -            catch (const WrapLL_ERRS::FatalException& e) +            catch (const WrapLLErrs::FatalException& e)              {                  what = e.what();              } @@ -238,13 +238,13 @@ namespace tut          std::string what;          Unkeyed* unkeyed = new Unkeyed;          { -            WrapLL_ERRS wrapper; +            WrapLLErrs wrapper;              Unkeyed::instance_iter i(Unkeyed::beginInstances());              try              {                  delete unkeyed;              } -            catch (const WrapLL_ERRS::FatalException& e) +            catch (const WrapLLErrs::FatalException& e)              {                  what = e.what();              } diff --git a/indra/llcommon/tests/llleap_test.cpp b/indra/llcommon/tests/llleap_test.cpp index 29060d4ef5..9ea822cb8d 100755 --- a/indra/llcommon/tests/llleap_test.cpp +++ b/indra/llcommon/tests/llleap_test.cpp @@ -22,7 +22,6 @@  // other Linden headers  #include "../test/lltut.h"  #include "../test/namedtempfile.h" -#include "../test/manageapr.h"  #include "../test/catch_and_store_what_in.h"  #include "wrapllerrs.h"  #include "llevents.h" @@ -33,8 +32,6 @@  using boost::assign::list_of; -static ManageAPR manager; -  StringVec sv(const StringVec& listof) { return listof; }  #if defined(LL_WINDOWS) diff --git a/indra/llcommon/tests/llprocess_test.cpp b/indra/llcommon/tests/llprocess_test.cpp index 3e68ef068e..e4e766d51b 100755 --- a/indra/llcommon/tests/llprocess_test.cpp +++ b/indra/llcommon/tests/llprocess_test.cpp @@ -29,7 +29,6 @@  //#include <boost/lambda/bind.hpp>  // other Linden headers  #include "../test/lltut.h" -#include "../test/manageapr.h"  #include "../test/namedtempfile.h"  #include "../test/catch_and_store_what_in.h"  #include "stringize.h" @@ -46,9 +45,12 @@  #endif  //namespace lambda = boost::lambda; - -// static instance of this manages APR init/cleanup -static ManageAPR manager; + std::string apr_strerror_helper(apr_status_t rv) +{ +    char errbuf[256]; +    apr_strerror(rv, errbuf, sizeof(errbuf)); +    return errbuf; +}  /*****************************************************************************  *   Helpers @@ -60,7 +62,8 @@ static ManageAPR manager;  #define aprchk(expr) aprchk_(#expr, (expr))  static void aprchk_(const char* call, apr_status_t rv, apr_status_t expected=APR_SUCCESS)  { -    tut::ensure_equals(STRINGIZE(call << " => " << rv << ": " << manager.strerror(rv)), +    tut::ensure_equals(STRINGIZE(call << " => " << rv << ": " << apr_strerror_helper +                                 (rv)),                         rv, expected);  } diff --git a/indra/llcommon/tests/llsdserialize_test.cpp b/indra/llcommon/tests/llsdserialize_test.cpp index 4d436e8897..b5893135ea 100755 --- a/indra/llcommon/tests/llsdserialize_test.cpp +++ b/indra/llcommon/tests/llsdserialize_test.cpp @@ -56,12 +56,9 @@ namespace lambda = boost::lambda;  #include "../llformat.h"  #include "../test/lltut.h" -#include "../test/manageapr.h"  #include "../test/namedtempfile.h"  #include "stringize.h" -static ManageAPR manager; -  std::vector<U8> string_to_vector(const std::string& str)  {  	return std::vector<U8>(str.begin(), str.end()); @@ -268,7 +265,7 @@ namespace tut  	{  		std::stringstream stream;	  		mFormatter->format(v, stream); -		//llinfos << "checkRoundTrip: length " << stream.str().length() << llendl; +		//LL_INFOS() << "checkRoundTrip: length " << stream.str().length() << LL_ENDL;  		LLSD w;  		mParser->reset();	// reset() call is needed since test code re-uses mParser  		mParser->parse(stream, w, stream.str().size()); @@ -1723,5 +1720,6 @@ namespace tut                        "This string\n"                        "has several\n"                        "lines."); +              }  } diff --git a/indra/llcommon/tests/lltrace_test.cpp b/indra/llcommon/tests/lltrace_test.cpp new file mode 100644 index 0000000000..0a9d85ad00 --- /dev/null +++ b/indra/llcommon/tests/lltrace_test.cpp @@ -0,0 +1,142 @@ +/**  + * @file llsingleton_test.cpp + * @date 2011-08-11 + * @brief Unit test for the LLSingleton class + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ + +#include "linden_common.h" + +#include "lltrace.h" +#include "lltracethreadrecorder.h" +#include "lltracerecording.h" +#include "../test/lltut.h" + +namespace LLUnits +{ +	// using powers of 2 to allow strict floating point equality +	LL_DECLARE_BASE_UNIT(Ounces, "oz"); +	LL_DECLARE_DERIVED_UNIT(TallCup, "", Ounces, / 12); +	LL_DECLARE_DERIVED_UNIT(GrandeCup, "", Ounces, / 16); +	LL_DECLARE_DERIVED_UNIT(VentiCup, "", Ounces, / 20); + +	LL_DECLARE_BASE_UNIT(Grams, "g"); +	LL_DECLARE_DERIVED_UNIT(Milligrams, "mg", Grams, * 1000); +} + +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Ounces); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, TallCup); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, GrandeCup); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, VentiCup); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Grams); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Milligrams); + + +namespace tut +{ +	using namespace LLTrace; +	struct trace +	{ +		ThreadRecorder mRecorder; +	}; + +	typedef test_group<trace> trace_t; +	typedef trace_t::object trace_object_t; +	tut::trace_t tut_singleton("LLTrace"); + +	static CountStatHandle<S32> sCupsOfCoffeeConsumed("coffeeconsumed", "Delicious cup of dark roast."); +	static SampleStatHandle<F32Milligrams> sCaffeineLevelStat("caffeinelevel", "Coffee buzz quotient"); +	static EventStatHandle<S32Ounces> sOuncesPerCup("cupsize", "Large, huge, or ginormous"); + +	static F32 sCaffeineLevel(0.f); +	const F32Milligrams sCaffeinePerOz(18.f); + +	void drink_coffee(S32 num_cups, S32Ounces cup_size) +	{ +		add(sCupsOfCoffeeConsumed, num_cups); +		for (S32 i = 0; i < num_cups; i++) +		{ +			record(sOuncesPerCup, cup_size); +		} + +		sCaffeineLevel += F32Ounces(num_cups * cup_size).value() * sCaffeinePerOz.value(); +		sample(sCaffeineLevelStat, sCaffeineLevel); +	} + +	// basic data collection +	template<> template<> +	void trace_object_t::test<1>() +	{ +		sample(sCaffeineLevelStat, sCaffeineLevel); + +		Recording all_day; +		Recording at_work; +		Recording after_3pm; + +		all_day.start(); +		{ +			// warm up with one grande cup +			drink_coffee(1, S32TallCup(1)); + +			// go to work +			at_work.start(); +			{ +				// drink 3 tall cups, 1 after 3 pm +				drink_coffee(2, S32GrandeCup(1)); +				after_3pm.start(); +				drink_coffee(1, S32GrandeCup(1)); +			} +			at_work.stop(); +			drink_coffee(1, S32VentiCup(1)); +		} +		// don't need to stop recordings to get accurate values out of them +		//after_3pm.stop(); +		//all_day.stop(); + +		ensure("count stats are counted when recording is active",  +			at_work.getSum(sCupsOfCoffeeConsumed) == 3  +				&& all_day.getSum(sCupsOfCoffeeConsumed) == 5 +				&& after_3pm.getSum(sCupsOfCoffeeConsumed) == 2); +		ensure("measurement sums are counted when recording is active",  +			at_work.getSum(sOuncesPerCup) == S32Ounces(48)  +				&& all_day.getSum(sOuncesPerCup) == S32Ounces(80) +				&& after_3pm.getSum(sOuncesPerCup) == S32Ounces(36)); +		ensure("measurement min is specific to when recording is active",  +			at_work.getMin(sOuncesPerCup) == S32GrandeCup(1)  +				&& all_day.getMin(sOuncesPerCup) == S32TallCup(1) +				&& after_3pm.getMin(sOuncesPerCup) == S32GrandeCup(1)); +		ensure("measurement max is specific to when recording is active",  +			at_work.getMax(sOuncesPerCup) == S32GrandeCup(1)  +				&& all_day.getMax(sOuncesPerCup) == S32VentiCup(1) +				&& after_3pm.getMax(sOuncesPerCup) == S32VentiCup(1)); +		ensure("sample min is specific to when recording is active",  +			at_work.getMin(sCaffeineLevelStat) == sCaffeinePerOz * ((S32Ounces)S32TallCup(1)).value() +				&& all_day.getMin(sCaffeineLevelStat) == F32Milligrams(0.f) +				&& after_3pm.getMin(sCaffeineLevelStat) == sCaffeinePerOz * ((S32Ounces)S32TallCup(1) + (S32Ounces)S32GrandeCup(2)).value()); +		ensure("sample max is specific to when recording is active",  +			at_work.getMax(sCaffeineLevelStat) == sCaffeinePerOz * ((S32Ounces)S32TallCup(1) + (S32Ounces)S32GrandeCup(3)).value() +				&& all_day.getMax(sCaffeineLevelStat) == sCaffeinePerOz * ((S32Ounces)S32TallCup(1) + (S32Ounces)S32GrandeCup(3) + (S32Ounces)S32VentiCup(1)).value() +				&& after_3pm.getMax(sCaffeineLevelStat) == sCaffeinePerOz * ((S32Ounces)S32TallCup(1) + (S32Ounces)S32GrandeCup(3) + (S32Ounces)S32VentiCup(1)).value()); +	} + +} diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp new file mode 100644 index 0000000000..57cf9810af --- /dev/null +++ b/indra/llcommon/tests/llunits_test.cpp @@ -0,0 +1,388 @@ +/**  + * @file llsingleton_test.cpp + * @date 2011-08-11 + * @brief Unit test for the LLSingleton class + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ + +#include "linden_common.h" + +#include "llunits.h" +#include "../test/lltut.h" + +namespace LLUnits +{ +	// using powers of 2 to allow strict floating point equality +	LL_DECLARE_BASE_UNIT(Quatloos, "Quat"); +	LL_DECLARE_DERIVED_UNIT(Latinum, "Lat", Quatloos, / 4); +	LL_DECLARE_DERIVED_UNIT(Solari, "Sol", Latinum, * 16); +} + +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Quatloos); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Latinum); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Solari); + +namespace LLUnits +{ +	LL_DECLARE_BASE_UNIT(Celcius, "c"); +	LL_DECLARE_DERIVED_UNIT(Fahrenheit, "f", Celcius, * 9 / 5 + 32); +	LL_DECLARE_DERIVED_UNIT(Kelvin, "k", Celcius, + 273.15f); +} + +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Celcius); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Fahrenheit); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Kelvin); + + +namespace tut +{ +	using namespace LLUnits; +	struct units +	{ +	}; + +	typedef test_group<units> units_t; +	typedef units_t::object units_object_t; +	tut::units_t tut_singleton("LLUnit"); + +	// storage type conversions +	template<> template<> +	void units_object_t::test<1>() +	{ +		LLUnit<F32, Quatloos> float_quatloos; +		ensure("default float unit is zero", float_quatloos == F32Quatloos(0.f)); + +		LLUnit<F32, Quatloos> float_initialize_quatloos(1); +		ensure("non-zero initialized unit", float_initialize_quatloos == F32Quatloos(1.f)); + +		LLUnit<S32, Quatloos> int_quatloos; +		ensure("default int unit is zero", int_quatloos == S32Quatloos(0)); + +		int_quatloos = S32Quatloos(42); +		ensure("int assignment is preserved", int_quatloos == S32Quatloos(42)); +		float_quatloos = int_quatloos; +		ensure("float assignment from int preserves value", float_quatloos == F32Quatloos(42.f)); + +		int_quatloos = float_quatloos; +		ensure("int assignment from float preserves value", int_quatloos == S32Quatloos(42)); + +		float_quatloos = F32Quatloos(42.1f); +		int_quatloos = float_quatloos; +		ensure("int units truncate float units on assignment", int_quatloos == S32Quatloos(42)); + +		LLUnit<U32, Quatloos> unsigned_int_quatloos(float_quatloos); +		ensure("unsigned int can be initialized from signed int", unsigned_int_quatloos == S32Quatloos(42)); + +		S32Solari int_solari(1); + +		float_quatloos = int_solari; +		ensure("fractional units are preserved in conversion from integer to float type", float_quatloos == F32Quatloos(0.25f)); + +		int_quatloos = S32Quatloos(1); +		F32Solari float_solari = int_quatloos; +		ensure("can convert with fractional intermediates from integer to float type", float_solari == F32Solari(4.f)); +	} + +	// conversions to/from base unit +	template<> template<> +	void units_object_t::test<2>() +	{ +		LLUnit<F32, Quatloos> quatloos(1.f); +		LLUnit<F32, Latinum> latinum_bars(quatloos); +		ensure("conversion between units is automatic via initialization", latinum_bars == F32Latinum(1.f / 4.f)); + +		latinum_bars = S32Latinum(256); +		quatloos = latinum_bars; +		ensure("conversion between units is automatic via assignment, and bidirectional", quatloos == S32Quatloos(1024)); + +		LLUnit<S32, Quatloos> single_quatloo(1); +		LLUnit<F32, Latinum> quarter_latinum = single_quatloo; +		ensure("division of integer unit preserves fractional values when converted to float unit", quarter_latinum == F32Latinum(0.25f)); +	} + +	// conversions across non-base units +	template<> template<> +	void units_object_t::test<3>() +	{ +		LLUnit<F32, Quatloos> quatloos(1024); +		LLUnit<F32, Solari> solari(quatloos); +		ensure("conversions can work between indirectly related units: Quatloos -> Latinum -> Solari", solari == S32Solari(4096)); + +		LLUnit<F32, Latinum> latinum_bars = solari; +		ensure("Non base units can be converted between each other", latinum_bars == S32Latinum(256)); +	} + +	// math operations +	template<> template<> +	void units_object_t::test<4>() +	{ +		// exercise math operations +		LLUnit<F32, Quatloos> quatloos(1.f); +		quatloos *= 4.f; +		ensure(quatloos == S32Quatloos(4)); +		quatloos = quatloos * 2; +		ensure(quatloos == S32Quatloos(8)); +		quatloos = 2.f * quatloos; +		ensure(quatloos == S32Quatloos(16)); + +		quatloos += F32Quatloos(4.f); +		ensure(quatloos == S32Quatloos(20)); +		quatloos += S32Quatloos(4); +		ensure(quatloos == S32Quatloos(24)); +		quatloos = quatloos + S32Quatloos(4); +		ensure(quatloos == S32Quatloos(28)); +		quatloos = S32Quatloos(4) + quatloos; +		ensure(quatloos == S32Quatloos(32)); +		quatloos += quatloos * 3; +		ensure(quatloos == S32Quatloos(128)); + +		quatloos -= quatloos / 4 * 3; +		ensure(quatloos == S32Quatloos(32)); +		quatloos = quatloos - S32Quatloos(8); +		ensure(quatloos == S32Quatloos(24)); +		quatloos -= S32Quatloos(4); +		ensure(quatloos == S32Quatloos(20)); +		quatloos -= F32Quatloos(4.f); +		ensure(quatloos == S32Quatloos(16)); + +		quatloos /= 2.f; +		ensure(quatloos == S32Quatloos(8)); +		quatloos = quatloos / 4; +		ensure(quatloos == S32Quatloos(2)); + +		F32 ratio = quatloos / LLUnit<F32, Quatloos>(2.f); +		ensure(ratio == 1); +		ratio = quatloos / LLUnit<F32, Solari>(8.f); +		ensure(ratio == 1); + +		quatloos += LLUnit<F32, Solari>(8.f); +		ensure(quatloos == S32Quatloos(4)); +		quatloos -= LLUnit<F32, Latinum>(1.f); +		ensure(quatloos == S32Quatloos(0)); +	} + +	// comparison operators +	template<> template<> +	void units_object_t::test<5>() +	{ +		LLUnit<S32, Quatloos> quatloos(1); +		ensure("can perform less than comparison against same type", quatloos < S32Quatloos(2)); +		ensure("can perform less than comparison against different storage type", quatloos < F32Quatloos(2.f)); +		ensure("can perform less than comparison against different units", quatloos < S32Latinum(5)); +		ensure("can perform less than comparison against different storage type and units", quatloos < F32Latinum(5.f)); + +		ensure("can perform greater than comparison against same type", quatloos > S32Quatloos(0)); +		ensure("can perform greater than comparison against different storage type", quatloos > F32Quatloos(0.f)); +		ensure("can perform greater than comparison against different units", quatloos > S32Latinum(0)); +		ensure("can perform greater than comparison against different storage type and units", quatloos > F32Latinum(0.f)); + +	} + +	bool accept_explicit_quatloos(S32Quatloos q) +	{ +		return true; +	} + +	bool accept_implicit_quatloos(S32Quatloos q) +	{ +		return true; +	} + +	// signature compatibility +	template<> template<> +	void units_object_t::test<6>() +	{ +		S32Quatloos quatloos(1); +		ensure("can pass unit values as argument", accept_explicit_quatloos(S32Quatloos(1))); +		ensure("can pass unit values as argument", accept_explicit_quatloos(quatloos)); +	} + +	// implicit units +	template<> template<> +	void units_object_t::test<7>() +	{ +		LLUnit<F32, Quatloos> quatloos; +		LLUnitImplicit<F32, Quatloos> quatloos_implicit = quatloos + S32Quatloos(1); +		ensure("can initialize implicit unit from explicit", quatloos_implicit == 1); + +		quatloos = quatloos_implicit; +		ensure("can assign implicit unit to explicit unit", quatloos == S32Quatloos(1)); +		quatloos += quatloos_implicit; +		ensure("can perform math operation using mixture of implicit and explicit units", quatloos == S32Quatloos(2)); + +		// math operations on implicits +		quatloos_implicit = 1; +		ensure(quatloos_implicit == 1); + +		quatloos_implicit += 2; +		ensure(quatloos_implicit == 3); + +		quatloos_implicit *= 2; +		ensure(quatloos_implicit == 6); + +		quatloos_implicit -= 1; +		ensure(quatloos_implicit == 5); + +		quatloos_implicit /= 5; +		ensure(quatloos_implicit == 1); + +		quatloos_implicit = quatloos_implicit + 3 + quatloos_implicit; +		ensure(quatloos_implicit == 5); + +		quatloos_implicit = 10 - quatloos_implicit - 1; +		ensure(quatloos_implicit == 4); + +		quatloos_implicit = 2 * quatloos_implicit * 2; +		ensure(quatloos_implicit == 16); + +		F32 one_half = quatloos_implicit / (quatloos_implicit * 2); +		ensure(one_half == 0.5f); + +		// implicit conversion to POD +		F32 float_val = quatloos_implicit; +		ensure("implicit units convert implicitly to regular values", float_val == 16); + +		S32 int_val = quatloos_implicit; +		ensure("implicit units convert implicitly to regular values", int_val == 16); + +		// conversion of implicits +		LLUnitImplicit<F32, Latinum> latinum_implicit(2); +		ensure("implicit units of different types are comparable", latinum_implicit * 2 == quatloos_implicit); + +		quatloos_implicit += F32Quatloos(10); +		ensure("can add-assign explicit units", quatloos_implicit == 26); + +		quatloos_implicit -= F32Quatloos(10); +		ensure("can subtract-assign explicit units", quatloos_implicit == 16); + +		// comparisons +		ensure("can compare greater than implicit unit", quatloos_implicit > F32QuatloosImplicit(0.f)); +		ensure("can compare greater than non-implicit unit", quatloos_implicit > F32Quatloos(0.f)); +		ensure("can compare greater than or equal to implicit unit", quatloos_implicit >= F32QuatloosImplicit(0.f)); +		ensure("can compare greater than or equal to non-implicit unit", quatloos_implicit >= F32Quatloos(0.f)); +		ensure("can compare less than implicit unit", quatloos_implicit < F32QuatloosImplicit(20.f)); +		ensure("can compare less than non-implicit unit", quatloos_implicit < F32Quatloos(20.f)); +		ensure("can compare less than or equal to implicit unit", quatloos_implicit <= F32QuatloosImplicit(20.f)); +		ensure("can compare less than or equal to non-implicit unit", quatloos_implicit <= F32Quatloos(20.f)); +	} + +	// precision tests +	template<> template<> +	void units_object_t::test<8>() +	{ +		U32Bytes max_bytes(U32_MAX); +		S32Megabytes mega_bytes = max_bytes; +		ensure("max available precision is used when converting units", mega_bytes == (S32Megabytes)4095); + +		mega_bytes = (S32Megabytes)-5 + (U32Megabytes)1; +		ensure("can mix signed and unsigned in units addition", mega_bytes == (S32Megabytes)-4); + +		mega_bytes = (U32Megabytes)5 + (S32Megabytes)-1; +		ensure("can mix unsigned and signed in units addition", mega_bytes == (S32Megabytes)4); +	} + +	// default units +	template<> template<> +	void units_object_t::test<9>() +	{ +		U32Gigabytes GB(1); +		U32Megabytes MB(GB); +		U32Kilobytes KB(GB); +		U32Bytes B(GB); + +		ensure("GB -> MB conversion", MB.value() == 1024); +		ensure("GB -> KB conversion", KB.value() == 1024 * 1024); +		ensure("GB -> B conversion", B.value() == 1024 * 1024 * 1024); + +		KB = U32Kilobytes(1); +		U32Kilobits Kb(KB); +		U32Bits b(KB); +		ensure("KB -> Kb conversion", Kb.value() == 8); +		ensure("KB -> b conversion", b.value() == 8 * 1024); + +		U32Days days(1); +		U32Hours hours(days); +		U32Minutes minutes(days); +		U32Seconds seconds(days); +		U32Milliseconds ms(days); +		 +		ensure("days -> hours conversion", hours.value() == 24); +		ensure("days -> minutes conversion", minutes.value() == 24 * 60); +		ensure("days -> seconds conversion", seconds.value() == 24 * 60 * 60); +		ensure("days -> ms conversion", ms.value() == 24 * 60 * 60 * 1000); + +		U32Kilometers km(1); +		U32Meters m(km); +		U32Centimeters cm(km); +		U32Millimeters mm(km); + +		ensure("km -> m conversion", m.value() == 1000); +		ensure("km -> cm conversion", cm.value() == 1000 * 100); +		ensure("km -> mm conversion", mm.value() == 1000 * 1000); +		 +		U32Gigahertz GHz(1); +		U32Megahertz MHz(GHz); +		U32Kilohertz KHz(GHz); +		U32Hertz	 Hz(GHz); + +		ensure("GHz -> MHz conversion", MHz.value() == 1000); +		ensure("GHz -> KHz conversion", KHz.value() == 1000 * 1000); +		ensure("GHz -> Hz conversion", Hz.value() == 1000 * 1000 * 1000); + +		F32Radians rad(6.2831853071795f); +		S32Degrees deg(rad); +		ensure("radians -> degrees conversion", deg.value() == 360); + +		F32Percent percent(50); +		F32Ratio ratio(percent); +		ensure("percent -> ratio conversion", ratio.value() == 0.5f); + +		U32Kilotriangles ktris(1); +		U32Triangles tris(ktris); +		ensure("kilotriangles -> triangles conversion", tris.value() == 1000); +	} + +	bool value_near(F32 value, F32 target, F32 threshold) +	{ +		return fabsf(value - target) < threshold; +	} + +	// linear transforms +	template<> template<> +	void units_object_t::test<10>() +	{ +		F32Celcius float_celcius(100); +		F32Fahrenheit float_fahrenheit(float_celcius); +		ensure("floating point celcius -> fahrenheit conversion using linear transform", value_near(float_fahrenheit.value(), 212, 0.1f) ); + +		float_celcius = float_fahrenheit; +		ensure("floating point fahrenheit -> celcius conversion using linear transform (round trip)", value_near(float_celcius.value(), 100.f, 0.1f) ); + +		S32Celcius int_celcius(100); +		S32Fahrenheit int_fahrenheit(int_celcius); +		ensure("integer celcius -> fahrenheit conversion using linear transform", int_fahrenheit.value() == 212); + +		int_celcius = int_fahrenheit; +		ensure("integer fahrenheit -> celcius conversion using linear transform (round trip)", int_celcius.value() == 100); +	} +} diff --git a/indra/llcommon/tests/reflection_test.cpp b/indra/llcommon/tests/reflection_test.cpp deleted file mode 100755 index 8980ebb1f1..0000000000 --- a/indra/llcommon/tests/reflection_test.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/**  - * @file reflection_test.cpp - * @date   May 2006 - * @brief Reflection unit tests. - * - * $LicenseInfo:firstyear=2006&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$ - */ - -#include "../linden_common.h" -#include "../reflective.h" -#include "../metaclasst.h" -#include "../metapropertyt.h" -#include "../stdtypes.h" - -#include "../test/lltut.h" - -namespace tut -{ -  class TestAggregatedData : public LLReflective -  { -  public: -	TestAggregatedData() {;} -	virtual const LLMetaClass& getMetaClass() const; -   -  private: -  }; -   -  class TestReflectionData : public LLReflective -  { -  public: -	TestReflectionData() : mInt(42), mString("foo"), mNullPtr(NULL), mPtr(new TestAggregatedData()), mRef(*(new TestAggregatedData)) {;} -	virtual ~TestReflectionData() {delete mPtr;} -	virtual const LLMetaClass& getMetaClass() const; -	 -	static U32 getPropertyCount() {return 5;} -	 -  private: -   -	friend class LLMetaClassT<TestReflectionData>; -    S32 mInt; -	std::string mString; -	TestAggregatedData* mNullPtr; -	TestAggregatedData* mPtr; -	TestAggregatedData mObj; -	TestAggregatedData& mRef; -  }; -} - -template <> -void LLMetaClassT<tut::TestReflectionData>::reflectProperties(LLMetaClass& meta_class) -{ -	reflectProperty(meta_class, "mInt", &tut::TestReflectionData::mInt); -	reflectProperty(meta_class, "mString", &tut::TestReflectionData::mString); -	reflectPtrProperty(meta_class, "mNullPtr", &tut::TestReflectionData::mNullPtr); -	reflectPtrProperty(meta_class, "mPtr", &tut::TestReflectionData::mPtr); -	reflectProperty(meta_class, "mObj", &tut::TestReflectionData::mObj); -	//reflectProperty(meta_class, "mRef", &tut::TestReflectionData::mRef); // AARGH! -} - -namespace tut -{ -	// virtual -	const LLMetaClass& TestReflectionData::getMetaClass() const -	{ -	   return LLMetaClassT<TestReflectionData>::instance(); -    } -	 -	const LLMetaClass& TestAggregatedData::getMetaClass() const -	{ -	   return LLMetaClassT<TestAggregatedData>::instance(); -    } -} - -namespace tut -{ -  typedef tut::test_group<TestReflectionData> TestReflectionGroup; -  typedef TestReflectionGroup::object TestReflectionObject; -  TestReflectionGroup gTestReflectionGroup("reflection"); - -  template<> template<> -  void TestReflectionObject::test<1>() -  { -	// Check properties can be found. -    const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance(); -	const LLMetaProperty* null = NULL; -	ensure_not_equals(meta_class.findProperty("mInt"), null); -	ensure_not_equals(meta_class.findProperty("mString"), null); -  } -   -  template<> template<> -  void TestReflectionObject::test<2>() -  { -	// Check non-existent property cannot be found. -    const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance(); -	const LLMetaProperty* null = NULL; -	ensure_equals(meta_class.findProperty("foo"), null); -  } -   -  template<> template<> -  void TestReflectionObject::test<3>() -  { -	// Check integer property has correct value.	 -    const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance(); -	ensure_equals(meta_class.findProperty("mInt")->getLLSD(this).asInteger(), 42); -  } -   -  template<> template<> -  void TestReflectionObject::test<4>() -  { -	// Check string property has correct value.	 -    const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance(); -	ensure_equals(meta_class.findProperty("mString")->getLLSD(this).asString(), std::string("foo")); -  } -   -  template<> template<> -  void TestReflectionObject::test<5>() -  { -	// Check NULL reference property has correct value. -	const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance(); -	const LLReflective* null = NULL; -	ensure_equals(meta_class.findProperty("mNullPtr")->get(this), null); -  } -   -  template<> template<> -  void TestReflectionObject::test<6>() -  { -	// Check reference property has correct value. -	const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance(); -	const LLReflective* null = NULL; -	const LLReflective* ref = meta_class.findProperty("mPtr")->get(this); -	ensure_not_equals(ref, null); -  } -   -  template<> template<> -  void TestReflectionObject::test<7>() -  { -	// Check reflective property has correct value. -	const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance(); -	const LLReflective* null = NULL; -	const LLReflective* ref = meta_class.findProperty("mObj")->get(this); -	ensure_not_equals(ref, null); -  } - -  template<> template<> -  void TestReflectionObject::test<8>() -  { -	// Check property count. -    const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance(); -	ensure_equals(meta_class.getPropertyCount(), TestReflectionData::getPropertyCount()); -  } -   -  template<> template<> -  void TestReflectionObject::test<9>() -  { -	// Check property iteration. -    const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance(); -	U32 count = 0; -	LLMetaClass::PropertyIterator iter; -	for(iter = meta_class.beginProperties(); iter != meta_class.endProperties(); ++iter) -	{ -		++count; -	} -	ensure_equals(count, TestReflectionData::getPropertyCount()); -  } -   -  template<> template<> -  void TestReflectionObject::test<10>() -  { -	// Check meta classes of different types do not compare equal. -	const LLMetaClass* reflection_data_meta_class = &(LLMetaClassT<TestReflectionData>::instance()); -	const LLMetaClass* aggregated_data_meta_class = &(LLMetaClassT<TestAggregatedData>::instance()); -	ensure_not_equals(reflection_data_meta_class, aggregated_data_meta_class); -  } -   -  template<> template<> -  void TestReflectionObject::test<11>() -  { -	// Check class cast checks. -	const LLMetaClass& meta_class = LLMetaClassT<TestReflectionData>::instance(); -	TestAggregatedData* aggregated_data = new TestAggregatedData(); -	LLMetaClass::PropertyIterator iter; -	U32 exception_count = 0; -	for(iter = meta_class.beginProperties(); iter != meta_class.endProperties(); ++iter) -	{ -		try -		{ -			const LLMetaProperty* property = (*iter).second; -			const LLReflective* reflective = property->get(aggregated_data); // Wrong reflective type, should throw exception. - -			// useless op to get rid of compiler warning. -			reflective = reflective; -		} -		catch(...) -		{ -			++exception_count; -		} -	} -	ensure_equals(exception_count, getPropertyCount()); -	 -  } -} diff --git a/indra/llcommon/tests/wrapllerrs.h b/indra/llcommon/tests/wrapllerrs.h index a4d3a4e026..3137bd8fea 100755 --- a/indra/llcommon/tests/wrapllerrs.h +++ b/indra/llcommon/tests/wrapllerrs.h @@ -46,9 +46,9 @@  // replicate, but better to reuse  extern void wouldHaveCrashed(const std::string& message); -struct WrapLL_ERRS +struct WrapLLErrs  { -    WrapLL_ERRS(): +    WrapLLErrs():          // Resetting Settings discards the default Recorder that writes to          // stderr. Otherwise, expected llerrs (LL_ERRS) messages clutter the          // console output of successful tests, potentially confusing things. @@ -57,10 +57,10 @@ struct WrapLL_ERRS          mPriorFatal(LLError::getFatalFunction())      {          // Make LL_ERRS call our own operator() method -        LLError::setFatalFunction(boost::bind(&WrapLL_ERRS::operator(), this, _1)); +        LLError::setFatalFunction(boost::bind(&WrapLLErrs::operator(), this, _1));      } -    ~WrapLL_ERRS() +    ~WrapLLErrs()      {          LLError::setFatalFunction(mPriorFatal);          LLError::restoreSettings(mPriorErrorSettings); | 
