From dc934629919bdcaea72c78e5291263914fb958ec Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 11 May 2009 20:05:46 +0000 Subject: svn merge -r113003:119136 svn+ssh://svn.lindenlab.com/svn/linden/branches/login-api/login-api-2 svn+ssh://svn.lindenlab.com/svn/linden/branches/login-api/login-api-3 --- .../viewer_components/login/tests/lllogin_test.cpp | 382 +++++++++++++++++++++ 1 file changed, 382 insertions(+) create mode 100644 indra/viewer_components/login/tests/lllogin_test.cpp (limited to 'indra/viewer_components/login/tests/lllogin_test.cpp') diff --git a/indra/viewer_components/login/tests/lllogin_test.cpp b/indra/viewer_components/login/tests/lllogin_test.cpp new file mode 100644 index 0000000000..07c9db1099 --- /dev/null +++ b/indra/viewer_components/login/tests/lllogin_test.cpp @@ -0,0 +1,382 @@ +/** + * @file llviewerlogin_test.cpp + * @author Mark Palange + * @date 2009-02-26 + * @brief Tests of lllazy.h. + * + * $LicenseInfo:firstyear=2009&license=internal$ + * Copyright (c) 2009, Linden Research, Inc. + * $/LicenseInfo$ + */ + +// Precompiled header +#include "linden_common.h" +// associated header +#include "../lllogin.h" +// STL headers +// std headers +#include +// external library headers +// other Linden headers +#include "llsd.h" +#include "../../../test/lltut.h" +#include "llevents.h" + +/***************************************************************************** +* TUT +*****************************************************************************/ +// This is a listener to receive results from lllogin. +class LoginListener +{ + std::string mName; + LLSD mLastEvent; +public: + LoginListener(const std::string& name) : + mName(name) + {} + + bool call(const LLSD& event) + { + std::cout << "LoginListener called!: " << event << std::endl; + mLastEvent = event; + return false; + } + + LLBoundListener listenTo(LLEventPump& pump) + { + return pump.listen(mName, boost::bind(&LoginListener::call, this, _1)); + } + + const LLSD& lastEvent() { return mLastEvent; } +}; + +class LLAresListener +{ + std::string mName; + LLSD mEvent; + bool mImmediateResponse; + bool mMultipleURIResponse; + +public: + LLAresListener(const std::string& name, + bool i = false, + bool m = false + ) : + mName(name), + mImmediateResponse(i), + mMultipleURIResponse(m) + {} + + bool handle_event(const LLSD& event) + { + std::cout << "LLAresListener called!: " << event << std::endl; + mEvent = event; + if(mImmediateResponse) + { + sendReply(); + } + return false; + } + + void sendReply() + { + if(mEvent["op"].asString() == "rewriteURI") + { + LLSD result; + if(mMultipleURIResponse) + { + result.append(LLSD("login.foo.com")); + } + result.append(mEvent["uri"]); + LLEventPumps::instance().obtain(mEvent["reply"]).post(result); + } + } + + LLBoundListener listenTo(LLEventPump& pump) + { + return pump.listen(mName, boost::bind(&LLAresListener::handle_event, this, _1)); + } +}; + +class LLXMLRPCListener +{ + std::string mName; + LLSD mEvent; + bool mImmediateResponse; + LLSD mResponse; + +public: + LLXMLRPCListener(const std::string& name, + bool i = false, + const LLSD& response = LLSD() + ) : + mName(name), + mImmediateResponse(i), + mResponse(response) + { + if(mResponse.isUndefined()) + { + mResponse["status"] = "Complete"; // StatusComplete + mResponse["errorcode"] = 0; + mResponse["error"] = "dummy response"; + mResponse["transfer_rate"] = 0; + mResponse["responses"]["login"] = true; + } + } + + void setResponse(const LLSD& r) + { + mResponse = r; + } + + bool handle_event(const LLSD& event) + { + std::cout << "LLXMLRPCListener called!: " << event << std::endl; + mEvent = event; + if(mImmediateResponse) + { + sendReply(); + } + return false; + } + + void sendReply() + { + LLEventPumps::instance().obtain(mEvent["reply"]).post(mResponse); + } + + LLBoundListener listenTo(LLEventPump& pump) + { + return pump.listen(mName, boost::bind(&LLXMLRPCListener::handle_event, this, _1)); + } +}; + +namespace tut +{ + struct llviewerlogin_data + { + llviewerlogin_data() : + pumps(LLEventPumps::instance()) + {} + LLEventPumps& pumps; + }; + + typedef test_group llviewerlogin_group; + typedef llviewerlogin_group::object llviewerlogin_object; + llviewerlogin_group llviewerlogingrp("llviewerlogin"); + + template<> template<> + void llviewerlogin_object::test<1>() + { + // Testing login with immediate repsonses from Ares and XMLPRC + // The response from both requests will come before the post request exits. + // This tests an edge case of the login state handling. + LLEventStream llaresPump("LLAres"); // Dummy LLAres pump. + LLEventStream xmlrpcPump("LLXMLRPCTransaction"); // Dummy XMLRPC pump + + bool respond_immediately = true; + // Have 'dummy ares' repsond immediately. + LLAresListener dummyLLAres("dummy_llares", respond_immediately); + dummyLLAres.listenTo(llaresPump); + + // Have dummy XMLRPC respond immediately. + LLXMLRPCListener dummyXMLRPC("dummy_xmlrpc", respond_immediately); + dummyXMLRPC.listenTo(xmlrpcPump); + + LLLogin login; + + LoginListener listener("test_ear"); + listener.listenTo(login.getEventPump()); + + LLSD credentials; + credentials["first"] = "foo"; + credentials["last"] = "bar"; + credentials["passwd"] = "secret"; + + login.connect("login.bar.com", credentials); + + ensure_equals("Online state", listener.lastEvent()["state"].asString(), "online"); + } + + template<> template<> + void llviewerlogin_object::test<2>() + { + // Tests a successful login in with delayed responses. + // Also includes 'failure' that cause the login module + // To re-attempt connection, once from a basic failure + // and once from the 'indeterminate' response. + + set_test_name("LLLogin multiple srv uris w/ success"); + + // Testing normal login procedure. + LLEventStream llaresPump("LLAres"); // Dummy LLAres pump. + LLEventStream xmlrpcPump("LLXMLRPCTransaction"); // Dummy XMLRPC pump + + bool respond_immediately = false; + bool multiple_addresses = true; + LLAresListener dummyLLAres("dummy_llares", respond_immediately, multiple_addresses); + dummyLLAres.listenTo(llaresPump); + + LLXMLRPCListener dummyXMLRPC("dummy_xmlrpc"); + dummyXMLRPC.listenTo(xmlrpcPump); + + LLLogin login; + + LoginListener listener("test_ear"); + listener.listenTo(login.getEventPump()); + + LLSD credentials; + credentials["first"] = "foo"; + credentials["last"] = "bar"; + credentials["passwd"] = "secret"; + + login.connect("login.bar.com", credentials); + + ensure_equals("SRV state", listener.lastEvent()["state"].asString(), "srvrequest"); + + dummyLLAres.sendReply(); + + // Test Authenticating State prior to first response. + ensure_equals("Auth state 1", listener.lastEvent()["state"].asString(), "authenticating"); + ensure_equals("Attempt 1", listener.lastEvent()["data"]["attempt"].asInteger(), 1); + ensure_equals("URI 1", listener.lastEvent()["data"]["request"]["uri"].asString(), "login.foo.com"); + + // First send emulated LLXMLRPCListener failure, + // this should return login to the authenticating step and increase the attempt + // count. + LLSD data; + data["status"] = "OtherError"; + data["errorcode"] = 0; + data["error"] = "dummy response"; + data["transfer_rate"] = 0; + dummyXMLRPC.setResponse(data); + dummyXMLRPC.sendReply(); + + ensure_equals("Fail back to authenticate 1", listener.lastEvent()["state"].asString(), "authenticating"); + ensure_equals("Attempt 2", listener.lastEvent()["data"]["attempt"].asInteger(), 2); + ensure_equals("URI 2", listener.lastEvent()["data"]["request"]["uri"].asString(), "login.bar.com"); + + // Now send the 'indeterminate' response. + data.clear(); + data["status"] = "Complete"; // StatusComplete + data["errorcode"] = 0; + data["error"] = "dummy response"; + data["transfer_rate"] = 0; + data["responses"]["login"] = "indeterminate"; + data["next_url"] = "login.indeterminate.com"; + data["next_method"] = "test_login_method"; + dummyXMLRPC.setResponse(data); + dummyXMLRPC.sendReply(); + + ensure_equals("Fail back to authenticate 2", listener.lastEvent()["state"].asString(), "authenticating"); + ensure_equals("Attempt 3", listener.lastEvent()["data"]["attempt"].asInteger(), 3); + ensure_equals("URI 3", listener.lastEvent()["data"]["request"]["uri"].asString(), "login.indeterminate.com"); + + // Finally let the auth succeed. + data.clear(); + data["status"] = "Complete"; // StatusComplete + data["errorcode"] = 0; + data["error"] = "dummy response"; + data["transfer_rate"] = 0; + data["responses"]["login"] = "true"; + dummyXMLRPC.setResponse(data); + dummyXMLRPC.sendReply(); + + ensure_equals("Success state", listener.lastEvent()["state"].asString(), "online"); + + login.disconnect(); + + ensure_equals("Disconnected state", listener.lastEvent()["state"].asString(), "offline"); + } + + template<> template<> + void llviewerlogin_object::test<3>() + { + // Test completed response, that fails to login. + set_test_name("LLLogin valid response, failure (eg. bad credentials)"); + + // Testing normal login procedure. + LLEventStream llaresPump("LLAres"); // Dummy LLAres pump. + LLEventStream xmlrpcPump("LLXMLRPCTransaction"); // Dummy XMLRPC pump + + LLAresListener dummyLLAres("dummy_llares"); + dummyLLAres.listenTo(llaresPump); + + LLXMLRPCListener dummyXMLRPC("dummy_xmlrpc"); + dummyXMLRPC.listenTo(xmlrpcPump); + + LLLogin login; + LoginListener listener("test_ear"); + listener.listenTo(login.getEventPump()); + + LLSD credentials; + credentials["first"] = "who"; + credentials["last"] = "what"; + credentials["passwd"] = "badpasswd"; + + login.connect("login.bar.com", credentials); + + ensure_equals("SRV state", listener.lastEvent()["state"].asString(), "srvrequest"); + + dummyLLAres.sendReply(); + + ensure_equals("Auth state", listener.lastEvent()["state"].asString(), "authenticating"); + + // Send the failed auth request reponse + LLSD data; + data["status"] = "Complete"; + data["errorcode"] = 0; + data["error"] = "dummy response"; + data["transfer_rate"] = 0; + data["responses"]["login"] = "false"; + dummyXMLRPC.setResponse(data); + dummyXMLRPC.sendReply(); + + ensure_equals("Failed to offline", listener.lastEvent()["state"].asString(), "offline"); + } + + template<> template<> + void llviewerlogin_object::test<4>() + { + // Test incomplete response, that end the attempt. + set_test_name("LLLogin valid response, failure (eg. bad credentials)"); + + // Testing normal login procedure. + LLEventStream llaresPump("LLAres"); // Dummy LLAres pump. + LLEventStream xmlrpcPump("LLXMLRPCTransaction"); // Dummy XMLRPC pump + + LLAresListener dummyLLAres("dummy_llares"); + dummyLLAres.listenTo(llaresPump); + + LLXMLRPCListener dummyXMLRPC("dummy_xmlrpc"); + dummyXMLRPC.listenTo(xmlrpcPump); + + LLLogin login; + LoginListener listener("test_ear"); + listener.listenTo(login.getEventPump()); + + LLSD credentials; + credentials["first"] = "these"; + credentials["last"] = "don't"; + credentials["passwd"] = "matter"; + + login.connect("login.bar.com", credentials); + + ensure_equals("SRV state", listener.lastEvent()["state"].asString(), "srvrequest"); + + dummyLLAres.sendReply(); + + ensure_equals("Auth state", listener.lastEvent()["state"].asString(), "authenticating"); + + // Send the failed auth request reponse + LLSD data; + data["status"] = "OtherError"; + data["errorcode"] = 0; + data["error"] = "dummy response"; + data["transfer_rate"] = 0; + dummyXMLRPC.setResponse(data); + dummyXMLRPC.sendReply(); + + ensure_equals("Failed to offline", listener.lastEvent()["state"].asString(), "offline"); + } +} -- cgit v1.3 From c607752a9dc17aaf2405ef36a78773d1a6400944 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 28 May 2009 21:25:58 +0000 Subject: DEV-32777: ensure that stack objects listening on persistent LLEventPumps get properly disconnected when destroyed. Break out Debug class and associated macros from lleventcoro_test.cpp into test/debug.h. Add Debug output to lllogin_test. --- indra/llcommon/tests/lleventcoro_test.cpp | 50 +--------------- indra/test/CMakeLists.txt | 1 + indra/test/debug.h | 68 ++++++++++++++++++++++ .../viewer_components/login/tests/lllogin_test.cpp | 57 +++++++++++++----- 4 files changed, 114 insertions(+), 62 deletions(-) create mode 100644 indra/test/debug.h (limited to 'indra/viewer_components/login/tests/lllogin_test.cpp') diff --git a/indra/llcommon/tests/lleventcoro_test.cpp b/indra/llcommon/tests/lleventcoro_test.cpp index 695b1ca9f4..3a2cda7735 100644 --- a/indra/llcommon/tests/lleventcoro_test.cpp +++ b/indra/llcommon/tests/lleventcoro_test.cpp @@ -65,55 +65,7 @@ #include "tests/wrapllerrs.h" #include "stringize.h" #include "lleventcoro.h" - -/***************************************************************************** -* Debugging stuff -*****************************************************************************/ -// This class is intended to illuminate entry to a given block, exit from the -// same block and checkpoints along the way. It also provides a convenient -// place to turn std::cout output on and off. -class Debug -{ -public: - Debug(const std::string& block): - mBlock(block) - { - (*this)("entry"); - } - - ~Debug() - { - (*this)("exit"); - } - - void operator()(const std::string& status) - { -// std::cout << mBlock << ' ' << status << std::endl; - } - -private: - const std::string mBlock; -}; - -// It's often convenient to use the name of the enclosing function as the name -// of the Debug block. -#define DEBUG Debug debug(__FUNCTION__) - -// These BEGIN/END macros are specifically for debugging output -- please -// don't assume you must use such for coroutines in general! They only help to -// make control flow (as well as exception exits) explicit. -#define BEGIN \ -{ \ - DEBUG; \ - try - -#define END \ - catch (...) \ - { \ -/* std::cout << "*** exceptional " << std::flush; */ \ - throw; \ - } \ -} +#include "../test/debug.h" /***************************************************************************** * from the banana.cpp example program borrowed for test<1>() diff --git a/indra/test/CMakeLists.txt b/indra/test/CMakeLists.txt index 88ef15a8d9..02dd01e1b0 100644 --- a/indra/test/CMakeLists.txt +++ b/indra/test/CMakeLists.txt @@ -90,6 +90,7 @@ set(test_SOURCE_FILES set(test_HEADER_FILES CMakeLists.txt + debug.h llpipeutil.h llsdtraits.h lltut.h diff --git a/indra/test/debug.h b/indra/test/debug.h new file mode 100644 index 0000000000..a00659d880 --- /dev/null +++ b/indra/test/debug.h @@ -0,0 +1,68 @@ +/** + * @file debug.h + * @author Nat Goodspeed + * @date 2009-05-28 + * @brief Debug output for unit test code + * + * $LicenseInfo:firstyear=2009&license=viewergpl$ + * Copyright (c) 2009, Linden Research, Inc. + * $/LicenseInfo$ + */ + +#if ! defined(LL_DEBUG_H) +#define LL_DEBUG_H + +#include + +/***************************************************************************** +* Debugging stuff +*****************************************************************************/ +// This class is intended to illuminate entry to a given block, exit from the +// same block and checkpoints along the way. It also provides a convenient +// place to turn std::cout output on and off. +class Debug +{ +public: + Debug(const std::string& block): + mBlock(block) + { + (*this)("entry"); + } + + ~Debug() + { + (*this)("exit"); + } + + void operator()(const std::string& status) + { +#if defined(DEBUG_ON) + std::cout << mBlock << ' ' << status << std::endl; +#endif + } + +private: + const std::string mBlock; +}; + +// It's often convenient to use the name of the enclosing function as the name +// of the Debug block. +#define DEBUG Debug debug(__FUNCTION__) + +// These BEGIN/END macros are specifically for debugging output -- please +// don't assume you must use such for coroutines in general! They only help to +// make control flow (as well as exception exits) explicit. +#define BEGIN \ +{ \ + DEBUG; \ + try + +#define END \ + catch (...) \ + { \ + debug("*** exceptional "); \ + throw; \ + } \ +} + +#endif /* ! defined(LL_DEBUG_H) */ diff --git a/indra/viewer_components/login/tests/lllogin_test.cpp b/indra/viewer_components/login/tests/lllogin_test.cpp index 07c9db1099..b9fe59c0a6 100644 --- a/indra/viewer_components/login/tests/lllogin_test.cpp +++ b/indra/viewer_components/login/tests/lllogin_test.cpp @@ -1,8 +1,8 @@ /** - * @file llviewerlogin_test.cpp + * @file lllogin_test.cpp * @author Mark Palange * @date 2009-02-26 - * @brief Tests of lllazy.h. + * @brief Tests of lllogin.cpp. * * $LicenseInfo:firstyear=2009&license=internal$ * Copyright (c) 2009, Linden Research, Inc. @@ -20,24 +20,29 @@ // other Linden headers #include "llsd.h" #include "../../../test/lltut.h" +//#define DEBUG_ON +#include "../../../test/debug.h" #include "llevents.h" +#include "stringize.h" /***************************************************************************** -* TUT +* Helper classes *****************************************************************************/ // This is a listener to receive results from lllogin. -class LoginListener +class LoginListener: public LLEventTrackable { std::string mName; LLSD mLastEvent; + Debug mDebug; public: LoginListener(const std::string& name) : - mName(name) + mName(name), + mDebug(stringize(*this)) {} bool call(const LLSD& event) { - std::cout << "LoginListener called!: " << event << std::endl; + mDebug(STRINGIZE("LoginListener called!: " << event)); mLastEvent = event; return false; } @@ -47,15 +52,21 @@ public: return pump.listen(mName, boost::bind(&LoginListener::call, this, _1)); } - const LLSD& lastEvent() { return mLastEvent; } + LLSD lastEvent() { return mLastEvent; } + + friend std::ostream& operator<<(std::ostream& out, const LoginListener& listener) + { + return out << "LoginListener(" << listener.mName << ')'; + } }; -class LLAresListener +class LLAresListener: public LLEventTrackable { std::string mName; LLSD mEvent; bool mImmediateResponse; bool mMultipleURIResponse; + Debug mDebug; public: LLAresListener(const std::string& name, @@ -64,12 +75,13 @@ public: ) : mName(name), mImmediateResponse(i), - mMultipleURIResponse(m) + mMultipleURIResponse(m), + mDebug(stringize(*this)) {} bool handle_event(const LLSD& event) { - std::cout << "LLAresListener called!: " << event << std::endl; + mDebug(STRINGIZE("LLAresListener called!: " << event)); mEvent = event; if(mImmediateResponse) { @@ -96,14 +108,20 @@ public: { return pump.listen(mName, boost::bind(&LLAresListener::handle_event, this, _1)); } + + friend std::ostream& operator<<(std::ostream& out, const LLAresListener& listener) + { + return out << "LLAresListener(" << listener.mName << ')'; + } }; -class LLXMLRPCListener +class LLXMLRPCListener: public LLEventTrackable { std::string mName; LLSD mEvent; bool mImmediateResponse; LLSD mResponse; + Debug mDebug; public: LLXMLRPCListener(const std::string& name, @@ -112,7 +130,8 @@ public: ) : mName(name), mImmediateResponse(i), - mResponse(response) + mResponse(response), + mDebug(stringize(*this)) { if(mResponse.isUndefined()) { @@ -131,7 +150,7 @@ public: bool handle_event(const LLSD& event) { - std::cout << "LLXMLRPCListener called!: " << event << std::endl; + mDebug(STRINGIZE("LLXMLRPCListener called!: " << event)); mEvent = event; if(mImmediateResponse) { @@ -149,8 +168,16 @@ public: { return pump.listen(mName, boost::bind(&LLXMLRPCListener::handle_event, this, _1)); } + + friend std::ostream& operator<<(std::ostream& out, const LLXMLRPCListener& listener) + { + return out << "LLXMLRPCListener(" << listener.mName << ')'; + } }; +/***************************************************************************** +* TUT +*****************************************************************************/ namespace tut { struct llviewerlogin_data @@ -168,6 +195,7 @@ namespace tut template<> template<> void llviewerlogin_object::test<1>() { + DEBUG; // Testing login with immediate repsonses from Ares and XMLPRC // The response from both requests will come before the post request exits. // This tests an edge case of the login state handling. @@ -201,6 +229,7 @@ namespace tut template<> template<> void llviewerlogin_object::test<2>() { + DEBUG; // Tests a successful login in with delayed responses. // Also includes 'failure' that cause the login module // To re-attempt connection, once from a basic failure @@ -292,6 +321,7 @@ namespace tut template<> template<> void llviewerlogin_object::test<3>() { + DEBUG; // Test completed response, that fails to login. set_test_name("LLLogin valid response, failure (eg. bad credentials)"); @@ -338,6 +368,7 @@ namespace tut template<> template<> void llviewerlogin_object::test<4>() { + DEBUG; // Test incomplete response, that end the attempt. set_test_name("LLLogin valid response, failure (eg. bad credentials)"); -- cgit v1.3 From ad40d64b0e421a6ab9546f1c721117a3bff754cb Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 17 Jun 2009 15:13:48 +0000 Subject: DEV-32777: tip won't even build on Windows without pacifying MSVC warning --- indra/viewer_components/login/tests/lllogin_test.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/viewer_components/login/tests/lllogin_test.cpp') diff --git a/indra/viewer_components/login/tests/lllogin_test.cpp b/indra/viewer_components/login/tests/lllogin_test.cpp index b9fe59c0a6..e43065d49f 100644 --- a/indra/viewer_components/login/tests/lllogin_test.cpp +++ b/indra/viewer_components/login/tests/lllogin_test.cpp @@ -9,6 +9,10 @@ * $/LicenseInfo$ */ +#if LL_WINDOWS +#pragma warning (disable : 4355) // 'this' used in initializer list: yes, intentionally +#endif + // Precompiled header #include "linden_common.h" // associated header -- cgit v1.3 From ec52e19dd16908acd72b78720880391a74ee8886 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 25 Sep 2009 10:55:25 -0400 Subject: DEV-32777, QAR-1619: Disable MSVC Release-build optimization for LLCoros::launchImpl(). This fixes the Release-build crash in lllogin_test.cpp. --- indra/llcommon/llcoros.cpp | 37 ++++++++++++++++------ .../viewer_components/login/tests/lllogin_test.cpp | 2 +- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'indra/viewer_components/login/tests/lllogin_test.cpp') diff --git a/indra/llcommon/llcoros.cpp b/indra/llcommon/llcoros.cpp index 5d23e1d284..377bfaa247 100644 --- a/indra/llcommon/llcoros.cpp +++ b/indra/llcommon/llcoros.cpp @@ -54,15 +54,6 @@ bool LLCoros::cleanup(const LLSD&) return false; } -std::string LLCoros::launchImpl(const std::string& prefix, coro* newCoro) -{ - std::string name(generateDistinctName(prefix)); - mCoros.insert(name, newCoro); - /* Run the coroutine until its first wait, then return here */ - (*newCoro)(std::nothrow); - return name; -} - std::string LLCoros::generateDistinctName(const std::string& prefix) const { // Allowing empty name would make getName()'s not-found return ambiguous. @@ -116,3 +107,31 @@ std::string LLCoros::getNameByID(const void* self_id) const } return ""; } + +/***************************************************************************** +* MUST BE LAST +*****************************************************************************/ +// Turn off MSVC optimizations for just LLCoros::launchImpl() -- see +// DEV-32777. But MSVC doesn't support push/pop for optimization flags as it +// does for warning suppression, and we really don't want to force +// optimization ON for other code even in Debug or RelWithDebInfo builds. + +#if LL_MSVC +// work around broken optimizations +#pragma warning(disable: 4748) +#pragma optimize("", off) +#endif // LL_MSVC + +std::string LLCoros::launchImpl(const std::string& prefix, coro* newCoro) +{ + std::string name(generateDistinctName(prefix)); + mCoros.insert(name, newCoro); + /* Run the coroutine until its first wait, then return here */ + (*newCoro)(std::nothrow); + return name; +} + +#if LL_MSVC +// reenable optimizations +#pragma optimize("", on) +#endif // LL_MSVC diff --git a/indra/viewer_components/login/tests/lllogin_test.cpp b/indra/viewer_components/login/tests/lllogin_test.cpp index e43065d49f..51f00c8344 100644 --- a/indra/viewer_components/login/tests/lllogin_test.cpp +++ b/indra/viewer_components/login/tests/lllogin_test.cpp @@ -56,7 +56,7 @@ public: return pump.listen(mName, boost::bind(&LoginListener::call, this, _1)); } - LLSD lastEvent() { return mLastEvent; } + LLSD lastEvent() const { return mLastEvent; } friend std::ostream& operator<<(std::ostream& out, const LoginListener& listener) { -- cgit v1.3 From e3a4e3dc10a96b0822674cea262f41774e55a660 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 9 Oct 2009 19:42:59 -0400 Subject: DEV-40930: Added ["change"] key to login-module status events. Changed existing event calls to use state as "offline" or "online", with "change" indicating the reason for this status event. Changed disconnect() to send state "offline", change "disconnect" -- instead of replaying last auth failure. Changed unit tests accordingly. Changed LLLoginInstance::handleLoginEvent() to use LLEventDispatcher to route calls to handleLoginFailure() et al. Added LLEventDispatcher::get() to allow retrieving Callable by name and testing for empty(). --- indra/llcommon/lleventdispatcher.cpp | 10 +++++++ indra/llcommon/lleventdispatcher.h | 4 +++ indra/newview/lllogininstance.cpp | 34 ++++++++++++---------- indra/newview/lllogininstance.h | 7 +++-- indra/newview/tests/lllogininstance_test.cpp | 7 +++++ indra/viewer_components/login/lllogin.cpp | 29 +++++++++++------- .../viewer_components/login/tests/lllogin_test.cpp | 16 +++++----- 7 files changed, 71 insertions(+), 36 deletions(-) (limited to 'indra/viewer_components/login/tests/lllogin_test.cpp') diff --git a/indra/llcommon/lleventdispatcher.cpp b/indra/llcommon/lleventdispatcher.cpp index 2dbd59b156..6b1413d054 100644 --- a/indra/llcommon/lleventdispatcher.cpp +++ b/indra/llcommon/lleventdispatcher.cpp @@ -109,6 +109,16 @@ bool LLEventDispatcher::attemptCall(const std::string& name, const LLSD& event) return true; // tell caller we were able to call } +LLEventDispatcher::Callable LLEventDispatcher::get(const std::string& name) const +{ + DispatchMap::const_iterator found = mDispatch.find(name); + if (found == mDispatch.end()) + { + return Callable(); + } + return found->second.first; +} + LLDispatchListener::LLDispatchListener(const std::string& pumpname, const std::string& key): LLEventDispatcher(pumpname, key), mPump(pumpname, true), // allow tweaking for uniqueness diff --git a/indra/llcommon/lleventdispatcher.h b/indra/llcommon/lleventdispatcher.h index ef83ebabc1..671f2a4d1c 100644 --- a/indra/llcommon/lleventdispatcher.h +++ b/indra/llcommon/lleventdispatcher.h @@ -80,6 +80,10 @@ public: /// @a required prototype specified at add() time, die with LL_ERRS. void operator()(const LLSD& event) const; + /// Fetch the Callable for the specified name. If no such name was + /// registered, return an empty() Callable. + Callable get(const std::string& name) const; + private: template void addMethod(const std::string& name, const METHOD& method, const LLSD& required) diff --git a/indra/newview/lllogininstance.cpp b/indra/newview/lllogininstance.cpp index 8bf769a132..e5f347ddc4 100644 --- a/indra/newview/lllogininstance.cpp +++ b/indra/newview/lllogininstance.cpp @@ -68,10 +68,14 @@ LLLoginInstance::LLLoginInstance() : mUserInteraction(true), mSkipOptionalUpdate(false), mAttemptComplete(false), - mTransferRate(0.0f) + mTransferRate(0.0f), + mDispatcher("LLLoginInstance", "change") { mLoginModule->getEventPump().listen("lllogininstance", boost::bind(&LLLoginInstance::handleLoginEvent, this, _1)); + mDispatcher.add("fail.login", boost::bind(&LLLoginInstance::handleLoginFailure, this, _1)); + mDispatcher.add("connect", boost::bind(&LLLoginInstance::handleLoginSuccess, this, _1)); + mDispatcher.add("disconnect", boost::bind(&LLLoginInstance::handleDisconnect, this, _1)); } LLLoginInstance::~LLLoginInstance() @@ -185,9 +189,9 @@ bool LLLoginInstance::handleLoginEvent(const LLSD& event) std::cout << "LoginListener called!: \n"; std::cout << event << "\n"; - if(!(event.has("state") && event.has("progress"))) + if(!(event.has("state") && event.has("change") && event.has("progress"))) { - llerrs << "Unknown message from LLLogin!" << llendl; + llerrs << "Unknown message from LLLogin: " << event << llendl; } mLoginState = event["state"].asString(); @@ -198,19 +202,17 @@ bool LLLoginInstance::handleLoginEvent(const LLSD& event) mTransferRate = event["transfer_rate"].asReal(); } - if(mLoginState == "offline") + // Call the method registered in constructor, if any, for more specific + // handling + LLEventDispatcher::Callable method(mDispatcher.get(event["change"])); + if (! method.empty()) { - handleLoginFailure(event); + method(event); } - else if(mLoginState == "online") - { - handleLoginSuccess(event); - } - return false; } -bool LLLoginInstance::handleLoginFailure(const LLSD& event) +void LLLoginInstance::handleLoginFailure(const LLSD& event) { // Login has failed. // Figure out why and respond... @@ -264,11 +266,9 @@ bool LLLoginInstance::handleLoginFailure(const LLSD& event) { attemptComplete(); } - - return false; } -bool LLLoginInstance::handleLoginSuccess(const LLSD& event) +void LLLoginInstance::handleLoginSuccess(const LLSD& event) { if(gSavedSettings.getBOOL("ForceMandatoryUpdate")) { @@ -286,7 +286,11 @@ bool LLLoginInstance::handleLoginSuccess(const LLSD& event) { attemptComplete(); } - return false; +} + +void LLLoginInstance::handleDisconnect(const LLSD& event) +{ + // placeholder } bool LLLoginInstance::handleTOSResponse(bool accepted, const std::string& key) diff --git a/indra/newview/lllogininstance.h b/indra/newview/lllogininstance.h index 6a2ccf919e..19d7449bc1 100644 --- a/indra/newview/lllogininstance.h +++ b/indra/newview/lllogininstance.h @@ -33,6 +33,7 @@ #ifndef LL_LLLOGININSTANCE_H #define LL_LLLOGININSTANCE_H +#include "lleventdispatcher.h" #include #include class LLLogin; @@ -85,8 +86,9 @@ private: bool updateDialogCallback(const LLSD& notification, const LLSD& response); bool handleLoginEvent(const LLSD& event); - bool handleLoginFailure(const LLSD& event); - bool handleLoginSuccess(const LLSD& event); + void handleLoginFailure(const LLSD& event); + void handleLoginSuccess(const LLSD& event); + void handleDisconnect(const LLSD& event); bool handleTOSResponse(bool v, const std::string& key); @@ -106,6 +108,7 @@ private: int mLastExecEvent; UpdaterLauncherCallback mUpdaterLauncher; boost::scoped_ptr mUpdateAppResponse; + LLEventDispatcher mDispatcher; }; #endif diff --git a/indra/newview/tests/lllogininstance_test.cpp b/indra/newview/tests/lllogininstance_test.cpp index 75db76df27..009be35f64 100644 --- a/indra/newview/tests/lllogininstance_test.cpp +++ b/indra/newview/tests/lllogininstance_test.cpp @@ -225,6 +225,7 @@ namespace tut // Dummy success response. LLSD response; response["state"] = "online"; + response["change"] = "connect"; response["progress"] = 1.0; response["transfer_rate"] = 7; response["data"] = "test_data"; @@ -240,6 +241,7 @@ namespace tut response.clear(); response["state"] = "offline"; + response["change"] = "disconnect"; response["progress"] = 0.0; response["transfer_rate"] = 0; response["data"] = "test_data"; @@ -267,6 +269,7 @@ namespace tut // TOS failure response. LLSD response; response["state"] = "offline"; + response["change"] = "fail.login"; response["progress"] = 0.0; response["transfer_rate"] = 7; response["data"]["reason"] = "tos"; @@ -326,6 +329,7 @@ namespace tut // Update needed failure response. LLSD response; response["state"] = "offline"; + response["change"] = "fail.login"; response["progress"] = 0.0; response["transfer_rate"] = 7; response["data"]["reason"] = "update"; @@ -351,6 +355,7 @@ namespace tut // Update needed failure response. LLSD response; response["state"] = "offline"; + response["change"] = "fail.login"; response["progress"] = 0.0; response["transfer_rate"] = 7; response["data"]["reason"] = "update"; @@ -376,6 +381,7 @@ namespace tut // Update needed failure response. LLSD response; response["state"] = "offline"; + response["change"] = "fail.login"; response["progress"] = 0.0; response["transfer_rate"] = 7; response["data"]["reason"] = "optional"; @@ -401,6 +407,7 @@ namespace tut // Update needed failure response. LLSD response; response["state"] = "offline"; + response["change"] = "fail.login"; response["progress"] = 0.0; response["transfer_rate"] = 7; response["data"]["reason"] = "optional"; diff --git a/indra/viewer_components/login/lllogin.cpp b/indra/viewer_components/login/lllogin.cpp index c0d35f31d3..7a30315b9a 100644 --- a/indra/viewer_components/login/lllogin.cpp +++ b/indra/viewer_components/login/lllogin.cpp @@ -70,10 +70,12 @@ public: LLEventPump& getEventPump() { return mPump; } private: - void sendProgressEvent(const std::string& desc, const LLSD& data = LLSD::emptyMap()) + void sendProgressEvent(const std::string& state, const std::string& change, + const LLSD& data = LLSD()) { LLSD status_data; - status_data["state"] = desc; + status_data["state"] = state; + status_data["change"] = change; status_data["progress"] = 0.0f; if(mAuthResponse.has("transfer_rate")) @@ -81,7 +83,7 @@ private: status_data["transfer_rate"] = mAuthResponse["transfer_rate"]; } - if(data.size() != 0) + if(data.isDefined()) { status_data["data"] = data; } @@ -133,7 +135,7 @@ void LLLogin::Impl::login_(LLCoros::self& self, std::string uri, LLSD credential LLSD rewrittenURIs; { LLEventTimeout filter(replyPump); - sendProgressEvent("srvrequest"); + sendProgressEvent("offline", "srvrequest"); // Request SRV record. LL_INFOS("LLLogin") << "Requesting SRV record from " << uri << LL_ENDL; @@ -172,7 +174,7 @@ void LLLogin::Impl::login_(LLCoros::self& self, std::string uri, LLSD credential LLSD progress_data; progress_data["attempt"] = attempts; progress_data["request"] = request; - sendProgressEvent("authenticating", progress_data); + sendProgressEvent("offline", "authenticating", progress_data); // We expect zero or more "Downloading" status events, followed by // exactly one event with some other status. Use postAndWait() the @@ -187,7 +189,7 @@ void LLLogin::Impl::login_(LLCoros::self& self, std::string uri, LLSD credential waitForEventOn(self, replyPump))) { // Still Downloading -- send progress update. - sendProgressEvent("downloading"); + sendProgressEvent("offline", "downloading"); } status = mAuthResponse["status"].asString(); @@ -215,9 +217,14 @@ void LLLogin::Impl::login_(LLCoros::self& self, std::string uri, LLSD credential // StatusComplete does not imply auth success. Check the // actual outcome of the request. We've already handled the // "indeterminate" case in the loop above. - sendProgressEvent((mAuthResponse["responses"]["login"].asString() == "true")? - "online" : "offline", - mAuthResponse["responses"]); + if (mAuthResponse["responses"]["login"].asString() == "true") + { + sendProgressEvent("online", "connect", mAuthResponse["responses"]); + } + else + { + sendProgressEvent("offline", "fail.login", mAuthResponse["responses"]); + } return; // Done! } // If we don't recognize status at all, trouble @@ -236,12 +243,12 @@ void LLLogin::Impl::login_(LLCoros::self& self, std::string uri, LLSD credential // Here we got through all the rewrittenURIs without succeeding. Tell // caller this didn't work out so well. Of course, the only failure data // we can reasonably show are from the last of the rewrittenURIs. - sendProgressEvent("offline", mAuthResponse["responses"]); + sendProgressEvent("offline", "fail.login", mAuthResponse["responses"]); } void LLLogin::Impl::disconnect() { - sendProgressEvent("offline", mAuthResponse["responses"]); + sendProgressEvent("offline", "disconnect"); } //********************* diff --git a/indra/viewer_components/login/tests/lllogin_test.cpp b/indra/viewer_components/login/tests/lllogin_test.cpp index 51f00c8344..a8ae2883d5 100644 --- a/indra/viewer_components/login/tests/lllogin_test.cpp +++ b/indra/viewer_components/login/tests/lllogin_test.cpp @@ -265,12 +265,12 @@ namespace tut login.connect("login.bar.com", credentials); - ensure_equals("SRV state", listener.lastEvent()["state"].asString(), "srvrequest"); + ensure_equals("SRV state", listener.lastEvent()["change"].asString(), "srvrequest"); dummyLLAres.sendReply(); // Test Authenticating State prior to first response. - ensure_equals("Auth state 1", listener.lastEvent()["state"].asString(), "authenticating"); + ensure_equals("Auth state 1", listener.lastEvent()["change"].asString(), "authenticating"); ensure_equals("Attempt 1", listener.lastEvent()["data"]["attempt"].asInteger(), 1); ensure_equals("URI 1", listener.lastEvent()["data"]["request"]["uri"].asString(), "login.foo.com"); @@ -285,7 +285,7 @@ namespace tut dummyXMLRPC.setResponse(data); dummyXMLRPC.sendReply(); - ensure_equals("Fail back to authenticate 1", listener.lastEvent()["state"].asString(), "authenticating"); + ensure_equals("Fail back to authenticate 1", listener.lastEvent()["change"].asString(), "authenticating"); ensure_equals("Attempt 2", listener.lastEvent()["data"]["attempt"].asInteger(), 2); ensure_equals("URI 2", listener.lastEvent()["data"]["request"]["uri"].asString(), "login.bar.com"); @@ -301,7 +301,7 @@ namespace tut dummyXMLRPC.setResponse(data); dummyXMLRPC.sendReply(); - ensure_equals("Fail back to authenticate 2", listener.lastEvent()["state"].asString(), "authenticating"); + ensure_equals("Fail back to authenticate 2", listener.lastEvent()["change"].asString(), "authenticating"); ensure_equals("Attempt 3", listener.lastEvent()["data"]["attempt"].asInteger(), 3); ensure_equals("URI 3", listener.lastEvent()["data"]["request"]["uri"].asString(), "login.indeterminate.com"); @@ -350,11 +350,11 @@ namespace tut login.connect("login.bar.com", credentials); - ensure_equals("SRV state", listener.lastEvent()["state"].asString(), "srvrequest"); + ensure_equals("SRV state", listener.lastEvent()["change"].asString(), "srvrequest"); dummyLLAres.sendReply(); - ensure_equals("Auth state", listener.lastEvent()["state"].asString(), "authenticating"); + ensure_equals("Auth state", listener.lastEvent()["change"].asString(), "authenticating"); // Send the failed auth request reponse LLSD data; @@ -397,11 +397,11 @@ namespace tut login.connect("login.bar.com", credentials); - ensure_equals("SRV state", listener.lastEvent()["state"].asString(), "srvrequest"); + ensure_equals("SRV state", listener.lastEvent()["change"].asString(), "srvrequest"); dummyLLAres.sendReply(); - ensure_equals("Auth state", listener.lastEvent()["state"].asString(), "authenticating"); + ensure_equals("Auth state", listener.lastEvent()["change"].asString(), "authenticating"); // Send the failed auth request reponse LLSD data; -- cgit v1.3