diff options
Diffstat (limited to 'indra/newview/tests')
32 files changed, 4944 insertions, 4944 deletions
diff --git a/indra/newview/tests/cppfeatures_test.cpp b/indra/newview/tests/cppfeatures_test.cpp index 923bb1e1b2..f5ea3a522b 100644 --- a/indra/newview/tests/cppfeatures_test.cpp +++ b/indra/newview/tests/cppfeatures_test.cpp @@ -7,21 +7,21 @@ * $LicenseInfo:firstyear=2021&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2021, 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$ */ @@ -44,35 +44,35 @@ tut::cpp_features_test_t tut_cpp_features_test("LLCPPFeatures"); template<> template<> void cpp_features_test_object_t::test<1>() { - S32 explicit_val{3}; - ensure(explicit_val==3); - - S32 default_val{}; - ensure(default_val==0); - - std::vector<S32> fibs{1,1,2,3,5}; - ensure(fibs[4]==5); + S32 explicit_val{3}; + ensure(explicit_val==3); + + S32 default_val{}; + ensure(default_val==0); + + std::vector<S32> fibs{1,1,2,3,5}; + ensure(fibs[4]==5); } // auto // // https://en.cppreference.com/w/cpp/language/auto -// +// // Can use auto in place of a more complex type specification, if the compiler can infer the type template<> template<> void cpp_features_test_object_t::test<2>() { - std::vector<S32> numbers{3,6,9}; + std::vector<S32> numbers{3,6,9}; - // auto element - auto& aval = numbers[1]; - ensure("auto element", aval==6); + // auto element + auto& aval = numbers[1]; + ensure("auto element", aval==6); - // auto iterator (non-const) - auto it = numbers.rbegin(); - *it += 1; - S32 val = *it; - ensure("auto iterator", val==10); + // auto iterator (non-const) + auto it = numbers.rbegin(); + *it += 1; + S32 val = *it; + ensure("auto iterator", val==10); } // range for @@ -84,42 +84,42 @@ template<> template<> void cpp_features_test_object_t::test<3>() { - // Traditional iterator for with container - // - // Problems: - // * Have to create a new variable for the iterator, which is unrelated to the problem you're trying to solve. - // * Redundant and somewhat fragile. Have to make sure begin() and end() are both from the right container. - std::vector<S32> numbers{3,6,9}; - for (auto it = numbers.begin(); it != numbers.end(); ++it) - { - auto& n = *it; - n *= 2; - } - ensure("iterator for vector", numbers[2]==18); - - // Range for with container - // - // Under the hood, this is doing the same thing as the traditional - // for loop above. Still uses begin() and end() but you don't have - // to access them directly. - std::vector<S32> numbersb{3,6,9}; - for (auto& n: numbersb) - { - n *= 2; - } - ensure("range for vector", numbersb[2]==18); - - // Range for over a C-style array. - // - // This is handy because the language determines the range automatically. - // Getting this right manually is a little trickier. - S32 pows[] = {1,2,4,8,16}; - S32 sum{}; - for (const auto& v: pows) - { - sum += v; - } - ensure("for C-array", sum==31); + // Traditional iterator for with container + // + // Problems: + // * Have to create a new variable for the iterator, which is unrelated to the problem you're trying to solve. + // * Redundant and somewhat fragile. Have to make sure begin() and end() are both from the right container. + std::vector<S32> numbers{3,6,9}; + for (auto it = numbers.begin(); it != numbers.end(); ++it) + { + auto& n = *it; + n *= 2; + } + ensure("iterator for vector", numbers[2]==18); + + // Range for with container + // + // Under the hood, this is doing the same thing as the traditional + // for loop above. Still uses begin() and end() but you don't have + // to access them directly. + std::vector<S32> numbersb{3,6,9}; + for (auto& n: numbersb) + { + n *= 2; + } + ensure("range for vector", numbersb[2]==18); + + // Range for over a C-style array. + // + // This is handy because the language determines the range automatically. + // Getting this right manually is a little trickier. + S32 pows[] = {1,2,4,8,16}; + S32 sum{}; + for (const auto& v: pows) + { + sum += v; + } + ensure("for C-array", sum==31); } // override specifier @@ -131,30 +131,30 @@ void cpp_features_test_object_t::test<3>() // * Makes code somewhat easier to read by showing intent. // * Prevents mistakes where you think something is an override but it doesn't actually match the declaration in the parent class. // Drawbacks: -// * Some compilers require that any class using override must use it consistently for all functions. -// This makes switching a class to use override a lot more work. +// * Some compilers require that any class using override must use it consistently for all functions. +// This makes switching a class to use override a lot more work. class Foo { public: - virtual bool is_happy() const = 0; + virtual bool is_happy() const = 0; }; class Bar: public Foo { public: - bool is_happy() const override { return true; } - // Override would fail: non-const declaration doesn't match parent - // bool is_happy() override { return true; } - // Override would fail: wrong name - // bool is_happx() override { return true; } + bool is_happy() const override { return true; } + // Override would fail: non-const declaration doesn't match parent + // bool is_happy() override { return true; } + // Override would fail: wrong name + // bool is_happx() override { return true; } }; template<> template<> void cpp_features_test_object_t::test<4>() { - Bar b; - ensure("override", b.is_happy()); + Bar b; + ensure("override", b.is_happy()); } // final @@ -166,27 +166,27 @@ void cpp_features_test_object_t::test<4>() class Vehicle { public: - virtual bool has_wheels() const = 0; + virtual bool has_wheels() const = 0; }; class WheeledVehicle: public Vehicle { public: - virtual bool has_wheels() const final override { return true; } + virtual bool has_wheels() const final override { return true; } }; class Bicycle: public WheeledVehicle { public: - // Error: can't override final version in WheeledVehicle - // virtual bool has_wheels() override const { return true; } + // Error: can't override final version in WheeledVehicle + // virtual bool has_wheels() override const { return true; } }; template<> template<> void cpp_features_test_object_t::test<5>() { - Bicycle bi; - ensure("final", bi.has_wheels()); + Bicycle bi; + ensure("final", bi.has_wheels()); } // deleted function declaration @@ -206,16 +206,16 @@ void cpp_features_test_object_t::test<5>() class DoNotCopy { public: - DoNotCopy() {} - DoNotCopy(const DoNotCopy& ref) = delete; + DoNotCopy() {} + DoNotCopy(const DoNotCopy& ref) = delete; }; template<> template<> void cpp_features_test_object_t::test<6>() { - DoNotCopy nc; // OK, default constructor - //DoNotCopy nc2(nc); // No, can't copy - //DoNotCopy nc3 = nc; // No, this also calls copy constructor (even though it looks like an assignment) + DoNotCopy nc; // OK, default constructor + //DoNotCopy nc2(nc); // No, can't copy + //DoNotCopy nc3 = nc; // No, this also calls copy constructor (even though it looks like an assignment) } // defaulted function declaration @@ -229,22 +229,22 @@ void cpp_features_test_object_t::test<6>() class DefaultCopyOK { public: - DefaultCopyOK(): mVal(123) {} - DefaultCopyOK(const DefaultCopyOK&) = default; - S32 val() const { return mVal; } + DefaultCopyOK(): mVal(123) {} + DefaultCopyOK(const DefaultCopyOK&) = default; + S32 val() const { return mVal; } private: - S32 mVal; + S32 mVal; }; template<> template<> void cpp_features_test_object_t::test<7>() { - DefaultCopyOK d; // OK - DefaultCopyOK d2(d); // OK - DefaultCopyOK d3 = d; // OK - ensure("default copy d", d.val()==123); - ensure("default copy d2", d.val()==d2.val()); - ensure("default copy d3", d.val()==d3.val()); + DefaultCopyOK d; // OK + DefaultCopyOK d2(d); // OK + DefaultCopyOK d3 = d; // OK + ensure("default copy d", d.val()==123); + ensure("default copy d2", d.val()==d2.val()); + ensure("default copy d3", d.val()==d3.val()); } // initialize class members inline @@ -259,32 +259,32 @@ void cpp_features_test_object_t::test<7>() class InitInline { public: - S32 mFoo{10}; + S32 mFoo{10}; }; class InitInlineWithConstructor { public: - // Here mFoo is not specified, so you will get the default value of 10. - // mBar is specified, so 25 will override the default value. - InitInlineWithConstructor(): - mBar(25) - {} - - // Default values set using two different styles, same effect. - S32 mFoo{10}; - S32 mBar = 20; + // Here mFoo is not specified, so you will get the default value of 10. + // mBar is specified, so 25 will override the default value. + InitInlineWithConstructor(): + mBar(25) + {} + + // Default values set using two different styles, same effect. + S32 mFoo{10}; + S32 mBar = 20; }; template<> template<> void cpp_features_test_object_t::test<8>() { - InitInline ii; - ensure("init member inline 1", ii.mFoo==10); + InitInline ii; + ensure("init member inline 1", ii.mFoo==10); - InitInlineWithConstructor iici; - ensure("init member inline 2", iici.mFoo=10); - ensure("init member inline 3", iici.mBar==25); + InitInlineWithConstructor iici; + ensure("init member inline 2", iici.mFoo=10); + ensure("init member inline 3", iici.mBar==25); } // constexpr @@ -296,25 +296,25 @@ constexpr S32 compute2() { return 2; } constexpr S32 ce_factorial(S32 n) { - if (n<=0) - { - return 1; - } - else - { - return n*ce_factorial(n-1); - } + if (n<=0) + { + return 1; + } + else + { + return n*ce_factorial(n-1); + } } template<> template<> void cpp_features_test_object_t::test<9>() { - S32 val = compute2(); - ensure("constexpr 1", val==2); + S32 val = compute2(); + ensure("constexpr 1", val==2); - // Compile-time factorial. You used to need complex templates to do something this useless. - S32 fac5 = ce_factorial(5); - ensure("constexpr 2", fac5==120); + // Compile-time factorial. You used to need complex templates to do something this useless. + S32 fac5 = ce_factorial(5); + ensure("constexpr 2", fac5==120); } // static assert @@ -331,14 +331,14 @@ void cpp_features_test_object_t::test<9>() template<> template<> void cpp_features_test_object_t::test<10>() { - // static_assert(ce_factorial(6)==720); No, needs a flag we don't currently set. - static_assert(ce_factorial(6)==720, "bad factorial"); // OK + // static_assert(ce_factorial(6)==720); No, needs a flag we don't currently set. + static_assert(ce_factorial(6)==720, "bad factorial"); // OK } // type aliases // // https://en.cppreference.com/w/cpp/language/type_alias -// +// // You can use the "using" statement to create simpler templates that // are aliases for more complex ones. "Template typedef" @@ -349,8 +349,8 @@ using stringmap = std::map<std::string, T>; template<> template<> void cpp_features_test_object_t::test<11>() { - stringmap<S32> name_counts{ {"alice", 3}, {"bob", 2} }; - ensure("type alias", name_counts["bob"]==2); + stringmap<S32> name_counts{ {"alice", 3}, {"bob", 2} }; + ensure("type alias", name_counts["bob"]==2); } // Other possibilities: diff --git a/indra/newview/tests/llagentaccess_test.cpp b/indra/newview/tests/llagentaccess_test.cpp index 45ce1ba62f..6739096baa 100644 --- a/indra/newview/tests/llagentaccess_test.cpp +++ b/indra/newview/tests/llagentaccess_test.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llagentaccess_test.cpp * @brief LLAgentAccess tests * * $LicenseInfo:firstyear=2001&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$ */ @@ -40,7 +40,7 @@ static U32 test_preferred_maturity = SIM_ACCESS_PG; LLControlGroup::LLControlGroup(const std::string& name) -: LLInstanceTracker<LLControlGroup, std::string>(name) +: LLInstanceTracker<LLControlGroup, std::string>(name) { } @@ -51,241 +51,241 @@ LLControlGroup::~LLControlGroup() // Implementation of just the LLControlGroup methods we requre LLControlVariable* LLControlGroup::declareU32(const std::string& name, U32 initial_val, const std::string& comment, LLControlVariable::ePersist persist) { - test_preferred_maturity = initial_val; - return NULL; + test_preferred_maturity = initial_val; + return NULL; } void LLControlGroup::setU32(const std::string& name, U32 val) { - test_preferred_maturity = val; + test_preferred_maturity = val; } U32 LLControlGroup::getU32(const std::string& name) { - return test_preferred_maturity; + return test_preferred_maturity; } //---------------------------------------------------------------------------- - + namespace tut { struct agentaccess { }; - - typedef test_group<agentaccess> agentaccess_t; - typedef agentaccess_t::object agentaccess_object_t; - tut::agentaccess_t tut_agentaccess("LLAgentAccess"); - - template<> template<> - void agentaccess_object_t::test<1>() - { - LLControlGroup cgr("test"); - cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", LLControlVariable::PERSIST_NO); - LLAgentAccess aa(cgr); - - cgr.setU32("PreferredMaturity", SIM_ACCESS_PG); + + typedef test_group<agentaccess> agentaccess_t; + typedef agentaccess_t::object agentaccess_object_t; + tut::agentaccess_t tut_agentaccess("LLAgentAccess"); + + template<> template<> + void agentaccess_object_t::test<1>() + { + LLControlGroup cgr("test"); + cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", LLControlVariable::PERSIST_NO); + LLAgentAccess aa(cgr); + + cgr.setU32("PreferredMaturity", SIM_ACCESS_PG); #ifndef HACKED_GODLIKE_VIEWER - ensure("1 prefersPG", aa.prefersPG()); - ensure("1 prefersMature", !aa.prefersMature()); - ensure("1 prefersAdult", !aa.prefersAdult()); + ensure("1 prefersPG", aa.prefersPG()); + ensure("1 prefersMature", !aa.prefersMature()); + ensure("1 prefersAdult", !aa.prefersAdult()); #endif // HACKED_GODLIKE_VIEWER - - cgr.setU32("PreferredMaturity", SIM_ACCESS_MATURE); + + cgr.setU32("PreferredMaturity", SIM_ACCESS_MATURE); #ifndef HACKED_GODLIKE_VIEWER - ensure("2 prefersPG", !aa.prefersPG()); - ensure("2 prefersMature", aa.prefersMature()); - ensure("2 prefersAdult", !aa.prefersAdult()); + ensure("2 prefersPG", !aa.prefersPG()); + ensure("2 prefersMature", aa.prefersMature()); + ensure("2 prefersAdult", !aa.prefersAdult()); #endif // HACKED_GODLIKE_VIEWER - - cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT); + + cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT); #ifndef HACKED_GODLIKE_VIEWER - ensure("3 prefersPG", !aa.prefersPG()); - ensure("3 prefersMature", aa.prefersMature()); - ensure("3 prefersAdult", aa.prefersAdult()); + ensure("3 prefersPG", !aa.prefersPG()); + ensure("3 prefersMature", aa.prefersMature()); + ensure("3 prefersAdult", aa.prefersAdult()); #endif // HACKED_GODLIKE_VIEWER } - - template<> template<> - void agentaccess_object_t::test<2>() - { - LLControlGroup cgr("test"); - cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", LLControlVariable::PERSIST_NO); - LLAgentAccess aa(cgr); - - // make sure default is PG + + template<> template<> + void agentaccess_object_t::test<2>() + { + LLControlGroup cgr("test"); + cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", LLControlVariable::PERSIST_NO); + LLAgentAccess aa(cgr); + + // make sure default is PG #ifndef HACKED_GODLIKE_VIEWER - ensure("1 isTeen", aa.isTeen()); - ensure("1 isMature", !aa.isMature()); - ensure("1 isAdult", !aa.isAdult()); + ensure("1 isTeen", aa.isTeen()); + ensure("1 isMature", !aa.isMature()); + ensure("1 isAdult", !aa.isAdult()); #endif // HACKED_GODLIKE_VIEWER - - // check the conversion routine + + // check the conversion routine #ifndef HACKED_GODLIKE_VIEWER - ensure_equals("1 conversion", SIM_ACCESS_PG, aa.convertTextToMaturity('P')); - ensure_equals("2 conversion", SIM_ACCESS_MATURE, aa.convertTextToMaturity('M')); - ensure_equals("3 conversion", SIM_ACCESS_ADULT, aa.convertTextToMaturity('A')); - ensure_equals("4 conversion", SIM_ACCESS_MIN, aa.convertTextToMaturity('Q')); + ensure_equals("1 conversion", SIM_ACCESS_PG, aa.convertTextToMaturity('P')); + ensure_equals("2 conversion", SIM_ACCESS_MATURE, aa.convertTextToMaturity('M')); + ensure_equals("3 conversion", SIM_ACCESS_ADULT, aa.convertTextToMaturity('A')); + ensure_equals("4 conversion", SIM_ACCESS_MIN, aa.convertTextToMaturity('Q')); #endif // HACKED_GODLIKE_VIEWER - - // now try the other method of setting it - PG - aa.setMaturity('P'); - ensure("2 isTeen", aa.isTeen()); + + // now try the other method of setting it - PG + aa.setMaturity('P'); + ensure("2 isTeen", aa.isTeen()); #ifndef HACKED_GODLIKE_VIEWER - ensure("2 isMature", !aa.isMature()); - ensure("2 isAdult", !aa.isAdult()); + ensure("2 isMature", !aa.isMature()); + ensure("2 isAdult", !aa.isAdult()); #endif // HACKED_GODLIKE_VIEWER - - // Mature - aa.setMaturity('M'); + + // Mature + aa.setMaturity('M'); #ifndef HACKED_GODLIKE_VIEWER - ensure("3 isTeen", !aa.isTeen()); - ensure("3 isMature", aa.isMature()); - ensure("3 isAdult", !aa.isAdult()); + ensure("3 isTeen", !aa.isTeen()); + ensure("3 isMature", aa.isMature()); + ensure("3 isAdult", !aa.isAdult()); #endif // HACKED_GODLIKE_VIEWER - - // Adult - aa.setMaturity('A'); + + // Adult + aa.setMaturity('A'); #ifndef HACKED_GODLIKE_VIEWER - ensure("4 isTeen", !aa.isTeen()); - ensure("4 isMature", aa.isMature()); - ensure("4 isAdult", aa.isAdult()); + ensure("4 isTeen", !aa.isTeen()); + ensure("4 isMature", aa.isMature()); + ensure("4 isAdult", aa.isAdult()); #endif // HACKED_GODLIKE_VIEWER - - } - - template<> template<> - void agentaccess_object_t::test<3>() - { - LLControlGroup cgr("test"); - cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", LLControlVariable::PERSIST_NO); - LLAgentAccess aa(cgr); - + + } + + template<> template<> + void agentaccess_object_t::test<3>() + { + LLControlGroup cgr("test"); + cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", LLControlVariable::PERSIST_NO); + LLAgentAccess aa(cgr); + #ifndef HACKED_GODLIKE_VIEWER - ensure("starts normal", !aa.isGodlike()); + ensure("starts normal", !aa.isGodlike()); #endif // HACKED_GODLIKE_VIEWER - aa.setGodLevel(GOD_NOT); + aa.setGodLevel(GOD_NOT); #ifndef HACKED_GODLIKE_VIEWER - ensure("stays normal", !aa.isGodlike()); + ensure("stays normal", !aa.isGodlike()); #endif // HACKED_GODLIKE_VIEWER - aa.setGodLevel(GOD_FULL); + aa.setGodLevel(GOD_FULL); #ifndef HACKED_GODLIKE_VIEWER - ensure("sets full", aa.isGodlike()); + ensure("sets full", aa.isGodlike()); #endif // HACKED_GODLIKE_VIEWER - aa.setGodLevel(GOD_NOT); + aa.setGodLevel(GOD_NOT); #ifndef HACKED_GODLIKE_VIEWER - ensure("resets normal", !aa.isGodlike()); + ensure("resets normal", !aa.isGodlike()); #endif // HACKED_GODLIKE_VIEWER - aa.setAdminOverride(true); + aa.setAdminOverride(true); #ifndef HACKED_GODLIKE_VIEWER - ensure("admin true", aa.getAdminOverride()); - ensure("overrides 1", aa.isGodlike()); + ensure("admin true", aa.getAdminOverride()); + ensure("overrides 1", aa.isGodlike()); #endif // HACKED_GODLIKE_VIEWER - aa.setGodLevel(GOD_FULL); + aa.setGodLevel(GOD_FULL); #ifndef HACKED_GODLIKE_VIEWER - ensure("overrides 2", aa.isGodlike()); + ensure("overrides 2", aa.isGodlike()); #endif // HACKED_GODLIKE_VIEWER - aa.setAdminOverride(false); + aa.setAdminOverride(false); #ifndef HACKED_GODLIKE_VIEWER - ensure("admin false", !aa.getAdminOverride()); - ensure("overrides 3", aa.isGodlike()); + ensure("admin false", !aa.getAdminOverride()); + ensure("overrides 3", aa.isGodlike()); #endif // HACKED_GODLIKE_VIEWER } - - template<> template<> - void agentaccess_object_t::test<4>() - { - LLControlGroup cgr("test"); - cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", LLControlVariable::PERSIST_NO); - LLAgentAccess aa(cgr); - + + template<> template<> + void agentaccess_object_t::test<4>() + { + LLControlGroup cgr("test"); + cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", LLControlVariable::PERSIST_NO); + LLAgentAccess aa(cgr); + #ifndef HACKED_GODLIKE_VIEWER - ensure("1 pg to start", aa.wantsPGOnly()); - ensure("2 pg to start", !aa.canAccessMature()); - ensure("3 pg to start", !aa.canAccessAdult()); + ensure("1 pg to start", aa.wantsPGOnly()); + ensure("2 pg to start", !aa.canAccessMature()); + ensure("3 pg to start", !aa.canAccessAdult()); #endif // HACKED_GODLIKE_VIEWER - - aa.setGodLevel(GOD_FULL); + + aa.setGodLevel(GOD_FULL); #ifndef HACKED_GODLIKE_VIEWER - ensure("1 full god", !aa.wantsPGOnly()); - ensure("2 full god", aa.canAccessMature()); - ensure("3 full god", aa.canAccessAdult()); + ensure("1 full god", !aa.wantsPGOnly()); + ensure("2 full god", aa.canAccessMature()); + ensure("3 full god", aa.canAccessAdult()); #endif // HACKED_GODLIKE_VIEWER - - aa.setGodLevel(GOD_NOT); - aa.setAdminOverride(true); + + aa.setGodLevel(GOD_NOT); + aa.setAdminOverride(true); #ifndef HACKED_GODLIKE_VIEWER - ensure("1 admin mode", !aa.wantsPGOnly()); - ensure("2 admin mode", aa.canAccessMature()); - ensure("3 admin mode", aa.canAccessAdult()); + ensure("1 admin mode", !aa.wantsPGOnly()); + ensure("2 admin mode", aa.canAccessMature()); + ensure("3 admin mode", aa.canAccessAdult()); #endif // HACKED_GODLIKE_VIEWER - aa.setAdminOverride(false); - aa.setMaturity('M'); - // preferred is still pg by default + aa.setAdminOverride(false); + aa.setMaturity('M'); + // preferred is still pg by default #ifndef HACKED_GODLIKE_VIEWER - ensure("1 mature pref pg", aa.wantsPGOnly()); - ensure("2 mature pref pg", !aa.canAccessMature()); - ensure("3 mature pref pg", !aa.canAccessAdult()); + ensure("1 mature pref pg", aa.wantsPGOnly()); + ensure("2 mature pref pg", !aa.canAccessMature()); + ensure("3 mature pref pg", !aa.canAccessAdult()); #endif // HACKED_GODLIKE_VIEWER - - cgr.setU32("PreferredMaturity", SIM_ACCESS_MATURE); + + cgr.setU32("PreferredMaturity", SIM_ACCESS_MATURE); #ifndef HACKED_GODLIKE_VIEWER - ensure("1 mature", !aa.wantsPGOnly()); - ensure("2 mature", aa.canAccessMature()); - ensure("3 mature", !aa.canAccessAdult()); + ensure("1 mature", !aa.wantsPGOnly()); + ensure("2 mature", aa.canAccessMature()); + ensure("3 mature", !aa.canAccessAdult()); #endif // HACKED_GODLIKE_VIEWER - - cgr.setU32("PreferredMaturity", SIM_ACCESS_PG); + + cgr.setU32("PreferredMaturity", SIM_ACCESS_PG); #ifndef HACKED_GODLIKE_VIEWER - ensure("1 mature pref pg", aa.wantsPGOnly()); - ensure("2 mature pref pg", !aa.canAccessMature()); - ensure("3 mature pref pg", !aa.canAccessAdult()); + ensure("1 mature pref pg", aa.wantsPGOnly()); + ensure("2 mature pref pg", !aa.canAccessMature()); + ensure("3 mature pref pg", !aa.canAccessAdult()); #endif // HACKED_GODLIKE_VIEWER - - aa.setMaturity('A'); + + aa.setMaturity('A'); #ifndef HACKED_GODLIKE_VIEWER - ensure("1 adult pref pg", aa.wantsPGOnly()); - ensure("2 adult pref pg", !aa.canAccessMature()); - ensure("3 adult pref pg", !aa.canAccessAdult()); + ensure("1 adult pref pg", aa.wantsPGOnly()); + ensure("2 adult pref pg", !aa.canAccessMature()); + ensure("3 adult pref pg", !aa.canAccessAdult()); #endif // HACKED_GODLIKE_VIEWER - cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT); + cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT); #ifndef HACKED_GODLIKE_VIEWER - ensure("1 adult", !aa.wantsPGOnly()); - ensure("2 adult", aa.canAccessMature()); - ensure("3 adult", aa.canAccessAdult()); + ensure("1 adult", !aa.wantsPGOnly()); + ensure("2 adult", aa.canAccessMature()); + ensure("3 adult", aa.canAccessAdult()); #endif // HACKED_GODLIKE_VIEWER - // make sure that even if pref is high, if access is low we block access - // this shouldn't occur in real life but we want to be safe - cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT); - aa.setMaturity('P'); + // make sure that even if pref is high, if access is low we block access + // this shouldn't occur in real life but we want to be safe + cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT); + aa.setMaturity('P'); #ifndef HACKED_GODLIKE_VIEWER - ensure("1 pref adult, actual pg", aa.wantsPGOnly()); - ensure("2 pref adult, actual pg", !aa.canAccessMature()); - ensure("3 pref adult, actual pg", !aa.canAccessAdult()); + ensure("1 pref adult, actual pg", aa.wantsPGOnly()); + ensure("2 pref adult, actual pg", !aa.canAccessMature()); + ensure("3 pref adult, actual pg", !aa.canAccessAdult()); #endif // HACKED_GODLIKE_VIEWER - - } - - template<> template<> - void agentaccess_object_t::test<5>() - { - LLControlGroup cgr("test"); - cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", LLControlVariable::PERSIST_NO); - LLAgentAccess aa(cgr); - - cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT); - aa.setMaturity('M'); + + } + + template<> template<> + void agentaccess_object_t::test<5>() + { + LLControlGroup cgr("test"); + cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", LLControlVariable::PERSIST_NO); + LLAgentAccess aa(cgr); + + cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT); + aa.setMaturity('M'); #ifndef HACKED_GODLIKE_VIEWER - ensure("1 preferred maturity pegged to M when maturity is M", cgr.getU32("PreferredMaturity") == SIM_ACCESS_MATURE); + ensure("1 preferred maturity pegged to M when maturity is M", cgr.getU32("PreferredMaturity") == SIM_ACCESS_MATURE); #endif // HACKED_GODLIKE_VIEWER - - aa.setMaturity('P'); + + aa.setMaturity('P'); #ifndef HACKED_GODLIKE_VIEWER - ensure("1 preferred maturity pegged to P when maturity is P", cgr.getU32("PreferredMaturity") == SIM_ACCESS_PG); + ensure("1 preferred maturity pegged to P when maturity is P", cgr.getU32("PreferredMaturity") == SIM_ACCESS_PG); #endif // HACKED_GODLIKE_VIEWER - } + } } diff --git a/indra/newview/tests/lldateutil_test.cpp b/indra/newview/tests/lldateutil_test.cpp index 62158d8f66..e9d4982e35 100644 --- a/indra/newview/tests/lldateutil_test.cpp +++ b/indra/newview/tests/lldateutil_test.cpp @@ -1,24 +1,24 @@ -/** +/** * @file lldateutil_test.cpp * * $LicenseInfo:firstyear=2001&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$ */ @@ -30,7 +30,7 @@ #include "../lldateutil.h" #include "lldate.h" -#include "llstring.h" // LLStringUtil::format() +#include "llstring.h" // LLStringUtil::format() #include "lltrans.h" #include "llui.h" @@ -47,150 +47,150 @@ std::map< count_string_t, std::string > gCountString; std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args, bool def_string) { - std::string text = gString[xml_desc]; - LLStringUtil::format(text, args); - return text; + std::string text = gString[xml_desc]; + LLStringUtil::format(text, args); + return text; } std::string LLTrans::getCountString(const std::string& language, const std::string& xml_desc, S32 count) { - count_string_t key(xml_desc, count); - if (gCountString.find(key) == gCountString.end()) - { - return std::string("Couldn't find ") + xml_desc; - } - return gCountString[ count_string_t(xml_desc, count) ]; + count_string_t key(xml_desc, count); + if (gCountString.find(key) == gCountString.end()) + { + return std::string("Couldn't find ") + xml_desc; + } + return gCountString[ count_string_t(xml_desc, count) ]; } std::string LLUI::getLanguage() { - return "en"; + return "en"; } namespace tut { struct dateutil { - // Hard-code a "now" date so unit test doesn't change with - // current time. Because server strings are in Pacific time - // roll this forward 8 hours to compensate. This represents - // 2009-12-31T00:00:00Z UTC. - dateutil() - : mNow(std::string("2009-12-31T08:00:00Z")) - { - // copied from strings.xml - gString["YearsMonthsOld"] = "[AGEYEARS] [AGEMONTHS] old"; - gString["YearsOld"] = "[AGEYEARS] old"; - gString["MonthsOld"] = "[AGEMONTHS] old"; - gString["WeeksOld"] = "[AGEWEEKS] old"; - gString["DaysOld"] = "[AGEDAYS] old"; - gString["TodayOld"] = "Joined today"; - - gCountString[ count_string_t("AgeYears", 1) ] = "1 year"; - gCountString[ count_string_t("AgeYears", 2) ] = "2 years"; - gCountString[ count_string_t("AgeMonths", 1) ] = "1 month"; - gCountString[ count_string_t("AgeMonths", 2) ] = "2 months"; - gCountString[ count_string_t("AgeMonths", 11) ]= "11 months"; - gCountString[ count_string_t("AgeWeeks", 1) ] = "1 week"; - gCountString[ count_string_t("AgeWeeks", 2) ] = "2 weeks"; - gCountString[ count_string_t("AgeWeeks", 3) ] = "3 weeks"; - gCountString[ count_string_t("AgeWeeks", 4) ] = "4 weeks"; - gCountString[ count_string_t("AgeDays", 1) ] = "1 day"; - gCountString[ count_string_t("AgeDays", 2) ] = "2 days"; - } - LLDate mNow; + // Hard-code a "now" date so unit test doesn't change with + // current time. Because server strings are in Pacific time + // roll this forward 8 hours to compensate. This represents + // 2009-12-31T00:00:00Z UTC. + dateutil() + : mNow(std::string("2009-12-31T08:00:00Z")) + { + // copied from strings.xml + gString["YearsMonthsOld"] = "[AGEYEARS] [AGEMONTHS] old"; + gString["YearsOld"] = "[AGEYEARS] old"; + gString["MonthsOld"] = "[AGEMONTHS] old"; + gString["WeeksOld"] = "[AGEWEEKS] old"; + gString["DaysOld"] = "[AGEDAYS] old"; + gString["TodayOld"] = "Joined today"; + + gCountString[ count_string_t("AgeYears", 1) ] = "1 year"; + gCountString[ count_string_t("AgeYears", 2) ] = "2 years"; + gCountString[ count_string_t("AgeMonths", 1) ] = "1 month"; + gCountString[ count_string_t("AgeMonths", 2) ] = "2 months"; + gCountString[ count_string_t("AgeMonths", 11) ]= "11 months"; + gCountString[ count_string_t("AgeWeeks", 1) ] = "1 week"; + gCountString[ count_string_t("AgeWeeks", 2) ] = "2 weeks"; + gCountString[ count_string_t("AgeWeeks", 3) ] = "3 weeks"; + gCountString[ count_string_t("AgeWeeks", 4) ] = "4 weeks"; + gCountString[ count_string_t("AgeDays", 1) ] = "1 day"; + gCountString[ count_string_t("AgeDays", 2) ] = "2 days"; + } + LLDate mNow; }; - - typedef test_group<dateutil> dateutil_t; - typedef dateutil_t::object dateutil_object_t; - tut::dateutil_t tut_dateutil("LLDateUtil"); - - template<> template<> - void dateutil_object_t::test<1>() - { - set_test_name("Years"); - ensure_equals("years + months", - LLDateUtil::ageFromDate("10/30/2007", mNow), - "2 years 2 months old" ); - ensure_equals("years", - LLDateUtil::ageFromDate("12/31/2007", mNow), - "2 years old" ); - ensure_equals("years", - LLDateUtil::ageFromDate("1/1/2008", mNow), - "1 year 11 months old" ); - ensure_equals("single year + one month", - LLDateUtil::ageFromDate("11/30/2008", mNow), - "1 year 1 month old" ); - ensure_equals("single year + a bit", - LLDateUtil::ageFromDate("12/12/2008", mNow), - "1 year old" ); - ensure_equals("single year", - LLDateUtil::ageFromDate("12/31/2008", mNow), - "1 year old" ); + + typedef test_group<dateutil> dateutil_t; + typedef dateutil_t::object dateutil_object_t; + tut::dateutil_t tut_dateutil("LLDateUtil"); + + template<> template<> + void dateutil_object_t::test<1>() + { + set_test_name("Years"); + ensure_equals("years + months", + LLDateUtil::ageFromDate("10/30/2007", mNow), + "2 years 2 months old" ); + ensure_equals("years", + LLDateUtil::ageFromDate("12/31/2007", mNow), + "2 years old" ); + ensure_equals("years", + LLDateUtil::ageFromDate("1/1/2008", mNow), + "1 year 11 months old" ); + ensure_equals("single year + one month", + LLDateUtil::ageFromDate("11/30/2008", mNow), + "1 year 1 month old" ); + ensure_equals("single year + a bit", + LLDateUtil::ageFromDate("12/12/2008", mNow), + "1 year old" ); + ensure_equals("single year", + LLDateUtil::ageFromDate("12/31/2008", mNow), + "1 year old" ); + } + + template<> template<> + void dateutil_object_t::test<2>() + { + set_test_name("Months"); + ensure_equals("months", + LLDateUtil::ageFromDate("10/30/2009", mNow), + "2 months old" ); + ensure_equals("months 2", + LLDateUtil::ageFromDate("10/31/2009", mNow), + "2 months old" ); + ensure_equals("single month", + LLDateUtil::ageFromDate("11/30/2009", mNow), + "1 month old" ); + } + + template<> template<> + void dateutil_object_t::test<3>() + { + set_test_name("Weeks"); + ensure_equals("4 weeks", + LLDateUtil::ageFromDate("12/1/2009", mNow), + "4 weeks old" ); + ensure_equals("weeks", + LLDateUtil::ageFromDate("12/17/2009", mNow), + "2 weeks old" ); + ensure_equals("single week", + LLDateUtil::ageFromDate("12/24/2009", mNow), + "1 week old" ); + } + + template<> template<> + void dateutil_object_t::test<4>() + { + set_test_name("Days"); + ensure_equals("days", + LLDateUtil::ageFromDate("12/29/2009", mNow), + "2 days old" ); + ensure_equals("single day", + LLDateUtil::ageFromDate("12/30/2009", mNow), + "1 day old" ); + ensure_equals("today", + LLDateUtil::ageFromDate("12/31/2009", mNow), + "Joined today" ); + } + + template<> template<> + void dateutil_object_t::test<5>() + { + set_test_name("2010 rollover"); + LLDate now(std::string("2010-01-04T12:00:00Z")); + ensure_equals("days", + LLDateUtil::ageFromDate("12/13/2009", now), + "3 weeks old" ); } - template<> template<> - void dateutil_object_t::test<2>() - { - set_test_name("Months"); - ensure_equals("months", - LLDateUtil::ageFromDate("10/30/2009", mNow), - "2 months old" ); - ensure_equals("months 2", - LLDateUtil::ageFromDate("10/31/2009", mNow), - "2 months old" ); - ensure_equals("single month", - LLDateUtil::ageFromDate("11/30/2009", mNow), - "1 month old" ); - } - - template<> template<> - void dateutil_object_t::test<3>() - { - set_test_name("Weeks"); - ensure_equals("4 weeks", - LLDateUtil::ageFromDate("12/1/2009", mNow), - "4 weeks old" ); - ensure_equals("weeks", - LLDateUtil::ageFromDate("12/17/2009", mNow), - "2 weeks old" ); - ensure_equals("single week", - LLDateUtil::ageFromDate("12/24/2009", mNow), - "1 week old" ); - } - - template<> template<> - void dateutil_object_t::test<4>() - { - set_test_name("Days"); - ensure_equals("days", - LLDateUtil::ageFromDate("12/29/2009", mNow), - "2 days old" ); - ensure_equals("single day", - LLDateUtil::ageFromDate("12/30/2009", mNow), - "1 day old" ); - ensure_equals("today", - LLDateUtil::ageFromDate("12/31/2009", mNow), - "Joined today" ); - } - - template<> template<> - void dateutil_object_t::test<5>() - { - set_test_name("2010 rollover"); - LLDate now(std::string("2010-01-04T12:00:00Z")); - ensure_equals("days", - LLDateUtil::ageFromDate("12/13/2009", now), - "3 weeks old" ); - } - - //template<> template<> - //void dateutil_object_t::test<6>() - //{ - // set_test_name("ISO dates"); - // LLDate now(std::string("2010-01-04T12:00:00Z")); - // ensure_equals("days", - // LLDateUtil::ageFromDateISO("2009-12-13", now), - // "3 weeks old" ); - //} + //template<> template<> + //void dateutil_object_t::test<6>() + //{ + // set_test_name("ISO dates"); + // LLDate now(std::string("2010-01-04T12:00:00Z")); + // ensure_equals("days", + // LLDateUtil::ageFromDateISO("2009-12-13", now), + // "3 weeks old" ); + //} } diff --git a/indra/newview/tests/lldir_stub.cpp b/indra/newview/tests/lldir_stub.cpp index 911e9334dd..5d9c2f718b 100644 --- a/indra/newview/tests/lldir_stub.cpp +++ b/indra/newview/tests/lldir_stub.cpp @@ -1,25 +1,25 @@ -/** +/** * @file lldir_stub.cpp * @brief stub class to allow unit testing * * $LicenseInfo:firstyear=2009&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$ */ @@ -46,9 +46,9 @@ public: LLDir_stub() = default; ~LLDir_stub() = default; - void initAppDirs(const std::string &app_name, const std::string &) override {} + void initAppDirs(const std::string &app_name, const std::string &) override {} - std::string getCurPath() override { return "CUR_PATH_FROM_LLDIR"; } + std::string getCurPath() override { return "CUR_PATH_FROM_LLDIR"; } bool fileExists(const std::string &filename) const override { return false; } std::string getLLPluginLauncher() override { return ""; } @@ -61,7 +61,7 @@ LLDir* gDirUtilp = &gDirUtil; std::string LLDir::getExpandedFilename(ELLPath loc, const std::string& subdir, const std::string& filename) const { - return subdir + " --- " + filename + " --- expanded!"; + return subdir + " --- " + filename + " --- expanded!"; } std::string LLDir::getExpandedFilename(ELLPath location, const std::string &filename) const diff --git a/indra/newview/tests/llglslshader_stub.cpp b/indra/newview/tests/llglslshader_stub.cpp index 8947a632c8..537434a6d8 100644 --- a/indra/newview/tests/llglslshader_stub.cpp +++ b/indra/newview/tests/llglslshader_stub.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llglslshader_stub.cpp * @brief stub class to allow unit testing * * $LicenseInfo:firstyear=2009&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$ */ diff --git a/indra/newview/tests/llhttpretrypolicy_test.cpp b/indra/newview/tests/llhttpretrypolicy_test.cpp index 21c83184dc..5c995c807b 100644 --- a/indra/newview/tests/llhttpretrypolicy_test.cpp +++ b/indra/newview/tests/llhttpretrypolicy_test.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llhttpretrypolicy_test.cpp * @brief Header tests to exercise the LLHTTPRetryPolicy classes. * * $LicenseInfo:firstyear=2013&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2013, 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$ */ @@ -34,141 +34,141 @@ struct TestData { }; -typedef test_group<TestData> RetryPolicyTestGroup; -typedef RetryPolicyTestGroup::object RetryPolicyTestObject; +typedef test_group<TestData> RetryPolicyTestGroup; +typedef RetryPolicyTestGroup::object RetryPolicyTestObject; RetryPolicyTestGroup retryPolicyTestGroup("retry_policy"); template<> template<> void RetryPolicyTestObject::test<1>() { - LLAdaptiveRetryPolicy never_retry(1.0,1.0,1.0,0); - LLSD headers; - F32 wait_seconds; - - // No retry until we've failed a try. - ensure("never retry 0", !never_retry.shouldRetry(wait_seconds)); - - // 0 retries max. - never_retry.onFailure(500,headers); - ensure("never retry 1", !never_retry.shouldRetry(wait_seconds)); + LLAdaptiveRetryPolicy never_retry(1.0,1.0,1.0,0); + LLSD headers; + F32 wait_seconds; + + // No retry until we've failed a try. + ensure("never retry 0", !never_retry.shouldRetry(wait_seconds)); + + // 0 retries max. + never_retry.onFailure(500,headers); + ensure("never retry 1", !never_retry.shouldRetry(wait_seconds)); } template<> template<> void RetryPolicyTestObject::test<2>() { - LLSD headers; - F32 wait_seconds; - - // Normally only retry on server error (5xx) - LLAdaptiveRetryPolicy noRetry404(1.0,2.0,3.0,10); - noRetry404.onFailure(404,headers); - ensure("no retry on 404", !noRetry404.shouldRetry(wait_seconds)); - - // Can retry on 4xx errors if enabled by flag. - bool do_retry_4xx = true; - LLAdaptiveRetryPolicy doRetry404(1.0,2.0,3.0,10,do_retry_4xx); - doRetry404.onFailure(404,headers); - ensure("do retry on 404", doRetry404.shouldRetry(wait_seconds)); + LLSD headers; + F32 wait_seconds; + + // Normally only retry on server error (5xx) + LLAdaptiveRetryPolicy noRetry404(1.0,2.0,3.0,10); + noRetry404.onFailure(404,headers); + ensure("no retry on 404", !noRetry404.shouldRetry(wait_seconds)); + + // Can retry on 4xx errors if enabled by flag. + bool do_retry_4xx = true; + LLAdaptiveRetryPolicy doRetry404(1.0,2.0,3.0,10,do_retry_4xx); + doRetry404.onFailure(404,headers); + ensure("do retry on 404", doRetry404.shouldRetry(wait_seconds)); } template<> template<> void RetryPolicyTestObject::test<3>() { - // Should retry after 1.0, 2.0, 3.0, 3.0 seconds. - LLAdaptiveRetryPolicy basic_retry(1.0,3.0,2.0,4); - LLSD headers; - F32 wait_seconds; - bool should_retry; - U32 frac_bits = 6; - - // No retry until we've failed a try. - ensure("basic_retry 0", !basic_retry.shouldRetry(wait_seconds)); - - // Starting wait 1.0 - basic_retry.onFailure(500,headers); - should_retry = basic_retry.shouldRetry(wait_seconds); - ensure("basic_retry 1", should_retry); - ensure_approximately_equals("basic_retry 1", wait_seconds, 1.0F, frac_bits); - - // Double wait to 2.0 - basic_retry.onFailure(500,headers); - should_retry = basic_retry.shouldRetry(wait_seconds); - ensure("basic_retry 2", should_retry); - ensure_approximately_equals("basic_retry 2", wait_seconds, 2.0F, frac_bits); - - // Hit max wait of 3.0 (4.0 clamped to max 3) - basic_retry.onFailure(500,headers); - should_retry = basic_retry.shouldRetry(wait_seconds); - ensure("basic_retry 3", should_retry); - ensure_approximately_equals("basic_retry 3", wait_seconds, 3.0F, frac_bits); - - // At max wait, should stay at 3.0 - basic_retry.onFailure(500,headers); - should_retry = basic_retry.shouldRetry(wait_seconds); - ensure("basic_retry 4", should_retry); - ensure_approximately_equals("basic_retry 4", wait_seconds, 3.0F, frac_bits); - - // Max retries, should fail now. - basic_retry.onFailure(500,headers); - should_retry = basic_retry.shouldRetry(wait_seconds); - ensure("basic_retry 5", !should_retry); - - // Max retries, should fail now. - basic_retry.onFailure(500,headers); - should_retry = basic_retry.shouldRetry(wait_seconds); - ensure("basic_retry 5", !should_retry); - - // After a success, should reset to the starting state. - basic_retry.onSuccess(); - - // No retry until we've failed a try. - ensure("basic_retry 6", !basic_retry.shouldRetry(wait_seconds)); - - // Starting wait 1.0 - basic_retry.onFailure(500,headers); - should_retry = basic_retry.shouldRetry(wait_seconds); - ensure("basic_retry 7", should_retry); - ensure_approximately_equals("basic_retry 7", wait_seconds, 1.0F, frac_bits); - - // Double wait to 2.0 - basic_retry.onFailure(500,headers); - should_retry = basic_retry.shouldRetry(wait_seconds); - ensure("basic_retry 8", should_retry); - ensure_approximately_equals("basic_retry 8", wait_seconds, 2.0F, frac_bits); + // Should retry after 1.0, 2.0, 3.0, 3.0 seconds. + LLAdaptiveRetryPolicy basic_retry(1.0,3.0,2.0,4); + LLSD headers; + F32 wait_seconds; + bool should_retry; + U32 frac_bits = 6; + + // No retry until we've failed a try. + ensure("basic_retry 0", !basic_retry.shouldRetry(wait_seconds)); + + // Starting wait 1.0 + basic_retry.onFailure(500,headers); + should_retry = basic_retry.shouldRetry(wait_seconds); + ensure("basic_retry 1", should_retry); + ensure_approximately_equals("basic_retry 1", wait_seconds, 1.0F, frac_bits); + + // Double wait to 2.0 + basic_retry.onFailure(500,headers); + should_retry = basic_retry.shouldRetry(wait_seconds); + ensure("basic_retry 2", should_retry); + ensure_approximately_equals("basic_retry 2", wait_seconds, 2.0F, frac_bits); + + // Hit max wait of 3.0 (4.0 clamped to max 3) + basic_retry.onFailure(500,headers); + should_retry = basic_retry.shouldRetry(wait_seconds); + ensure("basic_retry 3", should_retry); + ensure_approximately_equals("basic_retry 3", wait_seconds, 3.0F, frac_bits); + + // At max wait, should stay at 3.0 + basic_retry.onFailure(500,headers); + should_retry = basic_retry.shouldRetry(wait_seconds); + ensure("basic_retry 4", should_retry); + ensure_approximately_equals("basic_retry 4", wait_seconds, 3.0F, frac_bits); + + // Max retries, should fail now. + basic_retry.onFailure(500,headers); + should_retry = basic_retry.shouldRetry(wait_seconds); + ensure("basic_retry 5", !should_retry); + + // Max retries, should fail now. + basic_retry.onFailure(500,headers); + should_retry = basic_retry.shouldRetry(wait_seconds); + ensure("basic_retry 5", !should_retry); + + // After a success, should reset to the starting state. + basic_retry.onSuccess(); + + // No retry until we've failed a try. + ensure("basic_retry 6", !basic_retry.shouldRetry(wait_seconds)); + + // Starting wait 1.0 + basic_retry.onFailure(500,headers); + should_retry = basic_retry.shouldRetry(wait_seconds); + ensure("basic_retry 7", should_retry); + ensure_approximately_equals("basic_retry 7", wait_seconds, 1.0F, frac_bits); + + // Double wait to 2.0 + basic_retry.onFailure(500,headers); + should_retry = basic_retry.shouldRetry(wait_seconds); + ensure("basic_retry 8", should_retry); + ensure_approximately_equals("basic_retry 8", wait_seconds, 2.0F, frac_bits); } // Retries should stop as soon as a non-5xx error is received. template<> template<> void RetryPolicyTestObject::test<4>() { - // Should retry after 1.0, 2.0, 3.0, 3.0 seconds. - LLAdaptiveRetryPolicy killer404(1.0,3.0,2.0,4); - LLSD headers; - F32 wait_seconds; - bool should_retry; - U32 frac_bits = 6; - - // Starting wait 1.0 - killer404.onFailure(500,headers); - should_retry = killer404.shouldRetry(wait_seconds); - ensure("killer404 1", should_retry); - ensure_approximately_equals("killer404 1", wait_seconds, 1.0F, frac_bits); - - // Double wait to 2.0 - killer404.onFailure(500,headers); - should_retry = killer404.shouldRetry(wait_seconds); - ensure("killer404 2", should_retry); - ensure_approximately_equals("killer404 2", wait_seconds, 2.0F, frac_bits); - - // Should fail on non-5xx - killer404.onFailure(404,headers); - should_retry = killer404.shouldRetry(wait_seconds); - ensure("killer404 3", !should_retry); - - // After a non-5xx, should keep failing. - killer404.onFailure(500,headers); - should_retry = killer404.shouldRetry(wait_seconds); - ensure("killer404 4", !should_retry); + // Should retry after 1.0, 2.0, 3.0, 3.0 seconds. + LLAdaptiveRetryPolicy killer404(1.0,3.0,2.0,4); + LLSD headers; + F32 wait_seconds; + bool should_retry; + U32 frac_bits = 6; + + // Starting wait 1.0 + killer404.onFailure(500,headers); + should_retry = killer404.shouldRetry(wait_seconds); + ensure("killer404 1", should_retry); + ensure_approximately_equals("killer404 1", wait_seconds, 1.0F, frac_bits); + + // Double wait to 2.0 + killer404.onFailure(500,headers); + should_retry = killer404.shouldRetry(wait_seconds); + ensure("killer404 2", should_retry); + ensure_approximately_equals("killer404 2", wait_seconds, 2.0F, frac_bits); + + // Should fail on non-5xx + killer404.onFailure(404,headers); + should_retry = killer404.shouldRetry(wait_seconds); + ensure("killer404 3", !should_retry); + + // After a non-5xx, should keep failing. + killer404.onFailure(500,headers); + should_retry = killer404.shouldRetry(wait_seconds); + ensure("killer404 4", !should_retry); } // Test handling of "retry-after" header. If present, this header @@ -179,49 +179,49 @@ void RetryPolicyTestObject::test<4>() template<> template<> void RetryPolicyTestObject::test<5>() { - LLAdaptiveRetryPolicy policy(1.0,25.0,2.0,6); - LLSD headers_with_retry; - headers_with_retry[HTTP_IN_HEADER_RETRY_AFTER] = "666"; - LLSD headers_without_retry; - F32 wait_seconds; - bool should_retry; - U32 frac_bits = 6; - - policy.onFailure(500,headers_without_retry); - should_retry = policy.shouldRetry(wait_seconds); - ensure("retry header 1", should_retry); - ensure_approximately_equals("retry header 1", wait_seconds, 1.0F, frac_bits); - - policy.onFailure(500,headers_without_retry); - should_retry = policy.shouldRetry(wait_seconds); - ensure("retry header 2", should_retry); - ensure_approximately_equals("retry header 2", wait_seconds, 2.0F, frac_bits); - - policy.onFailure(500,headers_with_retry); - should_retry = policy.shouldRetry(wait_seconds); - ensure("retry header 3", should_retry); - // 4.0 overrides by header -> 666.0 - ensure_approximately_equals("retry header 3", wait_seconds, 666.0F, frac_bits); - - policy.onFailure(500,headers_with_retry); - should_retry = policy.shouldRetry(wait_seconds); - ensure("retry header 4", should_retry); - // 8.0 overrides by header -> 666.0 - ensure_approximately_equals("retry header 4", wait_seconds, 666.0F, frac_bits); - - policy.onFailure(500,headers_without_retry); - should_retry = policy.shouldRetry(wait_seconds); - ensure("retry header 5", should_retry); - ensure_approximately_equals("retry header 5", wait_seconds, 16.0F, frac_bits); - - policy.onFailure(500,headers_without_retry); - should_retry = policy.shouldRetry(wait_seconds); - ensure("retry header 6", should_retry); - ensure_approximately_equals("retry header 6", wait_seconds, 25.0F, frac_bits); - - policy.onFailure(500,headers_with_retry); - should_retry = policy.shouldRetry(wait_seconds); - ensure("retry header 7", !should_retry); + LLAdaptiveRetryPolicy policy(1.0,25.0,2.0,6); + LLSD headers_with_retry; + headers_with_retry[HTTP_IN_HEADER_RETRY_AFTER] = "666"; + LLSD headers_without_retry; + F32 wait_seconds; + bool should_retry; + U32 frac_bits = 6; + + policy.onFailure(500,headers_without_retry); + should_retry = policy.shouldRetry(wait_seconds); + ensure("retry header 1", should_retry); + ensure_approximately_equals("retry header 1", wait_seconds, 1.0F, frac_bits); + + policy.onFailure(500,headers_without_retry); + should_retry = policy.shouldRetry(wait_seconds); + ensure("retry header 2", should_retry); + ensure_approximately_equals("retry header 2", wait_seconds, 2.0F, frac_bits); + + policy.onFailure(500,headers_with_retry); + should_retry = policy.shouldRetry(wait_seconds); + ensure("retry header 3", should_retry); + // 4.0 overrides by header -> 666.0 + ensure_approximately_equals("retry header 3", wait_seconds, 666.0F, frac_bits); + + policy.onFailure(500,headers_with_retry); + should_retry = policy.shouldRetry(wait_seconds); + ensure("retry header 4", should_retry); + // 8.0 overrides by header -> 666.0 + ensure_approximately_equals("retry header 4", wait_seconds, 666.0F, frac_bits); + + policy.onFailure(500,headers_without_retry); + should_retry = policy.shouldRetry(wait_seconds); + ensure("retry header 5", should_retry); + ensure_approximately_equals("retry header 5", wait_seconds, 16.0F, frac_bits); + + policy.onFailure(500,headers_without_retry); + should_retry = policy.shouldRetry(wait_seconds); + ensure("retry header 6", should_retry); + ensure_approximately_equals("retry header 6", wait_seconds, 25.0F, frac_bits); + + policy.onFailure(500,headers_with_retry); + should_retry = policy.shouldRetry(wait_seconds); + ensure("retry header 7", !should_retry); } // Test getSecondsUntilRetryAfter(const std::string& retry_after, F32& seconds_to_wait), @@ -229,99 +229,99 @@ void RetryPolicyTestObject::test<5>() template<> template<> void RetryPolicyTestObject::test<6>() { - F32 seconds_to_wait; - bool success; + F32 seconds_to_wait; + bool success; - std::string str1("0"); - seconds_to_wait = F32_MAX; + std::string str1("0"); + seconds_to_wait = F32_MAX; success = LLAdaptiveRetryPolicy::getSecondsUntilRetryAfter(str1, seconds_to_wait); - ensure("parse 1", success); - ensure_equals("parse 1", seconds_to_wait, 0.0); + ensure("parse 1", success); + ensure_equals("parse 1", seconds_to_wait, 0.0); - std::string str2("999.9"); - seconds_to_wait = F32_MAX; + std::string str2("999.9"); + seconds_to_wait = F32_MAX; success = LLAdaptiveRetryPolicy::getSecondsUntilRetryAfter(str2, seconds_to_wait); - ensure("parse 2", success); - ensure_approximately_equals("parse 2", seconds_to_wait, 999.9F, 8); + ensure("parse 2", success); + ensure_approximately_equals("parse 2", seconds_to_wait, 999.9F, 8); - time_t nowseconds; - time(&nowseconds); - std::string str3 = LLDate((F64)(nowseconds+44)).asRFC1123(); - seconds_to_wait = F32_MAX; + time_t nowseconds; + time(&nowseconds); + std::string str3 = LLDate((F64)(nowseconds+44)).asRFC1123(); + seconds_to_wait = F32_MAX; success = LLAdaptiveRetryPolicy::getSecondsUntilRetryAfter(str3, seconds_to_wait); - std::cerr << " str3 [" << str3 << "]" << std::endl; - ensure("parse 3", success); - ensure_approximately_equals_range("parse 3", seconds_to_wait, 44.0F, 2.0F); + std::cerr << " str3 [" << str3 << "]" << std::endl; + ensure("parse 3", success); + ensure_approximately_equals_range("parse 3", seconds_to_wait, 44.0F, 2.0F); } // Test retry-after field in both llmessage and CoreHttp headers. template<> template<> void RetryPolicyTestObject::test<7>() { - std::cerr << "7 starts" << std::endl; - - LLSD sd_headers; - time_t nowseconds; - time(&nowseconds); - LLAdaptiveRetryPolicy policy(17.0,644.0,3.0,5); - F32 seconds_to_wait; - bool should_retry; - - // No retry until we've failed a try. - ensure("header 0", !policy.shouldRetry(seconds_to_wait)); - - // no retry header, use default. - policy.onFailure(500,LLSD()); - should_retry = policy.shouldRetry(seconds_to_wait); - ensure("header 1", should_retry); - ensure_approximately_equals("header 1", seconds_to_wait, 17.0F, 6); - - // retry header should override, give delay of 0 - std::string date_string = LLDate((F64)(nowseconds+7)).asRFC1123(); - sd_headers[HTTP_IN_HEADER_RETRY_AFTER] = date_string; - policy.onFailure(503,sd_headers); - should_retry = policy.shouldRetry(seconds_to_wait); - ensure("header 2", should_retry); - ensure_approximately_equals_range("header 2", seconds_to_wait, 7.0F, 2.0F); - - LLCore::HttpResponse *response; - LLCore::HttpHeaders::ptr_t headers; - - response = new LLCore::HttpResponse(); - headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders()); - response->setStatus(503); - response->setHeaders(headers); - headers->append(HTTP_IN_HEADER_RETRY_AFTER, std::string("600")); - policy.onFailure(response); - should_retry = policy.shouldRetry(seconds_to_wait); - ensure("header 3",should_retry); - ensure_approximately_equals("header 3", seconds_to_wait, 600.0F, 6); - response->release(); - - response = new LLCore::HttpResponse(); - headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders()); - response->setStatus(503); - response->setHeaders(headers); - time(&nowseconds); - date_string = LLDate((F64)(nowseconds+77)).asRFC1123(); - std::cerr << "date_string [" << date_string << "]" << std::endl; - headers->append(HTTP_IN_HEADER_RETRY_AFTER,date_string); - policy.onFailure(response); - should_retry = policy.shouldRetry(seconds_to_wait); - ensure("header 4",should_retry); - ensure_approximately_equals_range("header 4", seconds_to_wait, 77.0F, 2.0F); - response->release(); - - // Timeout should be clamped at max. - policy.onFailure(500,LLSD()); - should_retry = policy.shouldRetry(seconds_to_wait); - ensure("header 5", should_retry); - ensure_approximately_equals("header 5", seconds_to_wait, 644.0F, 6); - - // No more retries. - policy.onFailure(500,LLSD()); - should_retry = policy.shouldRetry(seconds_to_wait); - ensure("header 6", !should_retry); + std::cerr << "7 starts" << std::endl; + + LLSD sd_headers; + time_t nowseconds; + time(&nowseconds); + LLAdaptiveRetryPolicy policy(17.0,644.0,3.0,5); + F32 seconds_to_wait; + bool should_retry; + + // No retry until we've failed a try. + ensure("header 0", !policy.shouldRetry(seconds_to_wait)); + + // no retry header, use default. + policy.onFailure(500,LLSD()); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 1", should_retry); + ensure_approximately_equals("header 1", seconds_to_wait, 17.0F, 6); + + // retry header should override, give delay of 0 + std::string date_string = LLDate((F64)(nowseconds+7)).asRFC1123(); + sd_headers[HTTP_IN_HEADER_RETRY_AFTER] = date_string; + policy.onFailure(503,sd_headers); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 2", should_retry); + ensure_approximately_equals_range("header 2", seconds_to_wait, 7.0F, 2.0F); + + LLCore::HttpResponse *response; + LLCore::HttpHeaders::ptr_t headers; + + response = new LLCore::HttpResponse(); + headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders()); + response->setStatus(503); + response->setHeaders(headers); + headers->append(HTTP_IN_HEADER_RETRY_AFTER, std::string("600")); + policy.onFailure(response); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 3",should_retry); + ensure_approximately_equals("header 3", seconds_to_wait, 600.0F, 6); + response->release(); + + response = new LLCore::HttpResponse(); + headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders()); + response->setStatus(503); + response->setHeaders(headers); + time(&nowseconds); + date_string = LLDate((F64)(nowseconds+77)).asRFC1123(); + std::cerr << "date_string [" << date_string << "]" << std::endl; + headers->append(HTTP_IN_HEADER_RETRY_AFTER,date_string); + policy.onFailure(response); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 4",should_retry); + ensure_approximately_equals_range("header 4", seconds_to_wait, 77.0F, 2.0F); + response->release(); + + // Timeout should be clamped at max. + policy.onFailure(500,LLSD()); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 5", should_retry); + ensure_approximately_equals("header 5", seconds_to_wait, 644.0F, 6); + + // No more retries. + policy.onFailure(500,LLSD()); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 6", !should_retry); } } diff --git a/indra/newview/tests/lllogininstance_test.cpp b/indra/newview/tests/lllogininstance_test.cpp index 696fe3536c..62250cbbfd 100644 --- a/indra/newview/tests/lllogininstance_test.cpp +++ b/indra/newview/tests/lllogininstance_test.cpp @@ -1,25 +1,25 @@ /** * @file lllogininstance_test.cpp * @brief Test for lllogininstance.cpp. - * + * * $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$ */ @@ -83,33 +83,33 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil:: { return std::string("test_trans"); } - + class LLLogin::Impl { }; LLLogin::LLLogin() {} LLLogin::~LLLogin() {} LLEventPump& LLLogin::getEventPump() { return gTestPump; } -void LLLogin::connect(const std::string& uri, const LLSD& credentials) +void LLLogin::connect(const std::string& uri, const LLSD& credentials) { - gLoginURI = uri; - gLoginCreds = credentials; + gLoginURI = uri; + gLoginCreds = credentials; } -void LLLogin::disconnect() +void LLLogin::disconnect() { - gDisconnectCalled = true; + gDisconnectCalled = true; } LLSD LLCredential::getLoginParams() { - LLSD result = LLSD::emptyMap(); + LLSD result = LLSD::emptyMap(); - // legacy credential - result["passwd"] = "$1$testpasssd"; - result["first"] = "myfirst"; - result["last"] ="mylast"; - return result; + // legacy credential + result["passwd"] = "$1$testpasssd"; + result["first"] = "myfirst"; + result["last"] ="mylast"; + return result; } void LLCredential::identifierType(std::string &idType) { @@ -119,9 +119,9 @@ void LLCredential::authenticatorType(std::string &idType) { } -LLNotificationPtr LLNotificationsUtil::add(const std::string& name, - const LLSD& substitutions, - const LLSD& payload, +LLNotificationPtr LLNotificationsUtil::add(const std::string& name, + const LLSD& substitutions, + const LLSD& payload, boost::function<void (const LLSD&, const LLSD&)> functor) { return LLNotificationPtr((LLNotification*)NULL); @@ -140,33 +140,33 @@ LLGridManager::~LLGridManager() bool LLGridManager::addGrid(LLSD& grid_data) { - return true; + return true; } LLGridManager::LLGridManager() : - mIsInProductionGrid(false) -{ + mIsInProductionGrid(false) +{ } void LLGridManager::getLoginURIs(std::vector<std::string>& uris) { - uris.push_back(VIEWERLOGIN_URI); + uris.push_back(VIEWERLOGIN_URI); } -void LLGridManager::addSystemGrid(const std::string& label, - const std::string& name, - const std::string& login, - const std::string& helper, - const std::string& login_page, - const std::string& update_url_base, - const std::string& web_profile_url, - const std::string& login_id) +void LLGridManager::addSystemGrid(const std::string& label, + const std::string& name, + const std::string& login, + const std::string& helper, + const std::string& login_page, + const std::string& update_url_base, + const std::string& web_profile_url, + const std::string& login_id) { } std::map<std::string, std::string> LLGridManager::getKnownGrids() { - std::map<std::string, std::string> result; - return result; + std::map<std::string, std::string> result; + return result; } void LLGridManager::setGridChoice(const std::string& grid_name) @@ -175,16 +175,16 @@ void LLGridManager::setGridChoice(const std::string& grid_name) bool LLGridManager::isInProductionGrid() { - return false; + return false; } std::string LLGridManager::getSLURLBase(const std::string& grid_name) { - return "myslurl"; + return "myslurl"; } std::string LLGridManager::getAppSLURLBase(const std::string& grid_name) { - return "myappslurl"; + return "myappslurl"; } std::string LLGridManager::getGridId(const std::string& grid) { @@ -196,7 +196,7 @@ std::string LLGridManager::getGridId(const std::string& grid) LLControlGroup gSavedSettings("Global"); LLControlGroup::LLControlGroup(const std::string& name) : - LLInstanceTracker<LLControlGroup, std::string>(name){} + LLInstanceTracker<LLControlGroup, std::string>(name){} LLControlGroup::~LLControlGroup() {} void LLControlGroup::setBOOL(const std::string& name, BOOL val) {} BOOL LLControlGroup::getBOOL(const std::string& name) { return FALSE; } @@ -213,10 +213,10 @@ void LLUIColorTable::saveUserSettings(void)const {} //----------------------------------------------------------------------------- #include "../llversioninfo.h" -bool llHashedUniqueID(unsigned char* id) +bool llHashedUniqueID(unsigned char* id) { - memcpy( id, "66666666666666666666666666666666", MD5HEX_STR_SIZE ); - return true; + memcpy( id, "66666666666666666666666666666666", MD5HEX_STR_SIZE ); + return true; } //----------------------------------------------------------------------------- @@ -237,9 +237,9 @@ LLPointer<LLSecAPIHandler> gSecAPIHandler; //static LLFloater* LLFloaterReg::showInstance(const std::string& name, const LLSD& key, BOOL focus) { - gTOSType = name; - gTOSReplyPump = &LLEventPumps::instance().obtain(key["reply_pump"]); - return NULL; + gTOSType = name; + gTOSReplyPump = &LLEventPumps::instance().obtain(key["reply_pump"]); + return NULL; } //---------------------------------------------------------------------------- @@ -252,59 +252,59 @@ void LLProgressView::setMessage(std::string const &){} // LLNotifications class MockNotifications : public LLNotificationsInterface { - boost::function<void (const LLSD&, const LLSD&)> mResponder; - int mAddedCount; - -public: - MockNotifications() : - mResponder(0), - mAddedCount(0) - { - } - - virtual ~MockNotifications() {} - - /* virtual */ LLNotificationPtr add( - const std::string& name, - const LLSD& substitutions, - const LLSD& payload, - LLNotificationFunctorRegistry::ResponseFunctor functor) - { - mResponder = functor; - mAddedCount++; - return LLNotificationPtr((LLNotification*)NULL); - } - - void sendYesResponse() - { - LLSD notification; - LLSD response; - response = 1; - mResponder(notification, response); - } - - void sendNoResponse() - { - LLSD notification; - LLSD response; - response = 2; - mResponder(notification, response); - } - - void sendBogusResponse() - { - LLSD notification; - LLSD response; - response = 666; - mResponder(notification, response); - } - - int addedCount() { return mAddedCount; } + boost::function<void (const LLSD&, const LLSD&)> mResponder; + int mAddedCount; + +public: + MockNotifications() : + mResponder(0), + mAddedCount(0) + { + } + + virtual ~MockNotifications() {} + + /* virtual */ LLNotificationPtr add( + const std::string& name, + const LLSD& substitutions, + const LLSD& payload, + LLNotificationFunctorRegistry::ResponseFunctor functor) + { + mResponder = functor; + mAddedCount++; + return LLNotificationPtr((LLNotification*)NULL); + } + + void sendYesResponse() + { + LLSD notification; + LLSD response; + response = 1; + mResponder(notification, response); + } + + void sendNoResponse() + { + LLSD notification; + LLSD response; + response = 2; + mResponder(notification, response); + } + + void sendBogusResponse() + { + LLSD notification; + LLSD response; + response = 666; + mResponder(notification, response); + } + + int addedCount() { return mAddedCount; } }; S32 LLNotification::getSelectedOption(const LLSD& notification, const LLSD& response) { - return response.asInteger(); + return response.asInteger(); } //----------------------------------------------------------------------------- @@ -313,8 +313,8 @@ unsigned char gMACAddress[MAC_ADDRESS_BYTES] = {77,21,46,31,89,2}; S32 LLMachineID::getUniqueID(unsigned char *unique_id, size_t len) { - memcpy(unique_id, gMACAddress, len); - return 1; + memcpy(unique_id, gMACAddress, len); + return 1; } S32 LLMachineID::getLegacyID(unsigned char *unique_id, size_t len) { @@ -324,7 +324,7 @@ S32 LLMachineID::getLegacyID(unsigned char *unique_id, size_t len) // misc std::string xml_escape_string(const std::string& in) { - return in; + return in; } /***************************************************************************** @@ -334,50 +334,50 @@ namespace tut { struct lllogininstance_data { - lllogininstance_data() : logininstance(LLLoginInstance::getInstance()) - { - // Global initialization - gLoginURI.clear(); - gLoginCreds.clear(); - gDisconnectCalled = false; - - gTOSType = ""; // Set to invalid value. - gTOSReplyPump = 0; // clear the callback. - - - gSavedSettings.declareBOOL("NoInventoryLibrary", FALSE, "", LLControlVariable::PERSIST_NO); - gSavedSettings.declareBOOL("ConnectAsGod", FALSE, "", LLControlVariable::PERSIST_NO); - gSavedSettings.declareBOOL("UseDebugMenus", FALSE, "", LLControlVariable::PERSIST_NO); - gSavedSettings.declareString("ClientSettingsFile", "test_settings.xml", "", LLControlVariable::PERSIST_NO); - gSavedSettings.declareString("NextLoginLocation", "", "", LLControlVariable::PERSIST_NO); - gSavedSettings.declareBOOL("LoginLastLocation", FALSE, "", LLControlVariable::PERSIST_NO); + lllogininstance_data() : logininstance(LLLoginInstance::getInstance()) + { + // Global initialization + gLoginURI.clear(); + gLoginCreds.clear(); + gDisconnectCalled = false; + + gTOSType = ""; // Set to invalid value. + gTOSReplyPump = 0; // clear the callback. + + + gSavedSettings.declareBOOL("NoInventoryLibrary", FALSE, "", LLControlVariable::PERSIST_NO); + gSavedSettings.declareBOOL("ConnectAsGod", FALSE, "", LLControlVariable::PERSIST_NO); + gSavedSettings.declareBOOL("UseDebugMenus", FALSE, "", LLControlVariable::PERSIST_NO); + gSavedSettings.declareString("ClientSettingsFile", "test_settings.xml", "", LLControlVariable::PERSIST_NO); + gSavedSettings.declareString("NextLoginLocation", "", "", LLControlVariable::PERSIST_NO); + gSavedSettings.declareBOOL("LoginLastLocation", FALSE, "", LLControlVariable::PERSIST_NO); gSavedSettings.declareBOOL("CmdLineSkipUpdater", TRUE, "", LLControlVariable::PERSIST_NO); - LLSD authenticator = LLSD::emptyMap(); - LLSD identifier = LLSD::emptyMap(); - identifier["type"] = "agent"; - identifier["first_name"] = "testfirst"; - identifier["last_name"] = "testlast"; - authenticator["passwd"] = "testpass"; - agentCredential = new LLCredential(); - agentCredential->setCredentialData(identifier, authenticator); - - authenticator = LLSD::emptyMap(); - identifier = LLSD::emptyMap(); - identifier["type"] = "account"; - identifier["username"] = "testuser"; - authenticator["secret"] = "testsecret"; - accountCredential = new LLCredential(); - accountCredential->setCredentialData(identifier, authenticator); - - logininstance->setNotificationsInterface(¬ifications); - logininstance->setPlatformInfo("win", "1.3.5", "Windows Bogus Version 100.6.6.6"); - } - - LLLoginInstance* logininstance; - LLPointer<LLCredential> agentCredential; - LLPointer<LLCredential> accountCredential; - MockNotifications notifications; + LLSD authenticator = LLSD::emptyMap(); + LLSD identifier = LLSD::emptyMap(); + identifier["type"] = "agent"; + identifier["first_name"] = "testfirst"; + identifier["last_name"] = "testlast"; + authenticator["passwd"] = "testpass"; + agentCredential = new LLCredential(); + agentCredential->setCredentialData(identifier, authenticator); + + authenticator = LLSD::emptyMap(); + identifier = LLSD::emptyMap(); + identifier["type"] = "account"; + identifier["username"] = "testuser"; + authenticator["secret"] = "testsecret"; + accountCredential = new LLCredential(); + accountCredential->setCredentialData(identifier, authenticator); + + logininstance->setNotificationsInterface(¬ifications); + logininstance->setPlatformInfo("win", "1.3.5", "Windows Bogus Version 100.6.6.6"); + } + + LLLoginInstance* logininstance; + LLPointer<LLCredential> agentCredential; + LLPointer<LLCredential> accountCredential; + MockNotifications notifications; }; typedef test_group<lllogininstance_data> lllogininstance_group; @@ -387,103 +387,103 @@ namespace tut template<> template<> void lllogininstance_object::test<1>() { - set_test_name("Test Simple Success And Disconnect"); + set_test_name("Test Simple Success And Disconnect"); - // Test default connect. - logininstance->connect(agentCredential); + // Test default connect. + logininstance->connect(agentCredential); - ensure_equals("Default connect uri", gLoginURI, VIEWERLOGIN_URI); + ensure_equals("Default connect uri", gLoginURI, VIEWERLOGIN_URI); - // Dummy success response. - LLSD response; - response["state"] = "online"; - response["change"] = "connect"; - response["progress"] = 1.0; - response["transfer_rate"] = 7; - response["data"] = "test_data"; + // Dummy success response. + LLSD response; + response["state"] = "online"; + response["change"] = "connect"; + response["progress"] = 1.0; + response["transfer_rate"] = 7; + response["data"] = "test_data"; - gTestPump.post(response); + gTestPump.post(response); - ensure("Success response", logininstance->authSuccess()); - ensure_equals("Test Response Data", logininstance->getResponse().asString(), "test_data"); + ensure("Success response", logininstance->authSuccess()); + ensure_equals("Test Response Data", logininstance->getResponse().asString(), "test_data"); - logininstance->disconnect(); + logininstance->disconnect(); - ensure_equals("Called Login Module Disconnect", gDisconnectCalled, true); + ensure_equals("Called Login Module Disconnect", gDisconnectCalled, true); - response.clear(); - response["state"] = "offline"; - response["change"] = "disconnect"; - response["progress"] = 0.0; - response["transfer_rate"] = 0; - response["data"] = "test_data"; + response.clear(); + response["state"] = "offline"; + response["change"] = "disconnect"; + response["progress"] = 0.0; + response["transfer_rate"] = 0; + response["data"] = "test_data"; - gTestPump.post(response); + gTestPump.post(response); - ensure("Disconnected", !(logininstance->authSuccess())); + ensure("Disconnected", !(logininstance->authSuccess())); } template<> template<> void lllogininstance_object::test<2>() { - set_test_name("Test User TOS/Critical message Interaction"); - - const std::string test_uri = "testing-uri"; - - // Test default connect. - logininstance->connect(test_uri, agentCredential); - - // connect should call LLLogin::connect to init gLoginURI and gLoginCreds. - ensure_equals("Default connect uri", gLoginURI, "testing-uri"); - ensure_equals("Default for agree to tos", gLoginCreds["params"]["agree_to_tos"].asBoolean(), false); - ensure_equals("Default for read critical", gLoginCreds["params"]["read_critical"].asBoolean(), false); - - // TOS failure response. - LLSD response; - response["state"] = "offline"; - response["change"] = "fail.login"; - response["progress"] = 0.0; - response["transfer_rate"] = 7; - response["data"]["reason"] = "tos"; - gTestPump.post(response); - - ensure_equals("TOS Dialog type", gTOSType, "message_tos"); - ensure("TOS callback given", gTOSReplyPump != 0); - gTOSReplyPump->post(false); // Call callback denying TOS. - ensure("No TOS, failed auth", logininstance->authFailure()); - - // Start again. - logininstance->connect(test_uri, agentCredential); - gTestPump.post(response); // Fail for tos again. - gTOSReplyPump->post(true); // Accept tos, should reconnect w/ agree_to_tos. - ensure_equals("Accepted agree to tos", gLoginCreds["params"]["agree_to_tos"].asBoolean(), true); - ensure("Incomplete login status", !logininstance->authFailure() && !logininstance->authSuccess()); - - // Fail connection, attempt connect again. - // The new request should have reset agree to tos to default. - response["data"]["reason"] = "key"; // bad creds. - gTestPump.post(response); - ensure("TOS auth failure", logininstance->authFailure()); - - logininstance->connect(test_uri, agentCredential); - ensure_equals("Reset to default for agree to tos", gLoginCreds["params"]["agree_to_tos"].asBoolean(), false); - - // Critical Message failure response. - logininstance->connect(test_uri, agentCredential); - response["data"]["reason"] = "critical"; // Change response to "critical message" - gTestPump.post(response); - - ensure_equals("TOS Dialog type", gTOSType, "message_critical"); - ensure("TOS callback given", gTOSReplyPump != 0); - gTOSReplyPump->post(true); - ensure_equals("Accepted read critical message", gLoginCreds["params"]["read_critical"].asBoolean(), true); - ensure("Incomplete login status", !logininstance->authFailure() && !logininstance->authSuccess()); - - // Fail then attempt new connection - response["data"]["reason"] = "key"; // bad creds. - gTestPump.post(response); - ensure("TOS auth failure", logininstance->authFailure()); - logininstance->connect(test_uri, agentCredential); - ensure_equals("Default for agree to tos", gLoginCreds["params"]["read_critical"].asBoolean(), false); - } + set_test_name("Test User TOS/Critical message Interaction"); + + const std::string test_uri = "testing-uri"; + + // Test default connect. + logininstance->connect(test_uri, agentCredential); + + // connect should call LLLogin::connect to init gLoginURI and gLoginCreds. + ensure_equals("Default connect uri", gLoginURI, "testing-uri"); + ensure_equals("Default for agree to tos", gLoginCreds["params"]["agree_to_tos"].asBoolean(), false); + ensure_equals("Default for read critical", gLoginCreds["params"]["read_critical"].asBoolean(), false); + + // TOS failure response. + LLSD response; + response["state"] = "offline"; + response["change"] = "fail.login"; + response["progress"] = 0.0; + response["transfer_rate"] = 7; + response["data"]["reason"] = "tos"; + gTestPump.post(response); + + ensure_equals("TOS Dialog type", gTOSType, "message_tos"); + ensure("TOS callback given", gTOSReplyPump != 0); + gTOSReplyPump->post(false); // Call callback denying TOS. + ensure("No TOS, failed auth", logininstance->authFailure()); + + // Start again. + logininstance->connect(test_uri, agentCredential); + gTestPump.post(response); // Fail for tos again. + gTOSReplyPump->post(true); // Accept tos, should reconnect w/ agree_to_tos. + ensure_equals("Accepted agree to tos", gLoginCreds["params"]["agree_to_tos"].asBoolean(), true); + ensure("Incomplete login status", !logininstance->authFailure() && !logininstance->authSuccess()); + + // Fail connection, attempt connect again. + // The new request should have reset agree to tos to default. + response["data"]["reason"] = "key"; // bad creds. + gTestPump.post(response); + ensure("TOS auth failure", logininstance->authFailure()); + + logininstance->connect(test_uri, agentCredential); + ensure_equals("Reset to default for agree to tos", gLoginCreds["params"]["agree_to_tos"].asBoolean(), false); + + // Critical Message failure response. + logininstance->connect(test_uri, agentCredential); + response["data"]["reason"] = "critical"; // Change response to "critical message" + gTestPump.post(response); + + ensure_equals("TOS Dialog type", gTOSType, "message_critical"); + ensure("TOS callback given", gTOSReplyPump != 0); + gTOSReplyPump->post(true); + ensure_equals("Accepted read critical message", gLoginCreds["params"]["read_critical"].asBoolean(), true); + ensure("Incomplete login status", !logininstance->authFailure() && !logininstance->authSuccess()); + + // Fail then attempt new connection + response["data"]["reason"] = "key"; // bad creds. + gTestPump.post(response); + ensure("TOS auth failure", logininstance->authFailure()); + logininstance->connect(test_uri, agentCredential); + ensure_equals("Default for agree to tos", gLoginCreds["params"]["read_critical"].asBoolean(), false); + } } diff --git a/indra/newview/tests/llmediadataclient_test.cpp b/indra/newview/tests/llmediadataclient_test.cpp index 4c0acded9e..f741eb47f6 100644 --- a/indra/newview/tests/llmediadataclient_test.cpp +++ b/indra/newview/tests/llmediadataclient_test.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llmediadataclient_test.cpp * @brief LLMediaDatClient tests * * $LicenseInfo:firstyear=2001&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$ */ @@ -64,42 +64,42 @@ #define FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL_ERROR "foo_ObjectMediaNavigate_ERROR" #define MEDIA_DATA "\ -<array> \ -<string>http://foo.example.com</string> \ -<string>http://bar.example.com</string> \ -<string>baz</string> \ +<array> \ +<string>http://foo.example.com</string> \ +<string>http://bar.example.com</string> \ +<string>baz</string> \ </array>" -#define _DATA_URLS(ID,INTEREST,NEW,URL1,URL2) " \ -<llsd> \ - <map> \ - <key>uuid</key> \ - <string>" ID "</string> \ - <key>interest</key> \ - <real>" INTEREST "</real> \ - <key>cap_urls</key> \ - <map> \ - <key>ObjectMedia</key> \ - <string>" URL1 "</string> \ - <key>ObjectMediaNavigate</key> \ - <string>" URL2 "</string> \ - </map> \ +#define _DATA_URLS(ID,INTEREST,NEW,URL1,URL2) " \ +<llsd> \ + <map> \ + <key>uuid</key> \ + <string>" ID "</string> \ + <key>interest</key> \ + <real>" INTEREST "</real> \ + <key>cap_urls</key> \ + <map> \ + <key>ObjectMedia</key> \ + <string>" URL1 "</string> \ + <key>ObjectMediaNavigate</key> \ + <string>" URL2 "</string> \ + </map> \ <key>media_data</key> \ - " MEDIA_DATA " \ - <key>is_dead</key> \ - <boolean>false</boolean> \ - <key>is_new</key> \ - <boolean>" NEW "</boolean> \ - </map> \ + " MEDIA_DATA " \ + <key>is_dead</key> \ + <boolean>false</boolean> \ + <key>is_new</key> \ + <boolean>" NEW "</boolean> \ + </map> \ </llsd>" #define _DATA(ID,INTEREST,NEW) _DATA_URLS(ID,INTEREST,NEW,FAKE_OBJECT_MEDIA_CAP_URL,FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL) const char *DATA = _DATA(VALID_OBJECT_ID,"1.0","true"); - + #define STR(I) boost::lexical_cast<std::string>(I) -#define LOG_TEST(N) LL_DEBUGS("LLMediaDataClient") << "\n" << \ +#define LOG_TEST(N) LL_DEBUGS("LLMediaDataClient") << "\n" << \ "================================================================================\n" << \ "==================================== TEST " #N " ===================================\n" << \ "================================================================================\n" << LL_ENDL; @@ -109,36 +109,36 @@ F64 gMinimumInterestLevel = (F64)0.0; #if 0 // stubs: void LLHTTPClient::post( - const std::string& url, - const LLSD& body, - LLHTTPClient::ResponderPtr responder, - const LLSD& headers, - const F32 timeout) + const std::string& url, + const LLSD& body, + LLHTTPClient::ResponderPtr responder, + const LLSD& headers, + const F32 timeout) { - LLSD record; - record["url"] = url; - record["body"] = body; - record["headers"] = headers; - record["timeout"] = timeout; - gPostRecords->append(record); - - // Magic URL that triggers a 503: - LLSD result; - result[LLTextureEntry::OBJECT_ID_KEY] = body[LLTextureEntry::OBJECT_ID_KEY]; - if ( url == FAKE_OBJECT_MEDIA_CAP_URL_503 ) - { - LLSD content; - content["reason"] = "fake reason"; - responder->failureResult(HTTP_SERVICE_UNAVAILABLE, "fake reason", content); - return; - } - else if (url == FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL_ERROR) - { - LLSD error; - error["code"] = LLObjectMediaNavigateClient::ERROR_PERMISSION_DENIED_CODE; - result["error"] = error; - } - responder->successResult(result); + LLSD record; + record["url"] = url; + record["body"] = body; + record["headers"] = headers; + record["timeout"] = timeout; + gPostRecords->append(record); + + // Magic URL that triggers a 503: + LLSD result; + result[LLTextureEntry::OBJECT_ID_KEY] = body[LLTextureEntry::OBJECT_ID_KEY]; + if ( url == FAKE_OBJECT_MEDIA_CAP_URL_503 ) + { + LLSD content; + content["reason"] = "fake reason"; + responder->failureResult(HTTP_SERVICE_UNAVAILABLE, "fake reason", content); + return; + } + else if (url == FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL_ERROR) + { + LLSD error; + error["code"] = LLObjectMediaNavigateClient::ERROR_PERMISSION_DENIED_CODE; + result["error"] = error; + } + responder->successResult(result); } #endif @@ -147,70 +147,70 @@ const F32 HTTP_REQUEST_EXPIRY_SECS = 60.0f; class LLMediaDataClientObjectTest : public LLMediaDataClientObject { public: - LLMediaDataClientObjectTest(const char *data) - { - std::istringstream d(data); - LLSDSerialize::fromXML(mRep, d); - mNumBounceBacks = 0; - + LLMediaDataClientObjectTest(const char *data) + { + std::istringstream d(data); + LLSDSerialize::fromXML(mRep, d); + mNumBounceBacks = 0; + // std::cout << ll_pretty_print_sd(mRep) << std::endl; // std::cout << "ID: " << getID() << std::endl; - } - LLMediaDataClientObjectTest(const LLSD &rep) - : mRep(rep), mNumBounceBacks(0) {} - ~LLMediaDataClientObjectTest() - { LL_DEBUGS("LLMediaDataClient") << "~LLMediaDataClientObjectTest" << LL_ENDL; } - - virtual U8 getMediaDataCount() const - { return mRep["media_data"].size(); } - virtual LLSD getMediaDataLLSD(U8 index) const - { return mRep["media_data"][(LLSD::Integer)index]; } - virtual bool isCurrentMediaUrl(U8 index, const std::string &url) const - { return (mRep["media_data"][(LLSD::Integer)index].asString() == url); } - virtual LLUUID getID() const - { return mRep["uuid"]; } - virtual void mediaNavigateBounceBack(U8 index) - { mNumBounceBacks++; } - - virtual bool hasMedia() const - { return mRep.has("media_data"); } - - virtual void updateObjectMediaData(LLSD const &media_data_array, const std::string &media_version) - { mRep["media_data"] = media_data_array; mRep["media_version"] = media_version; } - - virtual F64 getMediaInterest() const - { return (LLSD::Real)mRep["interest"]; } - - virtual bool isInterestingEnough() const - { return getMediaInterest() > gMinimumInterestLevel; } - - virtual std::string getCapabilityUrl(const std::string &name) const - { return mRep["cap_urls"][name]; } - - virtual bool isDead() const - { return mRep["is_dead"]; } - - virtual U32 getMediaVersion() const - { return (LLSD::Integer)mRep["media_version"]; } - - virtual bool isNew() const - { return mRep["is_new"]; } - - void setMediaInterest(F64 val) - { mRep["interest"] = val; } - - int getNumBounceBacks() const - { return mNumBounceBacks; } - - void markDead() - { mRep["is_dead"] = true; } - - void markOld() - { mRep["is_new"] = false; } - + } + LLMediaDataClientObjectTest(const LLSD &rep) + : mRep(rep), mNumBounceBacks(0) {} + ~LLMediaDataClientObjectTest() + { LL_DEBUGS("LLMediaDataClient") << "~LLMediaDataClientObjectTest" << LL_ENDL; } + + virtual U8 getMediaDataCount() const + { return mRep["media_data"].size(); } + virtual LLSD getMediaDataLLSD(U8 index) const + { return mRep["media_data"][(LLSD::Integer)index]; } + virtual bool isCurrentMediaUrl(U8 index, const std::string &url) const + { return (mRep["media_data"][(LLSD::Integer)index].asString() == url); } + virtual LLUUID getID() const + { return mRep["uuid"]; } + virtual void mediaNavigateBounceBack(U8 index) + { mNumBounceBacks++; } + + virtual bool hasMedia() const + { return mRep.has("media_data"); } + + virtual void updateObjectMediaData(LLSD const &media_data_array, const std::string &media_version) + { mRep["media_data"] = media_data_array; mRep["media_version"] = media_version; } + + virtual F64 getMediaInterest() const + { return (LLSD::Real)mRep["interest"]; } + + virtual bool isInterestingEnough() const + { return getMediaInterest() > gMinimumInterestLevel; } + + virtual std::string getCapabilityUrl(const std::string &name) const + { return mRep["cap_urls"][name]; } + + virtual bool isDead() const + { return mRep["is_dead"]; } + + virtual U32 getMediaVersion() const + { return (LLSD::Integer)mRep["media_version"]; } + + virtual bool isNew() const + { return mRep["is_new"]; } + + void setMediaInterest(F64 val) + { mRep["interest"] = val; } + + int getNumBounceBacks() const + { return mNumBounceBacks; } + + void markDead() + { mRep["is_dead"] = true; } + + void markOld() + { mRep["is_new"] = false; } + private: - LLSD mRep; - int mNumBounceBacks; + LLSD mRep; + int mNumBounceBacks; }; // This special timer delay should ensure that the timer will fire on the very @@ -220,28 +220,28 @@ const F32 NO_PERIOD = -1000.0f; static void pump_timers() { - LLEventTimer::updateClass(); + LLEventTimer::updateClass(); } namespace tut { struct mediadataclient { - mediadataclient() { - gPostRecords = &mLLSD; - gMinimumInterestLevel = (F64)0.0; - -// LLError::setDefaultLevel(LLError::LEVEL_DEBUG); -// LLError::setClassLevel("LLMediaDataClient", LLError::LEVEL_DEBUG); -// LLError::setTagLevel("MediaOnAPrim", LLError::LEVEL_DEBUG); - } - LLSD mLLSD; + mediadataclient() { + gPostRecords = &mLLSD; + gMinimumInterestLevel = (F64)0.0; + +// LLError::setDefaultLevel(LLError::LEVEL_DEBUG); +// LLError::setClassLevel("LLMediaDataClient", LLError::LEVEL_DEBUG); +// LLError::setTagLevel("MediaOnAPrim", LLError::LEVEL_DEBUG); + } + LLSD mLLSD; }; - - typedef test_group<mediadataclient> mediadataclient_t; - typedef mediadataclient_t::object mediadataclient_object_t; - tut::mediadataclient_t tut_mediadataclient("LLMediaDataClient"); - + + typedef test_group<mediadataclient> mediadataclient_t; + typedef mediadataclient_t::object mediadataclient_object_t; + tut::mediadataclient_t tut_mediadataclient("LLMediaDataClient"); + void ensure(const std::string &msg, int value, int expected) { std::string m = msg; @@ -249,7 +249,7 @@ namespace tut m += ", expected: " + STR(expected); ensure(m, value == expected); } - + void ensure(const std::string &msg, const std::string & value, const std::string & expected) { std::string m = msg; @@ -257,7 +257,7 @@ namespace tut m += ", expected: " + expected; ensure(m, value == expected); } - + void ensure(const std::string &msg, const LLUUID & value, const LLUUID & expected) { std::string m = msg; @@ -265,13 +265,13 @@ namespace tut m += ", expected: " + expected.asString(); ensure(m, value == expected); } - + void ensure_llsd(const std::string &msg, const LLSD & value, const char *expected) { LLSD expected_llsd; std::istringstream e(expected); LLSDSerialize::fromXML(expected_llsd, e); - + std::string value_str = ll_pretty_print_sd(value); std::string expected_str = ll_pretty_print_sd(expected_llsd); std::string m = msg; @@ -280,694 +280,694 @@ namespace tut ensure(m, value_str == expected_str); } - ////////////////////////////////////////////////////////////////////////////////////////// - - template<> template<> - void mediadataclient_object_t::test<1>() - { - // - // Test fetchMedia() - // - LOG_TEST(1); - - LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest(DATA); - int num_refs_start = o->getNumRefs(); - { - LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); - mdc->fetchMedia(o); - - // Make sure no posts happened yet... - ensure("post records", gPostRecords->size(), 0); - - ::pump_timers(); - - ensure("post records", gPostRecords->size(), 1); - ensure("post url", (*gPostRecords)[0]["url"], FAKE_OBJECT_MEDIA_CAP_URL); - ensure("post GET", (*gPostRecords)[0]["body"]["verb"], "GET"); - ensure("post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID)); - ensure("queue empty", mdc->isEmpty()); - } - - // Make sure everyone's destroyed properly - ensure("REF COUNT", o->getNumRefs(), num_refs_start); + ////////////////////////////////////////////////////////////////////////////////////////// + + template<> template<> + void mediadataclient_object_t::test<1>() + { + // + // Test fetchMedia() + // + LOG_TEST(1); + + LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest(DATA); + int num_refs_start = o->getNumRefs(); + { + LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); + mdc->fetchMedia(o); + + // Make sure no posts happened yet... + ensure("post records", gPostRecords->size(), 0); + + ::pump_timers(); + + ensure("post records", gPostRecords->size(), 1); + ensure("post url", (*gPostRecords)[0]["url"], FAKE_OBJECT_MEDIA_CAP_URL); + ensure("post GET", (*gPostRecords)[0]["body"]["verb"], "GET"); + ensure("post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID)); + ensure("queue empty", mdc->isEmpty()); + } + + // Make sure everyone's destroyed properly + ensure("REF COUNT", o->getNumRefs(), num_refs_start); + } + + ////////////////////////////////////////////////////////////////////////////////////////// + + template<> template<> + void mediadataclient_object_t::test<2>() + { + // + // Test updateMedia() + // + LOG_TEST(2); + + LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest(DATA); + { + // queue time w/ no delay ensures that ::pump_timers() will hit the tick() + LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); + mdc->updateMedia(o); + ensure("post records", gPostRecords->size(), 0); + ::pump_timers(); + + ensure("post records", gPostRecords->size(), 1); + ensure("post url", (*gPostRecords)[0]["url"], FAKE_OBJECT_MEDIA_CAP_URL); + ensure("post UPDATE", (*gPostRecords)[0]["body"]["verb"], "UPDATE"); + ensure("post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID)); + ensure_llsd("post data llsd", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_MEDIA_DATA_KEY], + "<llsd>" MEDIA_DATA "</llsd>"); + ensure("queue empty", mdc->isEmpty()); + } + + ensure("REF COUNT", o->getNumRefs(), 1); } - ////////////////////////////////////////////////////////////////////////////////////////// - - template<> template<> - void mediadataclient_object_t::test<2>() - { - // - // Test updateMedia() - // - LOG_TEST(2); - - LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest(DATA); - { - // queue time w/ no delay ensures that ::pump_timers() will hit the tick() - LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); - mdc->updateMedia(o); - ensure("post records", gPostRecords->size(), 0); - ::pump_timers(); - - ensure("post records", gPostRecords->size(), 1); - ensure("post url", (*gPostRecords)[0]["url"], FAKE_OBJECT_MEDIA_CAP_URL); - ensure("post UPDATE", (*gPostRecords)[0]["body"]["verb"], "UPDATE"); - ensure("post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID)); - ensure_llsd("post data llsd", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_MEDIA_DATA_KEY], - "<llsd>" MEDIA_DATA "</llsd>"); - ensure("queue empty", mdc->isEmpty()); - } - - ensure("REF COUNT", o->getNumRefs(), 1); - } - - ////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////// template<> template<> void mediadataclient_object_t::test<3>() { - // - // Test navigate() - // - LOG_TEST(3); - - LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest(DATA); - { - LLPointer<LLObjectMediaNavigateClient> mdc = new LLObjectMediaNavigateClient(NO_PERIOD,NO_PERIOD); - const char *TEST_URL = "http://example.com"; - mdc->navigate(o, 0, TEST_URL); - ensure("post records", gPostRecords->size(), 0); - ::pump_timers(); - - // ensure no bounce back - ensure("bounce back", dynamic_cast<LLMediaDataClientObjectTest*>(static_cast<LLMediaDataClientObject*>(o))->getNumBounceBacks(), 0); - - ensure("post records", gPostRecords->size(), 1); - ensure("post url", (*gPostRecords)[0]["url"], FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL); - ensure("post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID)); - ensure("post data", (*gPostRecords)[0]["body"][LLTextureEntry::TEXTURE_INDEX_KEY], 0); - ensure("post data", (*gPostRecords)[0]["body"][LLMediaEntry::CURRENT_URL_KEY], TEST_URL); - ensure("queue empty", mdc->isEmpty()); - } - ensure("REF COUNT", o->getNumRefs(), 1); + // + // Test navigate() + // + LOG_TEST(3); + + LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest(DATA); + { + LLPointer<LLObjectMediaNavigateClient> mdc = new LLObjectMediaNavigateClient(NO_PERIOD,NO_PERIOD); + const char *TEST_URL = "http://example.com"; + mdc->navigate(o, 0, TEST_URL); + ensure("post records", gPostRecords->size(), 0); + ::pump_timers(); + + // ensure no bounce back + ensure("bounce back", dynamic_cast<LLMediaDataClientObjectTest*>(static_cast<LLMediaDataClientObject*>(o))->getNumBounceBacks(), 0); + + ensure("post records", gPostRecords->size(), 1); + ensure("post url", (*gPostRecords)[0]["url"], FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL); + ensure("post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID)); + ensure("post data", (*gPostRecords)[0]["body"][LLTextureEntry::TEXTURE_INDEX_KEY], 0); + ensure("post data", (*gPostRecords)[0]["body"][LLMediaEntry::CURRENT_URL_KEY], TEST_URL); + ensure("queue empty", mdc->isEmpty()); + } + ensure("REF COUNT", o->getNumRefs(), 1); } - - ////////////////////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////////////////////// template<> template<> void mediadataclient_object_t::test<4>() { - // - // Test queue ordering - // - LOG_TEST(4); - - LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest( - _DATA(VALID_OBJECT_ID_1,"1.0","true")); - LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest( - _DATA(VALID_OBJECT_ID_2,"3.0","true")); - LLMediaDataClientObject::ptr_t o3 = new LLMediaDataClientObjectTest( - _DATA(VALID_OBJECT_ID_3,"2.0","true")); - { - LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); - const char *ORDERED_OBJECT_IDS[] = { VALID_OBJECT_ID_2, VALID_OBJECT_ID_3, VALID_OBJECT_ID_1 }; - mdc->fetchMedia(o1); - mdc->fetchMedia(o2); - mdc->fetchMedia(o3); - - // Make sure no posts happened yet... - ensure("post records", gPostRecords->size(), 0); - - // tick 3 times... - ::pump_timers(); - ensure("post records", gPostRecords->size(), 1); - ::pump_timers(); - ensure("post records", gPostRecords->size(), 2); - ::pump_timers(); - ensure("post records", gPostRecords->size(), 3); - - for( int i=0; i < 3; i++ ) - { - ensure("[" + STR(i) + "] post url", (*gPostRecords)[i]["url"], FAKE_OBJECT_MEDIA_CAP_URL); - ensure("[" + STR(i) + "] post GET", (*gPostRecords)[i]["body"]["verb"], "GET"); - ensure("[" + STR(i) + "] post object id", (*gPostRecords)[i]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), - LLUUID(ORDERED_OBJECT_IDS[i])); - } - - ensure("queue empty", mdc->isEmpty()); - } - ensure("refcount of o1", o1->getNumRefs(), 1); - ensure("refcount of o2", o2->getNumRefs(), 1); - ensure("refcount of o3", o3->getNumRefs(), 1); + // + // Test queue ordering + // + LOG_TEST(4); + + LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest( + _DATA(VALID_OBJECT_ID_1,"1.0","true")); + LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest( + _DATA(VALID_OBJECT_ID_2,"3.0","true")); + LLMediaDataClientObject::ptr_t o3 = new LLMediaDataClientObjectTest( + _DATA(VALID_OBJECT_ID_3,"2.0","true")); + { + LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); + const char *ORDERED_OBJECT_IDS[] = { VALID_OBJECT_ID_2, VALID_OBJECT_ID_3, VALID_OBJECT_ID_1 }; + mdc->fetchMedia(o1); + mdc->fetchMedia(o2); + mdc->fetchMedia(o3); + + // Make sure no posts happened yet... + ensure("post records", gPostRecords->size(), 0); + + // tick 3 times... + ::pump_timers(); + ensure("post records", gPostRecords->size(), 1); + ::pump_timers(); + ensure("post records", gPostRecords->size(), 2); + ::pump_timers(); + ensure("post records", gPostRecords->size(), 3); + + for( int i=0; i < 3; i++ ) + { + ensure("[" + STR(i) + "] post url", (*gPostRecords)[i]["url"], FAKE_OBJECT_MEDIA_CAP_URL); + ensure("[" + STR(i) + "] post GET", (*gPostRecords)[i]["body"]["verb"], "GET"); + ensure("[" + STR(i) + "] post object id", (*gPostRecords)[i]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), + LLUUID(ORDERED_OBJECT_IDS[i])); + } + + ensure("queue empty", mdc->isEmpty()); + } + ensure("refcount of o1", o1->getNumRefs(), 1); + ensure("refcount of o2", o2->getNumRefs(), 1); + ensure("refcount of o3", o3->getNumRefs(), 1); } - ////////////////////////////////////////////////////////////////////////////////////////// - - template<> template<> - void mediadataclient_object_t::test<5>() - { - // - // Test fetchMedia() getting a 503 error - // - LOG_TEST(5); - - LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest( - _DATA_URLS(VALID_OBJECT_ID, - "1.0","true", - FAKE_OBJECT_MEDIA_CAP_URL_503, - FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL)); - int num_refs_start = o->getNumRefs(); - { - const int NUM_RETRIES = 5; - LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD,NUM_RETRIES); - - // This should generate a retry - mdc->fetchMedia(o); - - // Make sure no posts happened yet... - ensure("post records before", gPostRecords->size(), 0); - - // Once, causes retry - // Second, fires retry timer - // Third, fires queue timer again - for (int i=0; i<NUM_RETRIES; ++i) - { - ::pump_timers(); // Should pump (fire) the queue timer, causing a retry timer to be scheduled - // XXX This ensure is not guaranteed, because scheduling a timer might actually get it pumped in the same loop - //ensure("post records " + STR(i), gPostRecords->size(), i+1); - ::pump_timers(); // Should pump (fire) the retry timer, scheduling the queue timer - } - - // Do some extra pumps to make sure no other timer work occurs. - ::pump_timers(); - ::pump_timers(); - ::pump_timers(); - - // Make sure there were 2 posts - ensure("post records after", gPostRecords->size(), NUM_RETRIES); - for (int i=0; i<NUM_RETRIES; ++i) - { - ensure("[" + STR(i) + "] post url", (*gPostRecords)[i]["url"], FAKE_OBJECT_MEDIA_CAP_URL_503); - ensure("[" + STR(i) + "] post GET", (*gPostRecords)[i]["body"]["verb"], "GET"); - ensure("[" + STR(i) + "] post object id", (*gPostRecords)[i]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID)); - } - ensure("queue empty", mdc->isEmpty()); - } - - // Make sure everyone's destroyed properly - ensure("REF COUNT", o->getNumRefs(), num_refs_start); + ////////////////////////////////////////////////////////////////////////////////////////// + + template<> template<> + void mediadataclient_object_t::test<5>() + { + // + // Test fetchMedia() getting a 503 error + // + LOG_TEST(5); + + LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest( + _DATA_URLS(VALID_OBJECT_ID, + "1.0","true", + FAKE_OBJECT_MEDIA_CAP_URL_503, + FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL)); + int num_refs_start = o->getNumRefs(); + { + const int NUM_RETRIES = 5; + LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD,NUM_RETRIES); + + // This should generate a retry + mdc->fetchMedia(o); + + // Make sure no posts happened yet... + ensure("post records before", gPostRecords->size(), 0); + + // Once, causes retry + // Second, fires retry timer + // Third, fires queue timer again + for (int i=0; i<NUM_RETRIES; ++i) + { + ::pump_timers(); // Should pump (fire) the queue timer, causing a retry timer to be scheduled + // XXX This ensure is not guaranteed, because scheduling a timer might actually get it pumped in the same loop + //ensure("post records " + STR(i), gPostRecords->size(), i+1); + ::pump_timers(); // Should pump (fire) the retry timer, scheduling the queue timer + } + + // Do some extra pumps to make sure no other timer work occurs. + ::pump_timers(); + ::pump_timers(); + ::pump_timers(); + + // Make sure there were 2 posts + ensure("post records after", gPostRecords->size(), NUM_RETRIES); + for (int i=0; i<NUM_RETRIES; ++i) + { + ensure("[" + STR(i) + "] post url", (*gPostRecords)[i]["url"], FAKE_OBJECT_MEDIA_CAP_URL_503); + ensure("[" + STR(i) + "] post GET", (*gPostRecords)[i]["body"]["verb"], "GET"); + ensure("[" + STR(i) + "] post object id", (*gPostRecords)[i]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID)); + } + ensure("queue empty", mdc->isEmpty()); + } + + // Make sure everyone's destroyed properly + ensure("REF COUNT", o->getNumRefs(), num_refs_start); } template<> template<> void mediadataclient_object_t::test<6>() { - // - // Test navigate() with a bounce back - // - LOG_TEST(6); - - LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest( - _DATA_URLS(VALID_OBJECT_ID, - "1.0","true", - FAKE_OBJECT_MEDIA_CAP_URL, - FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL_ERROR)); - { - LLPointer<LLObjectMediaNavigateClient> mdc = new LLObjectMediaNavigateClient(NO_PERIOD,NO_PERIOD); - const char *TEST_URL = "http://example.com"; - mdc->navigate(o, 0, TEST_URL); - ensure("post records", gPostRecords->size(), 0); - ::pump_timers(); - - // ensure bounce back - ensure("bounce back", - dynamic_cast<LLMediaDataClientObjectTest*>(static_cast<LLMediaDataClientObject*>(o))->getNumBounceBacks(), - 1); - - ensure("post records", gPostRecords->size(), 1); - ensure("post url", (*gPostRecords)[0]["url"], FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL_ERROR); - ensure("post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID)); - ensure("post data", (*gPostRecords)[0]["body"][LLTextureEntry::TEXTURE_INDEX_KEY], 0); - ensure("post data", (*gPostRecords)[0]["body"][LLMediaEntry::CURRENT_URL_KEY], TEST_URL); - ensure("queue empty", mdc->isEmpty()); - } - ensure("REF COUNT", o->getNumRefs(), 1); + // + // Test navigate() with a bounce back + // + LOG_TEST(6); + + LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest( + _DATA_URLS(VALID_OBJECT_ID, + "1.0","true", + FAKE_OBJECT_MEDIA_CAP_URL, + FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL_ERROR)); + { + LLPointer<LLObjectMediaNavigateClient> mdc = new LLObjectMediaNavigateClient(NO_PERIOD,NO_PERIOD); + const char *TEST_URL = "http://example.com"; + mdc->navigate(o, 0, TEST_URL); + ensure("post records", gPostRecords->size(), 0); + ::pump_timers(); + + // ensure bounce back + ensure("bounce back", + dynamic_cast<LLMediaDataClientObjectTest*>(static_cast<LLMediaDataClientObject*>(o))->getNumBounceBacks(), + 1); + + ensure("post records", gPostRecords->size(), 1); + ensure("post url", (*gPostRecords)[0]["url"], FAKE_OBJECT_MEDIA_NAVIGATE_CAP_URL_ERROR); + ensure("post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID)); + ensure("post data", (*gPostRecords)[0]["body"][LLTextureEntry::TEXTURE_INDEX_KEY], 0); + ensure("post data", (*gPostRecords)[0]["body"][LLMediaEntry::CURRENT_URL_KEY], TEST_URL); + ensure("queue empty", mdc->isEmpty()); + } + ensure("REF COUNT", o->getNumRefs(), 1); } - template<> template<> + template<> template<> void mediadataclient_object_t::test<7>() { - // Test LLMediaDataClient::isInQueue() - LOG_TEST(7); - - LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest( - _DATA(VALID_OBJECT_ID_1,"3.0","true")); - LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest( - _DATA(VALID_OBJECT_ID_2,"1.0","true")); - int num_refs_start = o1->getNumRefs(); - { - LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); - - ensure("not in queue yet 1", ! mdc->isInQueue(o1)); - ensure("not in queue yet 2", ! mdc->isInQueue(o2)); - - mdc->fetchMedia(o1); - - ensure("is in queue", mdc->isInQueue(o1)); - ensure("is not in queue", ! mdc->isInQueue(o2)); - - ::pump_timers(); - - ensure("not in queue anymore", ! mdc->isInQueue(o1)); - ensure("still is not in queue", ! mdc->isInQueue(o2)); - - ensure("queue empty", mdc->isEmpty()); - } - - // Make sure everyone's destroyed properly - ensure("REF COUNT", o1->getNumRefs(), num_refs_start); - - } - - template<> template<> + // Test LLMediaDataClient::isInQueue() + LOG_TEST(7); + + LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest( + _DATA(VALID_OBJECT_ID_1,"3.0","true")); + LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest( + _DATA(VALID_OBJECT_ID_2,"1.0","true")); + int num_refs_start = o1->getNumRefs(); + { + LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); + + ensure("not in queue yet 1", ! mdc->isInQueue(o1)); + ensure("not in queue yet 2", ! mdc->isInQueue(o2)); + + mdc->fetchMedia(o1); + + ensure("is in queue", mdc->isInQueue(o1)); + ensure("is not in queue", ! mdc->isInQueue(o2)); + + ::pump_timers(); + + ensure("not in queue anymore", ! mdc->isInQueue(o1)); + ensure("still is not in queue", ! mdc->isInQueue(o2)); + + ensure("queue empty", mdc->isEmpty()); + } + + // Make sure everyone's destroyed properly + ensure("REF COUNT", o1->getNumRefs(), num_refs_start); + + } + + template<> template<> void mediadataclient_object_t::test<8>() { - // Test queue handling of objects that are marked dead. - LOG_TEST(8); - - LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_1,"4.0","true")); - LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_2,"3.0","true")); - LLMediaDataClientObject::ptr_t o3 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_3,"2.0","true")); - LLMediaDataClientObject::ptr_t o4 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_4,"1.0","true")); - { - LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); - - // queue up all 4 objects - mdc->fetchMedia(o1); - mdc->fetchMedia(o2); - mdc->fetchMedia(o3); - mdc->fetchMedia(o4); - - ensure("is in queue 1", mdc->isInQueue(o1)); - ensure("is in queue 2", mdc->isInQueue(o2)); - ensure("is in queue 3", mdc->isInQueue(o3)); - ensure("is in queue 4", mdc->isInQueue(o4)); - ensure("post records", gPostRecords->size(), 0); - - // and mark the second and fourth ones dead. Call removeFromQueue when marking dead, since this is what LLVOVolume will do. - dynamic_cast<LLMediaDataClientObjectTest*>(static_cast<LLMediaDataClientObject*>(o2))->markDead(); - mdc->removeFromQueue(o2); - dynamic_cast<LLMediaDataClientObjectTest*>(static_cast<LLMediaDataClientObject*>(o4))->markDead(); - mdc->removeFromQueue(o4); - - // The removeFromQueue calls should remove the second and fourth ones - ensure("is in queue 1", mdc->isInQueue(o1)); - ensure("is not in queue 2", !mdc->isInQueue(o2)); - ensure("is in queue 3", mdc->isInQueue(o3)); - ensure("is not in queue 4", !mdc->isInQueue(o4)); - ensure("post records", gPostRecords->size(), 0); - - ::pump_timers(); - - // The first tick should process the first item - ensure("is not in queue 1", !mdc->isInQueue(o1)); - ensure("is not in queue 2", !mdc->isInQueue(o2)); - ensure("is in queue 3", mdc->isInQueue(o3)); - ensure("is not in queue 4", !mdc->isInQueue(o4)); - ensure("post records", gPostRecords->size(), 1); - - ::pump_timers(); - - // The second tick should process the third, emptying the queue - ensure("is not in queue 3", !mdc->isInQueue(o3)); - ensure("post records", gPostRecords->size(), 2); - - ensure("queue empty", mdc->isEmpty()); - } - ensure("refcount of o1", o1->getNumRefs(), 1); - ensure("refcount of o2", o2->getNumRefs(), 1); - ensure("refcount of o3", o3->getNumRefs(), 1); - ensure("refcount of o4", o4->getNumRefs(), 1); - - } - - ////////////////////////////////////////////////////////////////////////////////////////// + // Test queue handling of objects that are marked dead. + LOG_TEST(8); + + LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_1,"4.0","true")); + LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_2,"3.0","true")); + LLMediaDataClientObject::ptr_t o3 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_3,"2.0","true")); + LLMediaDataClientObject::ptr_t o4 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_4,"1.0","true")); + { + LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); + + // queue up all 4 objects + mdc->fetchMedia(o1); + mdc->fetchMedia(o2); + mdc->fetchMedia(o3); + mdc->fetchMedia(o4); + + ensure("is in queue 1", mdc->isInQueue(o1)); + ensure("is in queue 2", mdc->isInQueue(o2)); + ensure("is in queue 3", mdc->isInQueue(o3)); + ensure("is in queue 4", mdc->isInQueue(o4)); + ensure("post records", gPostRecords->size(), 0); + + // and mark the second and fourth ones dead. Call removeFromQueue when marking dead, since this is what LLVOVolume will do. + dynamic_cast<LLMediaDataClientObjectTest*>(static_cast<LLMediaDataClientObject*>(o2))->markDead(); + mdc->removeFromQueue(o2); + dynamic_cast<LLMediaDataClientObjectTest*>(static_cast<LLMediaDataClientObject*>(o4))->markDead(); + mdc->removeFromQueue(o4); + + // The removeFromQueue calls should remove the second and fourth ones + ensure("is in queue 1", mdc->isInQueue(o1)); + ensure("is not in queue 2", !mdc->isInQueue(o2)); + ensure("is in queue 3", mdc->isInQueue(o3)); + ensure("is not in queue 4", !mdc->isInQueue(o4)); + ensure("post records", gPostRecords->size(), 0); + + ::pump_timers(); + + // The first tick should process the first item + ensure("is not in queue 1", !mdc->isInQueue(o1)); + ensure("is not in queue 2", !mdc->isInQueue(o2)); + ensure("is in queue 3", mdc->isInQueue(o3)); + ensure("is not in queue 4", !mdc->isInQueue(o4)); + ensure("post records", gPostRecords->size(), 1); + + ::pump_timers(); + + // The second tick should process the third, emptying the queue + ensure("is not in queue 3", !mdc->isInQueue(o3)); + ensure("post records", gPostRecords->size(), 2); + + ensure("queue empty", mdc->isEmpty()); + } + ensure("refcount of o1", o1->getNumRefs(), 1); + ensure("refcount of o2", o2->getNumRefs(), 1); + ensure("refcount of o3", o3->getNumRefs(), 1); + ensure("refcount of o4", o4->getNumRefs(), 1); + + } + + ////////////////////////////////////////////////////////////////////////////////////////// template<> template<> void mediadataclient_object_t::test<9>() { - // - // Test queue re-ordering - // - LOG_TEST(9); - - LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_1,"40.0","true")); - LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_2,"30.0","true")); - LLMediaDataClientObject::ptr_t o3 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_3,"20.0","true")); - LLMediaDataClientObjectTest *object4 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_4,"10.0","true")); - LLMediaDataClientObject::ptr_t o4 = object4; - { - LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); - - // queue up all 4 objects. They should now be in the queue in - // order 1 through 4, with 4 being at the front of the queue - mdc->fetchMedia(o1); - mdc->fetchMedia(o2); - mdc->fetchMedia(o3); - mdc->fetchMedia(o4); - - int tick_num = 0; - - ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 0); - - ::pump_timers(); - ++tick_num; - - // The first tick should remove the first one - ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 1); - - // Now, pretend that object 4 moved relative to the avatar such - // that it is now closest - object4->setMediaInterest(50.0); - - ::pump_timers(); - ++tick_num; - - // The second tick should still pick off item 2, but then re-sort - // have picked off object 4 - ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 2); - - ::pump_timers(); - ++tick_num; - - // The third tick should pick off object 2 - ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 3); - - // The fourth tick should pick off object 3 - ::pump_timers(); - ++tick_num; - - ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 4); - - ensure("queue empty", mdc->isEmpty()); - } - ensure("refcount of o1", o1->getNumRefs(), 1); - ensure("refcount of o2", o2->getNumRefs(), 1); - ensure("refcount of o3", o3->getNumRefs(), 1); - ensure("refcount of o4", o4->getNumRefs(), 1); + // + // Test queue re-ordering + // + LOG_TEST(9); + + LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_1,"40.0","true")); + LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_2,"30.0","true")); + LLMediaDataClientObject::ptr_t o3 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_3,"20.0","true")); + LLMediaDataClientObjectTest *object4 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_4,"10.0","true")); + LLMediaDataClientObject::ptr_t o4 = object4; + { + LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); + + // queue up all 4 objects. They should now be in the queue in + // order 1 through 4, with 4 being at the front of the queue + mdc->fetchMedia(o1); + mdc->fetchMedia(o2); + mdc->fetchMedia(o3); + mdc->fetchMedia(o4); + + int tick_num = 0; + + ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 0); + + ::pump_timers(); + ++tick_num; + + // The first tick should remove the first one + ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 1); + + // Now, pretend that object 4 moved relative to the avatar such + // that it is now closest + object4->setMediaInterest(50.0); + + ::pump_timers(); + ++tick_num; + + // The second tick should still pick off item 2, but then re-sort + // have picked off object 4 + ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 2); + + ::pump_timers(); + ++tick_num; + + // The third tick should pick off object 2 + ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 3); + + // The fourth tick should pick off object 3 + ::pump_timers(); + ++tick_num; + + ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 4); + + ensure("queue empty", mdc->isEmpty()); + } + ensure("refcount of o1", o1->getNumRefs(), 1); + ensure("refcount of o2", o2->getNumRefs(), 1); + ensure("refcount of o3", o3->getNumRefs(), 1); + ensure("refcount of o4", o4->getNumRefs(), 1); } - - - template<> template<> + + + template<> template<> void mediadataclient_object_t::test<10>() { - // - // Test using the "round-robin" queue - // - LOG_TEST(10); - - LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_1,"1.0","true")); - LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_2,"2.0","true")); - LLMediaDataClientObject::ptr_t o3 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_3,"3.0","false")); - LLMediaDataClientObject::ptr_t o4 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_4,"4.0","false")); - { - LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); - - // queue up all 4 objects. The first two should be in the sorted - // queue [2 1], the second in the round-robin queue. The queues - // are serviced interleaved, so we should expect: - // 2, 3, 1, 4 - mdc->fetchMedia(o1); - mdc->fetchMedia(o2); - mdc->fetchMedia(o3); - mdc->fetchMedia(o4); - - int tick_num = 0; - - // 0 - ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 0); - - ::pump_timers(); - ++tick_num; - - // 1 The first tick should remove object 2 - ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 1); - ensure(STR(tick_num) + ". post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_2)); - - ::pump_timers(); - ++tick_num; - - // 2 The second tick should send object 3 - ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 2); - ensure(STR(tick_num) + ". post object id", (*gPostRecords)[1]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_3)); - - ::pump_timers(); - ++tick_num; - - // 3 The third tick should remove object 1 - ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 3); - ensure(STR(tick_num) + ". post object id", (*gPostRecords)[2]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_1)); - - ::pump_timers(); - ++tick_num; - - // 4 The fourth tick should send object 4 - ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 4); - ensure(STR(tick_num) + ". post object id", (*gPostRecords)[3]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_4)); - - ::pump_timers(); - ++tick_num; - - // 5 The fifth tick should not change the state of anything. - ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 4); - - ::pump_timers(); - - // Whew....better be empty - ensure("queue empty", mdc->isEmpty()); - } - ensure("refcount of o1", o1->getNumRefs(), 1); - ensure("refcount of o2", o2->getNumRefs(), 1); - ensure("refcount of o3", o3->getNumRefs(), 1); - ensure("refcount of o4", o4->getNumRefs(), 1); - } - - - template<> template<> - void mediadataclient_object_t::test<11>() - { - // - // Test LLMediaDataClient's destructor - // - LOG_TEST(11); - - LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest(DATA); - int num_refs_start = o->getNumRefs(); - { - LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); - mdc->fetchMedia(o); - // must tick enough times to clear refcount of mdc - ::pump_timers(); - } - // Make sure everyone's destroyed properly - ensure("REF COUNT", o->getNumRefs(), num_refs_start); - } - - template<> template<> + // + // Test using the "round-robin" queue + // + LOG_TEST(10); + + LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_1,"1.0","true")); + LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_2,"2.0","true")); + LLMediaDataClientObject::ptr_t o3 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_3,"3.0","false")); + LLMediaDataClientObject::ptr_t o4 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_4,"4.0","false")); + { + LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); + + // queue up all 4 objects. The first two should be in the sorted + // queue [2 1], the second in the round-robin queue. The queues + // are serviced interleaved, so we should expect: + // 2, 3, 1, 4 + mdc->fetchMedia(o1); + mdc->fetchMedia(o2); + mdc->fetchMedia(o3); + mdc->fetchMedia(o4); + + int tick_num = 0; + + // 0 + ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 0); + + ::pump_timers(); + ++tick_num; + + // 1 The first tick should remove object 2 + ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 1); + ensure(STR(tick_num) + ". post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_2)); + + ::pump_timers(); + ++tick_num; + + // 2 The second tick should send object 3 + ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 2); + ensure(STR(tick_num) + ". post object id", (*gPostRecords)[1]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_3)); + + ::pump_timers(); + ++tick_num; + + // 3 The third tick should remove object 1 + ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 3); + ensure(STR(tick_num) + ". post object id", (*gPostRecords)[2]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_1)); + + ::pump_timers(); + ++tick_num; + + // 4 The fourth tick should send object 4 + ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 4); + ensure(STR(tick_num) + ". post object id", (*gPostRecords)[3]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_4)); + + ::pump_timers(); + ++tick_num; + + // 5 The fifth tick should not change the state of anything. + ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is not in queue 2", !mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 4); + + ::pump_timers(); + + // Whew....better be empty + ensure("queue empty", mdc->isEmpty()); + } + ensure("refcount of o1", o1->getNumRefs(), 1); + ensure("refcount of o2", o2->getNumRefs(), 1); + ensure("refcount of o3", o3->getNumRefs(), 1); + ensure("refcount of o4", o4->getNumRefs(), 1); + } + + + template<> template<> + void mediadataclient_object_t::test<11>() + { + // + // Test LLMediaDataClient's destructor + // + LOG_TEST(11); + + LLMediaDataClientObject::ptr_t o = new LLMediaDataClientObjectTest(DATA); + int num_refs_start = o->getNumRefs(); + { + LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); + mdc->fetchMedia(o); + // must tick enough times to clear refcount of mdc + ::pump_timers(); + } + // Make sure everyone's destroyed properly + ensure("REF COUNT", o->getNumRefs(), num_refs_start); + } + + template<> template<> void mediadataclient_object_t::test<12>() { - // - // Test the "not interesting enough" call - // - LOG_TEST(12); - - LLMediaDataClientObjectTest *object1 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_1,"1.0","true")); - LLMediaDataClientObject::ptr_t o1 = object1; - LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_2,"2.0","true")); - LLMediaDataClientObject::ptr_t o3 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_3,"3.0","true")); - LLMediaDataClientObject::ptr_t o4 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_4,"4.0","true")); - { - LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); - - // queue up all 4 objects. The first two are "interesting enough". - // Firing the timer 4 times should therefore leave them. - // Note that they should be sorted 4,3,2,1 - // Then, we'll make one "interesting enough", fire the timer a few - // times, and make sure only it gets pulled off the queue - gMinimumInterestLevel = 2.5; - mdc->fetchMedia(o1); - mdc->fetchMedia(o2); - mdc->fetchMedia(o3); - mdc->fetchMedia(o4); - - int tick_num = 0; - - // 0 - ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 0); - - ::pump_timers(); - ++tick_num; - - // 1 The first tick should remove object 4 - ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 1); - ensure(STR(tick_num) + ". post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_4)); - - ::pump_timers(); - ++tick_num; - - // 2 The second tick should send object 3 - ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 2); - ensure(STR(tick_num) + ". post object id", (*gPostRecords)[1]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_3)); - - ::pump_timers(); - ++tick_num; - - // 3 The third tick should not pull off anything - ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 2); - - ::pump_timers(); - ++tick_num; - - // 4 The fourth tick (for good measure) should not pull off anything - ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 2); - - // Okay, now futz with object 1's interest, such that it is now - // "interesting enough" - object1->setMediaInterest((F64)5.0); - - // This should sort so that the queue is now [1 2] - ::pump_timers(); - ++tick_num; - - // 5 The fifth tick should now identify objects 3 and 4 as no longer - // needing "updating", and remove them from the queue - ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 3); - ensure(STR(tick_num) + ". post object id", (*gPostRecords)[2]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_1)); - - ::pump_timers(); - ++tick_num; - - // 6 The sixth tick should not pull off anything - ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); - ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); - ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); - ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); - ensure(STR(tick_num) + ". post records", gPostRecords->size(), 3); - - ::pump_timers(); - ++tick_num; - - // Whew....better NOT be empty ... o2 should still be there - ensure("queue not empty", !mdc->isEmpty()); - - // But, we need to clear the queue, or else we won't destroy MDC... - // this is a strange interplay between the queue timer and the MDC - mdc->removeFromQueue(o2); - // tick - ::pump_timers(); - } - ensure("refcount of o1", o1->getNumRefs(), 1); - ensure("refcount of o2", o2->getNumRefs(), 1); - ensure("refcount of o3", o3->getNumRefs(), 1); - ensure("refcount of o4", o4->getNumRefs(), 1); - } - - template<> template<> - void mediadataclient_object_t::test<13>() - { - // - // Test supression of redundant navigates. - // - LOG_TEST(13); - - LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_1,"1.0","true")); - { - LLPointer<LLObjectMediaNavigateClient> mdc = new LLObjectMediaNavigateClient(NO_PERIOD,NO_PERIOD); - const char *TEST_URL = "http://foo.example.com"; - const char *TEST_URL_2 = "http://example.com"; - mdc->navigate(o1, 0, TEST_URL); - mdc->navigate(o1, 1, TEST_URL); - mdc->navigate(o1, 0, TEST_URL_2); - mdc->navigate(o1, 1, TEST_URL_2); - - // This should add two requests to the queue, one for face 0 of the object and one for face 1. - - ensure("before pump: 1 is in queue", mdc->isInQueue(o1)); - - ::pump_timers(); - - ensure("after first pump: 1 is in queue", mdc->isInQueue(o1)); - - ::pump_timers(); - - ensure("after second pump: 1 is not in queue", !mdc->isInQueue(o1)); - - ensure("first post has correct url", (*gPostRecords)[0]["body"][LLMediaEntry::CURRENT_URL_KEY].asString(), std::string(TEST_URL_2)); - ensure("second post has correct url", (*gPostRecords)[1]["body"][LLMediaEntry::CURRENT_URL_KEY].asString(), std::string(TEST_URL_2)); - - } - } - + // + // Test the "not interesting enough" call + // + LOG_TEST(12); + + LLMediaDataClientObjectTest *object1 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_1,"1.0","true")); + LLMediaDataClientObject::ptr_t o1 = object1; + LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_2,"2.0","true")); + LLMediaDataClientObject::ptr_t o3 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_3,"3.0","true")); + LLMediaDataClientObject::ptr_t o4 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_4,"4.0","true")); + { + LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); + + // queue up all 4 objects. The first two are "interesting enough". + // Firing the timer 4 times should therefore leave them. + // Note that they should be sorted 4,3,2,1 + // Then, we'll make one "interesting enough", fire the timer a few + // times, and make sure only it gets pulled off the queue + gMinimumInterestLevel = 2.5; + mdc->fetchMedia(o1); + mdc->fetchMedia(o2); + mdc->fetchMedia(o3); + mdc->fetchMedia(o4); + + int tick_num = 0; + + // 0 + ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is in queue 4", mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 0); + + ::pump_timers(); + ++tick_num; + + // 1 The first tick should remove object 4 + ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 1); + ensure(STR(tick_num) + ". post object id", (*gPostRecords)[0]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_4)); + + ::pump_timers(); + ++tick_num; + + // 2 The second tick should send object 3 + ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 2); + ensure(STR(tick_num) + ". post object id", (*gPostRecords)[1]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_3)); + + ::pump_timers(); + ++tick_num; + + // 3 The third tick should not pull off anything + ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 2); + + ::pump_timers(); + ++tick_num; + + // 4 The fourth tick (for good measure) should not pull off anything + ensure(STR(tick_num) + ". is in queue 1", mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 2); + + // Okay, now futz with object 1's interest, such that it is now + // "interesting enough" + object1->setMediaInterest((F64)5.0); + + // This should sort so that the queue is now [1 2] + ::pump_timers(); + ++tick_num; + + // 5 The fifth tick should now identify objects 3 and 4 as no longer + // needing "updating", and remove them from the queue + ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 3); + ensure(STR(tick_num) + ". post object id", (*gPostRecords)[2]["body"][LLTextureEntry::OBJECT_ID_KEY].asUUID(), LLUUID(VALID_OBJECT_ID_1)); + + ::pump_timers(); + ++tick_num; + + // 6 The sixth tick should not pull off anything + ensure(STR(tick_num) + ". is not in queue 1", !mdc->isInQueue(o1)); + ensure(STR(tick_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(tick_num) + ". is not in queue 3", !mdc->isInQueue(o3)); + ensure(STR(tick_num) + ". is not in queue 4", !mdc->isInQueue(o4)); + ensure(STR(tick_num) + ". post records", gPostRecords->size(), 3); + + ::pump_timers(); + ++tick_num; + + // Whew....better NOT be empty ... o2 should still be there + ensure("queue not empty", !mdc->isEmpty()); + + // But, we need to clear the queue, or else we won't destroy MDC... + // this is a strange interplay between the queue timer and the MDC + mdc->removeFromQueue(o2); + // tick + ::pump_timers(); + } + ensure("refcount of o1", o1->getNumRefs(), 1); + ensure("refcount of o2", o2->getNumRefs(), 1); + ensure("refcount of o3", o3->getNumRefs(), 1); + ensure("refcount of o4", o4->getNumRefs(), 1); + } + + template<> template<> + void mediadataclient_object_t::test<13>() + { + // + // Test supression of redundant navigates. + // + LOG_TEST(13); + + LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_1,"1.0","true")); + { + LLPointer<LLObjectMediaNavigateClient> mdc = new LLObjectMediaNavigateClient(NO_PERIOD,NO_PERIOD); + const char *TEST_URL = "http://foo.example.com"; + const char *TEST_URL_2 = "http://example.com"; + mdc->navigate(o1, 0, TEST_URL); + mdc->navigate(o1, 1, TEST_URL); + mdc->navigate(o1, 0, TEST_URL_2); + mdc->navigate(o1, 1, TEST_URL_2); + + // This should add two requests to the queue, one for face 0 of the object and one for face 1. + + ensure("before pump: 1 is in queue", mdc->isInQueue(o1)); + + ::pump_timers(); + + ensure("after first pump: 1 is in queue", mdc->isInQueue(o1)); + + ::pump_timers(); + + ensure("after second pump: 1 is not in queue", !mdc->isInQueue(o1)); + + ensure("first post has correct url", (*gPostRecords)[0]["body"][LLMediaEntry::CURRENT_URL_KEY].asString(), std::string(TEST_URL_2)); + ensure("second post has correct url", (*gPostRecords)[1]["body"][LLMediaEntry::CURRENT_URL_KEY].asString(), std::string(TEST_URL_2)); + + } + } + } diff --git a/indra/newview/tests/llpipeline_stub.cpp b/indra/newview/tests/llpipeline_stub.cpp index ad112cbf6a..62b71e51e5 100644 --- a/indra/newview/tests/llpipeline_stub.cpp +++ b/indra/newview/tests/llpipeline_stub.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llpipeline_stub.cpp * @brief stub class to allow unit testing * * $LicenseInfo:firstyear=2009&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$ */ diff --git a/indra/newview/tests/llremoteparcelrequest_test.cpp b/indra/newview/tests/llremoteparcelrequest_test.cpp index 4f7f87b6b0..c8fa2fbd6f 100644 --- a/indra/newview/tests/llremoteparcelrequest_test.cpp +++ b/indra/newview/tests/llremoteparcelrequest_test.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llremoteparcelrequest_test.cpp * @author Brad Kittenbrink <brad@lindenlab.com> * * $LicenseInfo:firstyear=2010&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$ */ @@ -37,7 +37,7 @@ #include "llpounceable.h" namespace { - const LLUUID TEST_PARCEL_ID("11111111-1111-1111-1111-111111111111"); + const LLUUID TEST_PARCEL_ID("11111111-1111-1111-1111-111111111111"); } LLCurl::Responder::Responder() { } @@ -49,14 +49,14 @@ void LLCurl::Responder::failureResult(S32 status, const std::string& reason, con void LLCurl::Responder::successResult(const LLSD& content) { } void LLCurl::Responder::completeResult(S32 status, const std::string& reason, const LLSD& content) { } std::string LLCurl::Responder::dumpResponse() const { return "(failure)"; } -void LLCurl::Responder::completedRaw(LLChannelDescriptors const &,boost::shared_ptr<LLBufferArray> const &) { } +void LLCurl::Responder::completedRaw(LLChannelDescriptors const &,std::shared_ptr<LLBufferArray> const &) { } void LLMessageSystem::getF32(char const *,char const *,F32 &,S32) { } void LLMessageSystem::getU8(char const *,char const *,U8 &,S32) { } void LLMessageSystem::getS32(char const *,char const *,S32 &,S32) { } void LLMessageSystem::getString(char const *,char const *, std::string &,S32) { } void LLMessageSystem::getUUID(char const *,char const *, LLUUID & out_id,S32) { - out_id = TEST_PARCEL_ID; + out_id = TEST_PARCEL_ID; } void LLMessageSystem::nextBlock(char const *) { } void LLMessageSystem::addUUID(char const *,LLUUID const &) { } @@ -79,61 +79,61 @@ void LLUrlEntryParcel::processParcelInfo(const LLUrlEntryParcel::LLParcelData& p namespace tut { - struct TestObserver : public LLRemoteParcelInfoObserver { - TestObserver() : mProcessed(false) { } + struct TestObserver : public LLRemoteParcelInfoObserver { + TestObserver() : mProcessed(false) { } - virtual void processParcelInfo(const LLParcelData& parcel_data) - { - mProcessed = true; - } + virtual void processParcelInfo(const LLParcelData& parcel_data) + { + mProcessed = true; + } - virtual void setParcelID(const LLUUID& parcel_id) { } + virtual void setParcelID(const LLUUID& parcel_id) { } - virtual void setErrorStatus(S32 status, const std::string& reason) { } + virtual void setErrorStatus(S32 status, const std::string& reason) { } - bool mProcessed; - }; + bool mProcessed; + }; struct RemoteParcelRequestData { - RemoteParcelRequestData() - { - } + RemoteParcelRequestData() + { + } }; - - typedef test_group<RemoteParcelRequestData> remoteparcelrequest_t; - typedef remoteparcelrequest_t::object remoteparcelrequest_object_t; - tut::remoteparcelrequest_t tut_remoteparcelrequest("LLRemoteParcelRequest"); - template<> template<> - void remoteparcelrequest_object_t::test<1>() - { - set_test_name("observer pointer"); + typedef test_group<RemoteParcelRequestData> remoteparcelrequest_t; + typedef remoteparcelrequest_t::object remoteparcelrequest_object_t; + tut::remoteparcelrequest_t tut_remoteparcelrequest("LLRemoteParcelRequest"); + + template<> template<> + void remoteparcelrequest_object_t::test<1>() + { + set_test_name("observer pointer"); - boost::scoped_ptr<TestObserver> observer(new TestObserver()); + std::unique_ptr<TestObserver> observer(new TestObserver()); - LLRemoteParcelInfoProcessor & processor = LLRemoteParcelInfoProcessor::instance(); - processor.addObserver(LLUUID(TEST_PARCEL_ID), observer.get()); + LLRemoteParcelInfoProcessor & processor = LLRemoteParcelInfoProcessor::instance(); + processor.addObserver(LLUUID(TEST_PARCEL_ID), observer.get()); - processor.processParcelInfoReply(gMessageSystem, NULL); + processor.processParcelInfoReply(gMessageSystem, NULL); - ensure(observer->mProcessed); - } + ensure(observer->mProcessed); + } - template<> template<> - void remoteparcelrequest_object_t::test<2>() - { - set_test_name("CHOP-220: dangling observer pointer"); + template<> template<> + void remoteparcelrequest_object_t::test<2>() + { + set_test_name("CHOP-220: dangling observer pointer"); - LLRemoteParcelInfoObserver * observer = new TestObserver(); + LLRemoteParcelInfoObserver * observer = new TestObserver(); - LLRemoteParcelInfoProcessor & processor = LLRemoteParcelInfoProcessor::instance(); - processor.addObserver(LLUUID(TEST_PARCEL_ID), observer); + LLRemoteParcelInfoProcessor & processor = LLRemoteParcelInfoProcessor::instance(); + processor.addObserver(LLUUID(TEST_PARCEL_ID), observer); - delete observer; - observer = NULL; + delete observer; + observer = NULL; - processor.processParcelInfoReply(gMessageSystem, NULL); - } + processor.processParcelInfoReply(gMessageSystem, NULL); + } } #endif diff --git a/indra/newview/tests/llsecapi_test.cpp b/indra/newview/tests/llsecapi_test.cpp index 7d2a9a436f..ef3da40397 100644 --- a/indra/newview/tests/llsecapi_test.cpp +++ b/indra/newview/tests/llsecapi_test.cpp @@ -1,4 +1,4 @@ -/** +/** * @file llsecapi_test.cpp * @author Roxie * @date 2009-02-10 @@ -7,21 +7,21 @@ * $LicenseInfo:firstyear=2009&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$ */ @@ -33,8 +33,8 @@ #include "../../llxml/llcontrol.h" -//---------------------------------------------------------------------------- -// Mock objects for the dependencies of the code we're testing +//---------------------------------------------------------------------------- +// Mock objects for the dependencies of the code we're testing LLControlGroup::LLControlGroup(const std::string& name) : LLInstanceTracker<LLControlGroup, std::string>(name) {} @@ -46,7 +46,7 @@ LLControlVariable* LLControlGroup::declareString(const std::string& name, void LLControlGroup::setString(const std::string& name, const std::string& val){} std::string LLControlGroup::getString(const std::string& name) { - return ""; + return ""; } @@ -83,51 +83,51 @@ void LLSecAPIBasicHandler::removeCredentialMap(const std::string& storage, const // ------------------------------------------------------------------------------------------- namespace tut { - // Test wrapper declaration : wrapping nothing for the moment - struct secapiTest - { - - secapiTest() - { - } - ~secapiTest() - { - } - }; - - // Tut templating thingamagic: test group, object and test instance - typedef test_group<secapiTest> secapiTestFactory; - typedef secapiTestFactory::object secapiTestObject; - tut::secapiTestFactory tut_test("LLSecAPI"); - - // --------------------------------------------------------------------------------------- - // Test functions - // --------------------------------------------------------------------------------------- - // registration - template<> template<> - void secapiTestObject::test<1>() - { - // retrieve an unknown handler + // Test wrapper declaration : wrapping nothing for the moment + struct secapiTest + { + + secapiTest() + { + } + ~secapiTest() + { + } + }; + + // Tut templating thingamagic: test group, object and test instance + typedef test_group<secapiTest> secapiTestFactory; + typedef secapiTestFactory::object secapiTestObject; + tut::secapiTestFactory tut_test("LLSecAPI"); + + // --------------------------------------------------------------------------------------- + // Test functions + // --------------------------------------------------------------------------------------- + // registration + template<> template<> + void secapiTestObject::test<1>() + { + // retrieve an unknown handler + + ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown")); + LLPointer<LLSecAPIHandler> test1_handler = new LLSecAPIBasicHandler(); + registerSecHandler("sectest1", test1_handler); + ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown")); + LLPointer<LLSecAPIHandler> retrieved_test1_handler = getSecHandler("sectest1"); + ensure("Retrieved sectest1 handler should be the same", + retrieved_test1_handler == test1_handler); + + // insert a second handler + LLPointer<LLSecAPIHandler> test2_handler = new LLSecAPIBasicHandler(); + registerSecHandler("sectest2", test2_handler); + ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown")); + retrieved_test1_handler = getSecHandler("sectest1"); + ensure("Retrieved sectest1 handler should be the same", + retrieved_test1_handler == test1_handler); - ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown")); - LLPointer<LLSecAPIHandler> test1_handler = new LLSecAPIBasicHandler(); - registerSecHandler("sectest1", test1_handler); - ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown")); - LLPointer<LLSecAPIHandler> retrieved_test1_handler = getSecHandler("sectest1"); - ensure("Retrieved sectest1 handler should be the same", - retrieved_test1_handler == test1_handler); - - // insert a second handler - LLPointer<LLSecAPIHandler> test2_handler = new LLSecAPIBasicHandler(); - registerSecHandler("sectest2", test2_handler); - ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown")); - retrieved_test1_handler = getSecHandler("sectest1"); - ensure("Retrieved sectest1 handler should be the same", - retrieved_test1_handler == test1_handler); + LLPointer<LLSecAPIHandler> retrieved_test2_handler = getSecHandler("sectest2"); + ensure("Retrieved sectest1 handler should be the same", + retrieved_test2_handler == test2_handler); - LLPointer<LLSecAPIHandler> retrieved_test2_handler = getSecHandler("sectest2"); - ensure("Retrieved sectest1 handler should be the same", - retrieved_test2_handler == test2_handler); - - } + } } diff --git a/indra/newview/tests/llsechandler_basic_test.cpp b/indra/newview/tests/llsechandler_basic_test.cpp index da742370fc..bfe32406cb 100644 --- a/indra/newview/tests/llsechandler_basic_test.cpp +++ b/indra/newview/tests/llsechandler_basic_test.cpp @@ -1,4 +1,4 @@ -/** +/** * @file llsechandler_basic_test.cpp * @author Roxie * @date 2009-02-10 @@ -7,21 +7,21 @@ * $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$ */ @@ -66,8 +66,8 @@ ensure("Exception cert is incorrect for " str, valueCompareLLSD(except.getCertDa extern bool _cert_hostname_wildcard_match(const std::string& hostname, const std::string& wildcard_string); -//---------------------------------------------------------------------------- -// Mock objects for the dependencies of the code we're testing +//---------------------------------------------------------------------------- +// Mock objects for the dependencies of the code we're testing std::string gFirstName; std::string gLastName; @@ -82,11 +82,11 @@ void LLControlGroup::setString(const std::string& name, const std::string& val){ std::string LLControlGroup::getString(const std::string& name) { - if (name == "FirstName") - return gFirstName; - else if (name == "LastName") - return gLastName; - return ""; + if (name == "FirstName") + return gFirstName; + else if (name == "LastName") + return gLastName; + return ""; } // Stub for --no-verify-ssl-cert @@ -94,13 +94,13 @@ BOOL LLControlGroup::getBOOL(const std::string& name) { return FALSE; } LLSD LLCredential::getLoginParams() { - LLSD result = LLSD::emptyMap(); - - // legacy credential - result["passwd"] = "$1$testpasssd"; - result["first"] = "myfirst"; - result["last"] ="mylast"; - return result; + LLSD result = LLSD::emptyMap(); + + // legacy credential + result["passwd"] = "$1$testpasssd"; + result["first"] = "myfirst"; + result["last"] ="mylast"; + return result; } void LLCredential::identifierType(std::string &idType) @@ -118,15 +118,15 @@ unsigned char gMACAddress[MAC_ADDRESS_BYTES] = {77,21,46,31,89,2}; S32 LLMachineID::getUniqueID(unsigned char *unique_id, size_t len) { - memcpy(unique_id, gMACAddress, len); - return 1; + memcpy(unique_id, gMACAddress, len); + return 1; } S32 LLMachineID::getLegacyID(unsigned char *unique_id, size_t len) { return 0; } S32 LLMachineID::init() { return 1; } - + LLCertException::LLCertException(const LLSD& cert_data, const std::string& msg) : LLException(msg), @@ -356,7 +356,7 @@ namespace tut "qCSO341jpZaEv/+LfkZ68MdzfHCK9RfQrMiJHteJQg9NZsTYuzaorsrhz+KI9s+w\n" "REpfgVBL1iiBzWzw7OYJCPJZkaJprMeB+qthPttv9n/bGp65XczMM/qVxveNSzDz\n" "-----END CERTIFICATE-----\n" - ); + ); const std::string mPemIntermediateCert( "Certificate:\n" @@ -607,73 +607,73 @@ namespace tut "BdUpK78NAw7pXivdCRj+XjBh\n" "-----END CERTIFICATE-----\n" ); - - // Test wrapper declaration : wrapping nothing for the moment - struct sechandler_basic_test - { - X509 *mX509TestCert, *mX509RootCert, *mX509IntermediateCert, *mX509ChildCert; + + // Test wrapper declaration : wrapping nothing for the moment + struct sechandler_basic_test + { + X509 *mX509TestCert, *mX509RootCert, *mX509IntermediateCert, *mX509ChildCert; LLSD mValidationDate; - - sechandler_basic_test() - { + + sechandler_basic_test() + { LLMachineID::init(); - OpenSSL_add_all_algorithms(); - OpenSSL_add_all_ciphers(); - OpenSSL_add_all_digests(); - ERR_load_crypto_strings(); - gFirstName = ""; - gLastName = ""; + OpenSSL_add_all_algorithms(); + OpenSSL_add_all_ciphers(); + OpenSSL_add_all_digests(); + ERR_load_crypto_strings(); + gFirstName = ""; + gLastName = ""; mValidationDate[CERT_VALIDATION_DATE] = LLDate("2017-04-11T00:00:00.00Z"); - LLFile::remove("test_password.dat"); - LLFile::remove("sechandler_settings.tmp"); + LLFile::remove("test_password.dat"); + LLFile::remove("sechandler_settings.tmp"); - mX509TestCert = NULL; - mX509RootCert = NULL; - mX509IntermediateCert = NULL; - mX509ChildCert = NULL; + mX509TestCert = NULL; + mX509RootCert = NULL; + mX509IntermediateCert = NULL; + mX509ChildCert = NULL; // Read each of the 4 Pem certs and store in mX509*Cert pointers - BIO * validation_bio; - validation_bio = BIO_new_mem_buf((void*)mPemTestCert.c_str(), mPemTestCert.length()); - PEM_read_bio_X509(validation_bio, &mX509TestCert, 0, NULL); - BIO_free(validation_bio); - - validation_bio = BIO_new_mem_buf((void*)mPemRootCert.c_str(), mPemRootCert.length()); - PEM_read_bio_X509(validation_bio, &mX509RootCert, 0, NULL); - BIO_free(validation_bio); - - validation_bio = BIO_new_mem_buf((void*)mPemIntermediateCert.c_str(), mPemIntermediateCert.length()); - PEM_read_bio_X509(validation_bio, &mX509IntermediateCert, 0, NULL); - BIO_free(validation_bio); - - validation_bio = BIO_new_mem_buf((void*)mPemChildCert.c_str(), mPemChildCert.length()); - PEM_read_bio_X509(validation_bio, &mX509ChildCert, 0, NULL); - BIO_free(validation_bio); - } - ~sechandler_basic_test() - { - LLFile::remove("test_password.dat"); - LLFile::remove("sechandler_settings.tmp"); - LLFile::remove("mycertstore.pem"); - X509_free(mX509TestCert); - X509_free(mX509RootCert); - X509_free(mX509IntermediateCert); - X509_free(mX509ChildCert); - } - }; - - // Tut templating thingamagic: test group, object and test instance - typedef test_group<sechandler_basic_test> sechandler_basic_test_factory; - typedef sechandler_basic_test_factory::object sechandler_basic_test_object; - tut::sechandler_basic_test_factory tut_test("LLSecHandler"); - - // --------------------------------------------------------------------------------------- - // Test functions - // --------------------------------------------------------------------------------------- - // test cert data retrieval - template<> template<> - void sechandler_basic_test_object::test<1>() - { + BIO * validation_bio; + validation_bio = BIO_new_mem_buf((void*)mPemTestCert.c_str(), mPemTestCert.length()); + PEM_read_bio_X509(validation_bio, &mX509TestCert, 0, NULL); + BIO_free(validation_bio); + + validation_bio = BIO_new_mem_buf((void*)mPemRootCert.c_str(), mPemRootCert.length()); + PEM_read_bio_X509(validation_bio, &mX509RootCert, 0, NULL); + BIO_free(validation_bio); + + validation_bio = BIO_new_mem_buf((void*)mPemIntermediateCert.c_str(), mPemIntermediateCert.length()); + PEM_read_bio_X509(validation_bio, &mX509IntermediateCert, 0, NULL); + BIO_free(validation_bio); + + validation_bio = BIO_new_mem_buf((void*)mPemChildCert.c_str(), mPemChildCert.length()); + PEM_read_bio_X509(validation_bio, &mX509ChildCert, 0, NULL); + BIO_free(validation_bio); + } + ~sechandler_basic_test() + { + LLFile::remove("test_password.dat"); + LLFile::remove("sechandler_settings.tmp"); + LLFile::remove("mycertstore.pem"); + X509_free(mX509TestCert); + X509_free(mX509RootCert); + X509_free(mX509IntermediateCert); + X509_free(mX509ChildCert); + } + }; + + // Tut templating thingamagic: test group, object and test instance + typedef test_group<sechandler_basic_test> sechandler_basic_test_factory; + typedef sechandler_basic_test_factory::object sechandler_basic_test_object; + tut::sechandler_basic_test_factory tut_test("LLSecHandler"); + + // --------------------------------------------------------------------------------------- + // Test functions + // --------------------------------------------------------------------------------------- + // test cert data retrieval + template<> template<> + void sechandler_basic_test_object::test<1>() + { try { LLPointer<LLBasicCertificate> test_cert(new LLBasicCertificate(mPemTestCert, &mValidationDate)); @@ -690,729 +690,729 @@ namespace tut fail("other exception"); } } - + template<> template<> void sechandler_basic_test_object::test<2>() { - LLPointer<LLCertificate> test_cert(new LLBasicCertificate(mPemChildCert, &mValidationDate)); - - LLSD llsd_cert; - test_cert->getLLSD(llsd_cert); - //std::ostringstream llsd_value; - //llsd_value << LLSDOStreamer<LLSDNotationFormatter>(llsd_cert) << std::endl; - LL_DEBUGS() << "test 1 cert " << llsd_cert << LL_ENDL; - - ensure_equals("Issuer Name/commonName", (std::string)llsd_cert["issuer_name"]["commonName"], "Integration Test Intermediate CA"); - ensure_equals("Issuer Name/countryName", (std::string)llsd_cert["issuer_name"]["countryName"], "US"); - ensure_equals("Issuer Name/state", (std::string)llsd_cert["issuer_name"]["stateOrProvinceName"], "California"); - ensure_equals("Issuer Name/org name", (std::string)llsd_cert["issuer_name"]["organizationName"], "Linden Lab"); - ensure_equals("Issuer Name/org unit", (std::string)llsd_cert["issuer_name"]["organizationalUnitName"], "Second Life Engineering"); - ensure_equals("Issuer name string", (std::string)llsd_cert["issuer_name_string"], + LLPointer<LLCertificate> test_cert(new LLBasicCertificate(mPemChildCert, &mValidationDate)); + + LLSD llsd_cert; + test_cert->getLLSD(llsd_cert); + //std::ostringstream llsd_value; + //llsd_value << LLSDOStreamer<LLSDNotationFormatter>(llsd_cert) << std::endl; + LL_DEBUGS() << "test 1 cert " << llsd_cert << LL_ENDL; + + ensure_equals("Issuer Name/commonName", (std::string)llsd_cert["issuer_name"]["commonName"], "Integration Test Intermediate CA"); + ensure_equals("Issuer Name/countryName", (std::string)llsd_cert["issuer_name"]["countryName"], "US"); + ensure_equals("Issuer Name/state", (std::string)llsd_cert["issuer_name"]["stateOrProvinceName"], "California"); + ensure_equals("Issuer Name/org name", (std::string)llsd_cert["issuer_name"]["organizationName"], "Linden Lab"); + ensure_equals("Issuer Name/org unit", (std::string)llsd_cert["issuer_name"]["organizationalUnitName"], "Second Life Engineering"); + ensure_equals("Issuer name string", (std::string)llsd_cert["issuer_name_string"], "emailAddress=noreply@lindenlab.com,CN=Integration Test Intermediate CA,OU=Second Life Engineering,O=Linden Lab,ST=California,C=US"); - ensure_equals("subject Name/commonName", (std::string)llsd_cert["subject_name"]["commonName"], + ensure_equals("subject Name/commonName", (std::string)llsd_cert["subject_name"]["commonName"], "Integration Test Server Cert"); - ensure_equals("subject Name/countryName", (std::string)llsd_cert["subject_name"]["countryName"], "US"); - ensure_equals("subject Name/state", (std::string)llsd_cert["subject_name"]["stateOrProvinceName"], "California"); - ensure_equals("subject Name/localityName", (std::string)llsd_cert["subject_name"]["localityName"], "San Francisco"); - ensure_equals("subject Name/org name", (std::string)llsd_cert["subject_name"]["organizationName"], "Linden Lab"); - ensure_equals("subjectName/org unit", - (std::string)llsd_cert["subject_name"]["organizationalUnitName"], "Second Life Engineering"); - - ensure_equals("subject name string", - (std::string)llsd_cert["subject_name_string"], + ensure_equals("subject Name/countryName", (std::string)llsd_cert["subject_name"]["countryName"], "US"); + ensure_equals("subject Name/state", (std::string)llsd_cert["subject_name"]["stateOrProvinceName"], "California"); + ensure_equals("subject Name/localityName", (std::string)llsd_cert["subject_name"]["localityName"], "San Francisco"); + ensure_equals("subject Name/org name", (std::string)llsd_cert["subject_name"]["organizationName"], "Linden Lab"); + ensure_equals("subjectName/org unit", + (std::string)llsd_cert["subject_name"]["organizationalUnitName"], "Second Life Engineering"); + + ensure_equals("subject name string", + (std::string)llsd_cert["subject_name_string"], "emailAddress=noreply@lindenlab.com,CN=Integration Test Server Cert,OU=Second Life Engineering,O=Linden Lab,L=San Francisco,ST=California,C=US"); - ensure_equals("serial number", (std::string)llsd_cert["serial_number"], "1000"); - ensure_equals("valid from", (std::string)llsd_cert["valid_from"], "2018-05-22T22:58:15Z"); - ensure_equals("valid to", (std::string)llsd_cert["valid_to"], "2024-07-19T22:58:15Z"); - LLSD expectedKeyUsage = LLSD::emptyArray(); - expectedKeyUsage.append(LLSD((std::string)"digitalSignature")); - expectedKeyUsage.append(LLSD((std::string)"keyEncipherment")); - ensure("key usage", valueCompareLLSD(llsd_cert["keyUsage"], expectedKeyUsage)); - ensure_equals("basic constraints", llsd_cert["basicConstraints"]["CA"].asInteger(), 0); - - ensure("x509 is equal", !X509_cmp(mX509ChildCert, test_cert->getOpenSSLX509())); - } - - - // test protected data - template<> template<> - void sechandler_basic_test_object::test<3>() - { - std::string protected_data = "sUSh3wj77NG9oAMyt3XIhaej3KLZhLZWFZvI6rIGmwUUOmmelrRg0NI9rkOj8ZDpTPxpwToaBT5u" - "GQhakdaGLJznr9bHr4/6HIC1bouKj4n2rs4TL6j2WSjto114QdlNfLsE8cbbE+ghww58g8SeyLQO" - "nyzXoz+/PBz0HD5SMFDuObccoPW24gmqYySz8YoEWhSwO0pUtEEqOjVRsAJgF5wLAtJZDeuilGsq" - "4ZT9Y4wZ9Rh8nnF3fDUL6IGamHe1ClXM1jgBu10F6UMhZbnH4C3aJ2E9+LiOntU+l3iCb2MpkEpr" - "82r2ZAMwIrpnirL/xoYoyz7MJQYwUuMvBPToZJrxNSsjI+S2Z+I3iEJAELMAAA=="; - - std::vector<U8> binary_data(apr_base64_decode_len(protected_data.c_str())); - apr_base64_decode_binary(&binary_data[0], protected_data.c_str()); - - LLXORCipher cipher(gMACAddress, MAC_ADDRESS_BYTES); - cipher.decrypt(&binary_data[0], 16); - unsigned char unique_id[MAC_ADDRESS_BYTES]; + ensure_equals("serial number", (std::string)llsd_cert["serial_number"], "1000"); + ensure_equals("valid from", (std::string)llsd_cert["valid_from"], "2018-05-22T22:58:15Z"); + ensure_equals("valid to", (std::string)llsd_cert["valid_to"], "2024-07-19T22:58:15Z"); + LLSD expectedKeyUsage = LLSD::emptyArray(); + expectedKeyUsage.append(LLSD((std::string)"digitalSignature")); + expectedKeyUsage.append(LLSD((std::string)"keyEncipherment")); + ensure("key usage", valueCompareLLSD(llsd_cert["keyUsage"], expectedKeyUsage)); + ensure_equals("basic constraints", llsd_cert["basicConstraints"]["CA"].asInteger(), 0); + + ensure("x509 is equal", !X509_cmp(mX509ChildCert, test_cert->getOpenSSLX509())); + } + + + // test protected data + template<> template<> + void sechandler_basic_test_object::test<3>() + { + std::string protected_data = "sUSh3wj77NG9oAMyt3XIhaej3KLZhLZWFZvI6rIGmwUUOmmelrRg0NI9rkOj8ZDpTPxpwToaBT5u" + "GQhakdaGLJznr9bHr4/6HIC1bouKj4n2rs4TL6j2WSjto114QdlNfLsE8cbbE+ghww58g8SeyLQO" + "nyzXoz+/PBz0HD5SMFDuObccoPW24gmqYySz8YoEWhSwO0pUtEEqOjVRsAJgF5wLAtJZDeuilGsq" + "4ZT9Y4wZ9Rh8nnF3fDUL6IGamHe1ClXM1jgBu10F6UMhZbnH4C3aJ2E9+LiOntU+l3iCb2MpkEpr" + "82r2ZAMwIrpnirL/xoYoyz7MJQYwUuMvBPToZJrxNSsjI+S2Z+I3iEJAELMAAA=="; + + std::vector<U8> binary_data(apr_base64_decode_len(protected_data.c_str())); + apr_base64_decode_binary(&binary_data[0], protected_data.c_str()); + + LLXORCipher cipher(gMACAddress, MAC_ADDRESS_BYTES); + cipher.decrypt(&binary_data[0], 16); + unsigned char unique_id[MAC_ADDRESS_BYTES]; LLMachineID::getUniqueID(unique_id, sizeof(unique_id)); - LLXORCipher cipher2(unique_id, sizeof(unique_id)); - cipher2.encrypt(&binary_data[0], 16); - std::ofstream temp_file("sechandler_settings.tmp", std::ofstream::binary); - temp_file.write((const char *)&binary_data[0], binary_data.size()); - temp_file.close(); - - LLPointer<LLSecAPIBasicHandler> handler = new LLSecAPIBasicHandler("sechandler_settings.tmp", - "test_password.dat"); - handler->init(); - // data retrieval for existing data - LLSD data = handler->getProtectedData("test_data_type", "test_data_id"); - - - ensure_equals("retrieve existing data1", (std::string)data["data1"], "test_data_1"); - ensure_equals("retrieve existing data2", (std::string)data["data2"], "test_data_2"); - ensure_equals("retrieve existing data3", (std::string)data["data3"]["elem1"], "test element1"); - - // data storage - LLSD store_data = LLSD::emptyMap(); - store_data["store_data1"] = "test_store_data1"; - store_data["store_data2"] = 27; - store_data["store_data3"] = LLSD::emptyMap(); - store_data["store_data3"]["subelem1"] = "test_subelem1"; - - handler->setProtectedData("test_data_type", "test_data_id1", store_data); - data = handler->getProtectedData("test_data_type", "test_data_id"); - - data = handler->getProtectedData("test_data_type", "test_data_id"); - // verify no overwrite of existing data - ensure_equals("verify no overwrite 1", (std::string)data["data1"], "test_data_1"); - ensure_equals("verify no overwrite 2", (std::string)data["data2"], "test_data_2"); - ensure_equals("verify no overwrite 3", (std::string)data["data3"]["elem1"], "test element1"); - - // verify written data is good - data = handler->getProtectedData("test_data_type", "test_data_id1"); - ensure_equals("verify stored data1", (std::string)data["store_data1"], "test_store_data1"); - ensure_equals("verify stored data2", (int)data["store_data2"], 27); - ensure_equals("verify stored data3", (std::string)data["store_data3"]["subelem1"], "test_subelem1"); - - // verify overwrite works - handler->setProtectedData("test_data_type", "test_data_id", store_data); - data = handler->getProtectedData("test_data_type", "test_data_id"); - ensure_equals("verify overwrite stored data1", (std::string)data["store_data1"], "test_store_data1"); - ensure_equals("verify overwrite stored data2", (int)data["store_data2"], 27); - ensure_equals("verify overwrite stored data3", (std::string)data["store_data3"]["subelem1"], "test_subelem1"); - - // verify other datatype doesn't conflict - store_data["store_data3"] = "test_store_data3"; - store_data["store_data4"] = 28; - store_data["store_data5"] = LLSD::emptyMap(); - store_data["store_data5"]["subelem2"] = "test_subelem2"; - - handler->setProtectedData("test_data_type1", "test_data_id", store_data); - data = handler->getProtectedData("test_data_type1", "test_data_id"); - ensure_equals("verify datatype stored data3", (std::string)data["store_data3"], "test_store_data3"); - ensure_equals("verify datatype stored data4", (int)data["store_data4"], 28); - ensure_equals("verify datatype stored data5", (std::string)data["store_data5"]["subelem2"], "test_subelem2"); - - // test data not found - - data = handler->getProtectedData("test_data_type1", "test_data_not_found"); - ensure("not found", data.isUndefined()); - - // cause a 'write' by using 'LLPointer' to delete then instantiate a handler - handler = NULL; - handler = new LLSecAPIBasicHandler("sechandler_settings.tmp", "test_password.dat"); - handler->init(); - - data = handler->getProtectedData("test_data_type1", "test_data_id"); - ensure_equals("verify datatype stored data3a", (std::string)data["store_data3"], "test_store_data3"); - ensure_equals("verify datatype stored data4a", (int)data["store_data4"], 28); - ensure_equals("verify datatype stored data5a", (std::string)data["store_data5"]["subelem2"], "test_subelem2"); - - // rewrite the initial file to verify reloads - handler = NULL; - std::ofstream temp_file2("sechandler_settings.tmp", std::ofstream::binary); - temp_file2.write((const char *)&binary_data[0], binary_data.size()); - temp_file2.close(); - - // cause a 'write' - handler = new LLSecAPIBasicHandler("sechandler_settings.tmp", "test_password.dat"); - handler->init(); - data = handler->getProtectedData("test_data_type1", "test_data_id"); - ensure("not found", data.isUndefined()); - - handler->deleteProtectedData("test_data_type", "test_data_id"); - ensure("Deleted data not found", handler->getProtectedData("test_data_type", "test_data_id").isUndefined()); - - LLFile::remove("sechandler_settings.tmp"); - handler = new LLSecAPIBasicHandler("sechandler_settings.tmp", "test_password.dat"); - handler->init(); - data = handler->getProtectedData("test_data_type1", "test_data_id"); - ensure("not found", data.isUndefined()); - handler = NULL; - - ensure(LLFile::isfile("sechandler_settings.tmp")); - } - - // test credenitals - template<> template<> - void sechandler_basic_test_object::test<4>() - { - LLPointer<LLSecAPIBasicHandler> handler = new LLSecAPIBasicHandler("sechandler_settings.tmp", "test_password.dat"); - handler->init(); - - LLSD my_id = LLSD::emptyMap(); - LLSD my_authenticator = LLSD::emptyMap(); - my_id["type"] = "test_type"; - my_id["username"] = "testuser@lindenlab.com"; - my_authenticator["type"] = "test_auth"; - my_authenticator["creds"] = "12345"; - - // test creation of credentials - LLPointer<LLCredential> my_cred = handler->createCredential("my_grid", my_id, my_authenticator); - - // test retrieval of credential components - ensure_equals("basic credential creation: identifier", my_id, my_cred->getIdentifier()); - ensure_equals("basic credential creation: authenticator", my_authenticator, my_cred->getAuthenticator()); - ensure_equals("basic credential creation: grid", "my_grid", my_cred->getGrid()); - - // test setting/overwriting of credential components - my_id["first_name"] = "firstname"; - my_id.erase("username"); - my_authenticator.erase("creds"); - my_authenticator["hash"] = "6563245"; - - my_cred->setCredentialData(my_id, my_authenticator); - ensure_equals("set credential data: identifier", my_id, my_cred->getIdentifier()); - ensure_equals("set credential data: authenticator", my_authenticator, my_cred->getAuthenticator()); - ensure_equals("set credential data: grid", "my_grid", my_cred->getGrid()); - - // test loading of a credential, that hasn't been saved, without - // any legacy saved credential data - LLPointer<LLCredential> my_new_cred = handler->loadCredential("my_grid2"); - ensure("unknown credential load test", my_new_cred->getIdentifier().isMap()); - ensure("unknown credential load test", !my_new_cred->getIdentifier().has("type")); - ensure("unknown credential load test", my_new_cred->getAuthenticator().isMap()); - ensure("unknown credential load test", !my_new_cred->getAuthenticator().has("type")); - // test saving of a credential - handler->saveCredential(my_cred, true); - - // test loading of a known credential - my_new_cred = handler->loadCredential("my_grid"); - ensure_equals("load a known credential: identifier", my_id, my_new_cred->getIdentifier()); - ensure_equals("load a known credential: authenticator",my_authenticator, my_new_cred->getAuthenticator()); - ensure_equals("load a known credential: grid", "my_grid", my_cred->getGrid()); - - // test deletion of a credential - handler->deleteCredential(my_new_cred); - - ensure("delete credential: identifier", my_new_cred->getIdentifier().isUndefined()); - ensure("delete credentialt: authenticator", my_new_cred->getIdentifier().isUndefined()); - ensure_equals("delete credential: grid", "my_grid", my_cred->getGrid()); - // load unknown cred - - my_new_cred = handler->loadCredential("my_grid"); - ensure("deleted credential load test", my_new_cred->getIdentifier().isMap()); - ensure("deleted credential load test", !my_new_cred->getIdentifier().has("type")); - ensure("deleted credential load test", my_new_cred->getAuthenticator().isMap()); - ensure("deleted credential load test", !my_new_cred->getAuthenticator().has("type")); - - // test loading of an unknown credential with legacy saved username, but without - // saved password - gFirstName = "myfirstname"; - gLastName = "mylastname"; - my_new_cred = handler->loadCredential("my_legacy_grid"); - ensure_equals("legacy credential with no password: type", - (const std::string)my_new_cred->getIdentifier()["type"], "agent"); - ensure_equals("legacy credential with no password: first_name", - (const std::string)my_new_cred->getIdentifier()["first_name"], "myfirstname"); - ensure_equals("legacy credential with no password: last_name", - (const std::string)my_new_cred->getIdentifier()["last_name"], "mylastname"); - - ensure("legacy credential with no password: no authenticator", my_new_cred->getAuthenticator().isUndefined()); - - // test loading of an unknown credential with legacy saved password and username - - std::string hashed_password = "fSQcLG03eyIWJmkzfyYaKm81dSweLmsxeSAYKGE7fSQ="; - int length = apr_base64_decode_len(hashed_password.c_str()); - std::vector<char> decoded_password(length); - apr_base64_decode(&decoded_password[0], hashed_password.c_str()); - LLXORCipher cipher(gMACAddress, MAC_ADDRESS_BYTES); - cipher.decrypt((U8*)&decoded_password[0], length); - unsigned char unique_id[MAC_ADDRESS_BYTES]; - LLMachineID::getUniqueID(unique_id, sizeof(unique_id)); - LLXORCipher cipher2(unique_id, sizeof(unique_id)); - cipher2.encrypt((U8*)&decoded_password[0], length); - llofstream password_file("test_password.dat", std::ofstream::binary); - password_file.write(&decoded_password[0], length); - password_file.close(); - - my_new_cred = handler->loadCredential("my_legacy_grid2"); - ensure_equals("legacy credential with password: type", - (const std::string)my_new_cred->getIdentifier()["type"], "agent"); - ensure_equals("legacy credential with password: first_name", - (const std::string)my_new_cred->getIdentifier()["first_name"], "myfirstname"); - ensure_equals("legacy credential with password: last_name", - (const std::string)my_new_cred->getIdentifier()["last_name"], "mylastname"); - - LLSD legacy_authenticator = my_new_cred->getAuthenticator(); - ensure_equals("legacy credential with password: type", - (std::string)legacy_authenticator["type"], - "hash"); - ensure_equals("legacy credential with password: algorithm", - (std::string)legacy_authenticator["algorithm"], - "md5"); - ensure_equals("legacy credential with password: algorithm", - (std::string)legacy_authenticator["secret"], - "01234567890123456789012345678901"); - - // test creation of credentials - my_cred = handler->createCredential("mysavedgrid", my_id, my_authenticator); - // test save without saving authenticator. - handler->saveCredential(my_cred, FALSE); - my_new_cred = handler->loadCredential("mysavedgrid"); - ensure_equals("saved credential without auth", - (const std::string)my_new_cred->getIdentifier()["type"], "test_type"); - ensure("no authenticator values were saved", my_new_cred->getAuthenticator().isUndefined()); - } - - // test cert vector - template<> template<> - void sechandler_basic_test_object::test<5>() - { - // validate create from empty vector - LLPointer<LLBasicCertificateVector> test_vector = new LLBasicCertificateVector(); - ensure_equals("when loading with nothing, we should result in no certs in vector", test_vector->size(), 0); - - test_vector->add(new LLBasicCertificate(mPemTestCert, &mValidationDate)); - ensure_equals("one element in vector", test_vector->size(), 1); - test_vector->add(new LLBasicCertificate(mPemChildCert, &mValidationDate)); - ensure_equals("two elements in vector after add", test_vector->size(), 2); - + LLXORCipher cipher2(unique_id, sizeof(unique_id)); + cipher2.encrypt(&binary_data[0], 16); + std::ofstream temp_file("sechandler_settings.tmp", std::ofstream::binary); + temp_file.write((const char *)&binary_data[0], binary_data.size()); + temp_file.close(); + + LLPointer<LLSecAPIBasicHandler> handler = new LLSecAPIBasicHandler("sechandler_settings.tmp", + "test_password.dat"); + handler->init(); + // data retrieval for existing data + LLSD data = handler->getProtectedData("test_data_type", "test_data_id"); + + + ensure_equals("retrieve existing data1", (std::string)data["data1"], "test_data_1"); + ensure_equals("retrieve existing data2", (std::string)data["data2"], "test_data_2"); + ensure_equals("retrieve existing data3", (std::string)data["data3"]["elem1"], "test element1"); + + // data storage + LLSD store_data = LLSD::emptyMap(); + store_data["store_data1"] = "test_store_data1"; + store_data["store_data2"] = 27; + store_data["store_data3"] = LLSD::emptyMap(); + store_data["store_data3"]["subelem1"] = "test_subelem1"; + + handler->setProtectedData("test_data_type", "test_data_id1", store_data); + data = handler->getProtectedData("test_data_type", "test_data_id"); + + data = handler->getProtectedData("test_data_type", "test_data_id"); + // verify no overwrite of existing data + ensure_equals("verify no overwrite 1", (std::string)data["data1"], "test_data_1"); + ensure_equals("verify no overwrite 2", (std::string)data["data2"], "test_data_2"); + ensure_equals("verify no overwrite 3", (std::string)data["data3"]["elem1"], "test element1"); + + // verify written data is good + data = handler->getProtectedData("test_data_type", "test_data_id1"); + ensure_equals("verify stored data1", (std::string)data["store_data1"], "test_store_data1"); + ensure_equals("verify stored data2", (int)data["store_data2"], 27); + ensure_equals("verify stored data3", (std::string)data["store_data3"]["subelem1"], "test_subelem1"); + + // verify overwrite works + handler->setProtectedData("test_data_type", "test_data_id", store_data); + data = handler->getProtectedData("test_data_type", "test_data_id"); + ensure_equals("verify overwrite stored data1", (std::string)data["store_data1"], "test_store_data1"); + ensure_equals("verify overwrite stored data2", (int)data["store_data2"], 27); + ensure_equals("verify overwrite stored data3", (std::string)data["store_data3"]["subelem1"], "test_subelem1"); + + // verify other datatype doesn't conflict + store_data["store_data3"] = "test_store_data3"; + store_data["store_data4"] = 28; + store_data["store_data5"] = LLSD::emptyMap(); + store_data["store_data5"]["subelem2"] = "test_subelem2"; + + handler->setProtectedData("test_data_type1", "test_data_id", store_data); + data = handler->getProtectedData("test_data_type1", "test_data_id"); + ensure_equals("verify datatype stored data3", (std::string)data["store_data3"], "test_store_data3"); + ensure_equals("verify datatype stored data4", (int)data["store_data4"], 28); + ensure_equals("verify datatype stored data5", (std::string)data["store_data5"]["subelem2"], "test_subelem2"); + + // test data not found + + data = handler->getProtectedData("test_data_type1", "test_data_not_found"); + ensure("not found", data.isUndefined()); + + // cause a 'write' by using 'LLPointer' to delete then instantiate a handler + handler = NULL; + handler = new LLSecAPIBasicHandler("sechandler_settings.tmp", "test_password.dat"); + handler->init(); + + data = handler->getProtectedData("test_data_type1", "test_data_id"); + ensure_equals("verify datatype stored data3a", (std::string)data["store_data3"], "test_store_data3"); + ensure_equals("verify datatype stored data4a", (int)data["store_data4"], 28); + ensure_equals("verify datatype stored data5a", (std::string)data["store_data5"]["subelem2"], "test_subelem2"); + + // rewrite the initial file to verify reloads + handler = NULL; + std::ofstream temp_file2("sechandler_settings.tmp", std::ofstream::binary); + temp_file2.write((const char *)&binary_data[0], binary_data.size()); + temp_file2.close(); + + // cause a 'write' + handler = new LLSecAPIBasicHandler("sechandler_settings.tmp", "test_password.dat"); + handler->init(); + data = handler->getProtectedData("test_data_type1", "test_data_id"); + ensure("not found", data.isUndefined()); + + handler->deleteProtectedData("test_data_type", "test_data_id"); + ensure("Deleted data not found", handler->getProtectedData("test_data_type", "test_data_id").isUndefined()); + + LLFile::remove("sechandler_settings.tmp"); + handler = new LLSecAPIBasicHandler("sechandler_settings.tmp", "test_password.dat"); + handler->init(); + data = handler->getProtectedData("test_data_type1", "test_data_id"); + ensure("not found", data.isUndefined()); + handler = NULL; + + ensure(LLFile::isfile("sechandler_settings.tmp")); + } + + // test credenitals + template<> template<> + void sechandler_basic_test_object::test<4>() + { + LLPointer<LLSecAPIBasicHandler> handler = new LLSecAPIBasicHandler("sechandler_settings.tmp", "test_password.dat"); + handler->init(); + + LLSD my_id = LLSD::emptyMap(); + LLSD my_authenticator = LLSD::emptyMap(); + my_id["type"] = "test_type"; + my_id["username"] = "testuser@lindenlab.com"; + my_authenticator["type"] = "test_auth"; + my_authenticator["creds"] = "12345"; + + // test creation of credentials + LLPointer<LLCredential> my_cred = handler->createCredential("my_grid", my_id, my_authenticator); + + // test retrieval of credential components + ensure_equals("basic credential creation: identifier", my_id, my_cred->getIdentifier()); + ensure_equals("basic credential creation: authenticator", my_authenticator, my_cred->getAuthenticator()); + ensure_equals("basic credential creation: grid", "my_grid", my_cred->getGrid()); + + // test setting/overwriting of credential components + my_id["first_name"] = "firstname"; + my_id.erase("username"); + my_authenticator.erase("creds"); + my_authenticator["hash"] = "6563245"; + + my_cred->setCredentialData(my_id, my_authenticator); + ensure_equals("set credential data: identifier", my_id, my_cred->getIdentifier()); + ensure_equals("set credential data: authenticator", my_authenticator, my_cred->getAuthenticator()); + ensure_equals("set credential data: grid", "my_grid", my_cred->getGrid()); + + // test loading of a credential, that hasn't been saved, without + // any legacy saved credential data + LLPointer<LLCredential> my_new_cred = handler->loadCredential("my_grid2"); + ensure("unknown credential load test", my_new_cred->getIdentifier().isMap()); + ensure("unknown credential load test", !my_new_cred->getIdentifier().has("type")); + ensure("unknown credential load test", my_new_cred->getAuthenticator().isMap()); + ensure("unknown credential load test", !my_new_cred->getAuthenticator().has("type")); + // test saving of a credential + handler->saveCredential(my_cred, true); + + // test loading of a known credential + my_new_cred = handler->loadCredential("my_grid"); + ensure_equals("load a known credential: identifier", my_id, my_new_cred->getIdentifier()); + ensure_equals("load a known credential: authenticator",my_authenticator, my_new_cred->getAuthenticator()); + ensure_equals("load a known credential: grid", "my_grid", my_cred->getGrid()); + + // test deletion of a credential + handler->deleteCredential(my_new_cred); + + ensure("delete credential: identifier", my_new_cred->getIdentifier().isUndefined()); + ensure("delete credentialt: authenticator", my_new_cred->getIdentifier().isUndefined()); + ensure_equals("delete credential: grid", "my_grid", my_cred->getGrid()); + // load unknown cred + + my_new_cred = handler->loadCredential("my_grid"); + ensure("deleted credential load test", my_new_cred->getIdentifier().isMap()); + ensure("deleted credential load test", !my_new_cred->getIdentifier().has("type")); + ensure("deleted credential load test", my_new_cred->getAuthenticator().isMap()); + ensure("deleted credential load test", !my_new_cred->getAuthenticator().has("type")); + + // test loading of an unknown credential with legacy saved username, but without + // saved password + gFirstName = "myfirstname"; + gLastName = "mylastname"; + my_new_cred = handler->loadCredential("my_legacy_grid"); + ensure_equals("legacy credential with no password: type", + (const std::string)my_new_cred->getIdentifier()["type"], "agent"); + ensure_equals("legacy credential with no password: first_name", + (const std::string)my_new_cred->getIdentifier()["first_name"], "myfirstname"); + ensure_equals("legacy credential with no password: last_name", + (const std::string)my_new_cred->getIdentifier()["last_name"], "mylastname"); + + ensure("legacy credential with no password: no authenticator", my_new_cred->getAuthenticator().isUndefined()); + + // test loading of an unknown credential with legacy saved password and username + + std::string hashed_password = "fSQcLG03eyIWJmkzfyYaKm81dSweLmsxeSAYKGE7fSQ="; + int length = apr_base64_decode_len(hashed_password.c_str()); + std::vector<char> decoded_password(length); + apr_base64_decode(&decoded_password[0], hashed_password.c_str()); + LLXORCipher cipher(gMACAddress, MAC_ADDRESS_BYTES); + cipher.decrypt((U8*)&decoded_password[0], length); + unsigned char unique_id[MAC_ADDRESS_BYTES]; + LLMachineID::getUniqueID(unique_id, sizeof(unique_id)); + LLXORCipher cipher2(unique_id, sizeof(unique_id)); + cipher2.encrypt((U8*)&decoded_password[0], length); + llofstream password_file("test_password.dat", std::ofstream::binary); + password_file.write(&decoded_password[0], length); + password_file.close(); + + my_new_cred = handler->loadCredential("my_legacy_grid2"); + ensure_equals("legacy credential with password: type", + (const std::string)my_new_cred->getIdentifier()["type"], "agent"); + ensure_equals("legacy credential with password: first_name", + (const std::string)my_new_cred->getIdentifier()["first_name"], "myfirstname"); + ensure_equals("legacy credential with password: last_name", + (const std::string)my_new_cred->getIdentifier()["last_name"], "mylastname"); + + LLSD legacy_authenticator = my_new_cred->getAuthenticator(); + ensure_equals("legacy credential with password: type", + (std::string)legacy_authenticator["type"], + "hash"); + ensure_equals("legacy credential with password: algorithm", + (std::string)legacy_authenticator["algorithm"], + "md5"); + ensure_equals("legacy credential with password: algorithm", + (std::string)legacy_authenticator["secret"], + "01234567890123456789012345678901"); + + // test creation of credentials + my_cred = handler->createCredential("mysavedgrid", my_id, my_authenticator); + // test save without saving authenticator. + handler->saveCredential(my_cred, FALSE); + my_new_cred = handler->loadCredential("mysavedgrid"); + ensure_equals("saved credential without auth", + (const std::string)my_new_cred->getIdentifier()["type"], "test_type"); + ensure("no authenticator values were saved", my_new_cred->getAuthenticator().isUndefined()); + } + + // test cert vector + template<> template<> + void sechandler_basic_test_object::test<5>() + { + // validate create from empty vector + LLPointer<LLBasicCertificateVector> test_vector = new LLBasicCertificateVector(); + ensure_equals("when loading with nothing, we should result in no certs in vector", test_vector->size(), 0); + + test_vector->add(new LLBasicCertificate(mPemTestCert, &mValidationDate)); + ensure_equals("one element in vector", test_vector->size(), 1); + test_vector->add(new LLBasicCertificate(mPemChildCert, &mValidationDate)); + ensure_equals("two elements in vector after add", test_vector->size(), 2); + // add duplicate; should be a no-op (and log at DEBUG level) - test_vector->add(new LLBasicCertificate(mPemChildCert, &mValidationDate)); - ensure_equals("two elements in vector after re-add", test_vector->size(), 2); - - // validate order - X509* test_cert = (*test_vector)[0]->getOpenSSLX509(); - ensure("first cert added remains first cert", !X509_cmp(test_cert, mX509TestCert)); - X509_free(test_cert); - - test_cert = (*test_vector)[1]->getOpenSSLX509(); - ensure("second cert is second cert", !X509_cmp(test_cert, mX509ChildCert)); - X509_free(test_cert); - - // - // validate iterator - // - LLBasicCertificateVector::iterator current_cert = test_vector->begin(); - LLBasicCertificateVector::iterator copy_current_cert = current_cert; - // operator++(int) - ensure("validate iterator++ element in vector is expected cert", *current_cert++ == (*test_vector)[0]); - ensure("validate 2nd iterator++ element in vector is expected cert", *current_cert++ == (*test_vector)[1]); - ensure("validate end iterator++", current_cert == test_vector->end()); - - // copy - ensure("validate copy iterator element in vector is expected cert", *copy_current_cert == (*test_vector)[0]); - - // operator--(int) - current_cert--; - ensure("validate iterator-- element in vector is expected cert", *current_cert-- == (*test_vector)[1]); - ensure("validate iterator-- element in vector is expected cert", *current_cert == (*test_vector)[0]); - - ensure("begin iterator is equal", current_cert == test_vector->begin()); - - // operator++ - ensure("validate ++iterator element in vector is expected cert", *++current_cert == (*test_vector)[1]); - ensure("end of cert vector after ++iterator", ++current_cert == test_vector->end()); - // operator-- - ensure("validate --iterator element in vector is expected cert", *--current_cert == (*test_vector)[1]); - ensure("validate 2nd --iterator element in vector is expected cert", *--current_cert == (*test_vector)[0]); - - test_vector->erase(test_vector->begin()); - ensure_equals("one element in store after remove", test_vector->size(), 1); - test_cert = (*test_vector)[0]->getOpenSSLX509(); - ensure("Child cert remains", !X509_cmp(test_cert, mX509ChildCert)); - X509_free(test_cert); - - // validate insert - test_vector->insert(test_vector->begin(), new LLBasicCertificate(mPemIntermediateCert, &mValidationDate)); - test_cert = (*test_vector)[0]->getOpenSSLX509(); - ensure_equals("two elements in store after insert", test_vector->size(), 2); - ensure("validate intermediate cert was inserted at first position", !X509_cmp(test_cert, mX509IntermediateCert)); - X509_free(test_cert); - test_cert = (*test_vector)[1]->getOpenSSLX509(); - ensure("validate child cert still there", !X509_cmp(test_cert, mX509ChildCert)); - X509_free(test_cert); - - //validate find - LLSD find_info = LLSD::emptyMap(); - find_info["subjectKeyIdentifier"] = "bb:59:9f:de:6b:51:a7:6c:b3:6d:5b:8b:42:f7:b1:65:77:17:a4:e4"; - LLBasicCertificateVector::iterator found_cert = test_vector->find(find_info); - ensure("found some cert", found_cert != test_vector->end()); + test_vector->add(new LLBasicCertificate(mPemChildCert, &mValidationDate)); + ensure_equals("two elements in vector after re-add", test_vector->size(), 2); + + // validate order + X509* test_cert = (*test_vector)[0]->getOpenSSLX509(); + ensure("first cert added remains first cert", !X509_cmp(test_cert, mX509TestCert)); + X509_free(test_cert); + + test_cert = (*test_vector)[1]->getOpenSSLX509(); + ensure("second cert is second cert", !X509_cmp(test_cert, mX509ChildCert)); + X509_free(test_cert); + + // + // validate iterator + // + LLBasicCertificateVector::iterator current_cert = test_vector->begin(); + LLBasicCertificateVector::iterator copy_current_cert = current_cert; + // operator++(int) + ensure("validate iterator++ element in vector is expected cert", *current_cert++ == (*test_vector)[0]); + ensure("validate 2nd iterator++ element in vector is expected cert", *current_cert++ == (*test_vector)[1]); + ensure("validate end iterator++", current_cert == test_vector->end()); + + // copy + ensure("validate copy iterator element in vector is expected cert", *copy_current_cert == (*test_vector)[0]); + + // operator--(int) + current_cert--; + ensure("validate iterator-- element in vector is expected cert", *current_cert-- == (*test_vector)[1]); + ensure("validate iterator-- element in vector is expected cert", *current_cert == (*test_vector)[0]); + + ensure("begin iterator is equal", current_cert == test_vector->begin()); + + // operator++ + ensure("validate ++iterator element in vector is expected cert", *++current_cert == (*test_vector)[1]); + ensure("end of cert vector after ++iterator", ++current_cert == test_vector->end()); + // operator-- + ensure("validate --iterator element in vector is expected cert", *--current_cert == (*test_vector)[1]); + ensure("validate 2nd --iterator element in vector is expected cert", *--current_cert == (*test_vector)[0]); + + test_vector->erase(test_vector->begin()); + ensure_equals("one element in store after remove", test_vector->size(), 1); + test_cert = (*test_vector)[0]->getOpenSSLX509(); + ensure("Child cert remains", !X509_cmp(test_cert, mX509ChildCert)); + X509_free(test_cert); + + // validate insert + test_vector->insert(test_vector->begin(), new LLBasicCertificate(mPemIntermediateCert, &mValidationDate)); + test_cert = (*test_vector)[0]->getOpenSSLX509(); + ensure_equals("two elements in store after insert", test_vector->size(), 2); + ensure("validate intermediate cert was inserted at first position", !X509_cmp(test_cert, mX509IntermediateCert)); + X509_free(test_cert); + test_cert = (*test_vector)[1]->getOpenSSLX509(); + ensure("validate child cert still there", !X509_cmp(test_cert, mX509ChildCert)); + X509_free(test_cert); + + //validate find + LLSD find_info = LLSD::emptyMap(); + find_info["subjectKeyIdentifier"] = "bb:59:9f:de:6b:51:a7:6c:b3:6d:5b:8b:42:f7:b1:65:77:17:a4:e4"; + LLBasicCertificateVector::iterator found_cert = test_vector->find(find_info); + ensure("found some cert", found_cert != test_vector->end()); X509* found_x509 = (*found_cert).get()->getOpenSSLX509(); - ensure("child cert was found", !X509_cmp(found_x509, mX509ChildCert)); - X509_free(found_x509); - - find_info["subjectKeyIdentifier"] = "00:00:00:00"; // bogus - current_cert =test_vector->find(find_info); - ensure("didn't find cert", current_cert == test_vector->end()); - } - - // test cert store - template<> template<> - void sechandler_basic_test_object::test<6>() - { - // validate load with nothing - LLFile::remove("mycertstore.pem"); - LLPointer<LLBasicCertificateStore> test_store = new LLBasicCertificateStore("mycertstore.pem"); - ensure_equals("when loading with nothing, we should result in no certs in store", test_store->size(), 0); - - // validate load with empty file - test_store->save(); - test_store = NULL; - test_store = new LLBasicCertificateStore("mycertstore.pem"); - ensure_equals("when loading with nothing, we should result in no certs in store", test_store->size(), 0); - test_store=NULL; - - // instantiate a cert store from a file - llofstream certstorefile("mycertstore.pem", std::ios::out); - certstorefile << mPemChildCert << std::endl << mPemTestCert << std::endl; - certstorefile.close(); - // validate loaded certs - test_store = new LLBasicCertificateStore("mycertstore.pem"); - ensure_equals("two elements in store", test_store->size(), 2); - - // operator[] - X509* test_cert = (*test_store)[0]->getOpenSSLX509(); - - ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); - X509_free(test_cert); - test_cert = (*test_store)[1]->getOpenSSLX509(); - ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509TestCert)); - X509_free(test_cert); - - - // validate save - LLFile::remove("mycertstore.pem"); - test_store->save(); - test_store = NULL; - test_store = new LLBasicCertificateStore("mycertstore.pem"); - ensure_equals("two elements in store after save", test_store->size(), 2); - LLCertificateStore::iterator current_cert = test_store->begin(); - test_cert = (*current_cert)->getOpenSSLX509(); - ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); - current_cert++; - X509_free(test_cert); - test_cert = (*current_cert)->getOpenSSLX509(); - ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509TestCert)); - X509_free(test_cert); - current_cert++; - ensure("end of cert store", current_cert == test_store->end()); - - } - - // cert name wildcard matching - template<> template<> - void sechandler_basic_test_object::test<7>() - { - ensure("simple name match", - _cert_hostname_wildcard_match("foo", "foo")); - - ensure("simple name match, with end period", - _cert_hostname_wildcard_match("foo.", "foo.")); - - ensure("simple name match, with begin period", - _cert_hostname_wildcard_match(".foo", ".foo")); - - ensure("simple name match, with mismatched period cn", - _cert_hostname_wildcard_match("foo.", "foo")); - - ensure("simple name match, with mismatched period hostname", - _cert_hostname_wildcard_match("foo", "foo.")); - - ensure("simple name match, with subdomain", - _cert_hostname_wildcard_match("foo.bar", "foo.bar")); - - ensure("stutter name match", - _cert_hostname_wildcard_match("foobbbbfoo", "foo*bbbfoo")); - - ensure("simple name match, with beginning wildcard", - _cert_hostname_wildcard_match("foobar", "*bar")); - - ensure("simple name match, with ending wildcard", - _cert_hostname_wildcard_match("foobar", "foo*")); - - ensure("simple name match, with beginning null wildcard", - _cert_hostname_wildcard_match("foobar", "*foobar")); - - ensure("simple name match, with ending null wildcard", - _cert_hostname_wildcard_match("foobar", "foobar*")); - - ensure("simple name match, with embedded wildcard", - _cert_hostname_wildcard_match("foobar", "f*r")); - - ensure("simple name match, with embedded null wildcard", - _cert_hostname_wildcard_match("foobar", "foo*bar")); - - ensure("simple name match, with dual embedded wildcard", - _cert_hostname_wildcard_match("foobar", "f*o*ar")); - - ensure("simple name mismatch", - !_cert_hostname_wildcard_match("bar", "foo")); - - ensure("simple name mismatch, with end period", - !_cert_hostname_wildcard_match("foobar.", "foo.")); - - ensure("simple name mismatch, with begin period", - !_cert_hostname_wildcard_match(".foobar", ".foo")); - - ensure("simple name mismatch, with subdomain", - !_cert_hostname_wildcard_match("foobar.bar", "foo.bar")); - - ensure("simple name mismatch, with beginning wildcard", - !_cert_hostname_wildcard_match("foobara", "*bar")); - - ensure("simple name mismatch, with ending wildcard", - !_cert_hostname_wildcard_match("oobar", "foo*")); - - ensure("simple name mismatch, with embedded wildcard", - !_cert_hostname_wildcard_match("oobar", "f*r")); - - ensure("simple name mismatch, with dual embedded wildcard", - !_cert_hostname_wildcard_match("foobar", "f*d*ar")); - - ensure("simple wildcard", - _cert_hostname_wildcard_match("foobar", "*")); - - ensure("long domain", - _cert_hostname_wildcard_match("foo.bar.com", "foo.bar.com")); - - ensure("long domain with multiple wildcards", - _cert_hostname_wildcard_match("foo.bar.com", "*.b*r.com")); - - ensure("end periods", - _cert_hostname_wildcard_match("foo.bar.com.", "*.b*r.com.")); - - ensure("match end period", - _cert_hostname_wildcard_match("foo.bar.com.", "*.b*r.com")); - - ensure("match end period2", - _cert_hostname_wildcard_match("foo.bar.com", "*.b*r.com.")); - - ensure("wildcard mismatch", - !_cert_hostname_wildcard_match("bar.com", "*.bar.com")); - - ensure("wildcard match", - _cert_hostname_wildcard_match("foo.bar.com", "*.bar.com")); - - ensure("wildcard match", - _cert_hostname_wildcard_match("foo.foo.bar.com", "*.bar.com")); - - ensure("wildcard match", - _cert_hostname_wildcard_match("foo.foo.bar.com", "*.*.com")); - - ensure("wildcard mismatch", - !_cert_hostname_wildcard_match("foo.foo.bar.com", "*.foo.com")); - } - - // test cert chain - template<> template<> - void sechandler_basic_test_object::test<8>() - { - // validate create from empty chain - LLPointer<LLBasicCertificateChain> test_chain = new LLBasicCertificateChain(NULL); - ensure_equals("when loading with nothing, we should result in no certs in chain", test_chain->size(), 0); - - // Single cert in the chain. - X509_STORE_CTX *test_store = X509_STORE_CTX_new(); + ensure("child cert was found", !X509_cmp(found_x509, mX509ChildCert)); + X509_free(found_x509); + + find_info["subjectKeyIdentifier"] = "00:00:00:00"; // bogus + current_cert =test_vector->find(find_info); + ensure("didn't find cert", current_cert == test_vector->end()); + } + + // test cert store + template<> template<> + void sechandler_basic_test_object::test<6>() + { + // validate load with nothing + LLFile::remove("mycertstore.pem"); + LLPointer<LLBasicCertificateStore> test_store = new LLBasicCertificateStore("mycertstore.pem"); + ensure_equals("when loading with nothing, we should result in no certs in store", test_store->size(), 0); + + // validate load with empty file + test_store->save(); + test_store = NULL; + test_store = new LLBasicCertificateStore("mycertstore.pem"); + ensure_equals("when loading with nothing, we should result in no certs in store", test_store->size(), 0); + test_store=NULL; + + // instantiate a cert store from a file + llofstream certstorefile("mycertstore.pem", std::ios::out); + certstorefile << mPemChildCert << std::endl << mPemTestCert << std::endl; + certstorefile.close(); + // validate loaded certs + test_store = new LLBasicCertificateStore("mycertstore.pem"); + ensure_equals("two elements in store", test_store->size(), 2); + + // operator[] + X509* test_cert = (*test_store)[0]->getOpenSSLX509(); + + ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); + X509_free(test_cert); + test_cert = (*test_store)[1]->getOpenSSLX509(); + ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509TestCert)); + X509_free(test_cert); + + + // validate save + LLFile::remove("mycertstore.pem"); + test_store->save(); + test_store = NULL; + test_store = new LLBasicCertificateStore("mycertstore.pem"); + ensure_equals("two elements in store after save", test_store->size(), 2); + LLCertificateStore::iterator current_cert = test_store->begin(); + test_cert = (*current_cert)->getOpenSSLX509(); + ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); + current_cert++; + X509_free(test_cert); + test_cert = (*current_cert)->getOpenSSLX509(); + ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509TestCert)); + X509_free(test_cert); + current_cert++; + ensure("end of cert store", current_cert == test_store->end()); + + } + + // cert name wildcard matching + template<> template<> + void sechandler_basic_test_object::test<7>() + { + ensure("simple name match", + _cert_hostname_wildcard_match("foo", "foo")); + + ensure("simple name match, with end period", + _cert_hostname_wildcard_match("foo.", "foo.")); + + ensure("simple name match, with begin period", + _cert_hostname_wildcard_match(".foo", ".foo")); + + ensure("simple name match, with mismatched period cn", + _cert_hostname_wildcard_match("foo.", "foo")); + + ensure("simple name match, with mismatched period hostname", + _cert_hostname_wildcard_match("foo", "foo.")); + + ensure("simple name match, with subdomain", + _cert_hostname_wildcard_match("foo.bar", "foo.bar")); + + ensure("stutter name match", + _cert_hostname_wildcard_match("foobbbbfoo", "foo*bbbfoo")); + + ensure("simple name match, with beginning wildcard", + _cert_hostname_wildcard_match("foobar", "*bar")); + + ensure("simple name match, with ending wildcard", + _cert_hostname_wildcard_match("foobar", "foo*")); + + ensure("simple name match, with beginning null wildcard", + _cert_hostname_wildcard_match("foobar", "*foobar")); + + ensure("simple name match, with ending null wildcard", + _cert_hostname_wildcard_match("foobar", "foobar*")); + + ensure("simple name match, with embedded wildcard", + _cert_hostname_wildcard_match("foobar", "f*r")); + + ensure("simple name match, with embedded null wildcard", + _cert_hostname_wildcard_match("foobar", "foo*bar")); + + ensure("simple name match, with dual embedded wildcard", + _cert_hostname_wildcard_match("foobar", "f*o*ar")); + + ensure("simple name mismatch", + !_cert_hostname_wildcard_match("bar", "foo")); + + ensure("simple name mismatch, with end period", + !_cert_hostname_wildcard_match("foobar.", "foo.")); + + ensure("simple name mismatch, with begin period", + !_cert_hostname_wildcard_match(".foobar", ".foo")); + + ensure("simple name mismatch, with subdomain", + !_cert_hostname_wildcard_match("foobar.bar", "foo.bar")); + + ensure("simple name mismatch, with beginning wildcard", + !_cert_hostname_wildcard_match("foobara", "*bar")); + + ensure("simple name mismatch, with ending wildcard", + !_cert_hostname_wildcard_match("oobar", "foo*")); + + ensure("simple name mismatch, with embedded wildcard", + !_cert_hostname_wildcard_match("oobar", "f*r")); + + ensure("simple name mismatch, with dual embedded wildcard", + !_cert_hostname_wildcard_match("foobar", "f*d*ar")); + + ensure("simple wildcard", + _cert_hostname_wildcard_match("foobar", "*")); + + ensure("long domain", + _cert_hostname_wildcard_match("foo.bar.com", "foo.bar.com")); + + ensure("long domain with multiple wildcards", + _cert_hostname_wildcard_match("foo.bar.com", "*.b*r.com")); + + ensure("end periods", + _cert_hostname_wildcard_match("foo.bar.com.", "*.b*r.com.")); + + ensure("match end period", + _cert_hostname_wildcard_match("foo.bar.com.", "*.b*r.com")); + + ensure("match end period2", + _cert_hostname_wildcard_match("foo.bar.com", "*.b*r.com.")); + + ensure("wildcard mismatch", + !_cert_hostname_wildcard_match("bar.com", "*.bar.com")); + + ensure("wildcard match", + _cert_hostname_wildcard_match("foo.bar.com", "*.bar.com")); + + ensure("wildcard match", + _cert_hostname_wildcard_match("foo.foo.bar.com", "*.bar.com")); + + ensure("wildcard match", + _cert_hostname_wildcard_match("foo.foo.bar.com", "*.*.com")); + + ensure("wildcard mismatch", + !_cert_hostname_wildcard_match("foo.foo.bar.com", "*.foo.com")); + } + + // test cert chain + template<> template<> + void sechandler_basic_test_object::test<8>() + { + // validate create from empty chain + LLPointer<LLBasicCertificateChain> test_chain = new LLBasicCertificateChain(NULL); + ensure_equals("when loading with nothing, we should result in no certs in chain", test_chain->size(), 0); + + // Single cert in the chain. + X509_STORE_CTX *test_store = X509_STORE_CTX_new(); X509_STORE_CTX_set_cert(test_store, mX509ChildCert); X509_STORE_CTX_set0_untrusted(test_store, NULL); - test_chain = new LLBasicCertificateChain(test_store); - X509_STORE_CTX_free(test_store); - ensure_equals("two elements in store", test_chain->size(), 1); - X509* test_cert = (*test_chain)[0]->getOpenSSLX509(); - ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); - X509_free(test_cert); - - // cert + CA - - test_store = X509_STORE_CTX_new(); + test_chain = new LLBasicCertificateChain(test_store); + X509_STORE_CTX_free(test_store); + ensure_equals("two elements in store", test_chain->size(), 1); + X509* test_cert = (*test_chain)[0]->getOpenSSLX509(); + ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); + X509_free(test_cert); + + // cert + CA + + test_store = X509_STORE_CTX_new(); X509_STORE_CTX_set_cert(test_store, mX509ChildCert); X509_STORE_CTX_set0_untrusted(test_store, sk_X509_new_null()); - sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509IntermediateCert); - test_chain = new LLBasicCertificateChain(test_store); - X509_STORE_CTX_free(test_store); - ensure_equals("two elements in store", test_chain->size(), 2); - test_cert = (*test_chain)[0]->getOpenSSLX509(); - ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); - X509_free(test_cert); - test_cert = (*test_chain)[1]->getOpenSSLX509(); - ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509IntermediateCert)); - X509_free(test_cert); - - // cert + nonrelated - - test_store = X509_STORE_CTX_new(); + sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509IntermediateCert); + test_chain = new LLBasicCertificateChain(test_store); + X509_STORE_CTX_free(test_store); + ensure_equals("two elements in store", test_chain->size(), 2); + test_cert = (*test_chain)[0]->getOpenSSLX509(); + ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); + X509_free(test_cert); + test_cert = (*test_chain)[1]->getOpenSSLX509(); + ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509IntermediateCert)); + X509_free(test_cert); + + // cert + nonrelated + + test_store = X509_STORE_CTX_new(); X509_STORE_CTX_set_cert(test_store, mX509ChildCert); X509_STORE_CTX_set0_untrusted(test_store, sk_X509_new_null()); - sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509TestCert); - test_chain = new LLBasicCertificateChain(test_store); - X509_STORE_CTX_free(test_store); - ensure_equals("two elements in store", test_chain->size(), 1); - test_cert = (*test_chain)[0]->getOpenSSLX509(); - ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); - X509_free(test_cert); - - // cert + CA + nonrelated - test_store = X509_STORE_CTX_new(); + sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509TestCert); + test_chain = new LLBasicCertificateChain(test_store); + X509_STORE_CTX_free(test_store); + ensure_equals("two elements in store", test_chain->size(), 1); + test_cert = (*test_chain)[0]->getOpenSSLX509(); + ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); + X509_free(test_cert); + + // cert + CA + nonrelated + test_store = X509_STORE_CTX_new(); X509_STORE_CTX_set_cert(test_store, mX509ChildCert); X509_STORE_CTX_set0_untrusted(test_store, sk_X509_new_null()); - sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509IntermediateCert); - sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509TestCert); - test_chain = new LLBasicCertificateChain(test_store); - X509_STORE_CTX_free(test_store); - ensure_equals("two elements in store", test_chain->size(), 2); - test_cert = (*test_chain)[0]->getOpenSSLX509(); - ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); - X509_free(test_cert); - test_cert = (*test_chain)[1]->getOpenSSLX509(); - ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509IntermediateCert)); - X509_free(test_cert); - - // cert + intermediate + CA - test_store = X509_STORE_CTX_new(); + sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509IntermediateCert); + sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509TestCert); + test_chain = new LLBasicCertificateChain(test_store); + X509_STORE_CTX_free(test_store); + ensure_equals("two elements in store", test_chain->size(), 2); + test_cert = (*test_chain)[0]->getOpenSSLX509(); + ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); + X509_free(test_cert); + test_cert = (*test_chain)[1]->getOpenSSLX509(); + ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509IntermediateCert)); + X509_free(test_cert); + + // cert + intermediate + CA + test_store = X509_STORE_CTX_new(); X509_STORE_CTX_set_cert(test_store, mX509ChildCert); X509_STORE_CTX_set0_untrusted(test_store, sk_X509_new_null()); - sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509IntermediateCert); - sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509RootCert); - test_chain = new LLBasicCertificateChain(test_store); - X509_STORE_CTX_free(test_store); - ensure_equals("three elements in store", test_chain->size(), 3); - test_cert = (*test_chain)[0]->getOpenSSLX509(); - ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); - X509_free(test_cert); - test_cert = (*test_chain)[1]->getOpenSSLX509(); - ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509IntermediateCert)); - X509_free(test_cert); - - test_cert = (*test_chain)[2]->getOpenSSLX509(); - ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509RootCert)); - X509_free(test_cert); - } - - // test cert validation - template<> template<> - void sechandler_basic_test_object::test<9>() - { - // start with a trusted store with our known root cert - LLFile::remove("mycertstore.pem"); - LLPointer<LLBasicCertificateStore> test_store = new LLBasicCertificateStore("mycertstore.pem"); - test_store->add(new LLBasicCertificate(mX509RootCert, &mValidationDate)); - LLSD validation_params; - - // validate basic trust for a chain containing only the intermediate cert. (1 deep) - LLPointer<LLBasicCertificateChain> test_chain = new LLBasicCertificateChain(NULL); - - test_chain->add(new LLBasicCertificate(mX509IntermediateCert, &mValidationDate)); - - test_store->validate(0, test_chain, validation_params); - - // add the root certificate to the chain and revalidate - test_chain->add(new LLBasicCertificate(mX509RootCert, &mValidationDate)); - test_store->validate(0, test_chain, validation_params); - - // add the child cert at the head of the chain, and revalidate (3 deep chain) - test_chain->insert(test_chain->begin(), new LLBasicCertificate(mX509ChildCert, &mValidationDate)); - test_store->validate(0, test_chain, validation_params); - - // basic failure cases - test_chain = new LLBasicCertificateChain(NULL); - //validate with only the child cert in chain, but child cert was previously - // trusted - test_chain->add(new LLBasicCertificate(mX509ChildCert, &mValidationDate)); - - // validate without the trust flag. - test_store->validate(VALIDATION_POLICY_TRUSTED, test_chain, validation_params); - - // Validate with child cert but no parent, and no parent in CA store - test_store = new LLBasicCertificateStore("mycertstore.pem"); - ensure_throws("no CA, with only a child cert", - LLCertValidationTrustException, - (*test_chain)[0], - test_store->validate, - VALIDATION_POLICY_TRUSTED, - test_chain, - validation_params); - - - // validate without the trust flag. - test_store->validate(0, test_chain, validation_params); - - // clear out the store - test_store = new LLBasicCertificateStore("mycertstore.pem"); - // append the intermediate cert - test_chain->add(new LLBasicCertificate(mX509IntermediateCert, &mValidationDate)); - ensure_throws("no CA, with child and intermediate certs", - LLCertValidationTrustException, - (*test_chain)[1], - test_store->validate, - VALIDATION_POLICY_TRUSTED | VALIDATION_POLICY_TRUSTED, - test_chain, - validation_params); - // validate without the trust flag - test_store->validate(0, test_chain, validation_params); - - // Test time validity - LLSD child_info; - ((*test_chain)[0])->getLLSD(child_info); - validation_params = LLSD::emptyMap(); - validation_params[CERT_VALIDATION_DATE] = LLDate(child_info[CERT_VALID_FROM].asDate().secondsSinceEpoch() + 1.0); - test_store->validate(VALIDATION_POLICY_TIME | VALIDATION_POLICY_TRUSTED, + sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509IntermediateCert); + sk_X509_push(X509_STORE_CTX_get0_untrusted(test_store), mX509RootCert); + test_chain = new LLBasicCertificateChain(test_store); + X509_STORE_CTX_free(test_store); + ensure_equals("three elements in store", test_chain->size(), 3); + test_cert = (*test_chain)[0]->getOpenSSLX509(); + ensure("validate first element in store is expected cert", !X509_cmp(test_cert, mX509ChildCert)); + X509_free(test_cert); + test_cert = (*test_chain)[1]->getOpenSSLX509(); + ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509IntermediateCert)); + X509_free(test_cert); + + test_cert = (*test_chain)[2]->getOpenSSLX509(); + ensure("validate second element in store is expected cert", !X509_cmp(test_cert, mX509RootCert)); + X509_free(test_cert); + } + + // test cert validation + template<> template<> + void sechandler_basic_test_object::test<9>() + { + // start with a trusted store with our known root cert + LLFile::remove("mycertstore.pem"); + LLPointer<LLBasicCertificateStore> test_store = new LLBasicCertificateStore("mycertstore.pem"); + test_store->add(new LLBasicCertificate(mX509RootCert, &mValidationDate)); + LLSD validation_params; + + // validate basic trust for a chain containing only the intermediate cert. (1 deep) + LLPointer<LLBasicCertificateChain> test_chain = new LLBasicCertificateChain(NULL); + + test_chain->add(new LLBasicCertificate(mX509IntermediateCert, &mValidationDate)); + + test_store->validate(0, test_chain, validation_params); + + // add the root certificate to the chain and revalidate + test_chain->add(new LLBasicCertificate(mX509RootCert, &mValidationDate)); + test_store->validate(0, test_chain, validation_params); + + // add the child cert at the head of the chain, and revalidate (3 deep chain) + test_chain->insert(test_chain->begin(), new LLBasicCertificate(mX509ChildCert, &mValidationDate)); + test_store->validate(0, test_chain, validation_params); + + // basic failure cases + test_chain = new LLBasicCertificateChain(NULL); + //validate with only the child cert in chain, but child cert was previously + // trusted + test_chain->add(new LLBasicCertificate(mX509ChildCert, &mValidationDate)); + + // validate without the trust flag. + test_store->validate(VALIDATION_POLICY_TRUSTED, test_chain, validation_params); + + // Validate with child cert but no parent, and no parent in CA store + test_store = new LLBasicCertificateStore("mycertstore.pem"); + ensure_throws("no CA, with only a child cert", + LLCertValidationTrustException, + (*test_chain)[0], + test_store->validate, + VALIDATION_POLICY_TRUSTED, + test_chain, + validation_params); + + + // validate without the trust flag. + test_store->validate(0, test_chain, validation_params); + + // clear out the store + test_store = new LLBasicCertificateStore("mycertstore.pem"); + // append the intermediate cert + test_chain->add(new LLBasicCertificate(mX509IntermediateCert, &mValidationDate)); + ensure_throws("no CA, with child and intermediate certs", + LLCertValidationTrustException, + (*test_chain)[1], + test_store->validate, + VALIDATION_POLICY_TRUSTED | VALIDATION_POLICY_TRUSTED, + test_chain, + validation_params); + // validate without the trust flag + test_store->validate(0, test_chain, validation_params); + + // Test time validity + LLSD child_info; + ((*test_chain)[0])->getLLSD(child_info); + validation_params = LLSD::emptyMap(); + validation_params[CERT_VALIDATION_DATE] = LLDate(child_info[CERT_VALID_FROM].asDate().secondsSinceEpoch() + 1.0); + test_store->validate(VALIDATION_POLICY_TIME | VALIDATION_POLICY_TRUSTED, test_chain, validation_params); - validation_params = LLSD::emptyMap(); - validation_params[CERT_VALIDATION_DATE] = child_info[CERT_VALID_FROM].asDate(); - - validation_params[CERT_VALIDATION_DATE] = LLDate(child_info[CERT_VALID_FROM].asDate().secondsSinceEpoch() - 1.0); - - // test not yet valid - ensure_throws("Child cert not yet valid" , - LLCertValidationExpirationException, - (*test_chain)[0], - test_store->validate, - VALIDATION_POLICY_TIME | VALIDATION_POLICY_TRUSTED, - test_chain, - validation_params); - validation_params = LLSD::emptyMap(); - validation_params[CERT_VALIDATION_DATE] = LLDate(child_info[CERT_VALID_TO].asDate().secondsSinceEpoch() + 1.0); - - // test cert expired - ensure_throws("Child cert expired", - LLCertValidationExpirationException, - (*test_chain)[0], - test_store->validate, - VALIDATION_POLICY_TIME | VALIDATION_POLICY_TRUSTED, - test_chain, - validation_params); - - // test SSL KU - // validate basic trust for a chain containing child and intermediate. - test_chain = new LLBasicCertificateChain(NULL); - test_chain->add(new LLBasicCertificate(mX509ChildCert, &mValidationDate)); - test_chain->add(new LLBasicCertificate(mX509IntermediateCert, &mValidationDate)); - test_store->validate(VALIDATION_POLICY_SSL_KU | VALIDATION_POLICY_TRUSTED, - test_chain, validation_params); - - test_chain = new LLBasicCertificateChain(NULL); - test_chain->add(new LLBasicCertificate(mX509TestCert, &mValidationDate)); - - test_store = new LLBasicCertificateStore("mycertstore.pem"); - ensure_throws("Cert doesn't have ku", - LLCertKeyUsageValidationException, - (*test_chain)[0], - test_store->validate, - VALIDATION_POLICY_SSL_KU | VALIDATION_POLICY_TRUSTED, - test_chain, - validation_params); - - test_store->validate(0, test_chain, validation_params); - } + validation_params = LLSD::emptyMap(); + validation_params[CERT_VALIDATION_DATE] = child_info[CERT_VALID_FROM].asDate(); + + validation_params[CERT_VALIDATION_DATE] = LLDate(child_info[CERT_VALID_FROM].asDate().secondsSinceEpoch() - 1.0); + + // test not yet valid + ensure_throws("Child cert not yet valid" , + LLCertValidationExpirationException, + (*test_chain)[0], + test_store->validate, + VALIDATION_POLICY_TIME | VALIDATION_POLICY_TRUSTED, + test_chain, + validation_params); + validation_params = LLSD::emptyMap(); + validation_params[CERT_VALIDATION_DATE] = LLDate(child_info[CERT_VALID_TO].asDate().secondsSinceEpoch() + 1.0); + + // test cert expired + ensure_throws("Child cert expired", + LLCertValidationExpirationException, + (*test_chain)[0], + test_store->validate, + VALIDATION_POLICY_TIME | VALIDATION_POLICY_TRUSTED, + test_chain, + validation_params); + + // test SSL KU + // validate basic trust for a chain containing child and intermediate. + test_chain = new LLBasicCertificateChain(NULL); + test_chain->add(new LLBasicCertificate(mX509ChildCert, &mValidationDate)); + test_chain->add(new LLBasicCertificate(mX509IntermediateCert, &mValidationDate)); + test_store->validate(VALIDATION_POLICY_SSL_KU | VALIDATION_POLICY_TRUSTED, + test_chain, validation_params); + + test_chain = new LLBasicCertificateChain(NULL); + test_chain->add(new LLBasicCertificate(mX509TestCert, &mValidationDate)); + + test_store = new LLBasicCertificateStore("mycertstore.pem"); + ensure_throws("Cert doesn't have ku", + LLCertKeyUsageValidationException, + (*test_chain)[0], + test_store->validate, + VALIDATION_POLICY_SSL_KU | VALIDATION_POLICY_TRUSTED, + test_chain, + validation_params); + + test_store->validate(0, test_chain, validation_params); + } }; diff --git a/indra/newview/tests/llsky_stub.cpp b/indra/newview/tests/llsky_stub.cpp index 241d740635..8faca2665a 100644 --- a/indra/newview/tests/llsky_stub.cpp +++ b/indra/newview/tests/llsky_stub.cpp @@ -5,21 +5,21 @@ * $LicenseInfo:firstyear=2009&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$ */ @@ -27,8 +27,8 @@ class LLSky { public: - void setOverrideSun(BOOL override); - void setSunDirection(const LLVector3 &sun_direction, const LLVector3 &sun_ang_velocity); + void setOverrideSun(BOOL override); + void setSunDirection(const LLVector3 &sun_direction, const LLVector3 &sun_ang_velocity); }; void LLSky::setOverrideSun(BOOL override) {} diff --git a/indra/newview/tests/llslurl_test.cpp b/indra/newview/tests/llslurl_test.cpp index 8d21b6ed69..92ba68a073 100644 --- a/indra/newview/tests/llslurl_test.cpp +++ b/indra/newview/tests/llslurl_test.cpp @@ -46,12 +46,12 @@ static const char * const TEST_FILENAME("llslurl_test.xml"); class LLTrans { public: - static std::string getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args, bool def_string = false); + static std::string getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args, bool def_string = false); }; std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args, bool def_string) { - return std::string(); + return std::string(); } //---------------------------------------------------------------------------- @@ -73,268 +73,268 @@ std::string gLoginPage; std::string gCurrentGrid; std::string LLControlGroup::getString(const std::string& name) { - if (name == "CmdLineGridChoice") - return gCmdLineGridChoice; - else if (name == "CmdLineHelperURI") - return gCmdLineHelperURI; - else if (name == "LoginPage") - return gLoginPage; - else if (name == "CurrentGrid") - return gCurrentGrid; - return ""; + if (name == "CmdLineGridChoice") + return gCmdLineGridChoice; + else if (name == "CmdLineHelperURI") + return gCmdLineHelperURI; + else if (name == "LoginPage") + return gLoginPage; + else if (name == "CurrentGrid") + return gCurrentGrid; + return ""; } LLSD LLControlGroup::getLLSD(const std::string& name) { - if (name == "CmdLineLoginURI") - { - if(!gCmdLineLoginURI.empty()) - { - return LLSD(gCmdLineLoginURI); - } - } - return LLSD(); + if (name == "CmdLineLoginURI") + { + if(!gCmdLineLoginURI.empty()) + { + return LLSD(gCmdLineLoginURI); + } + } + return LLSD(); } LLPointer<LLControlVariable> LLControlGroup::getControl(const std::string& name) { - ctrl_name_table_t::iterator iter = mNameTable.find(name); - return iter == mNameTable.end() ? LLPointer<LLControlVariable>() : iter->second; + ctrl_name_table_t::iterator iter = mNameTable.find(name); + return iter == mNameTable.end() ? LLPointer<LLControlVariable>() : iter->second; } LLControlGroup gSavedSettings("test"); const char *gSampleGridFile = - "<?xml version=\"1.0\"?>" - "<llsd>" - " <map>" - " <key>foo.bar.com</key>" - " <map>" - " <key>helper_uri</key><string>https://foobar/helpers/</string>" - " <key>label</key><string>Foobar Grid</string>" - " <key>login_page</key><string>foobar/loginpage</string>" - " <key>login_uri</key>" - " <array>" - " <string>foobar/loginuri</string>" - " </array>" - " <key>keyname</key><string>foo.bar.com</string>" - " <key>credential_type</key><string>agent</string>" - " <key>grid_login_id</key><string>FooBar</string>" - " </map>" - " <key>my.grid.com</key>" - " <map>" - " <key>helper_uri</key><string>https://mygrid/helpers/</string>" - " <key>label</key><string>My Grid</string>" - " <key>login_page</key><string>mygrid/loginpage</string>" - " <key>login_uri</key>" - " <array>" - " <string>mygrid/loginuri</string>" - " </array>" - " <key>keyname</key><string>my.grid.com</string>" - " <key>credential_type</key><string>agent</string>" - " <key>grid_login_id</key><string>MyGrid</string>" - " </map>" - " </map>" - "</llsd>" - ; + "<?xml version=\"1.0\"?>" + "<llsd>" + " <map>" + " <key>foo.bar.com</key>" + " <map>" + " <key>helper_uri</key><string>https://foobar/helpers/</string>" + " <key>label</key><string>Foobar Grid</string>" + " <key>login_page</key><string>foobar/loginpage</string>" + " <key>login_uri</key>" + " <array>" + " <string>foobar/loginuri</string>" + " </array>" + " <key>keyname</key><string>foo.bar.com</string>" + " <key>credential_type</key><string>agent</string>" + " <key>grid_login_id</key><string>FooBar</string>" + " </map>" + " <key>my.grid.com</key>" + " <map>" + " <key>helper_uri</key><string>https://mygrid/helpers/</string>" + " <key>label</key><string>My Grid</string>" + " <key>login_page</key><string>mygrid/loginpage</string>" + " <key>login_uri</key>" + " <array>" + " <string>mygrid/loginuri</string>" + " </array>" + " <key>keyname</key><string>my.grid.com</string>" + " <key>credential_type</key><string>agent</string>" + " <key>grid_login_id</key><string>MyGrid</string>" + " </map>" + " </map>" + "</llsd>" + ; // ------------------------------------------------------------------------------------------- // TUT // ------------------------------------------------------------------------------------------- namespace tut { - // Test wrapper declaration : wrapping nothing for the moment - struct slurlTest - { - slurlTest() - { - LLGridManager::getInstance()->initialize(std::string("")); - } - ~slurlTest() - { - } - }; - - // Tut templating thingamagic: test group, object and test instance - typedef test_group<slurlTest> slurlTestFactory; - typedef slurlTestFactory::object slurlTestObject; - tut::slurlTestFactory tut_test("LLSlurl"); - - // --------------------------------------------------------------------------------------- - // Test functions - // --------------------------------------------------------------------------------------- - // construction from slurl string - template<> template<> - void slurlTestObject::test<1>() - { - llofstream gridfile(TEST_FILENAME); - gridfile << gSampleGridFile; - gridfile.close(); - - LLGridManager::getInstance()->initialize(TEST_FILENAME); - - LLGridManager::getInstance()->setGridChoice("util.agni.lindenlab.com"); - - LLSLURL slurl = LLSLURL(""); - ensure_equals("null slurl", (int)slurl.getType(), LLSLURL::LAST_LOCATION); - - slurl = LLSLURL("http://slurl.com/secondlife/myregion"); - ensure_equals("slurl.com slurl, region only - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("slurl.com slurl, region only", slurl.getSLURLString(), - "http://maps.secondlife.com/secondlife/myregion/128/128/0"); - - slurl = LLSLURL("http://maps.secondlife.com/secondlife/myregion/1/2/3"); - ensure_equals("maps.secondlife.com slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("maps.secondlife.com slurl, region + coords", slurl.getSLURLString(), - "http://maps.secondlife.com/secondlife/myregion/1/2/3"); - - slurl = LLSLURL("secondlife://"); - ensure_equals("secondlife: slurl, empty - type", slurl.getType(), LLSLURL::EMPTY); - - slurl = LLSLURL("secondlife:///"); - ensure_equals("secondlife: slurl, root - type", slurl.getType(), LLSLURL::EMPTY); - - slurl = LLSLURL("secondlife://myregion"); - ensure_equals("secondlife: slurl, region only - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("secondlife: slurl, region only", slurl.getSLURLString(), - "http://maps.secondlife.com/secondlife/myregion/128/128/0"); - - slurl = LLSLURL("secondlife://myregion/1/2/3"); - ensure_equals("secondlife: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("secondlife slurl, region + coords", slurl.getSLURLString(), - "http://maps.secondlife.com/secondlife/myregion/1/2/3"); - - slurl = LLSLURL("/myregion"); - ensure_equals("/region slurl, region- type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("/region slurl, region ", slurl.getSLURLString(), - "http://maps.secondlife.com/secondlife/myregion/128/128/0"); - - slurl = LLSLURL("/myregion/1/2/3"); - ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("/ slurl, region + coords", slurl.getSLURLString(), - "http://maps.secondlife.com/secondlife/myregion/1/2/3"); - - slurl = LLSLURL("my region/1/2/3"); - ensure_equals(" slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals(" slurl, region + coords", slurl.getSLURLString(), - "http://maps.secondlife.com/secondlife/my%20region/1/2/3"); - - LLGridManager::getInstance()->setGridChoice("my.grid.com"); - slurl = LLSLURL("https://my.grid.com/region/my%20region/1/2/3"); - ensure_equals("grid slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("grid slurl, region + coords", slurl.getSLURLString(), - "https://my.grid.com/region/my%20region/1/2/3"); - - slurl = LLSLURL("https://my.grid.com/region/my region"); - ensure_equals("grid slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("grid slurl, region + coords", slurl.getSLURLString(), - "https://my.grid.com/region/my%20region/128/128/0"); - - LLGridManager::getInstance()->setGridChoice("foo.bar.com"); - slurl = LLSLURL("/myregion/1/2/3"); - ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("/ slurl, region + coords", slurl.getSLURLString(), - "https://foo.bar.com/region/myregion/1/2/3"); - - slurl = LLSLURL("myregion/1/2/3"); - ensure_equals(": slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals(" slurl, region + coords", slurl.getSLURLString(), - "https://foo.bar.com/region/myregion/1/2/3"); - - slurl = LLSLURL(LLSLURL::SIM_LOCATION_HOME); - ensure_equals("home", slurl.getType(), LLSLURL::HOME_LOCATION); - - slurl = LLSLURL(LLSLURL::SIM_LOCATION_LAST); - ensure_equals("last", slurl.getType(), LLSLURL::LAST_LOCATION); - - slurl = LLSLURL("secondlife:///app/foo/bar?12345"); - ensure_equals("app", slurl.getType(), LLSLURL::APP); - ensure_equals("appcmd", slurl.getAppCmd(), "foo"); - ensure_equals("apppath", slurl.getAppPath().size(), 1); - ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar"); - ensure_equals("appquery", slurl.getAppQuery(), "12345"); - ensure_equals("grid1", slurl.getGrid(), "FooBar"); - - slurl = LLSLURL("secondlife://Aditi/app/foo/bar?12345"); - ensure_equals("app", slurl.getType(), LLSLURL::APP); - ensure_equals("appcmd", slurl.getAppCmd(), "foo"); - ensure_equals("apppath", slurl.getAppPath().size(), 1); - ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar"); - ensure_equals("appquery", slurl.getAppQuery(), "12345"); - ensure_equals("grid2", slurl.getGrid(), "Aditi"); - - LLGridManager::getInstance()->setGridChoice("foo.bar.com"); - slurl = LLSLURL("secondlife:///secondlife/myregion/1/2/3"); - ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("location", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("region" , "myregion", slurl.getRegion()); - ensure_equals("grid3", slurl.getGrid(), "util.agni.lindenlab.com"); - - slurl = LLSLURL("secondlife://Aditi/secondlife/myregion/1/2/3"); - ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("location", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("region" , "myregion", slurl.getRegion()); - ensure_equals("grid4", slurl.getGrid(), "Aditi" ); - - LLGridManager::getInstance()->setGridChoice("my.grid.com"); - slurl = LLSLURL("https://my.grid.com/app/foo/bar?12345"); - ensure_equals("app", slurl.getType(), LLSLURL::APP); - ensure_equals("appcmd", slurl.getAppCmd(), "foo"); - ensure_equals("apppath", slurl.getAppPath().size(), 1); - ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar"); - ensure_equals("appquery", slurl.getAppQuery(), "12345"); - - } - - // construction from grid/region/vector combos - template<> template<> - void slurlTestObject::test<2>() - { - llofstream gridfile(TEST_FILENAME); - gridfile << gSampleGridFile; - gridfile.close(); - - LLGridManager::getInstance()->initialize(TEST_FILENAME); - - LLSLURL slurl = LLSLURL("my.grid.com", "my region"); - ensure_equals("grid/region - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals("grid/region", slurl.getSLURLString(), - "https://my.grid.com/region/my%20region/128/128/0"); - - slurl = LLSLURL("my.grid.com", "my region", LLVector3(1,2,3)); - ensure_equals("grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals(" grid/region/vector", slurl.getSLURLString(), - "https://my.grid.com/region/my%20region/1/2/3"); - - LLGridManager::getInstance()->setGridChoice("util.agni.lindenlab.com"); - slurl = LLSLURL("my region", LLVector3(1,2,3)); - ensure_equals("default grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals(" default grid/region/vector", slurl.getSLURLString(), - "http://maps.secondlife.com/secondlife/my%20region/1/2/3"); - - LLGridManager::getInstance()->setGridChoice("MyGrid"); - slurl = LLSLURL("my region", LLVector3(1,2,3)); - ensure_equals("default grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION); - ensure_equals(" default grid/region/vector", slurl.getSLURLString(), - "https://my.grid.com/region/my%20region/1/2/3"); - - } - // Accessors - template<> template<> - void slurlTestObject::test<3>() - { - llofstream gridfile(TEST_FILENAME); - gridfile << gSampleGridFile; - gridfile.close(); - - LLGridManager::getInstance()->initialize(TEST_FILENAME); - - LLGridManager::getInstance()->setGridChoice("my.grid.com"); - LLSLURL slurl = LLSLURL("https://my.grid.com/region/my%20region/1/2/3"); - ensure_equals("login string", slurl.getLoginString(), "uri:my region&1&2&3"); - ensure_equals("location string", slurl.getLocationString(), "my region/1/2/3"); - ensure_equals("grid", slurl.getGrid(), "my.grid.com"); - ensure_equals("region", slurl.getRegion(), "my region"); - ensure_equals("position", slurl.getPosition(), LLVector3(1, 2, 3)); - - } + // Test wrapper declaration : wrapping nothing for the moment + struct slurlTest + { + slurlTest() + { + LLGridManager::getInstance()->initialize(std::string("")); + } + ~slurlTest() + { + } + }; + + // Tut templating thingamagic: test group, object and test instance + typedef test_group<slurlTest> slurlTestFactory; + typedef slurlTestFactory::object slurlTestObject; + tut::slurlTestFactory tut_test("LLSlurl"); + + // --------------------------------------------------------------------------------------- + // Test functions + // --------------------------------------------------------------------------------------- + // construction from slurl string + template<> template<> + void slurlTestObject::test<1>() + { + llofstream gridfile(TEST_FILENAME); + gridfile << gSampleGridFile; + gridfile.close(); + + LLGridManager::getInstance()->initialize(TEST_FILENAME); + + LLGridManager::getInstance()->setGridChoice("util.agni.lindenlab.com"); + + LLSLURL slurl = LLSLURL(""); + ensure_equals("null slurl", (int)slurl.getType(), LLSLURL::LAST_LOCATION); + + slurl = LLSLURL("http://slurl.com/secondlife/myregion"); + ensure_equals("slurl.com slurl, region only - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("slurl.com slurl, region only", slurl.getSLURLString(), + "http://maps.secondlife.com/secondlife/myregion/128/128/0"); + + slurl = LLSLURL("http://maps.secondlife.com/secondlife/myregion/1/2/3"); + ensure_equals("maps.secondlife.com slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("maps.secondlife.com slurl, region + coords", slurl.getSLURLString(), + "http://maps.secondlife.com/secondlife/myregion/1/2/3"); + + slurl = LLSLURL("secondlife://"); + ensure_equals("secondlife: slurl, empty - type", slurl.getType(), LLSLURL::EMPTY); + + slurl = LLSLURL("secondlife:///"); + ensure_equals("secondlife: slurl, root - type", slurl.getType(), LLSLURL::EMPTY); + + slurl = LLSLURL("secondlife://myregion"); + ensure_equals("secondlife: slurl, region only - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("secondlife: slurl, region only", slurl.getSLURLString(), + "http://maps.secondlife.com/secondlife/myregion/128/128/0"); + + slurl = LLSLURL("secondlife://myregion/1/2/3"); + ensure_equals("secondlife: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("secondlife slurl, region + coords", slurl.getSLURLString(), + "http://maps.secondlife.com/secondlife/myregion/1/2/3"); + + slurl = LLSLURL("/myregion"); + ensure_equals("/region slurl, region- type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("/region slurl, region ", slurl.getSLURLString(), + "http://maps.secondlife.com/secondlife/myregion/128/128/0"); + + slurl = LLSLURL("/myregion/1/2/3"); + ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("/ slurl, region + coords", slurl.getSLURLString(), + "http://maps.secondlife.com/secondlife/myregion/1/2/3"); + + slurl = LLSLURL("my region/1/2/3"); + ensure_equals(" slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals(" slurl, region + coords", slurl.getSLURLString(), + "http://maps.secondlife.com/secondlife/my%20region/1/2/3"); + + LLGridManager::getInstance()->setGridChoice("my.grid.com"); + slurl = LLSLURL("https://my.grid.com/region/my%20region/1/2/3"); + ensure_equals("grid slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("grid slurl, region + coords", slurl.getSLURLString(), + "https://my.grid.com/region/my%20region/1/2/3"); + + slurl = LLSLURL("https://my.grid.com/region/my region"); + ensure_equals("grid slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("grid slurl, region + coords", slurl.getSLURLString(), + "https://my.grid.com/region/my%20region/128/128/0"); + + LLGridManager::getInstance()->setGridChoice("foo.bar.com"); + slurl = LLSLURL("/myregion/1/2/3"); + ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("/ slurl, region + coords", slurl.getSLURLString(), + "https://foo.bar.com/region/myregion/1/2/3"); + + slurl = LLSLURL("myregion/1/2/3"); + ensure_equals(": slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals(" slurl, region + coords", slurl.getSLURLString(), + "https://foo.bar.com/region/myregion/1/2/3"); + + slurl = LLSLURL(LLSLURL::SIM_LOCATION_HOME); + ensure_equals("home", slurl.getType(), LLSLURL::HOME_LOCATION); + + slurl = LLSLURL(LLSLURL::SIM_LOCATION_LAST); + ensure_equals("last", slurl.getType(), LLSLURL::LAST_LOCATION); + + slurl = LLSLURL("secondlife:///app/foo/bar?12345"); + ensure_equals("app", slurl.getType(), LLSLURL::APP); + ensure_equals("appcmd", slurl.getAppCmd(), "foo"); + ensure_equals("apppath", slurl.getAppPath().size(), 1); + ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar"); + ensure_equals("appquery", slurl.getAppQuery(), "12345"); + ensure_equals("grid1", slurl.getGrid(), "FooBar"); + + slurl = LLSLURL("secondlife://Aditi/app/foo/bar?12345"); + ensure_equals("app", slurl.getType(), LLSLURL::APP); + ensure_equals("appcmd", slurl.getAppCmd(), "foo"); + ensure_equals("apppath", slurl.getAppPath().size(), 1); + ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar"); + ensure_equals("appquery", slurl.getAppQuery(), "12345"); + ensure_equals("grid2", slurl.getGrid(), "Aditi"); + + LLGridManager::getInstance()->setGridChoice("foo.bar.com"); + slurl = LLSLURL("secondlife:///secondlife/myregion/1/2/3"); + ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("location", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("region" , "myregion", slurl.getRegion()); + ensure_equals("grid3", slurl.getGrid(), "util.agni.lindenlab.com"); + + slurl = LLSLURL("secondlife://Aditi/secondlife/myregion/1/2/3"); + ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("location", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("region" , "myregion", slurl.getRegion()); + ensure_equals("grid4", slurl.getGrid(), "Aditi" ); + + LLGridManager::getInstance()->setGridChoice("my.grid.com"); + slurl = LLSLURL("https://my.grid.com/app/foo/bar?12345"); + ensure_equals("app", slurl.getType(), LLSLURL::APP); + ensure_equals("appcmd", slurl.getAppCmd(), "foo"); + ensure_equals("apppath", slurl.getAppPath().size(), 1); + ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar"); + ensure_equals("appquery", slurl.getAppQuery(), "12345"); + + } + + // construction from grid/region/vector combos + template<> template<> + void slurlTestObject::test<2>() + { + llofstream gridfile(TEST_FILENAME); + gridfile << gSampleGridFile; + gridfile.close(); + + LLGridManager::getInstance()->initialize(TEST_FILENAME); + + LLSLURL slurl = LLSLURL("my.grid.com", "my region"); + ensure_equals("grid/region - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals("grid/region", slurl.getSLURLString(), + "https://my.grid.com/region/my%20region/128/128/0"); + + slurl = LLSLURL("my.grid.com", "my region", LLVector3(1,2,3)); + ensure_equals("grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals(" grid/region/vector", slurl.getSLURLString(), + "https://my.grid.com/region/my%20region/1/2/3"); + + LLGridManager::getInstance()->setGridChoice("util.agni.lindenlab.com"); + slurl = LLSLURL("my region", LLVector3(1,2,3)); + ensure_equals("default grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals(" default grid/region/vector", slurl.getSLURLString(), + "http://maps.secondlife.com/secondlife/my%20region/1/2/3"); + + LLGridManager::getInstance()->setGridChoice("MyGrid"); + slurl = LLSLURL("my region", LLVector3(1,2,3)); + ensure_equals("default grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION); + ensure_equals(" default grid/region/vector", slurl.getSLURLString(), + "https://my.grid.com/region/my%20region/1/2/3"); + + } + // Accessors + template<> template<> + void slurlTestObject::test<3>() + { + llofstream gridfile(TEST_FILENAME); + gridfile << gSampleGridFile; + gridfile.close(); + + LLGridManager::getInstance()->initialize(TEST_FILENAME); + + LLGridManager::getInstance()->setGridChoice("my.grid.com"); + LLSLURL slurl = LLSLURL("https://my.grid.com/region/my%20region/1/2/3"); + ensure_equals("login string", slurl.getLoginString(), "uri:my region&1&2&3"); + ensure_equals("location string", slurl.getLocationString(), "my region/1/2/3"); + ensure_equals("grid", slurl.getGrid(), "my.grid.com"); + ensure_equals("region", slurl.getRegion(), "my region"); + ensure_equals("position", slurl.getPosition(), LLVector3(1, 2, 3)); + + } } diff --git a/indra/newview/tests/lltextureinfo_test.cpp b/indra/newview/tests/lltextureinfo_test.cpp index 73ace1de37..d491ce0f65 100644 --- a/indra/newview/tests/lltextureinfo_test.cpp +++ b/indra/newview/tests/lltextureinfo_test.cpp @@ -1,4 +1,4 @@ -/** +/** * @file llwtextureinfo_test.cpp * @author Si & Gabriel * @date 2009-03-30 @@ -6,21 +6,21 @@ * $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$ */ @@ -37,7 +37,7 @@ // ------------------------------------------------------------------------------------------- // Stubbing: Declarations required to link and run the class being tested -// Notes: +// Notes: // * Add here stubbed implementation of the few classes and methods used in the class to be tested // * Add as little as possible (let the link errors guide you) // * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code) @@ -53,226 +53,226 @@ namespace tut { - // Test wrapper declarations - struct textureinfo_test - { - // Constructor and destructor of the test wrapper - textureinfo_test() - { - } - ~textureinfo_test() - { - } - }; - - // Tut templating thingamagic: test group, object and test instance - typedef test_group<textureinfo_test> textureinfo_t; - typedef textureinfo_t::object textureinfo_object_t; - tut::textureinfo_t tut_textureinfo("LLTectureInfo"); - - - // --------------------------------------------------------------------------------------- - // Test functions - // Notes: - // * Test as many as you possibly can without requiring a full blown simulation of everything - // * The tests are executed in sequence so the test instance state may change between calls - // * Remember that you cannot test private methods with tut - // --------------------------------------------------------------------------------------- - - // --------------------------------------------------------------------------------------- - // Test the LLTextureInfo - // --------------------------------------------------------------------------------------- - - - // Test instantiation - template<> template<> - void textureinfo_object_t::test<1>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - ensure("have we crashed?", true); - } - - // Check lltextureinfo does not contain UUIDs we haven't added - template<> template<> - void textureinfo_object_t::test<2>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - - LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1"); - ensure(!tex_info.has(nonExistant)); - } - - // Check we can add a request time for a texture - template<> template<> - void textureinfo_object_t::test<3>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - - LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3"); - tex_info.setRequestStartTime(id, 200); - - ensure_equals(tex_info.getRequestStartTime(id), 200); - } - - // Check time for non-existant texture - template<> template<> - void textureinfo_object_t::test<4>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - - LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1"); - ensure_equals(tex_info.getRequestStartTime(nonExistant), 0); - } - - // Check download complete time for non existant texture - template<> template<> - void textureinfo_object_t::test<5>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - - LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1"); - ensure_equals(tex_info.getRequestCompleteTime(nonExistant), 0); - } - - // requested size is passed in correctly - template<> template<> - void textureinfo_object_t::test<6>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - - LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3"); - tex_info.setRequestSize(id, 600); - - ensure_equals(tex_info.getRequestSize(id), 600); - } - - // transport type is recorded correctly (http) - template<> template<> - void textureinfo_object_t::test<7>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - - LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3"); - tex_info.setRequestType(id, LLTextureInfoDetails::REQUEST_TYPE_HTTP); - - ensure_equals(tex_info.getRequestType(id), LLTextureInfoDetails::REQUEST_TYPE_HTTP); - } - - // transport type is recorded correctly (udp) - template<> template<> - void textureinfo_object_t::test<8>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - - LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3"); - tex_info.setRequestType(id, LLTextureInfoDetails::REQUEST_TYPE_UDP); - - ensure_equals(tex_info.getRequestType(id), LLTextureInfoDetails::REQUEST_TYPE_UDP); - } - - // request offset is recorded correctly - template<> template<> - void textureinfo_object_t::test<9>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - - LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3"); - tex_info.setRequestOffset(id, 1234); - - ensure_equals(tex_info.getRequestOffset(id), 1234); - } - - // ask for averages gives us correct figure - template<> template<> - void textureinfo_object_t::test<10>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - - S32 requestStartTimeOne = 200; - S32 requestEndTimeOne = 400; - S32 requestSizeOne = 1024; - S32 requestSizeOneBits = requestSizeOne * 8; - LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3"); - tex_info.setRequestStartTime(id1, requestStartTimeOne); - tex_info.setRequestSize(id1, requestSizeOne); - tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP); - tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne); - - U32 requestStartTimeTwo = 100; - U32 requestEndTimeTwo = 500; - U32 requestSizeTwo = 2048; - S32 requestSizeTwoBits = requestSizeTwo * 8; - LLUUID id2("10e65d70-46fd-429f-841a-bf698e9424d4"); - tex_info.setRequestStartTime(id2, requestStartTimeTwo); - tex_info.setRequestSize(id2, requestSizeTwo); - tex_info.setRequestType(id2, LLTextureInfoDetails::REQUEST_TYPE_HTTP); - tex_info.setRequestCompleteTimeAndLog(id2, requestEndTimeTwo); - - S32 averageBitRate = ((requestSizeOneBits/(requestEndTimeOne - requestStartTimeOne)) + - (requestSizeTwoBits/(requestEndTimeTwo - requestStartTimeTwo))) / 2; - - S32 totalBytes = requestSizeOne + requestSizeTwo; - - LLSD results = tex_info.getAverages(); - ensure_equals("is average bits per second correct", results["bits_per_second"].asInteger(), averageBitRate); - ensure_equals("is total bytes is correct", results["bytes_downloaded"].asInteger(), totalBytes); - ensure_equals("is transport correct", results["transport"].asString(), std::string("HTTP")); - } - - // make sure averages cleared when reset is called - template<> template<> - void textureinfo_object_t::test<11>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - - S32 requestStartTimeOne = 200; - S32 requestEndTimeOne = 400; - S32 requestSizeOne = 1024; - LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3"); - tex_info.setRequestStartTime(id1, requestStartTimeOne); - tex_info.setRequestSize(id1, requestSizeOne); - tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP); - tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne); - - tex_info.getAverages(); - tex_info.reset(); - LLSD results = tex_info.getAverages(); - ensure_equals("is average bits per second correct", results["bits_per_second"].asInteger(), 0); - ensure_equals("is total bytes is correct", results["bytes_downloaded"].asInteger(), 0); - ensure_equals("is transport correct", results["transport"].asString(), std::string("NONE")); - } - - // make sure map item removed when expired - template<> template<> - void textureinfo_object_t::test<12>() - { - LLTextureInfo tex_info; - tex_info.setUpLogging(true, true); - - S32 requestStartTimeOne = 200; - S32 requestEndTimeOne = 400; - S32 requestSizeOne = 1024; - LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3"); - tex_info.setRequestStartTime(id1, requestStartTimeOne); - tex_info.setRequestSize(id1, requestSizeOne); - tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP); - - ensure_equals("map item created", tex_info.getTextureInfoMapSize(), 1); - - tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne); - - ensure_equals("map item removed when consumed", tex_info.getTextureInfoMapSize(), 0); - } + // Test wrapper declarations + struct textureinfo_test + { + // Constructor and destructor of the test wrapper + textureinfo_test() + { + } + ~textureinfo_test() + { + } + }; + + // Tut templating thingamagic: test group, object and test instance + typedef test_group<textureinfo_test> textureinfo_t; + typedef textureinfo_t::object textureinfo_object_t; + tut::textureinfo_t tut_textureinfo("LLTectureInfo"); + + + // --------------------------------------------------------------------------------------- + // Test functions + // Notes: + // * Test as many as you possibly can without requiring a full blown simulation of everything + // * The tests are executed in sequence so the test instance state may change between calls + // * Remember that you cannot test private methods with tut + // --------------------------------------------------------------------------------------- + + // --------------------------------------------------------------------------------------- + // Test the LLTextureInfo + // --------------------------------------------------------------------------------------- + + + // Test instantiation + template<> template<> + void textureinfo_object_t::test<1>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + ensure("have we crashed?", true); + } + + // Check lltextureinfo does not contain UUIDs we haven't added + template<> template<> + void textureinfo_object_t::test<2>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + + LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1"); + ensure(!tex_info.has(nonExistant)); + } + + // Check we can add a request time for a texture + template<> template<> + void textureinfo_object_t::test<3>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + + LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3"); + tex_info.setRequestStartTime(id, 200); + + ensure_equals(tex_info.getRequestStartTime(id), 200); + } + + // Check time for non-existant texture + template<> template<> + void textureinfo_object_t::test<4>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + + LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1"); + ensure_equals(tex_info.getRequestStartTime(nonExistant), 0); + } + + // Check download complete time for non existant texture + template<> template<> + void textureinfo_object_t::test<5>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + + LLUUID nonExistant("3a0efa3b-84dc-4e17-9b8c-79ea028850c1"); + ensure_equals(tex_info.getRequestCompleteTime(nonExistant), 0); + } + + // requested size is passed in correctly + template<> template<> + void textureinfo_object_t::test<6>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + + LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3"); + tex_info.setRequestSize(id, 600); + + ensure_equals(tex_info.getRequestSize(id), 600); + } + + // transport type is recorded correctly (http) + template<> template<> + void textureinfo_object_t::test<7>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + + LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3"); + tex_info.setRequestType(id, LLTextureInfoDetails::REQUEST_TYPE_HTTP); + + ensure_equals(tex_info.getRequestType(id), LLTextureInfoDetails::REQUEST_TYPE_HTTP); + } + + // transport type is recorded correctly (udp) + template<> template<> + void textureinfo_object_t::test<8>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + + LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3"); + tex_info.setRequestType(id, LLTextureInfoDetails::REQUEST_TYPE_UDP); + + ensure_equals(tex_info.getRequestType(id), LLTextureInfoDetails::REQUEST_TYPE_UDP); + } + + // request offset is recorded correctly + template<> template<> + void textureinfo_object_t::test<9>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + + LLUUID id("10e65d70-46fd-429f-841a-bf698e9424d3"); + tex_info.setRequestOffset(id, 1234); + + ensure_equals(tex_info.getRequestOffset(id), 1234); + } + + // ask for averages gives us correct figure + template<> template<> + void textureinfo_object_t::test<10>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + + S32 requestStartTimeOne = 200; + S32 requestEndTimeOne = 400; + S32 requestSizeOne = 1024; + S32 requestSizeOneBits = requestSizeOne * 8; + LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3"); + tex_info.setRequestStartTime(id1, requestStartTimeOne); + tex_info.setRequestSize(id1, requestSizeOne); + tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP); + tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne); + + U32 requestStartTimeTwo = 100; + U32 requestEndTimeTwo = 500; + U32 requestSizeTwo = 2048; + S32 requestSizeTwoBits = requestSizeTwo * 8; + LLUUID id2("10e65d70-46fd-429f-841a-bf698e9424d4"); + tex_info.setRequestStartTime(id2, requestStartTimeTwo); + tex_info.setRequestSize(id2, requestSizeTwo); + tex_info.setRequestType(id2, LLTextureInfoDetails::REQUEST_TYPE_HTTP); + tex_info.setRequestCompleteTimeAndLog(id2, requestEndTimeTwo); + + S32 averageBitRate = ((requestSizeOneBits/(requestEndTimeOne - requestStartTimeOne)) + + (requestSizeTwoBits/(requestEndTimeTwo - requestStartTimeTwo))) / 2; + + S32 totalBytes = requestSizeOne + requestSizeTwo; + + LLSD results = tex_info.getAverages(); + ensure_equals("is average bits per second correct", results["bits_per_second"].asInteger(), averageBitRate); + ensure_equals("is total bytes is correct", results["bytes_downloaded"].asInteger(), totalBytes); + ensure_equals("is transport correct", results["transport"].asString(), std::string("HTTP")); + } + + // make sure averages cleared when reset is called + template<> template<> + void textureinfo_object_t::test<11>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + + S32 requestStartTimeOne = 200; + S32 requestEndTimeOne = 400; + S32 requestSizeOne = 1024; + LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3"); + tex_info.setRequestStartTime(id1, requestStartTimeOne); + tex_info.setRequestSize(id1, requestSizeOne); + tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP); + tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne); + + tex_info.getAverages(); + tex_info.reset(); + LLSD results = tex_info.getAverages(); + ensure_equals("is average bits per second correct", results["bits_per_second"].asInteger(), 0); + ensure_equals("is total bytes is correct", results["bytes_downloaded"].asInteger(), 0); + ensure_equals("is transport correct", results["transport"].asString(), std::string("NONE")); + } + + // make sure map item removed when expired + template<> template<> + void textureinfo_object_t::test<12>() + { + LLTextureInfo tex_info; + tex_info.setUpLogging(true, true); + + S32 requestStartTimeOne = 200; + S32 requestEndTimeOne = 400; + S32 requestSizeOne = 1024; + LLUUID id1("10e65d70-46fd-429f-841a-bf698e9424d3"); + tex_info.setRequestStartTime(id1, requestStartTimeOne); + tex_info.setRequestSize(id1, requestSizeOne); + tex_info.setRequestType(id1, LLTextureInfoDetails::REQUEST_TYPE_HTTP); + + ensure_equals("map item created", tex_info.getTextureInfoMapSize(), 1); + + tex_info.setRequestCompleteTimeAndLog(id1, requestEndTimeOne); + + ensure_equals("map item removed when consumed", tex_info.getTextureInfoMapSize(), 0); + } } diff --git a/indra/newview/tests/lltextureinfodetails_test.cpp b/indra/newview/tests/lltextureinfodetails_test.cpp index 31ec5f9d4e..58cab03c50 100644 --- a/indra/newview/tests/lltextureinfodetails_test.cpp +++ b/indra/newview/tests/lltextureinfodetails_test.cpp @@ -1,4 +1,4 @@ -/** +/** * @file llwtextureinfodetails_test.cpp * @author Si & Gabriel * @date 2009-03-30 @@ -6,21 +6,21 @@ * $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$ */ @@ -36,7 +36,7 @@ // ------------------------------------------------------------------------------------------- // Stubbing: Declarations required to link and run the class being tested -// Notes: +// Notes: // * Add here stubbed implementation of the few classes and methods used in the class to be tested // * Add as little as possible (let the link errors guide you) // * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code) @@ -52,41 +52,41 @@ namespace tut { - // Test wrapper declarations - struct textureinfodetails_test - { - // Constructor and destructor of the test wrapper - textureinfodetails_test() - { - } - ~textureinfodetails_test() - { - } - }; + // Test wrapper declarations + struct textureinfodetails_test + { + // Constructor and destructor of the test wrapper + textureinfodetails_test() + { + } + ~textureinfodetails_test() + { + } + }; + + // Tut templating thingamagic: test group, object and test instance + typedef test_group<textureinfodetails_test> textureinfodetails_t; + typedef textureinfodetails_t::object textureinfodetails_object_t; + tut::textureinfodetails_t tut_textureinfodetails("LLTextureInfoDetails"); - // Tut templating thingamagic: test group, object and test instance - typedef test_group<textureinfodetails_test> textureinfodetails_t; - typedef textureinfodetails_t::object textureinfodetails_object_t; - tut::textureinfodetails_t tut_textureinfodetails("LLTextureInfoDetails"); - - // --------------------------------------------------------------------------------------- - // Test functions - // Notes: - // * Test as many as you possibly can without requiring a full blown simulation of everything - // * The tests are executed in sequence so the test instance state may change between calls - // * Remember that you cannot test private methods with tut - // --------------------------------------------------------------------------------------- + // --------------------------------------------------------------------------------------- + // Test functions + // Notes: + // * Test as many as you possibly can without requiring a full blown simulation of everything + // * The tests are executed in sequence so the test instance state may change between calls + // * Remember that you cannot test private methods with tut + // --------------------------------------------------------------------------------------- - // --------------------------------------------------------------------------------------- - // Test the LLTextureInfo - // --------------------------------------------------------------------------------------- + // --------------------------------------------------------------------------------------- + // Test the LLTextureInfo + // --------------------------------------------------------------------------------------- - // Test instantiation - template<> template<> - void textureinfodetails_object_t::test<1>() - { - ensure("have we crashed?", true); - } + // Test instantiation + template<> template<> + void textureinfodetails_object_t::test<1>() + { + ensure("have we crashed?", true); + } } diff --git a/indra/newview/tests/lltexturestatsuploader_test.cpp b/indra/newview/tests/lltexturestatsuploader_test.cpp index 4438523022..782a4892b9 100644 --- a/indra/newview/tests/lltexturestatsuploader_test.cpp +++ b/indra/newview/tests/lltexturestatsuploader_test.cpp @@ -1,4 +1,4 @@ -/** +/** * @file lltexturestatsuploader_test.cpp * @author Si * @date 2009-05-27 @@ -6,21 +6,21 @@ * $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$ */ @@ -36,7 +36,7 @@ // ------------------------------------------------------------------------------------------- // Stubbing: Declarations required to link and run the class being tested -// Notes: +// Notes: // * Add here stubbed implementation of the few classes and methods used in the class to be tested // * Add as little as possible (let the link errors guide you) // * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code) @@ -51,16 +51,16 @@ static std::string most_recent_url; static LLSD most_recent_body; void LLHTTPClient::post( - const std::string& url, - const LLSD& body, - ResponderPtr, - const LLSD& headers, - const F32 timeout) + const std::string& url, + const LLSD& body, + ResponderPtr, + const LLSD& headers, + const F32 timeout) { - // set some sensor code - most_recent_url = url; - most_recent_body = body; - return; + // set some sensor code + most_recent_url = url; + most_recent_body = body; + return; } // End Stubbing @@ -72,79 +72,79 @@ void LLHTTPClient::post( namespace tut { - // Test wrapper declarations - struct texturestatsuploader_test - { - // Constructor and destructor of the test wrapper - texturestatsuploader_test() - { - most_recent_url = "some sort of default text that should never match anything the tests are expecting!"; - LLSD blank_llsd; - most_recent_body = blank_llsd; - } - ~texturestatsuploader_test() - { - } - }; - - // Tut templating thingamagic: test group, object and test instance - typedef test_group<texturestatsuploader_test> texturestatsuploader_t; - typedef texturestatsuploader_t::object texturestatsuploader_object_t; - tut::texturestatsuploader_t tut_texturestatsuploader("LLTextureStatsUploader"); - - - // --------------------------------------------------------------------------------------- - // Test functions - // Notes: - // * Test as many as you possibly can without requiring a full blown simulation of everything - // * The tests are executed in sequence so the test instance state may change between calls - // * Remember that you cannot test private methods with tut - // --------------------------------------------------------------------------------------- - - // --------------------------------------------------------------------------------------- - // Test the LLTextureInfo - // --------------------------------------------------------------------------------------- - - - // Test instantiation - template<> template<> - void texturestatsuploader_object_t::test<1>() - { - LLTextureStatsUploader tsu; - LL_INFOS() << &tsu << LL_ENDL; - ensure("have we crashed?", true); - } - - // does it call out to the provided url if we ask it to? - template<> template<> - void texturestatsuploader_object_t::test<2>() - { - LLTextureStatsUploader tsu; - std::string url = "http://blahblahblah"; - LLSD texture_stats; - tsu.uploadStatsToSimulator(url, texture_stats); - ensure_equals("did the right url get called?", most_recent_url, url); - ensure_equals("did the right body get sent?", most_recent_body, texture_stats); - } - - // does it not call out to the provided url if we send it an ungranted cap? - template<> template<> - void texturestatsuploader_object_t::test<3>() - { - LLTextureStatsUploader tsu; - - // this url left intentionally blank to mirror - // not getting a cap in the caller. - std::string url_for_ungranted_cap = ""; - - LLSD texture_stats; - std::string most_recent_url_before_test = most_recent_url; - tsu.uploadStatsToSimulator(url_for_ungranted_cap, texture_stats); - - ensure_equals("hopefully no url got called!", most_recent_url, most_recent_url_before_test); - } - - // does it call out if the data is empty? - // should it even do that? + // Test wrapper declarations + struct texturestatsuploader_test + { + // Constructor and destructor of the test wrapper + texturestatsuploader_test() + { + most_recent_url = "some sort of default text that should never match anything the tests are expecting!"; + LLSD blank_llsd; + most_recent_body = blank_llsd; + } + ~texturestatsuploader_test() + { + } + }; + + // Tut templating thingamagic: test group, object and test instance + typedef test_group<texturestatsuploader_test> texturestatsuploader_t; + typedef texturestatsuploader_t::object texturestatsuploader_object_t; + tut::texturestatsuploader_t tut_texturestatsuploader("LLTextureStatsUploader"); + + + // --------------------------------------------------------------------------------------- + // Test functions + // Notes: + // * Test as many as you possibly can without requiring a full blown simulation of everything + // * The tests are executed in sequence so the test instance state may change between calls + // * Remember that you cannot test private methods with tut + // --------------------------------------------------------------------------------------- + + // --------------------------------------------------------------------------------------- + // Test the LLTextureInfo + // --------------------------------------------------------------------------------------- + + + // Test instantiation + template<> template<> + void texturestatsuploader_object_t::test<1>() + { + LLTextureStatsUploader tsu; + LL_INFOS() << &tsu << LL_ENDL; + ensure("have we crashed?", true); + } + + // does it call out to the provided url if we ask it to? + template<> template<> + void texturestatsuploader_object_t::test<2>() + { + LLTextureStatsUploader tsu; + std::string url = "http://blahblahblah"; + LLSD texture_stats; + tsu.uploadStatsToSimulator(url, texture_stats); + ensure_equals("did the right url get called?", most_recent_url, url); + ensure_equals("did the right body get sent?", most_recent_body, texture_stats); + } + + // does it not call out to the provided url if we send it an ungranted cap? + template<> template<> + void texturestatsuploader_object_t::test<3>() + { + LLTextureStatsUploader tsu; + + // this url left intentionally blank to mirror + // not getting a cap in the caller. + std::string url_for_ungranted_cap = ""; + + LLSD texture_stats; + std::string most_recent_url_before_test = most_recent_url; + tsu.uploadStatsToSimulator(url_for_ungranted_cap, texture_stats); + + ensure_equals("hopefully no url got called!", most_recent_url, most_recent_url_before_test); + } + + // does it call out if the data is empty? + // should it even do that? } diff --git a/indra/newview/tests/llversioninfo_test.cpp b/indra/newview/tests/llversioninfo_test.cpp index 51a6f8f113..8049e67fc5 100644 --- a/indra/newview/tests/llversioninfo_test.cpp +++ b/indra/newview/tests/llversioninfo_test.cpp @@ -1,24 +1,24 @@ -/** +/** * @file llversioninfo_test.cpp * * $LicenseInfo:firstyear=2010&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$ */ @@ -40,82 +40,82 @@ namespace tut { struct versioninfo { - versioninfo() - : mResetChannel("Reset Channel") - { - std::ostringstream stream; - stream << LL_VIEWER_VERSION_MAJOR << "." - << LL_VIEWER_VERSION_MINOR << "." - << LL_VIEWER_VERSION_PATCH << "." - << LL_VIEWER_VERSION_BUILD; - mVersion = stream.str(); - stream.str(""); + versioninfo() + : mResetChannel("Reset Channel") + { + std::ostringstream stream; + stream << LL_VIEWER_VERSION_MAJOR << "." + << LL_VIEWER_VERSION_MINOR << "." + << LL_VIEWER_VERSION_PATCH << "." + << LL_VIEWER_VERSION_BUILD; + mVersion = stream.str(); + stream.str(""); - stream << LL_VIEWER_VERSION_MAJOR << "." - << LL_VIEWER_VERSION_MINOR << "." - << LL_VIEWER_VERSION_PATCH; - mShortVersion = stream.str(); - stream.str(""); + stream << LL_VIEWER_VERSION_MAJOR << "." + << LL_VIEWER_VERSION_MINOR << "." + << LL_VIEWER_VERSION_PATCH; + mShortVersion = stream.str(); + stream.str(""); - stream << ll_viewer_channel - << " " - << mVersion; - mVersionAndChannel = stream.str(); - stream.str(""); + stream << ll_viewer_channel + << " " + << mVersion; + mVersionAndChannel = stream.str(); + stream.str(""); - stream << mResetChannel - << " " - << mVersion; - mResetVersionAndChannel = stream.str(); - } - std::string mResetChannel; - std::string mVersion; - std::string mShortVersion; - std::string mVersionAndChannel; - std::string mResetVersionAndChannel; + stream << mResetChannel + << " " + << mVersion; + mResetVersionAndChannel = stream.str(); + } + std::string mResetChannel; + std::string mVersion; + std::string mShortVersion; + std::string mVersionAndChannel; + std::string mResetVersionAndChannel; }; - - typedef test_group<versioninfo> versioninfo_t; - typedef versioninfo_t::object versioninfo_object_t; - tut::versioninfo_t tut_versioninfo("LLVersionInfo"); - template<> template<> - void versioninfo_object_t::test<1>() - { - std::cout << "What we parsed from CMake: " << LL_VIEWER_VERSION_BUILD << std::endl; - std::cout << "What we get from llversioninfo: " << LLVersionInfo::instance().getBuild() << std::endl; - ensure_equals("Major version", - LLVersionInfo::instance().getMajor(), - LL_VIEWER_VERSION_MAJOR); - ensure_equals("Minor version", - LLVersionInfo::instance().getMinor(), - LL_VIEWER_VERSION_MINOR); - ensure_equals("Patch version", - LLVersionInfo::instance().getPatch(), - LL_VIEWER_VERSION_PATCH); - ensure_equals("Build version", - LLVersionInfo::instance().getBuild(), - LL_VIEWER_VERSION_BUILD); - ensure_equals("Channel version", - LLVersionInfo::instance().getChannel(), - ll_viewer_channel); - ensure_equals("Version String", - LLVersionInfo::instance().getVersion(), - mVersion); - ensure_equals("Short Version String", - LLVersionInfo::instance().getShortVersion(), - mShortVersion); - ensure_equals("Version and channel String", - LLVersionInfo::instance().getChannelAndVersion(), - mVersionAndChannel); + typedef test_group<versioninfo> versioninfo_t; + typedef versioninfo_t::object versioninfo_object_t; + tut::versioninfo_t tut_versioninfo("LLVersionInfo"); + + template<> template<> + void versioninfo_object_t::test<1>() + { + std::cout << "What we parsed from CMake: " << LL_VIEWER_VERSION_BUILD << std::endl; + std::cout << "What we get from llversioninfo: " << LLVersionInfo::instance().getBuild() << std::endl; + ensure_equals("Major version", + LLVersionInfo::instance().getMajor(), + LL_VIEWER_VERSION_MAJOR); + ensure_equals("Minor version", + LLVersionInfo::instance().getMinor(), + LL_VIEWER_VERSION_MINOR); + ensure_equals("Patch version", + LLVersionInfo::instance().getPatch(), + LL_VIEWER_VERSION_PATCH); + ensure_equals("Build version", + LLVersionInfo::instance().getBuild(), + LL_VIEWER_VERSION_BUILD); + ensure_equals("Channel version", + LLVersionInfo::instance().getChannel(), + ll_viewer_channel); + ensure_equals("Version String", + LLVersionInfo::instance().getVersion(), + mVersion); + ensure_equals("Short Version String", + LLVersionInfo::instance().getShortVersion(), + mShortVersion); + ensure_equals("Version and channel String", + LLVersionInfo::instance().getChannelAndVersion(), + mVersionAndChannel); - LLVersionInfo::instance().resetChannel(mResetChannel); - ensure_equals("Reset channel version", - LLVersionInfo::instance().getChannel(), - mResetChannel); + LLVersionInfo::instance().resetChannel(mResetChannel); + ensure_equals("Reset channel version", + LLVersionInfo::instance().getChannel(), + mResetChannel); - ensure_equals("Reset Version and channel String", - LLVersionInfo::instance().getChannelAndVersion(), - mResetVersionAndChannel); - } + ensure_equals("Reset Version and channel String", + LLVersionInfo::instance().getChannelAndVersion(), + mResetVersionAndChannel); + } } diff --git a/indra/newview/tests/llviewerassetstats_test.cpp b/indra/newview/tests/llviewerassetstats_test.cpp index e2e7f09c3b..278de5f31c 100644 --- a/indra/newview/tests/llviewerassetstats_test.cpp +++ b/indra/newview/tests/llviewerassetstats_test.cpp @@ -1,4 +1,4 @@ -/** +/** * @file llviewerassetstats_tut.cpp * @date 2010-10-28 * @brief Test cases for some of newview/llviewerassetstats.cpp @@ -6,21 +6,21 @@ * $LicenseInfo:firstyear=2010&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$ */ @@ -40,88 +40,88 @@ namespace LLStatViewer { - LLTrace::SampleStatHandle<> FPS_SAMPLE("fpssample"); + LLTrace::SampleStatHandle<> FPS_SAMPLE("fpssample"); } void LLVOAvatar::getNearbyRezzedStats(std::vector<S32>& counts) { - counts.resize(3); - counts[0] = 0; - counts[1] = 0; - counts[2] = 1; + counts.resize(3); + counts[0] = 0; + counts[1] = 0; + counts[2] = 1; } // static std::string LLVOAvatar::rezStatusToString(S32 rez_status) { - if (rez_status==0) return "cloud"; - if (rez_status==1) return "gray"; - if (rez_status==2) return "textured"; - return "unknown"; + if (rez_status==0) return "cloud"; + if (rez_status==1) return "gray"; + if (rez_status==2) return "textured"; + return "unknown"; } // static LLViewerStats::StatsAccumulator& LLViewerStats::PhaseMap::getPhaseStats(const std::string& phase_name) { - static LLViewerStats::StatsAccumulator junk; - return junk; + static LLViewerStats::StatsAccumulator junk; + return junk; } -static const char * all_keys[] = +static const char * all_keys[] = { - "duration", - "fps", - "get_other_http", - "get_other_udp", - "get_texture_temp_http", - "get_texture_temp_udp", - "get_texture_non_temp_http", - "get_texture_non_temp_udp", - "get_wearable_http", - "get_wearable_udp", - "get_sound_http", - "get_sound_udp", - "get_gesture_http", - "get_gesture_udp" + "duration", + "fps", + "get_other_http", + "get_other_udp", + "get_texture_temp_http", + "get_texture_temp_udp", + "get_texture_non_temp_http", + "get_texture_non_temp_udp", + "get_wearable_http", + "get_wearable_udp", + "get_sound_http", + "get_sound_udp", + "get_gesture_http", + "get_gesture_udp" }; -static const char * resp_keys[] = +static const char * resp_keys[] = { - "get_other_http", - "get_other_udp", - "get_texture_temp_http", - "get_texture_temp_udp", - "get_texture_non_temp_http", - "get_texture_non_temp_udp", - "get_wearable_http", - "get_wearable_udp", - "get_sound_http", - "get_sound_udp", - "get_gesture_http", - "get_gesture_udp" + "get_other_http", + "get_other_udp", + "get_texture_temp_http", + "get_texture_temp_udp", + "get_texture_non_temp_http", + "get_texture_non_temp_udp", + "get_wearable_http", + "get_wearable_udp", + "get_sound_http", + "get_sound_udp", + "get_gesture_http", + "get_gesture_udp" }; static const char * sub_keys[] = { - "dequeued", - "enqueued", - "resp_count", - "resp_max", - "resp_min", - "resp_mean" + "dequeued", + "enqueued", + "resp_count", + "resp_max", + "resp_min", + "resp_mean" }; -static const char * mmm_resp_keys[] = +static const char * mmm_resp_keys[] = { - "fps" + "fps" }; static const char * mmm_sub_keys[] = { - "count", - "max", - "min", - "mean" + "count", + "max", + "min", + "mean" }; static const LLUUID region1("4e2d81a3-6263-6ffe-ad5c-8ce04bee07e8"); @@ -135,7 +135,7 @@ static const std::string region2_handle_str("0000030000004200"); static bool is_empty_map(const LLSD & sd) { - return sd.isMap() && 0 == sd.size(); + return sd.isMap() && 0 == sd.size(); } #endif @@ -143,433 +143,433 @@ is_empty_map(const LLSD & sd) static bool is_single_key_map(const LLSD & sd, const std::string & key) { - return sd.isMap() && 1 == sd.size() && sd.has(key); + return sd.isMap() && 1 == sd.size() && sd.has(key); } #endif static bool is_double_key_map(const LLSD & sd, const std::string & key1, const std::string & key2) { - return sd.isMap() && 2 == sd.size() && sd.has(key1) && sd.has(key2); + return sd.isMap() && 2 == sd.size() && sd.has(key1) && sd.has(key2); } #if 0 static bool is_triple_key_map(const LLSD & sd, const std::string & key1, const std::string & key2, const std::string& key3) { - return sd.isMap() && 3 == sd.size() && sd.has(key1) && sd.has(key2) && sd.has(key3); + return sd.isMap() && 3 == sd.size() && sd.has(key1) && sd.has(key2) && sd.has(key3); } #endif static bool is_no_stats_map(const LLSD & sd) { - return is_double_key_map(sd, "duration", "regions"); + return is_double_key_map(sd, "duration", "regions"); } static bool is_single_slot_array(const LLSD & sd, U64 region_handle) { - U32 grid_x(0), grid_y(0); - grid_from_region_handle(region_handle, &grid_x, &grid_y); - - return (sd.isArray() && - 1 == sd.size() && - sd[0].has("grid_x") && - sd[0].has("grid_y") && - sd[0]["grid_x"].isInteger() && - sd[0]["grid_y"].isInteger() && - grid_x == sd[0]["grid_x"].asInteger() && - grid_y == sd[0]["grid_y"].asInteger()); + U32 grid_x(0), grid_y(0); + grid_from_region_handle(region_handle, &grid_x, &grid_y); + + return (sd.isArray() && + 1 == sd.size() && + sd[0].has("grid_x") && + sd[0].has("grid_y") && + sd[0]["grid_x"].isInteger() && + sd[0]["grid_y"].isInteger() && + grid_x == sd[0]["grid_x"].asInteger() && + grid_y == sd[0]["grid_y"].asInteger()); } static bool is_double_slot_array(const LLSD & sd, U64 region_handle1, U64 region_handle2) { - U32 grid_x1(0), grid_y1(0); - U32 grid_x2(0), grid_y2(0); - grid_from_region_handle(region_handle1, &grid_x1, &grid_y1); - grid_from_region_handle(region_handle2, &grid_x2, &grid_y2); - - return (sd.isArray() && - 2 == sd.size() && - sd[0].has("grid_x") && - sd[0].has("grid_y") && - sd[0]["grid_x"].isInteger() && - sd[0]["grid_y"].isInteger() && - sd[1].has("grid_x") && - sd[1].has("grid_y") && - sd[1]["grid_x"].isInteger() && - sd[1]["grid_y"].isInteger() && - ((grid_x1 == sd[0]["grid_x"].asInteger() && - grid_y1 == sd[0]["grid_y"].asInteger() && - grid_x2 == sd[1]["grid_x"].asInteger() && - grid_y2 == sd[1]["grid_y"].asInteger()) || - (grid_x1 == sd[1]["grid_x"].asInteger() && - grid_y1 == sd[1]["grid_y"].asInteger() && - grid_x2 == sd[0]["grid_x"].asInteger() && - grid_y2 == sd[0]["grid_y"].asInteger()))); + U32 grid_x1(0), grid_y1(0); + U32 grid_x2(0), grid_y2(0); + grid_from_region_handle(region_handle1, &grid_x1, &grid_y1); + grid_from_region_handle(region_handle2, &grid_x2, &grid_y2); + + return (sd.isArray() && + 2 == sd.size() && + sd[0].has("grid_x") && + sd[0].has("grid_y") && + sd[0]["grid_x"].isInteger() && + sd[0]["grid_y"].isInteger() && + sd[1].has("grid_x") && + sd[1].has("grid_y") && + sd[1]["grid_x"].isInteger() && + sd[1]["grid_y"].isInteger() && + ((grid_x1 == sd[0]["grid_x"].asInteger() && + grid_y1 == sd[0]["grid_y"].asInteger() && + grid_x2 == sd[1]["grid_x"].asInteger() && + grid_y2 == sd[1]["grid_y"].asInteger()) || + (grid_x1 == sd[1]["grid_x"].asInteger() && + grid_y1 == sd[1]["grid_y"].asInteger() && + grid_x2 == sd[0]["grid_x"].asInteger() && + grid_y2 == sd[0]["grid_y"].asInteger()))); } static LLSD get_region(const LLSD & sd, U64 region_handle1) { - U32 grid_x(0), grid_y(0); - grid_from_region_handle(region_handle1, &grid_x, &grid_y); - - for (LLSD::array_const_iterator it(sd["regions"].beginArray()); - sd["regions"].endArray() != it; - ++it) - { - if ((*it).has("grid_x") && - (*it).has("grid_y") && - (*it)["grid_x"].isInteger() && - (*it)["grid_y"].isInteger() && - (*it)["grid_x"].asInteger() == grid_x && - (*it)["grid_y"].asInteger() == grid_y) - { - return *it; - } - } - return LLSD(); + U32 grid_x(0), grid_y(0); + grid_from_region_handle(region_handle1, &grid_x, &grid_y); + + for (LLSD::array_const_iterator it(sd["regions"].beginArray()); + sd["regions"].endArray() != it; + ++it) + { + if ((*it).has("grid_x") && + (*it).has("grid_y") && + (*it)["grid_x"].isInteger() && + (*it)["grid_y"].isInteger() && + (*it)["grid_x"].asInteger() == grid_x && + (*it)["grid_y"].asInteger() == grid_y) + { + return *it; + } + } + return LLSD(); } namespace tut { - struct tst_viewerassetstats_index - { - tst_viewerassetstats_index() - { - LLTrace::set_master_thread_recorder(&mThreadRecorder); - } - - ~tst_viewerassetstats_index() - { - LLTrace::set_master_thread_recorder(NULL); - } - - LLTrace::ThreadRecorder mThreadRecorder; - }; - typedef test_group<tst_viewerassetstats_index> tst_viewerassetstats_index_t; - typedef tst_viewerassetstats_index_t::object tst_viewerassetstats_index_object_t; - tut::tst_viewerassetstats_index_t tut_tst_viewerassetstats_index("tst_viewerassetstats_test"); - - // Testing free functions without global stats allocated - template<> template<> - void tst_viewerassetstats_index_object_t::test<1>() - { - // Check that helpers aren't bothered by missing global stats - ensure("Global gViewerAssetStats should be NULL", (NULL == gViewerAssetStats)); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, false, false); - - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, false, false); - - LLViewerAssetStatsFF::record_response(LLViewerAssetType::AT_GESTURE, false, false, (U64Microseconds)12300000ULL); - } - - // Create a non-global instance and check the structure - template<> template<> - void tst_viewerassetstats_index_object_t::test<2>() - { - ensure("Global gViewerAssetStats should be NULL", (NULL == gViewerAssetStats)); - - LLViewerAssetStats * it = new LLViewerAssetStats(); - - ensure("Global gViewerAssetStats should still be NULL", (NULL == gViewerAssetStats)); - - LLSD sd_full = it->asLLSD(false); - - // Default (NULL) region ID doesn't produce LLSD results so should - // get an empty map back from output - ensure("Stat-less LLSD initially", is_no_stats_map(sd_full)); - - // Once the region is set, we will get a response even with no data collection - it->setRegion(region1_handle); - sd_full = it->asLLSD(false); - ensure("Correct single-key LLSD map root", is_double_key_map(sd_full, "duration", "regions")); - ensure("Correct single-slot LLSD array regions", is_single_slot_array(sd_full["regions"], region1_handle)); - - LLSD sd = sd_full["regions"][0]; - - delete it; - - // Check the structure of the LLSD - for (int i = 0; i < LL_ARRAY_SIZE(all_keys); ++i) - { - std::string line = llformat("Has '%s' key", all_keys[i]); - ensure(line, sd.has(all_keys[i])); - } - - for (int i = 0; i < LL_ARRAY_SIZE(resp_keys); ++i) - { - for (int j = 0; j < LL_ARRAY_SIZE(sub_keys); ++j) - { - std::string line = llformat("Key '%s' has '%s' key", resp_keys[i], sub_keys[j]); - ensure(line, sd[resp_keys[i]].has(sub_keys[j])); - } - } - - for (int i = 0; i < LL_ARRAY_SIZE(mmm_resp_keys); ++i) - { - for (int j = 0; j < LL_ARRAY_SIZE(mmm_sub_keys); ++j) - { - std::string line = llformat("Key '%s' has '%s' key", mmm_resp_keys[i], mmm_sub_keys[j]); - ensure(line, sd[mmm_resp_keys[i]].has(mmm_sub_keys[j])); - } - } - } - - // Create a non-global instance and check some content - template<> template<> - void tst_viewerassetstats_index_object_t::test<3>() - { - LLViewerAssetStats * it = new LLViewerAssetStats(); - it->setRegion(region1_handle); - - LLSD sd = it->asLLSD(false); - ensure("Correct single-key LLSD map root", is_double_key_map(sd, "regions", "duration")); - ensure("Correct single-slot LLSD array regions", is_single_slot_array(sd["regions"], region1_handle)); - sd = sd[0]; - - delete it; - - // Check a few points on the tree for content - ensure("sd[get_texture_temp_http][dequeued] is 0", (0 == sd["get_texture_temp_http"]["dequeued"].asInteger())); - ensure("sd[get_sound_udp][resp_min] is 0", (0.0 == sd["get_sound_udp"]["resp_min"].asReal())); - } - - // Create a global instance and verify free functions do something useful - template<> template<> - void tst_viewerassetstats_index_object_t::test<4>() - { - gViewerAssetStats = new LLViewerAssetStats(); - LLViewerAssetStatsFF::set_region(region1_handle); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, false, false); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, false, false); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, false); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, false); - - LLSD sd = gViewerAssetStats->asLLSD(false); - ensure("Correct single-key LLSD map root", is_double_key_map(sd, "regions", "duration")); - ensure("Correct single-slot LLSD array regions", is_single_slot_array(sd["regions"], region1_handle)); - sd = sd["regions"][0]; - - // Check a few points on the tree for content - ensure("sd[get_texture_non_temp_udp][enqueued] is 1", (1 == sd["get_texture_non_temp_udp"]["enqueued"].asInteger())); - ensure("sd[get_texture_temp_udp][enqueued] is 0", (0 == sd["get_texture_temp_udp"]["enqueued"].asInteger())); - ensure("sd[get_texture_non_temp_http][enqueued] is 0", (0 == sd["get_texture_non_temp_http"]["enqueued"].asInteger())); - ensure("sd[get_texture_temp_http][enqueued] is 0", (0 == sd["get_texture_temp_http"]["enqueued"].asInteger())); - ensure("sd[get_gesture_udp][dequeued] is 0", (0 == sd["get_gesture_udp"]["dequeued"].asInteger())); - - // Reset and check zeros... - // Reset leaves current region in place - gViewerAssetStats->reset(); - sd = gViewerAssetStats->asLLSD(false)["regions"][region1_handle_str]; - - delete gViewerAssetStats; - gViewerAssetStats = NULL; - - ensure("sd[get_texture_non_temp_udp][enqueued] is reset", (0 == sd["get_texture_non_temp_udp"]["enqueued"].asInteger())); - ensure("sd[get_gesture_udp][dequeued] is reset", (0 == sd["get_gesture_udp"]["dequeued"].asInteger())); - } + struct tst_viewerassetstats_index + { + tst_viewerassetstats_index() + { + LLTrace::set_master_thread_recorder(&mThreadRecorder); + } + + ~tst_viewerassetstats_index() + { + LLTrace::set_master_thread_recorder(NULL); + } + + LLTrace::ThreadRecorder mThreadRecorder; + }; + typedef test_group<tst_viewerassetstats_index> tst_viewerassetstats_index_t; + typedef tst_viewerassetstats_index_t::object tst_viewerassetstats_index_object_t; + tut::tst_viewerassetstats_index_t tut_tst_viewerassetstats_index("tst_viewerassetstats_test"); + + // Testing free functions without global stats allocated + template<> template<> + void tst_viewerassetstats_index_object_t::test<1>() + { + // Check that helpers aren't bothered by missing global stats + ensure("Global gViewerAssetStats should be NULL", (NULL == gViewerAssetStats)); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, false, false); + + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, false, false); + + LLViewerAssetStatsFF::record_response(LLViewerAssetType::AT_GESTURE, false, false, (U64Microseconds)12300000ULL); + } + + // Create a non-global instance and check the structure + template<> template<> + void tst_viewerassetstats_index_object_t::test<2>() + { + ensure("Global gViewerAssetStats should be NULL", (NULL == gViewerAssetStats)); + + LLViewerAssetStats * it = new LLViewerAssetStats(); + + ensure("Global gViewerAssetStats should still be NULL", (NULL == gViewerAssetStats)); + + LLSD sd_full = it->asLLSD(false); + + // Default (NULL) region ID doesn't produce LLSD results so should + // get an empty map back from output + ensure("Stat-less LLSD initially", is_no_stats_map(sd_full)); + + // Once the region is set, we will get a response even with no data collection + it->setRegion(region1_handle); + sd_full = it->asLLSD(false); + ensure("Correct single-key LLSD map root", is_double_key_map(sd_full, "duration", "regions")); + ensure("Correct single-slot LLSD array regions", is_single_slot_array(sd_full["regions"], region1_handle)); + + LLSD sd = sd_full["regions"][0]; + + delete it; + + // Check the structure of the LLSD + for (int i = 0; i < LL_ARRAY_SIZE(all_keys); ++i) + { + std::string line = llformat("Has '%s' key", all_keys[i]); + ensure(line, sd.has(all_keys[i])); + } + + for (int i = 0; i < LL_ARRAY_SIZE(resp_keys); ++i) + { + for (int j = 0; j < LL_ARRAY_SIZE(sub_keys); ++j) + { + std::string line = llformat("Key '%s' has '%s' key", resp_keys[i], sub_keys[j]); + ensure(line, sd[resp_keys[i]].has(sub_keys[j])); + } + } + + for (int i = 0; i < LL_ARRAY_SIZE(mmm_resp_keys); ++i) + { + for (int j = 0; j < LL_ARRAY_SIZE(mmm_sub_keys); ++j) + { + std::string line = llformat("Key '%s' has '%s' key", mmm_resp_keys[i], mmm_sub_keys[j]); + ensure(line, sd[mmm_resp_keys[i]].has(mmm_sub_keys[j])); + } + } + } + + // Create a non-global instance and check some content + template<> template<> + void tst_viewerassetstats_index_object_t::test<3>() + { + LLViewerAssetStats * it = new LLViewerAssetStats(); + it->setRegion(region1_handle); + + LLSD sd = it->asLLSD(false); + ensure("Correct single-key LLSD map root", is_double_key_map(sd, "regions", "duration")); + ensure("Correct single-slot LLSD array regions", is_single_slot_array(sd["regions"], region1_handle)); + sd = sd[0]; + + delete it; + + // Check a few points on the tree for content + ensure("sd[get_texture_temp_http][dequeued] is 0", (0 == sd["get_texture_temp_http"]["dequeued"].asInteger())); + ensure("sd[get_sound_udp][resp_min] is 0", (0.0 == sd["get_sound_udp"]["resp_min"].asReal())); + } + + // Create a global instance and verify free functions do something useful + template<> template<> + void tst_viewerassetstats_index_object_t::test<4>() + { + gViewerAssetStats = new LLViewerAssetStats(); + LLViewerAssetStatsFF::set_region(region1_handle); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, false, false); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, false, false); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, false); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, false); + + LLSD sd = gViewerAssetStats->asLLSD(false); + ensure("Correct single-key LLSD map root", is_double_key_map(sd, "regions", "duration")); + ensure("Correct single-slot LLSD array regions", is_single_slot_array(sd["regions"], region1_handle)); + sd = sd["regions"][0]; + + // Check a few points on the tree for content + ensure("sd[get_texture_non_temp_udp][enqueued] is 1", (1 == sd["get_texture_non_temp_udp"]["enqueued"].asInteger())); + ensure("sd[get_texture_temp_udp][enqueued] is 0", (0 == sd["get_texture_temp_udp"]["enqueued"].asInteger())); + ensure("sd[get_texture_non_temp_http][enqueued] is 0", (0 == sd["get_texture_non_temp_http"]["enqueued"].asInteger())); + ensure("sd[get_texture_temp_http][enqueued] is 0", (0 == sd["get_texture_temp_http"]["enqueued"].asInteger())); + ensure("sd[get_gesture_udp][dequeued] is 0", (0 == sd["get_gesture_udp"]["dequeued"].asInteger())); + + // Reset and check zeros... + // Reset leaves current region in place + gViewerAssetStats->reset(); + sd = gViewerAssetStats->asLLSD(false)["regions"][region1_handle_str]; + + delete gViewerAssetStats; + gViewerAssetStats = NULL; + + ensure("sd[get_texture_non_temp_udp][enqueued] is reset", (0 == sd["get_texture_non_temp_udp"]["enqueued"].asInteger())); + ensure("sd[get_gesture_udp][dequeued] is reset", (0 == sd["get_gesture_udp"]["dequeued"].asInteger())); + } // Check multiple region collection - template<> template<> - void tst_viewerassetstats_index_object_t::test<5>() - { - gViewerAssetStats = new LLViewerAssetStats(); - - LLViewerAssetStatsFF::set_region(region1_handle); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, false, false); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, false, false); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, false); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, false); - - LLViewerAssetStatsFF::set_region(region2_handle); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - - LLSD sd = gViewerAssetStats->asLLSD(false); - - // std::cout << sd << std::endl; - - ensure("Correct double-key LLSD map root", is_double_key_map(sd, "duration", "regions")); - ensure("Correct double-slot LLSD array regions", is_double_slot_array(sd["regions"], region1_handle, region2_handle)); - LLSD sd1 = get_region(sd, region1_handle); - LLSD sd2 = get_region(sd, region2_handle); - ensure("Region1 is present in results", sd1.isMap()); - ensure("Region2 is present in results", sd2.isMap()); - - // Check a few points on the tree for content - ensure_equals("sd1[get_texture_non_temp_udp][enqueued] is 1", sd1["get_texture_non_temp_udp"]["enqueued"].asInteger(), 1); - ensure_equals("sd1[get_texture_temp_udp][enqueued] is 0", sd1["get_texture_temp_udp"]["enqueued"].asInteger(), 0); - ensure_equals("sd1[get_texture_non_temp_http][enqueued] is 0", sd1["get_texture_non_temp_http"]["enqueued"].asInteger(), 0); - ensure_equals("sd1[get_texture_temp_http][enqueued] is 0", sd1["get_texture_temp_http"]["enqueued"].asInteger(), 0); - ensure_equals("sd1[get_gesture_udp][dequeued] is 0", sd1["get_gesture_udp"]["dequeued"].asInteger(), 0); - - // Check a few points on the tree for content - ensure("sd2[get_gesture_udp][enqueued] is 4", (4 == sd2["get_gesture_udp"]["enqueued"].asInteger())); - ensure("sd2[get_gesture_udp][dequeued] is 0", (0 == sd2["get_gesture_udp"]["dequeued"].asInteger())); - ensure("sd2[get_texture_non_temp_udp][enqueued] is 0", (0 == sd2["get_texture_non_temp_udp"]["enqueued"].asInteger())); - - // Reset and check zeros... - // Reset leaves current region in place - gViewerAssetStats->reset(); - sd = gViewerAssetStats->asLLSD(false); - ensure("Correct single-key LLSD map root", is_double_key_map(sd, "regions", "duration")); - ensure("Correct single-slot LLSD array regions (p2)", is_single_slot_array(sd["regions"], region2_handle)); - sd2 = sd["regions"][0]; - - delete gViewerAssetStats; - gViewerAssetStats = NULL; - - ensure("sd2[get_texture_non_temp_udp][enqueued] is reset", (0 == sd2["get_texture_non_temp_udp"]["enqueued"].asInteger())); - ensure("sd2[get_gesture_udp][enqueued] is reset", (0 == sd2["get_gesture_udp"]["enqueued"].asInteger())); - } + template<> template<> + void tst_viewerassetstats_index_object_t::test<5>() + { + gViewerAssetStats = new LLViewerAssetStats(); + + LLViewerAssetStatsFF::set_region(region1_handle); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, false, false); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, false, false); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, false); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, false); + + LLViewerAssetStatsFF::set_region(region2_handle); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + + LLSD sd = gViewerAssetStats->asLLSD(false); + + // std::cout << sd << std::endl; + + ensure("Correct double-key LLSD map root", is_double_key_map(sd, "duration", "regions")); + ensure("Correct double-slot LLSD array regions", is_double_slot_array(sd["regions"], region1_handle, region2_handle)); + LLSD sd1 = get_region(sd, region1_handle); + LLSD sd2 = get_region(sd, region2_handle); + ensure("Region1 is present in results", sd1.isMap()); + ensure("Region2 is present in results", sd2.isMap()); + + // Check a few points on the tree for content + ensure_equals("sd1[get_texture_non_temp_udp][enqueued] is 1", sd1["get_texture_non_temp_udp"]["enqueued"].asInteger(), 1); + ensure_equals("sd1[get_texture_temp_udp][enqueued] is 0", sd1["get_texture_temp_udp"]["enqueued"].asInteger(), 0); + ensure_equals("sd1[get_texture_non_temp_http][enqueued] is 0", sd1["get_texture_non_temp_http"]["enqueued"].asInteger(), 0); + ensure_equals("sd1[get_texture_temp_http][enqueued] is 0", sd1["get_texture_temp_http"]["enqueued"].asInteger(), 0); + ensure_equals("sd1[get_gesture_udp][dequeued] is 0", sd1["get_gesture_udp"]["dequeued"].asInteger(), 0); + + // Check a few points on the tree for content + ensure("sd2[get_gesture_udp][enqueued] is 4", (4 == sd2["get_gesture_udp"]["enqueued"].asInteger())); + ensure("sd2[get_gesture_udp][dequeued] is 0", (0 == sd2["get_gesture_udp"]["dequeued"].asInteger())); + ensure("sd2[get_texture_non_temp_udp][enqueued] is 0", (0 == sd2["get_texture_non_temp_udp"]["enqueued"].asInteger())); + + // Reset and check zeros... + // Reset leaves current region in place + gViewerAssetStats->reset(); + sd = gViewerAssetStats->asLLSD(false); + ensure("Correct single-key LLSD map root", is_double_key_map(sd, "regions", "duration")); + ensure("Correct single-slot LLSD array regions (p2)", is_single_slot_array(sd["regions"], region2_handle)); + sd2 = sd["regions"][0]; + + delete gViewerAssetStats; + gViewerAssetStats = NULL; + + ensure("sd2[get_texture_non_temp_udp][enqueued] is reset", (0 == sd2["get_texture_non_temp_udp"]["enqueued"].asInteger())); + ensure("sd2[get_gesture_udp][enqueued] is reset", (0 == sd2["get_gesture_udp"]["enqueued"].asInteger())); + } // Check multiple region collection jumping back-and-forth between regions - template<> template<> - void tst_viewerassetstats_index_object_t::test<6>() - { - gViewerAssetStats = new LLViewerAssetStats(); + template<> template<> + void tst_viewerassetstats_index_object_t::test<6>() + { + gViewerAssetStats = new LLViewerAssetStats(); + + LLViewerAssetStatsFF::set_region(region1_handle); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, false, false); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, false, false); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, false); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, false); + + LLViewerAssetStatsFF::set_region(region2_handle); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + + LLViewerAssetStatsFF::set_region(region1_handle); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, true, true); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, true, true); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, false); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, false); + + LLViewerAssetStatsFF::set_region(region2_handle); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); + + LLSD sd = gViewerAssetStats->asLLSD(false); + + ensure("Correct double-key LLSD map root", is_double_key_map(sd, "duration", "regions")); + ensure("Correct double-slot LLSD array regions", is_double_slot_array(sd["regions"], region1_handle, region2_handle)); + LLSD sd1 = get_region(sd, region1_handle); + LLSD sd2 = get_region(sd, region2_handle); + ensure("Region1 is present in results", sd1.isMap()); + ensure("Region2 is present in results", sd2.isMap()); + + // Check a few points on the tree for content + ensure("sd1[get_texture_non_temp_udp][enqueued] is 1", (1 == sd1["get_texture_non_temp_udp"]["enqueued"].asInteger())); + ensure("sd1[get_texture_temp_udp][enqueued] is 0", (0 == sd1["get_texture_temp_udp"]["enqueued"].asInteger())); + ensure("sd1[get_texture_non_temp_http][enqueued] is 0", (0 == sd1["get_texture_non_temp_http"]["enqueued"].asInteger())); + ensure("sd1[get_texture_temp_http][enqueued] is 1", (1 == sd1["get_texture_temp_http"]["enqueued"].asInteger())); + ensure("sd1[get_gesture_udp][dequeued] is 0", (0 == sd1["get_gesture_udp"]["dequeued"].asInteger())); + + // Check a few points on the tree for content + ensure("sd2[get_gesture_udp][enqueued] is 8", (8 == sd2["get_gesture_udp"]["enqueued"].asInteger())); + ensure("sd2[get_gesture_udp][dequeued] is 0", (0 == sd2["get_gesture_udp"]["dequeued"].asInteger())); + ensure("sd2[get_texture_non_temp_udp][enqueued] is 0", (0 == sd2["get_texture_non_temp_udp"]["enqueued"].asInteger())); + + // Reset and check zeros... + // Reset leaves current region in place + gViewerAssetStats->reset(); + sd = gViewerAssetStats->asLLSD(false); + ensure("Correct single-key LLSD map root", is_double_key_map(sd, "duration", "regions")); + ensure("Correct single-slot LLSD array regions (p2)", is_single_slot_array(sd["regions"], region2_handle)); + sd2 = get_region(sd, region2_handle); + ensure("Region2 is present in results", sd2.isMap()); + + delete gViewerAssetStats; + gViewerAssetStats = NULL; + + ensure_equals("sd2[get_texture_non_temp_udp][enqueued] is reset", sd2["get_texture_non_temp_udp"]["enqueued"].asInteger(), 0); + ensure_equals("sd2[get_gesture_udp][enqueued] is reset", sd2["get_gesture_udp"]["enqueued"].asInteger(), 0); + } + + // Non-texture assets ignore transport and persistence flags + template<> template<> + void tst_viewerassetstats_index_object_t::test<7>() + { + gViewerAssetStats = new LLViewerAssetStats(); + LLViewerAssetStatsFF::set_region(region1_handle); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, false, false); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, false, false); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, false); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, false); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, true); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, true); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, true, false); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, true, false); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, true, true); + LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, true, true); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_LSL_BYTECODE, false, false); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_LSL_BYTECODE, false, true); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_LSL_BYTECODE, true, false); + + LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_LSL_BYTECODE, true, true); + + LLSD sd = gViewerAssetStats->asLLSD(false); + ensure("Correct single-key LLSD map root", is_double_key_map(sd, "regions", "duration")); + ensure("Correct single-slot LLSD array regions", is_single_slot_array(sd["regions"], region1_handle)); + sd = get_region(sd, region1_handle); + ensure("Region1 is present in results", sd.isMap()); + + // Check a few points on the tree for content + ensure("sd[get_gesture_udp][enqueued] is 0", (0 == sd["get_gesture_udp"]["enqueued"].asInteger())); + ensure("sd[get_gesture_udp][dequeued] is 0", (0 == sd["get_gesture_udp"]["dequeued"].asInteger())); + + ensure("sd[get_wearable_http][enqueued] is 2", (2 == sd["get_wearable_http"]["enqueued"].asInteger())); + ensure("sd[get_wearable_http][dequeued] is 2", (2 == sd["get_wearable_http"]["dequeued"].asInteger())); + + ensure("sd[get_wearable_udp][enqueued] is 2", (2 == sd["get_wearable_udp"]["enqueued"].asInteger())); + ensure("sd[get_wearable_udp][dequeued] is 2", (2 == sd["get_wearable_udp"]["dequeued"].asInteger())); - LLViewerAssetStatsFF::set_region(region1_handle); + ensure("sd[get_other_http][enqueued] is 2", (2 == sd["get_other_http"]["enqueued"].asInteger())); + ensure("sd[get_other_http][dequeued] is 0", (0 == sd["get_other_http"]["dequeued"].asInteger())); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, false, false); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, false, false); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, false); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, false); - - LLViewerAssetStatsFF::set_region(region2_handle); + ensure("sd[get_other_udp][enqueued] is 2", (2 == sd["get_other_udp"]["enqueued"].asInteger())); + ensure("sd[get_other_udp][dequeued] is 0", (0 == sd["get_other_udp"]["dequeued"].asInteger())); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - - LLViewerAssetStatsFF::set_region(region1_handle); + // Reset and check zeros... + // Reset leaves current region in place + gViewerAssetStats->reset(); + sd = get_region(gViewerAssetStats->asLLSD(false), region1_handle); + ensure("Region1 is present in results", sd.isMap()); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, true, true); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, true, true); + delete gViewerAssetStats; + gViewerAssetStats = NULL; - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, false); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, false); - - LLViewerAssetStatsFF::set_region(region2_handle); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_GESTURE, false, false); - - LLSD sd = gViewerAssetStats->asLLSD(false); - - ensure("Correct double-key LLSD map root", is_double_key_map(sd, "duration", "regions")); - ensure("Correct double-slot LLSD array regions", is_double_slot_array(sd["regions"], region1_handle, region2_handle)); - LLSD sd1 = get_region(sd, region1_handle); - LLSD sd2 = get_region(sd, region2_handle); - ensure("Region1 is present in results", sd1.isMap()); - ensure("Region2 is present in results", sd2.isMap()); - - // Check a few points on the tree for content - ensure("sd1[get_texture_non_temp_udp][enqueued] is 1", (1 == sd1["get_texture_non_temp_udp"]["enqueued"].asInteger())); - ensure("sd1[get_texture_temp_udp][enqueued] is 0", (0 == sd1["get_texture_temp_udp"]["enqueued"].asInteger())); - ensure("sd1[get_texture_non_temp_http][enqueued] is 0", (0 == sd1["get_texture_non_temp_http"]["enqueued"].asInteger())); - ensure("sd1[get_texture_temp_http][enqueued] is 1", (1 == sd1["get_texture_temp_http"]["enqueued"].asInteger())); - ensure("sd1[get_gesture_udp][dequeued] is 0", (0 == sd1["get_gesture_udp"]["dequeued"].asInteger())); - - // Check a few points on the tree for content - ensure("sd2[get_gesture_udp][enqueued] is 8", (8 == sd2["get_gesture_udp"]["enqueued"].asInteger())); - ensure("sd2[get_gesture_udp][dequeued] is 0", (0 == sd2["get_gesture_udp"]["dequeued"].asInteger())); - ensure("sd2[get_texture_non_temp_udp][enqueued] is 0", (0 == sd2["get_texture_non_temp_udp"]["enqueued"].asInteger())); - - // Reset and check zeros... - // Reset leaves current region in place - gViewerAssetStats->reset(); - sd = gViewerAssetStats->asLLSD(false); - ensure("Correct single-key LLSD map root", is_double_key_map(sd, "duration", "regions")); - ensure("Correct single-slot LLSD array regions (p2)", is_single_slot_array(sd["regions"], region2_handle)); - sd2 = get_region(sd, region2_handle); - ensure("Region2 is present in results", sd2.isMap()); - - delete gViewerAssetStats; - gViewerAssetStats = NULL; - - ensure_equals("sd2[get_texture_non_temp_udp][enqueued] is reset", sd2["get_texture_non_temp_udp"]["enqueued"].asInteger(), 0); - ensure_equals("sd2[get_gesture_udp][enqueued] is reset", sd2["get_gesture_udp"]["enqueued"].asInteger(), 0); - } - - // Non-texture assets ignore transport and persistence flags - template<> template<> - void tst_viewerassetstats_index_object_t::test<7>() - { - gViewerAssetStats = new LLViewerAssetStats(); - LLViewerAssetStatsFF::set_region(region1_handle); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_TEXTURE, false, false); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_TEXTURE, false, false); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, false); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, false); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, false, true); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, false, true); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, true, false); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, true, false); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_BODYPART, true, true); - LLViewerAssetStatsFF::record_dequeue(LLViewerAssetType::AT_BODYPART, true, true); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_LSL_BYTECODE, false, false); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_LSL_BYTECODE, false, true); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_LSL_BYTECODE, true, false); - - LLViewerAssetStatsFF::record_enqueue(LLViewerAssetType::AT_LSL_BYTECODE, true, true); - - LLSD sd = gViewerAssetStats->asLLSD(false); - ensure("Correct single-key LLSD map root", is_double_key_map(sd, "regions", "duration")); - ensure("Correct single-slot LLSD array regions", is_single_slot_array(sd["regions"], region1_handle)); - sd = get_region(sd, region1_handle); - ensure("Region1 is present in results", sd.isMap()); - - // Check a few points on the tree for content - ensure("sd[get_gesture_udp][enqueued] is 0", (0 == sd["get_gesture_udp"]["enqueued"].asInteger())); - ensure("sd[get_gesture_udp][dequeued] is 0", (0 == sd["get_gesture_udp"]["dequeued"].asInteger())); - - ensure("sd[get_wearable_http][enqueued] is 2", (2 == sd["get_wearable_http"]["enqueued"].asInteger())); - ensure("sd[get_wearable_http][dequeued] is 2", (2 == sd["get_wearable_http"]["dequeued"].asInteger())); - - ensure("sd[get_wearable_udp][enqueued] is 2", (2 == sd["get_wearable_udp"]["enqueued"].asInteger())); - ensure("sd[get_wearable_udp][dequeued] is 2", (2 == sd["get_wearable_udp"]["dequeued"].asInteger())); - - ensure("sd[get_other_http][enqueued] is 2", (2 == sd["get_other_http"]["enqueued"].asInteger())); - ensure("sd[get_other_http][dequeued] is 0", (0 == sd["get_other_http"]["dequeued"].asInteger())); - - ensure("sd[get_other_udp][enqueued] is 2", (2 == sd["get_other_udp"]["enqueued"].asInteger())); - ensure("sd[get_other_udp][dequeued] is 0", (0 == sd["get_other_udp"]["dequeued"].asInteger())); - - // Reset and check zeros... - // Reset leaves current region in place - gViewerAssetStats->reset(); - sd = get_region(gViewerAssetStats->asLLSD(false), region1_handle); - ensure("Region1 is present in results", sd.isMap()); - - delete gViewerAssetStats; - gViewerAssetStats = NULL; - - ensure_equals("sd[get_texture_non_temp_udp][enqueued] is reset", sd["get_texture_non_temp_udp"]["enqueued"].asInteger(), 0); - ensure_equals("sd[get_gesture_udp][dequeued] is reset", sd["get_gesture_udp"]["dequeued"].asInteger(), 0); - } + ensure_equals("sd[get_texture_non_temp_udp][enqueued] is reset", sd["get_texture_non_temp_udp"]["enqueued"].asInteger(), 0); + ensure_equals("sd[get_gesture_udp][dequeued] is reset", sd["get_gesture_udp"]["dequeued"].asInteger(), 0); + } } diff --git a/indra/newview/tests/llviewercontrollistener_test.cpp b/indra/newview/tests/llviewercontrollistener_test.cpp index 8aed2a8043..a5eeae8e5b 100644 --- a/indra/newview/tests/llviewercontrollistener_test.cpp +++ b/indra/newview/tests/llviewercontrollistener_test.cpp @@ -3,7 +3,7 @@ * @author Nat Goodspeed * @date 2022-06-09 * @brief Test for llviewercontrollistener. - * + * * $LicenseInfo:firstyear=2022&license=viewerlgpl$ * Copyright (c) 2022, Linden Research, Inc. * $/LicenseInfo$ diff --git a/indra/newview/tests/llviewerhelputil_test.cpp b/indra/newview/tests/llviewerhelputil_test.cpp index f6456a2839..7890e9330c 100644 --- a/indra/newview/tests/llviewerhelputil_test.cpp +++ b/indra/newview/tests/llviewerhelputil_test.cpp @@ -1,4 +1,4 @@ -/** +/** * @file llviewerhelputil_test.cpp * @brief LLViewerHelpUtil tests * @author Tofu Linden @@ -6,21 +6,21 @@ * $LicenseInfo:firstyear=2001&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$ */ @@ -47,29 +47,29 @@ static std::string gOS; // Mock objects for the dependencies of the code we're testing LLControlGroup::LLControlGroup(const std::string& name) - : LLInstanceTracker<LLControlGroup, std::string>(name) {} + : LLInstanceTracker<LLControlGroup, std::string>(name) {} LLControlGroup::~LLControlGroup() {} LLControlVariable* LLControlGroup::declareString(const std::string& name, - const std::string& initial_val, - const std::string& comment, - LLControlVariable::ePersist persist) {return NULL;} + const std::string& initial_val, + const std::string& comment, + LLControlVariable::ePersist persist) {return NULL;} void LLControlGroup::setString(const std::string& name, const std::string& val){} std::string LLControlGroup::getString(const std::string& name) { - if (name == "HelpURLFormat") - return gHelpURL; - return ""; + if (name == "HelpURLFormat") + return gHelpURL; + return ""; } LLControlGroup gSavedSettings("test"); static void substitute_string(std::string &input, const std::string &search, const std::string &replace) { - size_t pos = input.find(search); - while (pos != std::string::npos) - { - input = input.replace(pos, search.size(), replace); - pos = input.find(search); - } + size_t pos = input.find(search); + while (pos != std::string::npos) + { + input = input.replace(pos, search.size(), replace); + pos = input.find(search); + } } #include "../llagent.h" @@ -80,81 +80,81 @@ bool LLAgent::isGodlike() const { return FALSE; } LLAgent gAgent; std::string LLWeb::expandURLSubstitutions(const std::string &url, - const LLSD &default_subs) + const LLSD &default_subs) { - (void)gAgent.isGodlike(); // ref symbol to stop compiler from stripping it - std::string new_url = url; - substitute_string(new_url, "[TOPIC]", default_subs["TOPIC"].asString()); - substitute_string(new_url, "[VERSION]", gVersion); - substitute_string(new_url, "[CHANNEL]", gChannel); - substitute_string(new_url, "[LANGUAGE]", gLanguage); - substitute_string(new_url, "[GRID]", gGrid); - substitute_string(new_url, "[OS]", gOS); - return new_url; + (void)gAgent.isGodlike(); // ref symbol to stop compiler from stripping it + std::string new_url = url; + substitute_string(new_url, "[TOPIC]", default_subs["TOPIC"].asString()); + substitute_string(new_url, "[VERSION]", gVersion); + substitute_string(new_url, "[CHANNEL]", gChannel); + substitute_string(new_url, "[LANGUAGE]", gLanguage); + substitute_string(new_url, "[GRID]", gGrid); + substitute_string(new_url, "[OS]", gOS); + return new_url; } //---------------------------------------------------------------------------- - + namespace tut { struct viewerhelputil { }; - - typedef test_group<viewerhelputil> viewerhelputil_t; - typedef viewerhelputil_t::object viewerhelputil_object_t; - tut::viewerhelputil_t tut_viewerhelputil("LLViewerHelpUtil"); - - template<> template<> - void viewerhelputil_object_t::test<1>() - { - std::string topic("test_topic"); - std::string subresult; - - gHelpURL = "fooformat"; - subresult = LLViewerHelpUtil::buildHelpURL(topic); - ensure_equals("no substitution tags", subresult, "fooformat"); - - gHelpURL = ""; - subresult = LLViewerHelpUtil::buildHelpURL(topic); - ensure_equals("blank substitution format", subresult, ""); - - gHelpURL = "[TOPIC]"; - subresult = LLViewerHelpUtil::buildHelpURL(topic); - ensure_equals("topic name", subresult, "test_topic"); - - gHelpURL = "[LANGUAGE]"; - gLanguage = ""; - subresult = LLViewerHelpUtil::buildHelpURL(topic); - ensure_equals("simple substitution with blank", subresult, ""); - - gHelpURL = "[LANGUAGE]"; - gLanguage = "Esperanto"; - subresult = LLViewerHelpUtil::buildHelpURL(topic); - ensure_equals("simple substitution", subresult, "Esperanto"); - - gHelpURL = "http://secondlife.com/[LANGUAGE]"; - gLanguage = "Gaelic"; - subresult = LLViewerHelpUtil::buildHelpURL(topic); - ensure_equals("simple substitution with url", subresult, "http://secondlife.com/Gaelic"); - - gHelpURL = "[XXX]"; - subresult = LLViewerHelpUtil::buildHelpURL(topic); - ensure_equals("unknown substitution", subresult, "[XXX]"); - - gHelpURL = "[LANGUAGE]/[LANGUAGE]"; - gLanguage = "Esperanto"; - subresult = LLViewerHelpUtil::buildHelpURL(topic); - ensure_equals("multiple substitution", subresult, "Esperanto/Esperanto"); - - gHelpURL = "http://[CHANNEL]/[VERSION]/[LANGUAGE]/[OS]/[GRID]/[XXX]"; - gChannel = "Second Life Test"; - gVersion = "2.0"; - gLanguage = "gaelic"; - gOS = "AmigaOS 2.1"; - gGrid = "mysim"; - subresult = LLViewerHelpUtil::buildHelpURL(topic); - ensure_equals("complex substitution", subresult, "http://Second Life Test/2.0/gaelic/AmigaOS 2.1/mysim/[XXX]"); - } + + typedef test_group<viewerhelputil> viewerhelputil_t; + typedef viewerhelputil_t::object viewerhelputil_object_t; + tut::viewerhelputil_t tut_viewerhelputil("LLViewerHelpUtil"); + + template<> template<> + void viewerhelputil_object_t::test<1>() + { + std::string topic("test_topic"); + std::string subresult; + + gHelpURL = "fooformat"; + subresult = LLViewerHelpUtil::buildHelpURL(topic); + ensure_equals("no substitution tags", subresult, "fooformat"); + + gHelpURL = ""; + subresult = LLViewerHelpUtil::buildHelpURL(topic); + ensure_equals("blank substitution format", subresult, ""); + + gHelpURL = "[TOPIC]"; + subresult = LLViewerHelpUtil::buildHelpURL(topic); + ensure_equals("topic name", subresult, "test_topic"); + + gHelpURL = "[LANGUAGE]"; + gLanguage = ""; + subresult = LLViewerHelpUtil::buildHelpURL(topic); + ensure_equals("simple substitution with blank", subresult, ""); + + gHelpURL = "[LANGUAGE]"; + gLanguage = "Esperanto"; + subresult = LLViewerHelpUtil::buildHelpURL(topic); + ensure_equals("simple substitution", subresult, "Esperanto"); + + gHelpURL = "http://secondlife.com/[LANGUAGE]"; + gLanguage = "Gaelic"; + subresult = LLViewerHelpUtil::buildHelpURL(topic); + ensure_equals("simple substitution with url", subresult, "http://secondlife.com/Gaelic"); + + gHelpURL = "[XXX]"; + subresult = LLViewerHelpUtil::buildHelpURL(topic); + ensure_equals("unknown substitution", subresult, "[XXX]"); + + gHelpURL = "[LANGUAGE]/[LANGUAGE]"; + gLanguage = "Esperanto"; + subresult = LLViewerHelpUtil::buildHelpURL(topic); + ensure_equals("multiple substitution", subresult, "Esperanto/Esperanto"); + + gHelpURL = "http://[CHANNEL]/[VERSION]/[LANGUAGE]/[OS]/[GRID]/[XXX]"; + gChannel = "Second Life Test"; + gVersion = "2.0"; + gLanguage = "gaelic"; + gOS = "AmigaOS 2.1"; + gGrid = "mysim"; + subresult = LLViewerHelpUtil::buildHelpURL(topic); + ensure_equals("complex substitution", subresult, "http://Second Life Test/2.0/gaelic/AmigaOS 2.1/mysim/[XXX]"); + } } diff --git a/indra/newview/tests/llviewernetwork_test.cpp b/indra/newview/tests/llviewernetwork_test.cpp index fe81fd63ea..cd5e20f6dd 100644 --- a/indra/newview/tests/llviewernetwork_test.cpp +++ b/indra/newview/tests/llviewernetwork_test.cpp @@ -45,22 +45,22 @@ static const char * const TEST_FILENAME("llviewernetwork_test.xml"); class LLTrans { public: - static std::string getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args, bool def_string = false); + static std::string getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args, bool def_string = false); }; std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args, bool def_string) { - std::string grid_label = std::string(); - if(xml_desc == "AgniGridLabel") - { - grid_label = "Second Life Main Grid (Agni)"; - } - else if(xml_desc == "AditiGridLabel") - { - grid_label = "Second Life Beta Test Grid (Aditi)"; - } - - return grid_label; + std::string grid_label = std::string(); + if(xml_desc == "AgniGridLabel") + { + grid_label = "Second Life Main Grid (Agni)"; + } + else if(xml_desc == "AditiGridLabel") + { + grid_label = "Second Life Beta Test Grid (Aditi)"; + } + + return grid_label; } //---------------------------------------------------------------------------- @@ -82,89 +82,89 @@ std::string gLoginPage; std::string gCurrentGrid; std::string LLControlGroup::getString(const std::string& name) { - if (name == "CmdLineGridChoice") - return gCmdLineGridChoice; - else if (name == "CmdLineHelperURI") - return gCmdLineHelperURI; - else if (name == "LoginPage") - return gLoginPage; - else if (name == "CurrentGrid") - return gCurrentGrid; - return ""; + if (name == "CmdLineGridChoice") + return gCmdLineGridChoice; + else if (name == "CmdLineHelperURI") + return gCmdLineHelperURI; + else if (name == "LoginPage") + return gLoginPage; + else if (name == "CurrentGrid") + return gCurrentGrid; + return ""; } LLSD LLControlGroup::getLLSD(const std::string& name) { - if (name == "CmdLineLoginURI") - { - if(!gCmdLineLoginURI.empty()) - { - return LLSD(gCmdLineLoginURI); - } - } - return LLSD(); + if (name == "CmdLineLoginURI") + { + if(!gCmdLineLoginURI.empty()) + { + return LLSD(gCmdLineLoginURI); + } + } + return LLSD(); } LLPointer<LLControlVariable> LLControlGroup::getControl(const std::string& name) { - ctrl_name_table_t::iterator iter = mNameTable.find(name); - return iter == mNameTable.end() ? LLPointer<LLControlVariable>() : iter->second; + ctrl_name_table_t::iterator iter = mNameTable.find(name); + return iter == mNameTable.end() ? LLPointer<LLControlVariable>() : iter->second; } LLControlGroup gSavedSettings("test"); const char *gSampleGridFile = - "<?xml version=\"1.0\"?>" - "<llsd>" - " <map>" - " <key>altgrid.long.name</key>" - " <map>" - " <key>helper_uri</key><string>https://helper1/helpers/</string>" - " <key>label</key><string>Alternative Grid</string>" - " <key>login_page</key><string>altgrid/loginpage</string>" - " <key>login_uri</key>" - " <array>" - " <string>altgrid/myloginuri1</string>" - " <string>altgrid/myloginuri2</string>" - " </array>" - " <key>keyname</key><string>altgrid.long.name</string>" - " <key>credential_type</key><string>agent</string>" - " <key>grid_login_id</key><string>AltGrid</string>" - " </map>" - " <key>minimal.long.name</key>" - " <map>" - " <key>keyname</key><string>minimal.long.name</string>" - " </map>" - " <!-- Note that the values for agni and aditi below are deliberately" - " incorrect to test that they are not overwritten -->" - " <key>util.agni.lindenlab.com</key> <!-- conflict -->" - " <map>" - " <key>helper_uri</key><string>https://helper1/helpers/</string>" - " <key>grid_login_id</key><string>mylabel</string>" - " <key>label</key><string>mylabel</string>" - " <key>login_page</key><string>loginpage</string>" - " <key>login_uri</key>" - " <array>" - " <string>myloginuri</string>" - " </array>" - " <key>keyname</key><string>util.agni.lindenlab.com</string> <!-- conflict -->" - " </map>" - " <key>util.foobar.lindenlab.com</key>" - " <map>" - " <key>helper_uri</key><string>https://helper1/helpers/</string>" - " <key>grid_login_id</key><string>Aditi</string> <!-- conflict -->" - " <key>label</key><string>mylabel</string>" - " <key>login_page</key><string>loginpage</string>" - " <key>login_uri</key>" - " <array>" - " <string>myloginuri</string>" - " </array>" - " <key>update_query_url_base</key><string>https://update.secondlife.com/update</string>" - " <key>keyname</key><string>util.foobar.lindenlab.com</string>" - " </map>" - " </map>" - "</llsd>" - ; + "<?xml version=\"1.0\"?>" + "<llsd>" + " <map>" + " <key>altgrid.long.name</key>" + " <map>" + " <key>helper_uri</key><string>https://helper1/helpers/</string>" + " <key>label</key><string>Alternative Grid</string>" + " <key>login_page</key><string>altgrid/loginpage</string>" + " <key>login_uri</key>" + " <array>" + " <string>altgrid/myloginuri1</string>" + " <string>altgrid/myloginuri2</string>" + " </array>" + " <key>keyname</key><string>altgrid.long.name</string>" + " <key>credential_type</key><string>agent</string>" + " <key>grid_login_id</key><string>AltGrid</string>" + " </map>" + " <key>minimal.long.name</key>" + " <map>" + " <key>keyname</key><string>minimal.long.name</string>" + " </map>" + " <!-- Note that the values for agni and aditi below are deliberately" + " incorrect to test that they are not overwritten -->" + " <key>util.agni.lindenlab.com</key> <!-- conflict -->" + " <map>" + " <key>helper_uri</key><string>https://helper1/helpers/</string>" + " <key>grid_login_id</key><string>mylabel</string>" + " <key>label</key><string>mylabel</string>" + " <key>login_page</key><string>loginpage</string>" + " <key>login_uri</key>" + " <array>" + " <string>myloginuri</string>" + " </array>" + " <key>keyname</key><string>util.agni.lindenlab.com</string> <!-- conflict -->" + " </map>" + " <key>util.foobar.lindenlab.com</key>" + " <map>" + " <key>helper_uri</key><string>https://helper1/helpers/</string>" + " <key>grid_login_id</key><string>Aditi</string> <!-- conflict -->" + " <key>label</key><string>mylabel</string>" + " <key>login_page</key><string>loginpage</string>" + " <key>login_uri</key>" + " <array>" + " <string>myloginuri</string>" + " </array>" + " <key>update_query_url_base</key><string>https://update.secondlife.com/update</string>" + " <key>keyname</key><string>util.foobar.lindenlab.com</string>" + " </map>" + " </map>" + "</llsd>" + ; // ------------------------------------------------------------------------------------------- // TUT // ------------------------------------------------------------------------------------------- @@ -172,279 +172,279 @@ namespace tut { // Test wrapper declaration : wrapping nothing for the moment struct viewerNetworkTest - { - viewerNetworkTest() - { - LLFile::remove(TEST_FILENAME); - gCmdLineLoginURI.clear(); - gCmdLineGridChoice.clear(); - gCmdLineHelperURI.clear(); - gLoginPage.clear(); - gCurrentGrid.clear(); - } - ~viewerNetworkTest() - { - LLFile::remove(TEST_FILENAME); - } - }; - - // Tut templating thingamagic: test group, object and test instance - typedef test_group<viewerNetworkTest> viewerNetworkTestFactory; - typedef viewerNetworkTestFactory::object viewerNetworkTestObject; - tut::viewerNetworkTestFactory tut_test("LLViewerNetwork"); - - // --------------------------------------------------------------------------------------- - // Test functions - // --------------------------------------------------------------------------------------- - // initialization without a grid file - template<> template<> - void viewerNetworkTestObject::test<1>() - { - LLGridManager *manager = LLGridManager::getInstance(); - // grid file doesn't exist - manager->initialize(TEST_FILENAME); - // validate that some of the defaults are available. - std::map<std::string, std::string> known_grids = manager->getKnownGrids(); - ensure_equals("Known grids is a string-string map of size 2", known_grids.size(), 2); - ensure_equals("Agni has the right name and label", - known_grids[std::string("util.agni.lindenlab.com")], - std::string("Second Life Main Grid (Agni)")); - ensure_equals("Aditi has the right name and label", - known_grids[std::string("util.aditi.lindenlab.com")], - std::string("Second Life Beta Test Grid (Aditi)")); - ensure_equals("name for agni", - LLGridManager::getInstance()->getGrid("util.agni.lindenlab.com"), - std::string("util.agni.lindenlab.com")); - ensure_equals("id for agni", - std::string("Agni"), - LLGridManager::getInstance()->getGridId("util.agni.lindenlab.com")); - ensure_equals("update url base for Agni", // relies on agni being the default - std::string("https://update.secondlife.com/update"), - LLGridManager::getInstance()->getUpdateServiceURL()); - ensure_equals("label for agni", - LLGridManager::getInstance()->getGridLabel("util.agni.lindenlab.com"), - std::string("Second Life Main Grid (Agni)")); - - std::vector<std::string> login_uris; - LLGridManager::getInstance()->getLoginURIs(std::string("util.agni.lindenlab.com"), login_uris); - ensure_equals("Number of login uris for agni", 1, login_uris.size()); - ensure_equals("Agni login uri", - login_uris[0], - std::string("https://login.agni.lindenlab.com/cgi-bin/login.cgi")); - ensure_equals("Agni helper uri", - LLGridManager::getInstance()->getHelperURI("util.agni.lindenlab.com"), - std::string("https://secondlife.com/helpers/")); - ensure_equals("Agni login page", - LLGridManager::getInstance()->getLoginPage("util.agni.lindenlab.com"), - std::string("https://viewer-splash.secondlife.com/")); - ensure("Agni is a system grid", - LLGridManager::getInstance()->isSystemGrid("util.agni.lindenlab.com")); - - ensure_equals("name for aditi", - LLGridManager::getInstance()->getGrid("util.aditi.lindenlab.com"), - std::string("util.aditi.lindenlab.com")); - ensure_equals("id for aditi", - LLGridManager::getInstance()->getGridId("util.aditi.lindenlab.com"), - std::string("Aditi")); - ensure_equals("label for aditi", - LLGridManager::getInstance()->getGridLabel("util.aditi.lindenlab.com"), - std::string("Second Life Beta Test Grid (Aditi)")); - - LLGridManager::getInstance()->getLoginURIs(std::string("util.aditi.lindenlab.com"), login_uris); - - ensure_equals("Number of login uris for aditi", 1, login_uris.size()); - ensure_equals("Aditi login uri", - login_uris[0], - std::string("https://login.aditi.lindenlab.com/cgi-bin/login.cgi")); - ensure_equals("Aditi helper uri", - LLGridManager::getInstance()->getHelperURI("util.aditi.lindenlab.com"), + { + viewerNetworkTest() + { + LLFile::remove(TEST_FILENAME); + gCmdLineLoginURI.clear(); + gCmdLineGridChoice.clear(); + gCmdLineHelperURI.clear(); + gLoginPage.clear(); + gCurrentGrid.clear(); + } + ~viewerNetworkTest() + { + LLFile::remove(TEST_FILENAME); + } + }; + + // Tut templating thingamagic: test group, object and test instance + typedef test_group<viewerNetworkTest> viewerNetworkTestFactory; + typedef viewerNetworkTestFactory::object viewerNetworkTestObject; + tut::viewerNetworkTestFactory tut_test("LLViewerNetwork"); + + // --------------------------------------------------------------------------------------- + // Test functions + // --------------------------------------------------------------------------------------- + // initialization without a grid file + template<> template<> + void viewerNetworkTestObject::test<1>() + { + LLGridManager *manager = LLGridManager::getInstance(); + // grid file doesn't exist + manager->initialize(TEST_FILENAME); + // validate that some of the defaults are available. + std::map<std::string, std::string> known_grids = manager->getKnownGrids(); + ensure_equals("Known grids is a string-string map of size 2", known_grids.size(), 2); + ensure_equals("Agni has the right name and label", + known_grids[std::string("util.agni.lindenlab.com")], + std::string("Second Life Main Grid (Agni)")); + ensure_equals("Aditi has the right name and label", + known_grids[std::string("util.aditi.lindenlab.com")], + std::string("Second Life Beta Test Grid (Aditi)")); + ensure_equals("name for agni", + LLGridManager::getInstance()->getGrid("util.agni.lindenlab.com"), + std::string("util.agni.lindenlab.com")); + ensure_equals("id for agni", + std::string("Agni"), + LLGridManager::getInstance()->getGridId("util.agni.lindenlab.com")); + ensure_equals("update url base for Agni", // relies on agni being the default + std::string("https://update.secondlife.com/update"), + LLGridManager::getInstance()->getUpdateServiceURL()); + ensure_equals("label for agni", + LLGridManager::getInstance()->getGridLabel("util.agni.lindenlab.com"), + std::string("Second Life Main Grid (Agni)")); + + std::vector<std::string> login_uris; + LLGridManager::getInstance()->getLoginURIs(std::string("util.agni.lindenlab.com"), login_uris); + ensure_equals("Number of login uris for agni", 1, login_uris.size()); + ensure_equals("Agni login uri", + login_uris[0], + std::string("https://login.agni.lindenlab.com/cgi-bin/login.cgi")); + ensure_equals("Agni helper uri", + LLGridManager::getInstance()->getHelperURI("util.agni.lindenlab.com"), + std::string("https://secondlife.com/helpers/")); + ensure_equals("Agni login page", + LLGridManager::getInstance()->getLoginPage("util.agni.lindenlab.com"), + std::string("https://viewer-splash.secondlife.com/")); + ensure("Agni is a system grid", + LLGridManager::getInstance()->isSystemGrid("util.agni.lindenlab.com")); + + ensure_equals("name for aditi", + LLGridManager::getInstance()->getGrid("util.aditi.lindenlab.com"), + std::string("util.aditi.lindenlab.com")); + ensure_equals("id for aditi", + LLGridManager::getInstance()->getGridId("util.aditi.lindenlab.com"), + std::string("Aditi")); + ensure_equals("label for aditi", + LLGridManager::getInstance()->getGridLabel("util.aditi.lindenlab.com"), + std::string("Second Life Beta Test Grid (Aditi)")); + + LLGridManager::getInstance()->getLoginURIs(std::string("util.aditi.lindenlab.com"), login_uris); + + ensure_equals("Number of login uris for aditi", 1, login_uris.size()); + ensure_equals("Aditi login uri", + login_uris[0], + std::string("https://login.aditi.lindenlab.com/cgi-bin/login.cgi")); + ensure_equals("Aditi helper uri", + LLGridManager::getInstance()->getHelperURI("util.aditi.lindenlab.com"), std::string("https://secondlife.aditi.lindenlab.com/helpers/")); - ensure_equals("Aditi login page", - LLGridManager::getInstance()->getLoginPage("util.aditi.lindenlab.com"), - std::string("https://viewer-splash.secondlife.com/")); - ensure("Aditi is a system grid", - LLGridManager::getInstance()->isSystemGrid("util.aditi.lindenlab.com")); - } - - // initialization with a grid file - template<> template<> - void viewerNetworkTestObject::test<2>() - { - llofstream gridfile(TEST_FILENAME); - gridfile << gSampleGridFile; - gridfile.close(); - - LLGridManager::getInstance()->initialize(TEST_FILENAME); - std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids(); - ensure_equals("adding a grid via a grid file increases known grid size",4, - known_grids.size()); - - // Verify that Agni and Aditi were not overwritten - ensure_equals("Agni has the right name and label", - known_grids[std::string("util.agni.lindenlab.com")], - std::string("Second Life Main Grid (Agni)")); - ensure_equals("Aditi has the right name and label", - known_grids[std::string("util.aditi.lindenlab.com")], - std::string("Second Life Beta Test Grid (Aditi)")); - ensure_equals("name for agni", - LLGridManager::getInstance()->getGrid("util.agni.lindenlab.com"), - std::string("util.agni.lindenlab.com")); - ensure_equals("id for agni", - LLGridManager::getInstance()->getGridId("util.agni.lindenlab.com"), - std::string("Agni")); - ensure_equals("update url base for Agni", // relies on agni being the default - std::string("https://update.secondlife.com/update"), - LLGridManager::getInstance()->getUpdateServiceURL()); - ensure_equals("label for agni", - LLGridManager::getInstance()->getGridLabel("util.agni.lindenlab.com"), - std::string("Second Life Main Grid (Agni)")); - std::vector<std::string> login_uris; - LLGridManager::getInstance()->getLoginURIs(std::string("util.agni.lindenlab.com"), login_uris); - ensure_equals("Number of login uris for agni", 1, login_uris.size()); - ensure_equals("Agni login uri", - login_uris[0], - std::string("https://login.agni.lindenlab.com/cgi-bin/login.cgi")); - ensure_equals("Agni helper uri", - LLGridManager::getInstance()->getHelperURI("util.agni.lindenlab.com"), - std::string("https://secondlife.com/helpers/")); - ensure_equals("Agni login page", - LLGridManager::getInstance()->getLoginPage("util.agni.lindenlab.com"), - std::string("https://viewer-splash.secondlife.com/")); - ensure("Agni is a system grid", - LLGridManager::getInstance()->isSystemGrid("util.agni.lindenlab.com")); - - ensure_equals("name for aditi", - LLGridManager::getInstance()->getGrid("util.aditi.lindenlab.com"), - std::string("util.aditi.lindenlab.com")); - ensure_equals("id for aditi", - LLGridManager::getInstance()->getGridId("util.aditi.lindenlab.com"), - std::string("Aditi")); - ensure_equals("label for aditi", - LLGridManager::getInstance()->getGridLabel("util.aditi.lindenlab.com"), - std::string("Second Life Beta Test Grid (Aditi)")); - - LLGridManager::getInstance()->getLoginURIs(std::string("util.aditi.lindenlab.com"), login_uris); - ensure_equals("Number of login uris for aditi", 1, login_uris.size()); - ensure_equals("Aditi login uri", - login_uris[0], - std::string("https://login.aditi.lindenlab.com/cgi-bin/login.cgi")); - ensure_equals("Aditi helper uri", - LLGridManager::getInstance()->getHelperURI("util.aditi.lindenlab.com"), + ensure_equals("Aditi login page", + LLGridManager::getInstance()->getLoginPage("util.aditi.lindenlab.com"), + std::string("https://viewer-splash.secondlife.com/")); + ensure("Aditi is a system grid", + LLGridManager::getInstance()->isSystemGrid("util.aditi.lindenlab.com")); + } + + // initialization with a grid file + template<> template<> + void viewerNetworkTestObject::test<2>() + { + llofstream gridfile(TEST_FILENAME); + gridfile << gSampleGridFile; + gridfile.close(); + + LLGridManager::getInstance()->initialize(TEST_FILENAME); + std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids(); + ensure_equals("adding a grid via a grid file increases known grid size",4, + known_grids.size()); + + // Verify that Agni and Aditi were not overwritten + ensure_equals("Agni has the right name and label", + known_grids[std::string("util.agni.lindenlab.com")], + std::string("Second Life Main Grid (Agni)")); + ensure_equals("Aditi has the right name and label", + known_grids[std::string("util.aditi.lindenlab.com")], + std::string("Second Life Beta Test Grid (Aditi)")); + ensure_equals("name for agni", + LLGridManager::getInstance()->getGrid("util.agni.lindenlab.com"), + std::string("util.agni.lindenlab.com")); + ensure_equals("id for agni", + LLGridManager::getInstance()->getGridId("util.agni.lindenlab.com"), + std::string("Agni")); + ensure_equals("update url base for Agni", // relies on agni being the default + std::string("https://update.secondlife.com/update"), + LLGridManager::getInstance()->getUpdateServiceURL()); + ensure_equals("label for agni", + LLGridManager::getInstance()->getGridLabel("util.agni.lindenlab.com"), + std::string("Second Life Main Grid (Agni)")); + std::vector<std::string> login_uris; + LLGridManager::getInstance()->getLoginURIs(std::string("util.agni.lindenlab.com"), login_uris); + ensure_equals("Number of login uris for agni", 1, login_uris.size()); + ensure_equals("Agni login uri", + login_uris[0], + std::string("https://login.agni.lindenlab.com/cgi-bin/login.cgi")); + ensure_equals("Agni helper uri", + LLGridManager::getInstance()->getHelperURI("util.agni.lindenlab.com"), + std::string("https://secondlife.com/helpers/")); + ensure_equals("Agni login page", + LLGridManager::getInstance()->getLoginPage("util.agni.lindenlab.com"), + std::string("https://viewer-splash.secondlife.com/")); + ensure("Agni is a system grid", + LLGridManager::getInstance()->isSystemGrid("util.agni.lindenlab.com")); + + ensure_equals("name for aditi", + LLGridManager::getInstance()->getGrid("util.aditi.lindenlab.com"), + std::string("util.aditi.lindenlab.com")); + ensure_equals("id for aditi", + LLGridManager::getInstance()->getGridId("util.aditi.lindenlab.com"), + std::string("Aditi")); + ensure_equals("label for aditi", + LLGridManager::getInstance()->getGridLabel("util.aditi.lindenlab.com"), + std::string("Second Life Beta Test Grid (Aditi)")); + + LLGridManager::getInstance()->getLoginURIs(std::string("util.aditi.lindenlab.com"), login_uris); + ensure_equals("Number of login uris for aditi", 1, login_uris.size()); + ensure_equals("Aditi login uri", + login_uris[0], + std::string("https://login.aditi.lindenlab.com/cgi-bin/login.cgi")); + ensure_equals("Aditi helper uri", + LLGridManager::getInstance()->getHelperURI("util.aditi.lindenlab.com"), std::string("https://secondlife.aditi.lindenlab.com/helpers/")); - ensure_equals("Aditi login page", - LLGridManager::getInstance()->getLoginPage("util.aditi.lindenlab.com"), - std::string("https://viewer-splash.secondlife.com/")); - ensure("Aditi is a system grid", - LLGridManager::getInstance()->isSystemGrid("util.aditi.lindenlab.com")); - - // Check the additional grid from the file - ensure_equals("alternative grid is in name<->label map", - known_grids["altgrid.long.name"], - std::string("Alternative Grid")); - ensure_equals("alternative grid name is set", - LLGridManager::getInstance()->getGrid("altgrid.long.name"), - std::string("altgrid.long.name")); - ensure_equals("alternative grid id", - LLGridManager::getInstance()->getGridId("altgrid.long.name"), - std::string("AltGrid")); - ensure_equals("alternative grid label", - LLGridManager::getInstance()->getGridLabel("altgrid.long.name"), - std::string("Alternative Grid")); - std::vector<std::string> alt_login_uris; - LLGridManager::getInstance()->getLoginURIs(std::string("altgrid.long.name"), alt_login_uris); - ensure_equals("Number of login uris for altgrid", 2, alt_login_uris.size()); - ensure_equals("alternative grid first login uri", - alt_login_uris[0], - std::string("altgrid/myloginuri1")); - ensure_equals("alternative grid second login uri", - alt_login_uris[1], - std::string("altgrid/myloginuri2")); - ensure_equals("alternative grid helper uri", - LLGridManager::getInstance()->getHelperURI("altgrid.long.name"), - std::string("https://helper1/helpers/")); - ensure_equals("alternative grid login page", - LLGridManager::getInstance()->getLoginPage("altgrid.long.name"), - std::string("altgrid/loginpage")); - ensure("alternative grid is NOT a system grid", - ! LLGridManager::getInstance()->isSystemGrid("altgrid.long.name")); - - ensure_equals("minimal grid is in name<->label map", - known_grids["minimal.long.name"], - std::string("minimal.long.name")); - ensure_equals("minimal grid name is set", - LLGridManager::getInstance()->getGrid("minimal.long.name"), - std::string("minimal.long.name")); - ensure_equals("minimal grid id", - LLGridManager::getInstance()->getGridId("minimal.long.name"), - std::string("minimal.long.name")); - ensure_equals("minimal grid label", - LLGridManager::getInstance()->getGridLabel("minimal.long.name"), - std::string("minimal.long.name")); - - LLGridManager::getInstance()->getLoginURIs(std::string("minimal.long.name"), alt_login_uris); - ensure_equals("Number of login uris for altgrid", 1, alt_login_uris.size()); - ensure_equals("minimal grid login uri", - alt_login_uris[0], - std::string("https://minimal.long.name/cgi-bin/login.cgi")); - ensure_equals("minimal grid helper uri", - LLGridManager::getInstance()->getHelperURI("minimal.long.name"), - std::string("https://minimal.long.name/helpers/")); - ensure_equals("minimal grid login page", - LLGridManager::getInstance()->getLoginPage("minimal.long.name"), - std::string("http://minimal.long.name/app/login/")); - - } - - - // validate grid selection - template<> template<> - void viewerNetworkTestObject::test<7>() - { - // adding a grid with simply a name will populate the values. - llofstream gridfile(TEST_FILENAME); - gridfile << gSampleGridFile; - gridfile.close(); - - LLGridManager::getInstance()->initialize(TEST_FILENAME); - - LLGridManager::getInstance()->setGridChoice("util.agni.lindenlab.com"); - ensure_equals("getGridLabel", - LLGridManager::getInstance()->getGridLabel(), - std::string("Second Life Main Grid (Agni)")); - ensure_equals("getGridId", - LLGridManager::getInstance()->getGridId(), - std::string("Agni")); - ensure_equals("getGrid", - LLGridManager::getInstance()->getGrid(), - std::string("util.agni.lindenlab.com")); - ensure_equals("getHelperURI", - LLGridManager::getInstance()->getHelperURI(), - std::string("https://secondlife.com/helpers/")); - ensure_equals("getLoginPage", - LLGridManager::getInstance()->getLoginPage(), - std::string("https://viewer-splash.secondlife.com/")); - ensure_equals("update url base for Agni", // relies on agni being the default - std::string("https://update.secondlife.com/update"), - LLGridManager::getInstance()->getUpdateServiceURL()); - ensure("Is Agni a production grid", LLGridManager::getInstance()->isInProductionGrid()); - std::vector<std::string> uris; - LLGridManager::getInstance()->getLoginURIs(uris); - ensure_equals("getLoginURIs size", 1, uris.size()); - ensure_equals("getLoginURIs", - uris[0], - std::string("https://login.agni.lindenlab.com/cgi-bin/login.cgi")); - - LLGridManager::getInstance()->setGridChoice("altgrid.long.name"); - ensure_equals("getGridLabel", - LLGridManager::getInstance()->getGridLabel(), - std::string("Alternative Grid")); - ensure_equals("getGridId", - LLGridManager::getInstance()->getGridId(), - std::string("AltGrid")); - ensure("alternative grid is not a system grid", - !LLGridManager::getInstance()->isSystemGrid()); - ensure("alternative grid is not a production grid", - !LLGridManager::getInstance()->isInProductionGrid()); - } + ensure_equals("Aditi login page", + LLGridManager::getInstance()->getLoginPage("util.aditi.lindenlab.com"), + std::string("https://viewer-splash.secondlife.com/")); + ensure("Aditi is a system grid", + LLGridManager::getInstance()->isSystemGrid("util.aditi.lindenlab.com")); + + // Check the additional grid from the file + ensure_equals("alternative grid is in name<->label map", + known_grids["altgrid.long.name"], + std::string("Alternative Grid")); + ensure_equals("alternative grid name is set", + LLGridManager::getInstance()->getGrid("altgrid.long.name"), + std::string("altgrid.long.name")); + ensure_equals("alternative grid id", + LLGridManager::getInstance()->getGridId("altgrid.long.name"), + std::string("AltGrid")); + ensure_equals("alternative grid label", + LLGridManager::getInstance()->getGridLabel("altgrid.long.name"), + std::string("Alternative Grid")); + std::vector<std::string> alt_login_uris; + LLGridManager::getInstance()->getLoginURIs(std::string("altgrid.long.name"), alt_login_uris); + ensure_equals("Number of login uris for altgrid", 2, alt_login_uris.size()); + ensure_equals("alternative grid first login uri", + alt_login_uris[0], + std::string("altgrid/myloginuri1")); + ensure_equals("alternative grid second login uri", + alt_login_uris[1], + std::string("altgrid/myloginuri2")); + ensure_equals("alternative grid helper uri", + LLGridManager::getInstance()->getHelperURI("altgrid.long.name"), + std::string("https://helper1/helpers/")); + ensure_equals("alternative grid login page", + LLGridManager::getInstance()->getLoginPage("altgrid.long.name"), + std::string("altgrid/loginpage")); + ensure("alternative grid is NOT a system grid", + ! LLGridManager::getInstance()->isSystemGrid("altgrid.long.name")); + + ensure_equals("minimal grid is in name<->label map", + known_grids["minimal.long.name"], + std::string("minimal.long.name")); + ensure_equals("minimal grid name is set", + LLGridManager::getInstance()->getGrid("minimal.long.name"), + std::string("minimal.long.name")); + ensure_equals("minimal grid id", + LLGridManager::getInstance()->getGridId("minimal.long.name"), + std::string("minimal.long.name")); + ensure_equals("minimal grid label", + LLGridManager::getInstance()->getGridLabel("minimal.long.name"), + std::string("minimal.long.name")); + + LLGridManager::getInstance()->getLoginURIs(std::string("minimal.long.name"), alt_login_uris); + ensure_equals("Number of login uris for altgrid", 1, alt_login_uris.size()); + ensure_equals("minimal grid login uri", + alt_login_uris[0], + std::string("https://minimal.long.name/cgi-bin/login.cgi")); + ensure_equals("minimal grid helper uri", + LLGridManager::getInstance()->getHelperURI("minimal.long.name"), + std::string("https://minimal.long.name/helpers/")); + ensure_equals("minimal grid login page", + LLGridManager::getInstance()->getLoginPage("minimal.long.name"), + std::string("http://minimal.long.name/app/login/")); + + } + + + // validate grid selection + template<> template<> + void viewerNetworkTestObject::test<7>() + { + // adding a grid with simply a name will populate the values. + llofstream gridfile(TEST_FILENAME); + gridfile << gSampleGridFile; + gridfile.close(); + + LLGridManager::getInstance()->initialize(TEST_FILENAME); + + LLGridManager::getInstance()->setGridChoice("util.agni.lindenlab.com"); + ensure_equals("getGridLabel", + LLGridManager::getInstance()->getGridLabel(), + std::string("Second Life Main Grid (Agni)")); + ensure_equals("getGridId", + LLGridManager::getInstance()->getGridId(), + std::string("Agni")); + ensure_equals("getGrid", + LLGridManager::getInstance()->getGrid(), + std::string("util.agni.lindenlab.com")); + ensure_equals("getHelperURI", + LLGridManager::getInstance()->getHelperURI(), + std::string("https://secondlife.com/helpers/")); + ensure_equals("getLoginPage", + LLGridManager::getInstance()->getLoginPage(), + std::string("https://viewer-splash.secondlife.com/")); + ensure_equals("update url base for Agni", // relies on agni being the default + std::string("https://update.secondlife.com/update"), + LLGridManager::getInstance()->getUpdateServiceURL()); + ensure("Is Agni a production grid", LLGridManager::getInstance()->isInProductionGrid()); + std::vector<std::string> uris; + LLGridManager::getInstance()->getLoginURIs(uris); + ensure_equals("getLoginURIs size", 1, uris.size()); + ensure_equals("getLoginURIs", + uris[0], + std::string("https://login.agni.lindenlab.com/cgi-bin/login.cgi")); + + LLGridManager::getInstance()->setGridChoice("altgrid.long.name"); + ensure_equals("getGridLabel", + LLGridManager::getInstance()->getGridLabel(), + std::string("Alternative Grid")); + ensure_equals("getGridId", + LLGridManager::getInstance()->getGridId(), + std::string("AltGrid")); + ensure("alternative grid is not a system grid", + !LLGridManager::getInstance()->isSystemGrid()); + ensure("alternative grid is not a production grid", + !LLGridManager::getInstance()->isInProductionGrid()); + } } diff --git a/indra/newview/tests/llvieweroctree_stub.cpp b/indra/newview/tests/llvieweroctree_stub.cpp index ab180c49a3..caf9299a2f 100644 --- a/indra/newview/tests/llvieweroctree_stub.cpp +++ b/indra/newview/tests/llvieweroctree_stub.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llvieweroctree_stub.cpp * @brief stub implementations to allow unit testing * * $LicenseInfo:firstyear=2023&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$ */ diff --git a/indra/newview/tests/llviewershadermgr_stub.cpp b/indra/newview/tests/llviewershadermgr_stub.cpp index 18eff72f3c..5d6cb33019 100644 --- a/indra/newview/tests/llviewershadermgr_stub.cpp +++ b/indra/newview/tests/llviewershadermgr_stub.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llglslshader_stub.cpp * @brief stub class to allow unit testing * * $LicenseInfo:firstyear=2009&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$ */ @@ -35,12 +35,12 @@ LLViewerShaderMgr::~LLViewerShaderMgr() {} LLViewerShaderMgr* stub_instance = NULL; LLViewerShaderMgr* LLViewerShaderMgr::instance() { - if(NULL == stub_instance) - { - stub_instance = new LLViewerShaderMgr(); - } + if(NULL == stub_instance) + { + stub_instance = new LLViewerShaderMgr(); + } - return stub_instance; + return stub_instance; } LLViewerShaderMgr::shader_iter fake_iter; LLViewerShaderMgr::shader_iter LLViewerShaderMgr::beginShaders() const {return fake_iter;} diff --git a/indra/newview/tests/llviewertexture_stub.cpp b/indra/newview/tests/llviewertexture_stub.cpp index 889ab9bea5..8ac3bf2279 100644 --- a/indra/newview/tests/llviewertexture_stub.cpp +++ b/indra/newview/tests/llviewertexture_stub.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llviewertexture_stub.cpp * @brief stub class to allow unit testing * * $LicenseInfo:firstyear=2012&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$ */ diff --git a/indra/newview/tests/llwlanimator_stub.cpp b/indra/newview/tests/llwlanimator_stub.cpp index f5e15b2e7b..2b4510a6b7 100644 --- a/indra/newview/tests/llwlanimator_stub.cpp +++ b/indra/newview/tests/llwlanimator_stub.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llwlanimator_stub.cpp * @brief stub class to allow unit testing * * $LicenseInfo:firstyear=2009&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$ */ diff --git a/indra/newview/tests/llwldaycycle_stub.cpp b/indra/newview/tests/llwldaycycle_stub.cpp index a7bc9a7b83..cd82e9b200 100644 --- a/indra/newview/tests/llwldaycycle_stub.cpp +++ b/indra/newview/tests/llwldaycycle_stub.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llwldaycycle_stub.cpp * @brief stub class to allow unit testing * * $LicenseInfo:firstyear=2009&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$ */ @@ -34,13 +34,13 @@ LLWLDayCycle::~LLWLDayCycle(void) bool LLWLDayCycle::getKeytime(LLWLParamKey keyFrame, F32& keyTime) { - keyTime = 0.5; - return true; + keyTime = 0.5; + return true; } bool LLWLDayCycle::removeKeyframe(F32 time) { - return true; + return true; } void LLWLDayCycle::loadDayCycleFromFile(const std::string& fileName) diff --git a/indra/newview/tests/llwlparammanager_test.cpp b/indra/newview/tests/llwlparammanager_test.cpp index be0dc9fd0c..2838ddb719 100644 --- a/indra/newview/tests/llwlparammanager_test.cpp +++ b/indra/newview/tests/llwlparammanager_test.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llwlparammanager_test.cpp * @brief LLWLParamManager tests * * $LicenseInfo:firstyear=2009&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$ */ @@ -53,219 +53,219 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil:: char* curl_unescape(const char* c_str, int length) { - char* copy = new char[length+4]; - memcpy(copy, c_str, length); - copy[length+0] = 'E'; - copy[length+1] = 'S'; - copy[length+2] = 'C'; - copy[length+3] = '\0'; - return copy; + char* copy = new char[length+4]; + memcpy(copy, c_str, length); + copy[length+0] = 'E'; + copy[length+1] = 'S'; + copy[length+2] = 'C'; + copy[length+3] = '\0'; + return copy; } void curl_free(void* p) {delete[] ((char*)p);} char* curl_escape(const char* c_str, int length) { - char* copy = new char[length+6]; - memcpy(copy, c_str, length); - copy[length+0] = 'U'; - copy[length+1] = 'N'; - copy[length+2] = 'E'; - copy[length+3] = 'S'; - copy[length+4] = 'C'; - copy[length+5] = '\0'; - return copy; + char* copy = new char[length+6]; + memcpy(copy, c_str, length); + copy[length+0] = 'U'; + copy[length+1] = 'N'; + copy[length+2] = 'E'; + copy[length+3] = 'S'; + copy[length+4] = 'C'; + copy[length+5] = '\0'; + return copy; } namespace tut { - // Main Setup - struct LLWLParamManagerFixture - { - class LLWLParamManagerTest - { - }; + // Main Setup + struct LLWLParamManagerFixture + { + class LLWLParamManagerTest + { + }; - LLWLParamManager* mTestManager; + LLWLParamManager* mTestManager; - LLWLParamManagerFixture() - : mTestManager(LLWLParamManager::getInstance()) - { - } + LLWLParamManagerFixture() + : mTestManager(LLWLParamManager::getInstance()) + { + } - ~LLWLParamManagerFixture() - { - } - }; - typedef test_group<LLWLParamManagerFixture> factory; - typedef factory::object object; - factory tf("LLWLParamManager test"); + ~LLWLParamManagerFixture() + { + } + }; + typedef test_group<LLWLParamManagerFixture> factory; + typedef factory::object object; + factory tf("LLWLParamManager test"); - // Tests - template<> template<> - void object::test<1>() - { - try - { - std::string preset = - "<llsd>\ - <map>\ - <key>ambient</key>\ - <array>\ - <real>1.0499999523162842</real>\ - <real>1.0499999523162842</real>\ - <real>1.0499999523162842</real>\ - <real>0.34999999403953552</real>\ - </array>\ - <key>blue_density</key>\ - <array>\ - <real>0.2447581488182351</real>\ - <real>0.44872328639030457</real>\ - <real>0.75999999046325684</real>\ - <real>0.38000004053115788</real>\ - </array>\ - <key>blue_horizon</key>\ - <array>\ - <real>0.49548382097675159</real>\ - <real>0.49548381382419748</real>\ - <real>0.63999999284744291</real>\ - <real>0.31999999642372146</real>\ - </array>\ - <key>cloud_color</key>\ - <array>\ - <real>0.40999999165535073</real>\ - <real>0.40999999165535073</real>\ - <real>0.40999999165535073</real>\ - <real>0.40999999165535073</real>\ - </array>\ - <key>cloud_pos_density1</key>\ - <array>\ - <real>1.6884100437164307</real>\ - <real>0.52609699964523315</real>\ - <real>0.99999999999999289</real>\ - <real>1</real>\ - </array>\ - <key>cloud_pos_density2</key>\ - <array>\ - <real>1.6884100437164307</real>\ - <real>0.52609699964523315</real>\ - <real>0.125</real>\ - <real>1</real>\ - </array>\ - <key>cloud_scale</key>\ - <array>\ - <real>0.4199999868869746</real>\ - <real>0</real>\ - <real>0</real>\ - <real>1</real>\ - </array>\ - <key>cloud_scroll_rate</key>\ - <array>\ - <real>10.199999809265137</real>\ - <real>10.01099967956543</real>\ - </array>\ - <key>cloud_shadow</key>\ - <array>\ - <real>0.26999998092651367</real>\ - <real>0</real>\ - <real>0</real>\ - <real>1</real>\ - </array>\ - <key>density_multiplier</key>\ - <array>\ - <real>0.00017999998817685818</real>\ - <real>0</real>\ - <real>0</real>\ - <real>1</real>\ - </array>\ - <key>distance_multiplier</key>\ - <array>\ - <real>0.80000001192093606</real>\ - <real>0</real>\ - <real>0</real>\ - <real>1</real>\ - </array>\ - <key>east_angle</key>\ - <real>0</real>\ - <key>enable_cloud_scroll</key>\ - <array>\ - <boolean>1</boolean>\ - <boolean>1</boolean>\ - </array>\ - <key>gamma</key>\ - <array>\ - <real>1</real>\ - <real>0</real>\ - <real>0</real>\ - <real>1</real>\ - </array>\ - <key>glow</key>\ - <array>\ - <real>5</real>\ - <real>0.0010000000474974513</real>\ - <real>-0.47999998927116394</real>\ - <real>1</real>\ - </array>\ - <key>haze_density</key>\ - <array>\ - <real>0.69999998807907104</real>\ - <real>0</real>\ - <real>0</real>\ - <real>1</real>\ - </array>\ - <key>haze_horizon</key>\ - <array>\ - <real>0.18999999761581243</real>\ - <real>0.19915600121021271</real>\ - <real>0.19915600121021271</real>\ - <real>1</real>\ - </array>\ - <key>lightnorm</key>\ - <array>\ - <real>0</real>\ - <real>0.70710659027099609</real>\ - <real>-0.70710694789886475</real>\ - <real>0</real>\ - </array>\ - <key>max_y</key>\ - <array>\ - <real>1605</real>\ - <real>0</real>\ - <real>0</real>\ - <real>1</real>\ - </array>\ - <key>preset_num</key>\ - <integer>22</integer>\ - <key>star_brightness</key>\ - <real>0</real>\ - <key>sun_angle</key>\ - <real>2.3561947345733643</real>\ - <key>sunlight_color</key>\ - <array>\ - <real>0.73421055078505759</real>\ - <real>0.78157895803450828</real>\ - <real>0.89999997615813498</real>\ - <real>0.29999998211860301</real>\ - </array>\ - </map>\ - </llsd>"; + // Tests + template<> template<> + void object::test<1>() + { + try + { + std::string preset = + "<llsd>\ + <map>\ + <key>ambient</key>\ + <array>\ + <real>1.0499999523162842</real>\ + <real>1.0499999523162842</real>\ + <real>1.0499999523162842</real>\ + <real>0.34999999403953552</real>\ + </array>\ + <key>blue_density</key>\ + <array>\ + <real>0.2447581488182351</real>\ + <real>0.44872328639030457</real>\ + <real>0.75999999046325684</real>\ + <real>0.38000004053115788</real>\ + </array>\ + <key>blue_horizon</key>\ + <array>\ + <real>0.49548382097675159</real>\ + <real>0.49548381382419748</real>\ + <real>0.63999999284744291</real>\ + <real>0.31999999642372146</real>\ + </array>\ + <key>cloud_color</key>\ + <array>\ + <real>0.40999999165535073</real>\ + <real>0.40999999165535073</real>\ + <real>0.40999999165535073</real>\ + <real>0.40999999165535073</real>\ + </array>\ + <key>cloud_pos_density1</key>\ + <array>\ + <real>1.6884100437164307</real>\ + <real>0.52609699964523315</real>\ + <real>0.99999999999999289</real>\ + <real>1</real>\ + </array>\ + <key>cloud_pos_density2</key>\ + <array>\ + <real>1.6884100437164307</real>\ + <real>0.52609699964523315</real>\ + <real>0.125</real>\ + <real>1</real>\ + </array>\ + <key>cloud_scale</key>\ + <array>\ + <real>0.4199999868869746</real>\ + <real>0</real>\ + <real>0</real>\ + <real>1</real>\ + </array>\ + <key>cloud_scroll_rate</key>\ + <array>\ + <real>10.199999809265137</real>\ + <real>10.01099967956543</real>\ + </array>\ + <key>cloud_shadow</key>\ + <array>\ + <real>0.26999998092651367</real>\ + <real>0</real>\ + <real>0</real>\ + <real>1</real>\ + </array>\ + <key>density_multiplier</key>\ + <array>\ + <real>0.00017999998817685818</real>\ + <real>0</real>\ + <real>0</real>\ + <real>1</real>\ + </array>\ + <key>distance_multiplier</key>\ + <array>\ + <real>0.80000001192093606</real>\ + <real>0</real>\ + <real>0</real>\ + <real>1</real>\ + </array>\ + <key>east_angle</key>\ + <real>0</real>\ + <key>enable_cloud_scroll</key>\ + <array>\ + <boolean>1</boolean>\ + <boolean>1</boolean>\ + </array>\ + <key>gamma</key>\ + <array>\ + <real>1</real>\ + <real>0</real>\ + <real>0</real>\ + <real>1</real>\ + </array>\ + <key>glow</key>\ + <array>\ + <real>5</real>\ + <real>0.0010000000474974513</real>\ + <real>-0.47999998927116394</real>\ + <real>1</real>\ + </array>\ + <key>haze_density</key>\ + <array>\ + <real>0.69999998807907104</real>\ + <real>0</real>\ + <real>0</real>\ + <real>1</real>\ + </array>\ + <key>haze_horizon</key>\ + <array>\ + <real>0.18999999761581243</real>\ + <real>0.19915600121021271</real>\ + <real>0.19915600121021271</real>\ + <real>1</real>\ + </array>\ + <key>lightnorm</key>\ + <array>\ + <real>0</real>\ + <real>0.70710659027099609</real>\ + <real>-0.70710694789886475</real>\ + <real>0</real>\ + </array>\ + <key>max_y</key>\ + <array>\ + <real>1605</real>\ + <real>0</real>\ + <real>0</real>\ + <real>1</real>\ + </array>\ + <key>preset_num</key>\ + <integer>22</integer>\ + <key>star_brightness</key>\ + <real>0</real>\ + <key>sun_angle</key>\ + <real>2.3561947345733643</real>\ + <key>sunlight_color</key>\ + <array>\ + <real>0.73421055078505759</real>\ + <real>0.78157895803450828</real>\ + <real>0.89999997615813498</real>\ + <real>0.29999998211860301</real>\ + </array>\ + </map>\ + </llsd>"; - std::stringstream preset_stream(preset); - mTestManager->loadPresetFromXML(LLWLParamKey("test1", LLWLParamKey::SCOPE_LOCAL), preset_stream); - LLWLParamSet dummy; - ensure("Couldn't get ParamSet after loading it", mTestManager->getParamSet(LLWLParamKey("test1", LLWLParamKey::SCOPE_LOCAL), dummy)); - } - catch (...) - { - fail("loadPresetFromXML test crashed!"); - } - } + std::stringstream preset_stream(preset); + mTestManager->loadPresetFromXML(LLWLParamKey("test1", LLWLParamKey::SCOPE_LOCAL), preset_stream); + LLWLParamSet dummy; + ensure("Couldn't get ParamSet after loading it", mTestManager->getParamSet(LLWLParamKey("test1", LLWLParamKey::SCOPE_LOCAL), dummy)); + } + catch (...) + { + fail("loadPresetFromXML test crashed!"); + } + } - template<> template<> - void object::test<2>() - { - mTestManager->propagateParameters(); - ensure_equals("Wrong value from getDomeOffset()", mTestManager->getDomeOffset(), 0.96f); - ensure_equals("Wrong value from getDomeRadius()", mTestManager->getDomeRadius(), 15000.f); - ensure_equals("Wrong value from getLightDir()", mTestManager->getLightDir(), LLVector4(-0,0,1,0)); - ensure_equals("Wrong value from getClampedLightDir()", mTestManager->getClampedLightDir(), LLVector4(-0,0,1,0)); - ensure_equals("Wrong value from getRotatedLightDir()", mTestManager->getRotatedLightDir(), LLVector4(0,0,0,1)); - } + template<> template<> + void object::test<2>() + { + mTestManager->propagateParameters(); + ensure_equals("Wrong value from getDomeOffset()", mTestManager->getDomeOffset(), 0.96f); + ensure_equals("Wrong value from getDomeRadius()", mTestManager->getDomeRadius(), 15000.f); + ensure_equals("Wrong value from getLightDir()", mTestManager->getLightDir(), LLVector4(-0,0,1,0)); + ensure_equals("Wrong value from getClampedLightDir()", mTestManager->getClampedLightDir(), LLVector4(-0,0,1,0)); + ensure_equals("Wrong value from getRotatedLightDir()", mTestManager->getRotatedLightDir(), LLVector4(0,0,0,1)); + } } diff --git a/indra/newview/tests/llwlparamset_stub.cpp b/indra/newview/tests/llwlparamset_stub.cpp index ccb99db475..e6c4221895 100644 --- a/indra/newview/tests/llwlparamset_stub.cpp +++ b/indra/newview/tests/llwlparamset_stub.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llwlparamset_stub.cpp * @brief stub class to allow unit testing * * $LicenseInfo:firstyear=2009&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$ */ diff --git a/indra/newview/tests/llworldmap_test.cpp b/indra/newview/tests/llworldmap_test.cpp index f1dd8acccf..03ab9de96c 100644 --- a/indra/newview/tests/llworldmap_test.cpp +++ b/indra/newview/tests/llworldmap_test.cpp @@ -1,4 +1,4 @@ -/** +/** * @file llworldmap_test.cpp * @author Merov Linden * @date 2009-03-09 @@ -6,21 +6,21 @@ * $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$ */ @@ -40,7 +40,7 @@ // ------------------------------------------------------------------------------------------- // Stubbing: Declarations required to link and run the class being tested -// Notes: +// Notes: // * Add here stubbed implementation of the few classes and methods used in the class to be tested // * Add as little as possible (let the link errors guide you) // * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code) @@ -50,7 +50,7 @@ void LLGLTexture::setBoostLevel(S32 ) { } void LLGLTexture::setAddressMode(LLTexUnit::eTextureAddressMode ) { } LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTexture(const LLUUID&, FTType, BOOL, LLGLTexture::EBoostLevel, S8, - LLGLint, LLGLenum, LLHost ) { return NULL; } + LLGLint, LLGLenum, LLHost ) { return NULL; } // Stub related map calls LLWorldMapMessage::LLWorldMapMessage() { } @@ -88,428 +88,428 @@ const std::string SIM_NAME_TEST = "Sim Foo"; namespace tut { - // Test wrapper declarations - struct iteminfo_test - { - // Instance to be tested - LLItemInfo* mItem; - - // Constructor and destructor of the test wrapper - iteminfo_test() - { - LLUUID id; - mItem = new LLItemInfo(X_WORLD_TEST, Y_WORLD_TEST, ITEM_NAME_TEST, id); - } - ~iteminfo_test() - { - delete mItem; - } - }; - - struct siminfo_test - { - // Instance to be tested - LLSimInfo* mSim; - - // Constructor and destructor of the test wrapper - siminfo_test() - { - U64 handle = to_region_handle_global(X_WORLD_TEST, Y_WORLD_TEST); - mSim = new LLSimInfo(handle); - } - ~siminfo_test() - { - delete mSim; - } - }; - - struct worldmap_test - { - // Instance to be tested - LLWorldMap* mWorld; - - // Constructor and destructor of the test wrapper - worldmap_test() - { - mWorld = LLWorldMap::getInstance(); - } - ~worldmap_test() - { - mWorld = NULL; - } - }; - - // Tut templating thingamagic: test group, object and test instance - typedef test_group<iteminfo_test> iteminfo_t; - typedef iteminfo_t::object iteminfo_object_t; - tut::iteminfo_t tut_iteminfo("LLItemInfo"); - - typedef test_group<siminfo_test> siminfo_t; - typedef siminfo_t::object siminfo_object_t; - tut::siminfo_t tut_siminfo("LLSimInfo"); - - typedef test_group<worldmap_test> worldmap_t; - typedef worldmap_t::object worldmap_object_t; - tut::worldmap_t tut_worldmap("LLWorldMap"); - - // --------------------------------------------------------------------------------------- - // Test functions - // Notes: - // * Test as many as you possibly can without requiring a full blown simulation of everything - // * The tests are executed in sequence so the test instance state may change between calls - // * Remember that you cannot test private methods with tut - // --------------------------------------------------------------------------------------- - - // --------------------------------------------------------------------------------------- - // Test the LLItemInfo interface - // --------------------------------------------------------------------------------------- - template<> template<> - void iteminfo_object_t::test<1>() - { - // Test 1 : setCount() / getCount() - mItem->setCount(10); - ensure("LLItemInfo::setCount() test failed", mItem->getCount() == 10); - // Test 2 : setTooltip() / getToolTip() - std::string tooltip = TOOLTIP_TEST; - mItem->setTooltip(tooltip); - ensure("LLItemInfo::setTooltip() test failed", mItem->getToolTip() == TOOLTIP_TEST); - // Test 3 : setElevation() / getGlobalPosition() - mItem->setElevation(Z_WORLD_TEST); - LLVector3d pos = mItem->getGlobalPosition(); - LLVector3d ref(X_WORLD_TEST, Y_WORLD_TEST, Z_WORLD_TEST); - ensure("LLItemInfo::getGlobalPosition() test failed", pos == ref); - // Test 4 : getName() - std::string name = mItem->getName(); - ensure("LLItemInfo::getName() test failed", name == ITEM_NAME_TEST); - // Test 5 : isName() - ensure("LLItemInfo::isName() test failed", mItem->isName(name)); - // Test 6 : getUUID() - LLUUID id; - ensure("LLItemInfo::getUUID() test failed", mItem->getUUID() == id); - // Test 7 : getRegionHandle() - U64 handle = to_region_handle_global(X_WORLD_TEST, Y_WORLD_TEST); - ensure("LLItemInfo::getRegionHandle() test failed", mItem->getRegionHandle() == handle); - } - // --------------------------------------------------------------------------------------- - // Test the LLSimInfo interface - // --------------------------------------------------------------------------------------- - // Test Setters and Accessors methods - template<> template<> - void siminfo_object_t::test<1>() - { - // Test 1 : setName() / getName() - std::string name = SIM_NAME_TEST; - mSim->setName(name); - ensure("LLSimInfo::setName() test failed", mSim->getName() == SIM_NAME_TEST); - // Test 2 : isName() - ensure("LLSimInfo::isName() test failed", mSim->isName(name)); - // Test 3 : getGlobalPos() - LLVector3 local; - LLVector3d ref(X_WORLD_TEST, Y_WORLD_TEST, 0.0f); - LLVector3d pos = mSim->getGlobalPos(local); - ensure("LLSimInfo::getGlobalPos() test failed", pos == ref); - // Test 4 : getGlobalOrigin() - pos = mSim->getGlobalOrigin(); - ensure("LLSimInfo::getGlobalOrigin() test failed", pos == ref); - // Test 5 : clearImage() - try { - mSim->clearImage(); - } catch (...) { - fail("LLSimInfo::clearImage() test failed"); - } - // Test 6 : dropImagePriority() - try { - mSim->dropImagePriority(); - } catch (...) { - fail("LLSimInfo::dropImagePriority() test failed"); - } - // Test 7 : updateAgentCount() - try { - mSim->updateAgentCount(0.0f); - } catch (...) { - fail("LLSimInfo::updateAgentCount() test failed"); - } - // Test 8 : getAgentCount() - S32 agents = mSim->getAgentCount(); - ensure("LLSimInfo::getAgentCount() test failed", agents == 0); - // Test 9 : setLandForSaleImage() / getLandForSaleImage() - LLUUID id; - mSim->setLandForSaleImage(id); - LLPointer<LLViewerFetchedTexture> image = mSim->getLandForSaleImage(); - ensure("LLSimInfo::getLandForSaleImage() test failed", image.isNull()); - // Test 10 : isPG() - mSim->setAccess(SIM_ACCESS_PG); - ensure("LLSimInfo::isPG() test failed", mSim->isPG()); - // Test 11 : isDown() - mSim->setAccess(SIM_ACCESS_DOWN); - ensure("LLSimInfo::isDown() test failed", mSim->isDown()); - // Test 12 : Access strings can't be accessed from unit test... - //ensure("LLSimInfo::getAccessString() test failed", mSim->getAccessString() == "Offline"); - // Test 13 : Region strings can't be accessed from unit test... - //mSim->setRegionFlags(REGION_FLAGS_SANDBOX); - //ensure("LLSimInfo::setRegionFlags() test failed", mSim->getFlagsString() == "Sandbox"); - } - // Test management of LLInfoItem lists - template<> template<> - void siminfo_object_t::test<2>() - { - // Test 14 : clearItems() - try { - mSim->clearItems(); - } catch (...) { - fail("LLSimInfo::clearItems() at init test failed"); - } - - // Test 15 : Verify that all the lists are empty - LLSimInfo::item_info_list_t list; - list = mSim->getTeleHub(); - ensure("LLSimInfo::getTeleHub() empty at init test failed", list.empty()); - list = mSim->getInfoHub(); - ensure("LLSimInfo::getInfoHub() empty at init test failed", list.empty()); - list = mSim->getPGEvent(); - ensure("LLSimInfo::getPGEvent() empty at init test failed", list.empty()); - list = mSim->getMatureEvent(); - ensure("LLSimInfo::getMatureEvent() empty at init test failed", list.empty()); - list = mSim->getLandForSale(); - ensure("LLSimInfo::getLandForSale() empty at init test failed", list.empty()); - list = mSim->getAgentLocation(); - ensure("LLSimInfo::getAgentLocation() empty at init test failed", list.empty()); - - // Create an item to be inserted - LLUUID id; - LLItemInfo item(X_WORLD_TEST, Y_WORLD_TEST, ITEM_NAME_TEST, id); - - // Insert the item in each list - mSim->insertTeleHub(item); - mSim->insertInfoHub(item); - mSim->insertPGEvent(item); - mSim->insertMatureEvent(item); - mSim->insertLandForSale(item); - mSim->insertAgentLocation(item); - - // Test 16 : Verify that the lists contain 1 item each - list = mSim->getTeleHub(); - ensure("LLSimInfo::insertTeleHub() test failed", list.size() == 1); - list = mSim->getInfoHub(); - ensure("LLSimInfo::insertInfoHub() test failed", list.size() == 1); - list = mSim->getPGEvent(); - ensure("LLSimInfo::insertPGEvent() test failed", list.size() == 1); - list = mSim->getMatureEvent(); - ensure("LLSimInfo::insertMatureEvent() test failed", list.size() == 1); - list = mSim->getLandForSale(); - ensure("LLSimInfo::insertLandForSale() test failed", list.size() == 1); - list = mSim->getAgentLocation(); - ensure("LLSimInfo::insertAgentLocation() test failed", list.size() == 1); - - // Test 17 : clearItems() - try { - mSim->clearItems(); - } catch (...) { - fail("LLSimInfo::clearItems() at end test failed"); - } - - // Test 18 : Verify that all the lists are empty again... *except* agent which is persisted!! (on purpose) - list = mSim->getTeleHub(); - ensure("LLSimInfo::getTeleHub() empty after clear test failed", list.empty()); - list = mSim->getInfoHub(); - ensure("LLSimInfo::getInfoHub() empty after clear test failed", list.empty()); - list = mSim->getPGEvent(); - ensure("LLSimInfo::getPGEvent() empty after clear test failed", list.empty()); - list = mSim->getMatureEvent(); - ensure("LLSimInfo::getMatureEvent() empty after clear test failed", list.empty()); - list = mSim->getLandForSale(); - ensure("LLSimInfo::getLandForSale() empty after clear test failed", list.empty()); - list = mSim->getAgentLocation(); - ensure("LLSimInfo::getAgentLocation() empty after clear test failed", list.size() == 1); - } - - // --------------------------------------------------------------------------------------- - // Test the LLWorldMap interface - // --------------------------------------------------------------------------------------- - // Test Setters and Accessors methods - template<> template<> - void worldmap_object_t::test<1>() - { - // Test 1 : reset() - try { - mWorld->reset(); - } catch (...) { - fail("LLWorldMap::reset() at init test failed"); - } - // Test 2 : clearImageRefs() - try { - mWorld->clearImageRefs(); - } catch (...) { - fail("LLWorldMap::clearImageRefs() test failed"); - } - // Test 3 : dropImagePriorities() - try { - mWorld->dropImagePriorities(); - } catch (...) { - fail("LLWorldMap::dropImagePriorities() test failed"); - } - // Test 4 : reloadItems() - try { - mWorld->reloadItems(true); - } catch (...) { - fail("LLWorldMap::reloadItems() test failed"); - } - // Test 5 : updateRegions() - try { - mWorld->updateRegions(1000, 1000, 1004, 1004); - } catch (...) { - fail("LLWorldMap::updateRegions() test failed"); - } - // Test 6 : equalizeBoostLevels() - try { - mWorld->equalizeBoostLevels(); - } catch (...) { - fail("LLWorldMap::equalizeBoostLevels() test failed"); - } - // Test 7 : getObjectsTile() - try { - LLPointer<LLViewerFetchedTexture> image = mWorld->getObjectsTile((U32)(X_WORLD_TEST/REGION_WIDTH_METERS), (U32)(Y_WORLD_TEST/REGION_WIDTH_METERS), 1); - ensure("LLWorldMap::getObjectsTile() failed", image.isNull()); - } catch (...) { - fail("LLWorldMap::getObjectsTile() test failed with exception"); - } - } - // Test management of LLSimInfo lists - template<> template<> - void worldmap_object_t::test<2>() - { - // Test 8 : reset() - try { - mWorld->reset(); - } catch (...) { - fail("LLWorldMap::reset() at init test failed"); - } - - // Test 9 : Verify that all the region list is empty - LLWorldMap::sim_info_map_t list; - list = mWorld->getRegionMap(); - ensure("LLWorldMap::getRegionMap() empty at init test failed", list.empty()); - - // Test 10 : Insert a region - bool success; - LLUUID id; - std::string name_sim = SIM_NAME_TEST; - success = mWorld->insertRegion( U32(X_WORLD_TEST), - U32(Y_WORLD_TEST), - name_sim, - id, - SIM_ACCESS_PG, - REGION_FLAGS_SANDBOX); - list = mWorld->getRegionMap(); - ensure("LLWorldMap::insertRegion() failed", success && (list.size() == 1)); - - // Test 11 : Insert an item in the same region -> number of regions doesn't increase - std::string name_item = ITEM_NAME_TEST; - success = mWorld->insertItem( U32(X_WORLD_TEST + REGION_WIDTH_METERS/2), - U32(Y_WORLD_TEST + REGION_WIDTH_METERS/2), - name_item, - id, - MAP_ITEM_LAND_FOR_SALE, - 0, 0); - list = mWorld->getRegionMap(); - ensure("LLWorldMap::insertItem() in existing region failed", success && (list.size() == 1)); - - // Test 12 : Insert an item in another region -> number of regions increases - success = mWorld->insertItem( U32(X_WORLD_TEST + REGION_WIDTH_METERS*2), - U32(Y_WORLD_TEST + REGION_WIDTH_METERS*2), - name_item, - id, - MAP_ITEM_LAND_FOR_SALE, - 0, 0); - list = mWorld->getRegionMap(); - ensure("LLWorldMap::insertItem() in unexisting region failed", success && (list.size() == 2)); - - // Test 13 : simInfoFromPosGlobal() in region - LLVector3d pos1( X_WORLD_TEST + REGION_WIDTH_METERS*2 + REGION_WIDTH_METERS/2, - Y_WORLD_TEST + REGION_WIDTH_METERS*2 + REGION_WIDTH_METERS/2, - 0.0f); - LLSimInfo* sim; - sim = mWorld->simInfoFromPosGlobal(pos1); - ensure("LLWorldMap::simInfoFromPosGlobal() test on existing region failed", sim != NULL); - - // Test 14 : simInfoFromPosGlobal() outside region - LLVector3d pos2( X_WORLD_TEST + REGION_WIDTH_METERS*4 + REGION_WIDTH_METERS/2, - Y_WORLD_TEST + REGION_WIDTH_METERS*4 + REGION_WIDTH_METERS/2, - 0.0f); - sim = mWorld->simInfoFromPosGlobal(pos2); - ensure("LLWorldMap::simInfoFromPosGlobal() test outside region failed", sim == NULL); - - // Test 15 : simInfoFromName() - sim = mWorld->simInfoFromName(name_sim); - ensure("LLWorldMap::simInfoFromName() test on existing region failed", sim != NULL); - - // Test 16 : simInfoFromHandle() - U64 handle = to_region_handle_global(X_WORLD_TEST, Y_WORLD_TEST); - sim = mWorld->simInfoFromHandle(handle); - ensure("LLWorldMap::simInfoFromHandle() test on existing region failed", sim != NULL); - - // Test 17 : simNameFromPosGlobal() - LLVector3d pos3( X_WORLD_TEST + REGION_WIDTH_METERS/2, - Y_WORLD_TEST + REGION_WIDTH_METERS/2, - 0.0f); - success = mWorld->simNameFromPosGlobal(pos3, name_sim); - ensure("LLWorldMap::simNameFromPosGlobal() test on existing region failed", success && (name_sim == SIM_NAME_TEST)); - - // Test 18 : reset() - try { - mWorld->reset(); - } catch (...) { - fail("LLWorldMap::reset() at end test failed"); - } - - // Test 19 : Verify that all the region list is empty - list = mWorld->getRegionMap(); - ensure("LLWorldMap::getRegionMap() empty at end test failed", list.empty()); - } - // Test tracking - template<> template<> - void worldmap_object_t::test<3>() - { - // Point to track - LLVector3d pos( X_WORLD_TEST + REGION_WIDTH_METERS/2, Y_WORLD_TEST + REGION_WIDTH_METERS/2, Z_WORLD_TEST); - - // Test 20 : no tracking - mWorld->cancelTracking(); - ensure("LLWorldMap::cancelTracking() at begin test failed", mWorld->isTracking() == false); - - // Test 21 : set tracking - mWorld->setTracking(pos); - ensure("LLWorldMap::setTracking() failed", mWorld->isTracking() && !mWorld->isTrackingValidLocation()); - - // Test 22 : set click and commit flags - mWorld->setTrackingDoubleClick(); - ensure("LLWorldMap::setTrackingDoubleClick() failed", mWorld->isTrackingDoubleClick()); - mWorld->setTrackingCommit(); - ensure("LLWorldMap::setTrackingCommit() failed", mWorld->isTrackingCommit()); - - // Test 23 : in rectangle test - bool inRect = mWorld->isTrackingInRectangle( X_WORLD_TEST, Y_WORLD_TEST, - X_WORLD_TEST + REGION_WIDTH_METERS, - Y_WORLD_TEST + REGION_WIDTH_METERS); - ensure("LLWorldMap::isTrackingInRectangle() in rectangle failed", inRect); - inRect = mWorld->isTrackingInRectangle( X_WORLD_TEST + REGION_WIDTH_METERS, - Y_WORLD_TEST + REGION_WIDTH_METERS, - X_WORLD_TEST + 2 * REGION_WIDTH_METERS, - Y_WORLD_TEST + 2 * REGION_WIDTH_METERS); - ensure("LLWorldMap::isTrackingInRectangle() outside rectangle failed", !inRect); - - // Test 24 : set tracking to valid and invalid - mWorld->setTrackingValid(); - ensure("LLWorldMap::setTrackingValid() failed", mWorld->isTrackingValidLocation() && !mWorld->isTrackingInvalidLocation()); - mWorld->setTrackingInvalid(); - ensure("LLWorldMap::setTrackingInvalid() failed", !mWorld->isTrackingValidLocation() && mWorld->isTrackingInvalidLocation()); - - // Test 25 : getTrackedPositionGlobal() - LLVector3d res = mWorld->getTrackedPositionGlobal(); - ensure("LLWorldMap::getTrackedPositionGlobal() failed", res == pos); - - // Test 26 : reset tracking - mWorld->cancelTracking(); - ensure("LLWorldMap::cancelTracking() at end test failed", mWorld->isTracking() == false); - } + // Test wrapper declarations + struct iteminfo_test + { + // Instance to be tested + LLItemInfo* mItem; + + // Constructor and destructor of the test wrapper + iteminfo_test() + { + LLUUID id; + mItem = new LLItemInfo(X_WORLD_TEST, Y_WORLD_TEST, ITEM_NAME_TEST, id); + } + ~iteminfo_test() + { + delete mItem; + } + }; + + struct siminfo_test + { + // Instance to be tested + LLSimInfo* mSim; + + // Constructor and destructor of the test wrapper + siminfo_test() + { + U64 handle = to_region_handle_global(X_WORLD_TEST, Y_WORLD_TEST); + mSim = new LLSimInfo(handle); + } + ~siminfo_test() + { + delete mSim; + } + }; + + struct worldmap_test + { + // Instance to be tested + LLWorldMap* mWorld; + + // Constructor and destructor of the test wrapper + worldmap_test() + { + mWorld = LLWorldMap::getInstance(); + } + ~worldmap_test() + { + mWorld = NULL; + } + }; + + // Tut templating thingamagic: test group, object and test instance + typedef test_group<iteminfo_test> iteminfo_t; + typedef iteminfo_t::object iteminfo_object_t; + tut::iteminfo_t tut_iteminfo("LLItemInfo"); + + typedef test_group<siminfo_test> siminfo_t; + typedef siminfo_t::object siminfo_object_t; + tut::siminfo_t tut_siminfo("LLSimInfo"); + + typedef test_group<worldmap_test> worldmap_t; + typedef worldmap_t::object worldmap_object_t; + tut::worldmap_t tut_worldmap("LLWorldMap"); + + // --------------------------------------------------------------------------------------- + // Test functions + // Notes: + // * Test as many as you possibly can without requiring a full blown simulation of everything + // * The tests are executed in sequence so the test instance state may change between calls + // * Remember that you cannot test private methods with tut + // --------------------------------------------------------------------------------------- + + // --------------------------------------------------------------------------------------- + // Test the LLItemInfo interface + // --------------------------------------------------------------------------------------- + template<> template<> + void iteminfo_object_t::test<1>() + { + // Test 1 : setCount() / getCount() + mItem->setCount(10); + ensure("LLItemInfo::setCount() test failed", mItem->getCount() == 10); + // Test 2 : setTooltip() / getToolTip() + std::string tooltip = TOOLTIP_TEST; + mItem->setTooltip(tooltip); + ensure("LLItemInfo::setTooltip() test failed", mItem->getToolTip() == TOOLTIP_TEST); + // Test 3 : setElevation() / getGlobalPosition() + mItem->setElevation(Z_WORLD_TEST); + LLVector3d pos = mItem->getGlobalPosition(); + LLVector3d ref(X_WORLD_TEST, Y_WORLD_TEST, Z_WORLD_TEST); + ensure("LLItemInfo::getGlobalPosition() test failed", pos == ref); + // Test 4 : getName() + std::string name = mItem->getName(); + ensure("LLItemInfo::getName() test failed", name == ITEM_NAME_TEST); + // Test 5 : isName() + ensure("LLItemInfo::isName() test failed", mItem->isName(name)); + // Test 6 : getUUID() + LLUUID id; + ensure("LLItemInfo::getUUID() test failed", mItem->getUUID() == id); + // Test 7 : getRegionHandle() + U64 handle = to_region_handle_global(X_WORLD_TEST, Y_WORLD_TEST); + ensure("LLItemInfo::getRegionHandle() test failed", mItem->getRegionHandle() == handle); + } + // --------------------------------------------------------------------------------------- + // Test the LLSimInfo interface + // --------------------------------------------------------------------------------------- + // Test Setters and Accessors methods + template<> template<> + void siminfo_object_t::test<1>() + { + // Test 1 : setName() / getName() + std::string name = SIM_NAME_TEST; + mSim->setName(name); + ensure("LLSimInfo::setName() test failed", mSim->getName() == SIM_NAME_TEST); + // Test 2 : isName() + ensure("LLSimInfo::isName() test failed", mSim->isName(name)); + // Test 3 : getGlobalPos() + LLVector3 local; + LLVector3d ref(X_WORLD_TEST, Y_WORLD_TEST, 0.0f); + LLVector3d pos = mSim->getGlobalPos(local); + ensure("LLSimInfo::getGlobalPos() test failed", pos == ref); + // Test 4 : getGlobalOrigin() + pos = mSim->getGlobalOrigin(); + ensure("LLSimInfo::getGlobalOrigin() test failed", pos == ref); + // Test 5 : clearImage() + try { + mSim->clearImage(); + } catch (...) { + fail("LLSimInfo::clearImage() test failed"); + } + // Test 6 : dropImagePriority() + try { + mSim->dropImagePriority(); + } catch (...) { + fail("LLSimInfo::dropImagePriority() test failed"); + } + // Test 7 : updateAgentCount() + try { + mSim->updateAgentCount(0.0f); + } catch (...) { + fail("LLSimInfo::updateAgentCount() test failed"); + } + // Test 8 : getAgentCount() + S32 agents = mSim->getAgentCount(); + ensure("LLSimInfo::getAgentCount() test failed", agents == 0); + // Test 9 : setLandForSaleImage() / getLandForSaleImage() + LLUUID id; + mSim->setLandForSaleImage(id); + LLPointer<LLViewerFetchedTexture> image = mSim->getLandForSaleImage(); + ensure("LLSimInfo::getLandForSaleImage() test failed", image.isNull()); + // Test 10 : isPG() + mSim->setAccess(SIM_ACCESS_PG); + ensure("LLSimInfo::isPG() test failed", mSim->isPG()); + // Test 11 : isDown() + mSim->setAccess(SIM_ACCESS_DOWN); + ensure("LLSimInfo::isDown() test failed", mSim->isDown()); + // Test 12 : Access strings can't be accessed from unit test... + //ensure("LLSimInfo::getAccessString() test failed", mSim->getAccessString() == "Offline"); + // Test 13 : Region strings can't be accessed from unit test... + //mSim->setRegionFlags(REGION_FLAGS_SANDBOX); + //ensure("LLSimInfo::setRegionFlags() test failed", mSim->getFlagsString() == "Sandbox"); + } + // Test management of LLInfoItem lists + template<> template<> + void siminfo_object_t::test<2>() + { + // Test 14 : clearItems() + try { + mSim->clearItems(); + } catch (...) { + fail("LLSimInfo::clearItems() at init test failed"); + } + + // Test 15 : Verify that all the lists are empty + LLSimInfo::item_info_list_t list; + list = mSim->getTeleHub(); + ensure("LLSimInfo::getTeleHub() empty at init test failed", list.empty()); + list = mSim->getInfoHub(); + ensure("LLSimInfo::getInfoHub() empty at init test failed", list.empty()); + list = mSim->getPGEvent(); + ensure("LLSimInfo::getPGEvent() empty at init test failed", list.empty()); + list = mSim->getMatureEvent(); + ensure("LLSimInfo::getMatureEvent() empty at init test failed", list.empty()); + list = mSim->getLandForSale(); + ensure("LLSimInfo::getLandForSale() empty at init test failed", list.empty()); + list = mSim->getAgentLocation(); + ensure("LLSimInfo::getAgentLocation() empty at init test failed", list.empty()); + + // Create an item to be inserted + LLUUID id; + LLItemInfo item(X_WORLD_TEST, Y_WORLD_TEST, ITEM_NAME_TEST, id); + + // Insert the item in each list + mSim->insertTeleHub(item); + mSim->insertInfoHub(item); + mSim->insertPGEvent(item); + mSim->insertMatureEvent(item); + mSim->insertLandForSale(item); + mSim->insertAgentLocation(item); + + // Test 16 : Verify that the lists contain 1 item each + list = mSim->getTeleHub(); + ensure("LLSimInfo::insertTeleHub() test failed", list.size() == 1); + list = mSim->getInfoHub(); + ensure("LLSimInfo::insertInfoHub() test failed", list.size() == 1); + list = mSim->getPGEvent(); + ensure("LLSimInfo::insertPGEvent() test failed", list.size() == 1); + list = mSim->getMatureEvent(); + ensure("LLSimInfo::insertMatureEvent() test failed", list.size() == 1); + list = mSim->getLandForSale(); + ensure("LLSimInfo::insertLandForSale() test failed", list.size() == 1); + list = mSim->getAgentLocation(); + ensure("LLSimInfo::insertAgentLocation() test failed", list.size() == 1); + + // Test 17 : clearItems() + try { + mSim->clearItems(); + } catch (...) { + fail("LLSimInfo::clearItems() at end test failed"); + } + + // Test 18 : Verify that all the lists are empty again... *except* agent which is persisted!! (on purpose) + list = mSim->getTeleHub(); + ensure("LLSimInfo::getTeleHub() empty after clear test failed", list.empty()); + list = mSim->getInfoHub(); + ensure("LLSimInfo::getInfoHub() empty after clear test failed", list.empty()); + list = mSim->getPGEvent(); + ensure("LLSimInfo::getPGEvent() empty after clear test failed", list.empty()); + list = mSim->getMatureEvent(); + ensure("LLSimInfo::getMatureEvent() empty after clear test failed", list.empty()); + list = mSim->getLandForSale(); + ensure("LLSimInfo::getLandForSale() empty after clear test failed", list.empty()); + list = mSim->getAgentLocation(); + ensure("LLSimInfo::getAgentLocation() empty after clear test failed", list.size() == 1); + } + + // --------------------------------------------------------------------------------------- + // Test the LLWorldMap interface + // --------------------------------------------------------------------------------------- + // Test Setters and Accessors methods + template<> template<> + void worldmap_object_t::test<1>() + { + // Test 1 : reset() + try { + mWorld->reset(); + } catch (...) { + fail("LLWorldMap::reset() at init test failed"); + } + // Test 2 : clearImageRefs() + try { + mWorld->clearImageRefs(); + } catch (...) { + fail("LLWorldMap::clearImageRefs() test failed"); + } + // Test 3 : dropImagePriorities() + try { + mWorld->dropImagePriorities(); + } catch (...) { + fail("LLWorldMap::dropImagePriorities() test failed"); + } + // Test 4 : reloadItems() + try { + mWorld->reloadItems(true); + } catch (...) { + fail("LLWorldMap::reloadItems() test failed"); + } + // Test 5 : updateRegions() + try { + mWorld->updateRegions(1000, 1000, 1004, 1004); + } catch (...) { + fail("LLWorldMap::updateRegions() test failed"); + } + // Test 6 : equalizeBoostLevels() + try { + mWorld->equalizeBoostLevels(); + } catch (...) { + fail("LLWorldMap::equalizeBoostLevels() test failed"); + } + // Test 7 : getObjectsTile() + try { + LLPointer<LLViewerFetchedTexture> image = mWorld->getObjectsTile((U32)(X_WORLD_TEST/REGION_WIDTH_METERS), (U32)(Y_WORLD_TEST/REGION_WIDTH_METERS), 1); + ensure("LLWorldMap::getObjectsTile() failed", image.isNull()); + } catch (...) { + fail("LLWorldMap::getObjectsTile() test failed with exception"); + } + } + // Test management of LLSimInfo lists + template<> template<> + void worldmap_object_t::test<2>() + { + // Test 8 : reset() + try { + mWorld->reset(); + } catch (...) { + fail("LLWorldMap::reset() at init test failed"); + } + + // Test 9 : Verify that all the region list is empty + LLWorldMap::sim_info_map_t list; + list = mWorld->getRegionMap(); + ensure("LLWorldMap::getRegionMap() empty at init test failed", list.empty()); + + // Test 10 : Insert a region + bool success; + LLUUID id; + std::string name_sim = SIM_NAME_TEST; + success = mWorld->insertRegion( U32(X_WORLD_TEST), + U32(Y_WORLD_TEST), + name_sim, + id, + SIM_ACCESS_PG, + REGION_FLAGS_SANDBOX); + list = mWorld->getRegionMap(); + ensure("LLWorldMap::insertRegion() failed", success && (list.size() == 1)); + + // Test 11 : Insert an item in the same region -> number of regions doesn't increase + std::string name_item = ITEM_NAME_TEST; + success = mWorld->insertItem( U32(X_WORLD_TEST + REGION_WIDTH_METERS/2), + U32(Y_WORLD_TEST + REGION_WIDTH_METERS/2), + name_item, + id, + MAP_ITEM_LAND_FOR_SALE, + 0, 0); + list = mWorld->getRegionMap(); + ensure("LLWorldMap::insertItem() in existing region failed", success && (list.size() == 1)); + + // Test 12 : Insert an item in another region -> number of regions increases + success = mWorld->insertItem( U32(X_WORLD_TEST + REGION_WIDTH_METERS*2), + U32(Y_WORLD_TEST + REGION_WIDTH_METERS*2), + name_item, + id, + MAP_ITEM_LAND_FOR_SALE, + 0, 0); + list = mWorld->getRegionMap(); + ensure("LLWorldMap::insertItem() in unexisting region failed", success && (list.size() == 2)); + + // Test 13 : simInfoFromPosGlobal() in region + LLVector3d pos1( X_WORLD_TEST + REGION_WIDTH_METERS*2 + REGION_WIDTH_METERS/2, + Y_WORLD_TEST + REGION_WIDTH_METERS*2 + REGION_WIDTH_METERS/2, + 0.0f); + LLSimInfo* sim; + sim = mWorld->simInfoFromPosGlobal(pos1); + ensure("LLWorldMap::simInfoFromPosGlobal() test on existing region failed", sim != NULL); + + // Test 14 : simInfoFromPosGlobal() outside region + LLVector3d pos2( X_WORLD_TEST + REGION_WIDTH_METERS*4 + REGION_WIDTH_METERS/2, + Y_WORLD_TEST + REGION_WIDTH_METERS*4 + REGION_WIDTH_METERS/2, + 0.0f); + sim = mWorld->simInfoFromPosGlobal(pos2); + ensure("LLWorldMap::simInfoFromPosGlobal() test outside region failed", sim == NULL); + + // Test 15 : simInfoFromName() + sim = mWorld->simInfoFromName(name_sim); + ensure("LLWorldMap::simInfoFromName() test on existing region failed", sim != NULL); + + // Test 16 : simInfoFromHandle() + U64 handle = to_region_handle_global(X_WORLD_TEST, Y_WORLD_TEST); + sim = mWorld->simInfoFromHandle(handle); + ensure("LLWorldMap::simInfoFromHandle() test on existing region failed", sim != NULL); + + // Test 17 : simNameFromPosGlobal() + LLVector3d pos3( X_WORLD_TEST + REGION_WIDTH_METERS/2, + Y_WORLD_TEST + REGION_WIDTH_METERS/2, + 0.0f); + success = mWorld->simNameFromPosGlobal(pos3, name_sim); + ensure("LLWorldMap::simNameFromPosGlobal() test on existing region failed", success && (name_sim == SIM_NAME_TEST)); + + // Test 18 : reset() + try { + mWorld->reset(); + } catch (...) { + fail("LLWorldMap::reset() at end test failed"); + } + + // Test 19 : Verify that all the region list is empty + list = mWorld->getRegionMap(); + ensure("LLWorldMap::getRegionMap() empty at end test failed", list.empty()); + } + // Test tracking + template<> template<> + void worldmap_object_t::test<3>() + { + // Point to track + LLVector3d pos( X_WORLD_TEST + REGION_WIDTH_METERS/2, Y_WORLD_TEST + REGION_WIDTH_METERS/2, Z_WORLD_TEST); + + // Test 20 : no tracking + mWorld->cancelTracking(); + ensure("LLWorldMap::cancelTracking() at begin test failed", mWorld->isTracking() == false); + + // Test 21 : set tracking + mWorld->setTracking(pos); + ensure("LLWorldMap::setTracking() failed", mWorld->isTracking() && !mWorld->isTrackingValidLocation()); + + // Test 22 : set click and commit flags + mWorld->setTrackingDoubleClick(); + ensure("LLWorldMap::setTrackingDoubleClick() failed", mWorld->isTrackingDoubleClick()); + mWorld->setTrackingCommit(); + ensure("LLWorldMap::setTrackingCommit() failed", mWorld->isTrackingCommit()); + + // Test 23 : in rectangle test + bool inRect = mWorld->isTrackingInRectangle( X_WORLD_TEST, Y_WORLD_TEST, + X_WORLD_TEST + REGION_WIDTH_METERS, + Y_WORLD_TEST + REGION_WIDTH_METERS); + ensure("LLWorldMap::isTrackingInRectangle() in rectangle failed", inRect); + inRect = mWorld->isTrackingInRectangle( X_WORLD_TEST + REGION_WIDTH_METERS, + Y_WORLD_TEST + REGION_WIDTH_METERS, + X_WORLD_TEST + 2 * REGION_WIDTH_METERS, + Y_WORLD_TEST + 2 * REGION_WIDTH_METERS); + ensure("LLWorldMap::isTrackingInRectangle() outside rectangle failed", !inRect); + + // Test 24 : set tracking to valid and invalid + mWorld->setTrackingValid(); + ensure("LLWorldMap::setTrackingValid() failed", mWorld->isTrackingValidLocation() && !mWorld->isTrackingInvalidLocation()); + mWorld->setTrackingInvalid(); + ensure("LLWorldMap::setTrackingInvalid() failed", !mWorld->isTrackingValidLocation() && mWorld->isTrackingInvalidLocation()); + + // Test 25 : getTrackedPositionGlobal() + LLVector3d res = mWorld->getTrackedPositionGlobal(); + ensure("LLWorldMap::getTrackedPositionGlobal() failed", res == pos); + + // Test 26 : reset tracking + mWorld->cancelTracking(); + ensure("LLWorldMap::cancelTracking() at end test failed", mWorld->isTracking() == false); + } } diff --git a/indra/newview/tests/llworldmipmap_test.cpp b/indra/newview/tests/llworldmipmap_test.cpp index 142d75bcfd..dcbee79536 100644 --- a/indra/newview/tests/llworldmipmap_test.cpp +++ b/indra/newview/tests/llworldmipmap_test.cpp @@ -1,4 +1,4 @@ -/** +/** * @file llworldmipmap_test.cpp * @author Merov Linden * @date 2009-02-03 @@ -6,21 +6,21 @@ * $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$ */ @@ -36,15 +36,15 @@ // ------------------------------------------------------------------------------------------- // Stubbing: Declarations required to link and run the class being tested -// Notes: +// Notes: // * Add here stubbed implementation of the few classes and methods used in the class to be tested // * Add as little as possible (let the link errors guide you) // * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code) // * A simulator for a class can be implemented here. Please comment and document thoroughly. void LLGLTexture::setBoostLevel(S32 ) { } -LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromUrl(const std::string&, FTType, BOOL, LLGLTexture::EBoostLevel, S8, - LLGLint, LLGLenum, const LLUUID& ) { return NULL; } +LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromUrl(const std::string&, FTType, BOOL, LLGLTexture::EBoostLevel, S8, + LLGLint, LLGLenum, const LLUUID& ) { return NULL; } LLControlGroup::LLControlGroup(const std::string& name) : LLInstanceTracker<LLControlGroup, std::string>(name) { } LLControlGroup::~LLControlGroup() { } @@ -59,107 +59,107 @@ LLControlGroup gSavedSettings("test_settings"); // ------------------------------------------------------------------------------------------- namespace tut { - // Test wrapper declaration - struct worldmipmap_test - { - // Derived test class - class LLTestWorldMipmap : public LLWorldMipmap - { - // Put here stubbs of virtual methods we shouldn't call all the way down - }; - // Instance to be tested - LLTestWorldMipmap* mMap; + // Test wrapper declaration + struct worldmipmap_test + { + // Derived test class + class LLTestWorldMipmap : public LLWorldMipmap + { + // Put here stubbs of virtual methods we shouldn't call all the way down + }; + // Instance to be tested + LLTestWorldMipmap* mMap; - // Constructor and destructor of the test wrapper - worldmipmap_test() - { - mMap = new LLTestWorldMipmap; - } - ~worldmipmap_test() - { - delete mMap; - } - }; + // Constructor and destructor of the test wrapper + worldmipmap_test() + { + mMap = new LLTestWorldMipmap; + } + ~worldmipmap_test() + { + delete mMap; + } + }; - // Tut templating thingamagic: test group, object and test instance - typedef test_group<worldmipmap_test> worldmipmap_t; - typedef worldmipmap_t::object worldmipmap_object_t; - tut::worldmipmap_t tut_worldmipmap("LLWorldMipmap"); + // Tut templating thingamagic: test group, object and test instance + typedef test_group<worldmipmap_test> worldmipmap_t; + typedef worldmipmap_t::object worldmipmap_object_t; + tut::worldmipmap_t tut_worldmipmap("LLWorldMipmap"); - // --------------------------------------------------------------------------------------- - // Test functions - // Notes: - // * Test as many as you possibly can without requiring a full blown simulation of everything - // * The tests are executed in sequence so the test instance state may change between calls - // * Remember that you cannot test private methods with tut - // --------------------------------------------------------------------------------------- - // Test static methods - // Test 1 : scaleToLevel() - template<> template<> - void worldmipmap_object_t::test<1>() - { - S32 level = mMap->scaleToLevel(0.0); - ensure("scaleToLevel() test 1 failed", level == LLWorldMipmap::MAP_LEVELS); - level = mMap->scaleToLevel((F32)LLWorldMipmap::MAP_TILE_SIZE); - ensure("scaleToLevel() test 2 failed", level == 1); - level = mMap->scaleToLevel(10.f * LLWorldMipmap::MAP_TILE_SIZE); - ensure("scaleToLevel() test 3 failed", level == 1); - } - // Test 2 : globalToMipmap() - template<> template<> - void worldmipmap_object_t::test<2>() - { - U32 grid_x, grid_y; - mMap->globalToMipmap(1000.f*REGION_WIDTH_METERS, 1000.f*REGION_WIDTH_METERS, 1, &grid_x, &grid_y); - ensure("globalToMipmap() test 1 failed", (grid_x == 1000) && (grid_y == 1000)); - mMap->globalToMipmap(0.0, 0.0, LLWorldMipmap::MAP_LEVELS, &grid_x, &grid_y); - ensure("globalToMipmap() test 2 failed", (grid_x == 0) && (grid_y == 0)); - } - // Test 3 : getObjectsTile() - template<> template<> - void worldmipmap_object_t::test<3>() - { - // Depends on some inline methods in LLViewerImage... Thinking about how to make this work - // LLPointer<LLViewerImage> img = mMap->getObjectsTile(0, 0, 1); - // ensure("getObjectsTile() test failed", img.isNull()); - } - // Test 4 : equalizeBoostLevels() - template<> template<> - void worldmipmap_object_t::test<4>() - { - try - { - mMap->equalizeBoostLevels(); - } - catch (...) - { - fail("equalizeBoostLevels() test failed"); - } - } - // Test 5 : dropBoostLevels() - template<> template<> - void worldmipmap_object_t::test<5>() - { - try - { - mMap->dropBoostLevels(); - } - catch (...) - { - fail("dropBoostLevels() test failed"); - } - } - // Test 6 : reset() - template<> template<> - void worldmipmap_object_t::test<6>() - { - try - { - mMap->reset(); - } - catch (...) - { - fail("reset() test failed"); - } - } + // --------------------------------------------------------------------------------------- + // Test functions + // Notes: + // * Test as many as you possibly can without requiring a full blown simulation of everything + // * The tests are executed in sequence so the test instance state may change between calls + // * Remember that you cannot test private methods with tut + // --------------------------------------------------------------------------------------- + // Test static methods + // Test 1 : scaleToLevel() + template<> template<> + void worldmipmap_object_t::test<1>() + { + S32 level = mMap->scaleToLevel(0.0); + ensure("scaleToLevel() test 1 failed", level == LLWorldMipmap::MAP_LEVELS); + level = mMap->scaleToLevel((F32)LLWorldMipmap::MAP_TILE_SIZE); + ensure("scaleToLevel() test 2 failed", level == 1); + level = mMap->scaleToLevel(10.f * LLWorldMipmap::MAP_TILE_SIZE); + ensure("scaleToLevel() test 3 failed", level == 1); + } + // Test 2 : globalToMipmap() + template<> template<> + void worldmipmap_object_t::test<2>() + { + U32 grid_x, grid_y; + mMap->globalToMipmap(1000.f*REGION_WIDTH_METERS, 1000.f*REGION_WIDTH_METERS, 1, &grid_x, &grid_y); + ensure("globalToMipmap() test 1 failed", (grid_x == 1000) && (grid_y == 1000)); + mMap->globalToMipmap(0.0, 0.0, LLWorldMipmap::MAP_LEVELS, &grid_x, &grid_y); + ensure("globalToMipmap() test 2 failed", (grid_x == 0) && (grid_y == 0)); + } + // Test 3 : getObjectsTile() + template<> template<> + void worldmipmap_object_t::test<3>() + { + // Depends on some inline methods in LLViewerImage... Thinking about how to make this work + // LLPointer<LLViewerImage> img = mMap->getObjectsTile(0, 0, 1); + // ensure("getObjectsTile() test failed", img.isNull()); + } + // Test 4 : equalizeBoostLevels() + template<> template<> + void worldmipmap_object_t::test<4>() + { + try + { + mMap->equalizeBoostLevels(); + } + catch (...) + { + fail("equalizeBoostLevels() test failed"); + } + } + // Test 5 : dropBoostLevels() + template<> template<> + void worldmipmap_object_t::test<5>() + { + try + { + mMap->dropBoostLevels(); + } + catch (...) + { + fail("dropBoostLevels() test failed"); + } + } + // Test 6 : reset() + template<> template<> + void worldmipmap_object_t::test<6>() + { + try + { + mMap->reset(); + } + catch (...) + { + fail("reset() test failed"); + } + } } diff --git a/indra/newview/tests/llxmlrpclistener_test.cpp b/indra/newview/tests/llxmlrpclistener_test.cpp index dbaae7280c..ee6281fc24 100644 --- a/indra/newview/tests/llxmlrpclistener_test.cpp +++ b/indra/newview/tests/llxmlrpclistener_test.cpp @@ -3,25 +3,25 @@ * @author Nat Goodspeed * @date 2009-03-20 * @brief Test for llxmlrpclistener. - * + * * $LicenseInfo:firstyear=2009&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$ */ |