diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2023-10-02 13:09:02 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2023-10-02 13:09:02 -0400 |
commit | bd20c548dd02778a2c7a6c318e2b8df6b2fc36c3 (patch) | |
tree | 22f7be2715442845e917b74e7f8d30fc3a3dcb20 /indra/newview/tests/llluamanager_test.cpp | |
parent | de61551df3219dae2238591bae5fa7b6c857e6b0 (diff) |
DRTVWR-589: Add initial integration test for LLLUAmanager.
The first test runs a Lua script that calls post_on(), listen_events() and
await_event() to engage in LLEventPump handshakes with the test program.
Make llluamanager.cpp testable by putting LL_TEST conditionals around lots of
viewer-internals headers and the lua_function definitions that engage them.
Since LuaListener::connect() is called by its constructor, make it a static
method that explicitly accepts the lua_State* (instead of finding it as
mState). Add that parameter to its two existing calls.
Add a debug log message when LuaListener is destroyed. This surfaced the need
to pass a no-op deleter when listen_events() constructs a LuaListener::ptr_t.
When compiled for LL_TEST, make LuaListener::mReplyPump an
LLEventLogProxyFor<LLEventStream> instead of a plain LLEventStream.
For debugging purposes, add a type string "LLEventLogProxy" for
LLEventPumps::make(). A make() call with this type will return an
LLEventLogProxyFor<LLEventStream>.
Diffstat (limited to 'indra/newview/tests/llluamanager_test.cpp')
-rw-r--r-- | indra/newview/tests/llluamanager_test.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/indra/newview/tests/llluamanager_test.cpp b/indra/newview/tests/llluamanager_test.cpp new file mode 100644 index 0000000000..e5e06b095c --- /dev/null +++ b/indra/newview/tests/llluamanager_test.cpp @@ -0,0 +1,101 @@ +/** + * @file llluamanager_test.cpp + * @author Nat Goodspeed + * @date 2023-09-28 + * @brief Test for llluamanager. + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Copyright (c) 2023, Linden Research, Inc. + * $/LicenseInfo$ + */ + +// Precompiled header +//#include "llviewerprecompiledheaders.h" +// associated header +#include "../newview/llluamanager.h" +// STL headers +// std headers +// external library headers +// other Linden headers +#include "../test/lltut.h" +#include "llapp.h" +#include "llevents.h" +#include "lleventcoro.h" +#include "stringize.h" +#include "../llcommon/tests/StringVec.h" + +class LLTestApp : public LLApp +{ +public: + bool init() override { return true; } + bool cleanup() override { return true; } + bool frame() override { return true; } +}; + +/***************************************************************************** +* TUT +*****************************************************************************/ +namespace tut +{ + struct llluamanager_data + { + // We need an LLApp instance because LLLUAmanager uses coroutines, + // which suspend, and when a coroutine suspends it checks LLApp state, + // and if it's not APP_STATUS_RUNNING the coroutine terminates. + LLTestApp mApp; + }; + typedef test_group<llluamanager_data> llluamanager_group; + typedef llluamanager_group::object object; + llluamanager_group llluamanagergrp("llluamanager"); + + template<> template<> + void object::test<1>() + { + set_test_name("test post_on(), listen_events(), await_event()"); + StringVec posts; + LLEventStream replypump("testpump"); + LLTempBoundListener conn( + replypump.listen("test<1>", + [&posts](const LLSD& post) + { + posts.push_back(post.asString()); + return false; + })); + const std::string lua( + "-- test post_on,listen_events,await_event\n" + "post_on('testpump', 'entry')\n" + "callback = function(pump, data)\n" + " -- just echo the data we received\n" + " post_on('testpump', data)\n" + "end\n" + "post_on('testpump', 'listen_events()')\n" + "replypump, cmdpump = listen_events(callback)\n" + "post_on('testpump', replypump)\n" + "post_on('testpump', 'await_event()')\n" + "await_event(replypump)\n" + "post_on('testpump', 'exit')\n" + ); + LLLUAmanager::runScriptLine(lua); + StringVec expected{ + "entry", + "listen_events()", + "", + "await_event()", + "message", + "exit" + }; + for (int i = 0; i < 10 && posts.size() <= 2 && posts[2].empty(); ++i) + { + llcoro::suspend(); + } + expected[2] = posts.at(2); + LL_DEBUGS() << "Found pumpname '" << expected[2] << "'" << LL_ENDL; + LLEventPump& luapump{ LLEventPumps::instance().obtain(expected[2]) }; + LL_DEBUGS() << "Found pump '" << luapump.getName() << "', type '" + << LLError::Log::classname(luapump) + << "': post('" << expected[4] << "')" << LL_ENDL; + luapump.post(expected[4]); + llcoro::suspend(); + ensure_equals("post_on() sequence", posts, expected); + } +} // namespace tut |