diff options
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 | ||||
-rwxr-xr-x | indra/llcommon/tests/llerror_test.cpp | 90 | ||||
-rwxr-xr-x | indra/llcommon/tests/llsdserialize_test.cpp | 2 | ||||
-rw-r--r-- | indra/llcommon/tests/llunits_test.cpp | 211 | ||||
-rwxr-xr-x | indra/llcommon/tests/reflection_test.cpp | 220 |
6 files changed, 263 insertions, 272 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/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/llsdserialize_test.cpp b/indra/llcommon/tests/llsdserialize_test.cpp index 4d436e8897..235008a5ae 100755 --- a/indra/llcommon/tests/llsdserialize_test.cpp +++ b/indra/llcommon/tests/llsdserialize_test.cpp @@ -268,7 +268,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()); diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp new file mode 100644 index 0000000000..8546bcbc54 --- /dev/null +++ b/indra/llcommon/tests/llunits_test.cpp @@ -0,0 +1,211 @@ +/** + * @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 "llunit.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(Quatloos, * 4, Latinum, "Lat"); + LL_DECLARE_DERIVED_UNIT(Latinum, / 16, Solari, "Sol"); +} + +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 == 0.f); + + LLUnit<F32, Quatloos> float_initialize_quatloos(1); + ensure("non-zero initialized unit", float_initialize_quatloos == 1.f); + + LLUnit<S32, Quatloos> int_quatloos; + ensure("default int unit is zero", int_quatloos == 0); + + int_quatloos = 42; + ensure("int assignment is preserved", int_quatloos == 42); + float_quatloos = int_quatloos; + ensure("float assignment from int preserves value", float_quatloos == 42.f); + + int_quatloos = float_quatloos; + ensure("int assignment from float preserves value", int_quatloos == 42); + + float_quatloos = 42.1f; + int_quatloos = float_quatloos; + ensure("int units truncate float units on assignment", int_quatloos == 42); + + LLUnit<U32, Quatloos> unsigned_int_quatloos(float_quatloos); + ensure("unsigned int can be initialized from signed int", unsigned_int_quatloos == 42); + } + + // 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 == 1.f / 4.f); + + latinum_bars = 256; + quatloos = latinum_bars; + ensure("conversion between units is automatic via assignment, and bidirectional", quatloos == 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 == 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 == 4096); + + LLUnit<F32, Latinum> latinum_bars = solari; + ensure("Non base units can be converted between each other", latinum_bars == 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 == 4); + quatloos = quatloos * 2; + ensure(quatloos == 8); + quatloos = 2.f * quatloos; + ensure(quatloos == 16); + + quatloos += 4.f; + ensure(quatloos == 20); + quatloos += 4; + ensure(quatloos == 24); + quatloos = quatloos + 4; + ensure(quatloos == 28); + quatloos = 4 + quatloos; + ensure(quatloos == 32); + quatloos += quatloos * 3; + ensure(quatloos == 128); + + quatloos -= quatloos / 4 * 3; + ensure(quatloos == 32); + quatloos = quatloos - 8; + ensure(quatloos == 24); + quatloos -= 4; + ensure(quatloos == 20); + quatloos -= 4.f; + ensure(quatloos == 16); + + quatloos /= 2.f; + ensure(quatloos == 8); + quatloos = quatloos / 4; + ensure(quatloos == 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 == 4); + quatloos -= LLUnit<F32, Latinum>(1.f); + ensure(quatloos == 0); + } + + // implicit units + template<> template<> + void units_object_t::test<5>() + { + LLUnit<F32, Quatloos> quatloos; + LLUnitImplicit<F32, Quatloos> quatloos_implicit = quatloos + 1; + ensure("can initialize implicit unit from explicit", quatloos_implicit == 1); + + quatloos = quatloos_implicit; + ensure("can assign implicit unit to explicit unit", quatloos == 1); + quatloos += quatloos_implicit; + ensure("can perform math operation using mixture of implicit and explicit units", quatloos == 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); + } +} 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()); - - } -} |