summaryrefslogtreecommitdiff
path: root/indra/newview/tests/llluamanager_test.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-03-08 10:53:50 -0500
committerNat Goodspeed <nat@lindenlab.com>2024-03-08 10:53:50 -0500
commitefdda0b93d2dbf28e7722150028476286f0ec623 (patch)
treee1e0e544272d987dd146f411d9cadfa54c2bde52 /indra/newview/tests/llluamanager_test.cpp
parent27d6bbd3d98bde278cc828d6673a93c4702b3e80 (diff)
Enhance llluamanager_test.cpp.
Sketch in an initial test that requires one of our bundled Lua modules. Each time we run Lua, report any error returned by the Lua engine. Use llcoro::suspendUntilEventOn(LLEventMailDrop) as shorthand for initializing an explicit LLTempBoundListener with a listen() call with a lambda.
Diffstat (limited to 'indra/newview/tests/llluamanager_test.cpp')
-rw-r--r--indra/newview/tests/llluamanager_test.cpp34
1 files changed, 23 insertions, 11 deletions
diff --git a/indra/newview/tests/llluamanager_test.cpp b/indra/newview/tests/llluamanager_test.cpp
index 81ec186cf4..1c2be900d3 100644
--- a/indra/newview/tests/llluamanager_test.cpp
+++ b/indra/newview/tests/llluamanager_test.cpp
@@ -94,9 +94,10 @@ namespace tut
{
auto [count, result] =
LLLUAmanager::waitScriptLine(L, "return " + luax.expr);
- auto desc{ stringize("waitScriptLine(", luax.desc, ")") };
- ensure_equals(desc + ".count", count, 1);
- ensure_equals(desc + ".result", result, luax.expect);
+ auto desc{ stringize("waitScriptLine(", luax.desc, "): ") };
+ // if count < 0, report Lua error message
+ ensure_equals(desc + result.asString(), count, 1);
+ ensure_equals(desc + "result", result, luax.expect);
}
}
@@ -116,7 +117,7 @@ namespace tut
// We woke up again ourselves because the coroutine running Lua has
// finished. But our Lua chunk didn't actually return anything, so we
// expect count to be 0 and result to be undefined.
- ensure_equals(desc + " count", count, 0);
+ ensure_equals(desc + ": " + result.asString(), count, 0);
ensure_equals(desc, fromlua, expect);
}
@@ -172,16 +173,13 @@ namespace tut
<< "': post('" << expected[4] << "')" << LL_ENDL;
luapump.post(expected[4]);
auto [count, result] = future.get();
+ ensure_equals("post_on(): " + result.asString(), count, 0);
ensure_equals("post_on() sequence", posts, expected);
}
void round_trip(const std::string& desc, const LLSD& send, const LLSD& expect)
{
- LLSD reply;
- LLEventStream replypump("testpump");
- LLTempBoundListener conn(
- replypump.listen("llluamanager_test",
- listener([&reply](const LLSD& post){ reply = post; })));
+ LLEventMailDrop replypump("testpump");
const std::string lua(
"-- test LLSD round trip\n"
"replypump, cmdpump = get_event_pumps()\n"
@@ -195,12 +193,12 @@ namespace tut
// reached the get_event_next() call, which suspends the calling C++
// coroutine (including the Lua code running on it) until we post
// something to that reply pump.
- auto luapump{ reply.asString() };
- reply.clear();
+ auto luapump{ llcoro::suspendUntilEventOn(replypump).asString() };
LLEventPumps::instance().post(luapump, send);
// The C++ coroutine running the Lua script is now ready to run. Run
// it so it will echo the LLSD back to us.
auto [count, result] = future.get();
+ ensure_equals(stringize("round_trip(", desc, "): ", result.asString()), count, 1);
ensure_equals(desc, result, expect);
}
@@ -304,4 +302,18 @@ namespace tut
}
round_trip("nested map", send_map, expect_map);
}
+
+ template<> template<>
+ void object::test<5>()
+ {
+ set_test_name("test leap.lua");
+ const std::string lua(
+ "-- test leap.lua\n"
+ "leap = require('leap')\n"
+ );
+ LuaState L;
+ auto future = LLLUAmanager::startScriptLine(L, lua);
+ auto [count, result] = future.get();
+ ensure_equals("leap.lua: " + result.asString(), count, 0);
+ }
} // namespace tut