summaryrefslogtreecommitdiff
path: root/indra/llcommon/tests/lazyeventapi_test.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2022-06-22 10:51:11 -0400
committerNat Goodspeed <nat@lindenlab.com>2022-06-22 10:51:11 -0400
commit6b53036f7499a4e42813378009050eaf02c0b69d (patch)
treecfa65d470b614a6ef246dce074186e54b4ffbc23 /indra/llcommon/tests/lazyeventapi_test.cpp
parentf9d810ac2a02ef96c843e214c7479146dd4f4157 (diff)
DRTVWR-564: Allow LLLeapListener to report LazyEventAPIs too.
One important factor in the design of LazyEventAPI was the desire to allow LLLeapListener to query metadata for an LLEventAPI even if it hasn't yet been instantiated by LazyEventAPI. That's why LazyEventAPI requires the same metadata required by a classic LLEventAPI. Instead of just publicly exposing its data members, give LazyEventAPI a query API mimicking LLEventAPI / LLEventDispatcher. Protect data members and private methods. Adapt lazyeventapi_test.cpp accordingly. Extend LLLeapListener::getAPIs() and getAPI() to look through LazyEventAPIBase instances after first checking existing LLEventAPI instances. Because the query API for LazyEventAPIBase mimics LLEventAPI's, extract getAPI()'s actual metadata reporting to a new internal template function reportAPI(). While we're touching LLLeapListener, we no longer need BOOST_FOREACH().
Diffstat (limited to 'indra/llcommon/tests/lazyeventapi_test.cpp')
-rw-r--r--indra/llcommon/tests/lazyeventapi_test.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/indra/llcommon/tests/lazyeventapi_test.cpp b/indra/llcommon/tests/lazyeventapi_test.cpp
index 4c78fd7105..31b2d6d17f 100644
--- a/indra/llcommon/tests/lazyeventapi_test.cpp
+++ b/indra/llcommon/tests/lazyeventapi_test.cpp
@@ -109,16 +109,28 @@ namespace tut
{
set_test_name("LazyEventAPI metadata");
MyRegistrar regster;
+ // Of course we have 'regster' in hand; we don't need to search for
+ // it. But this next test verifies that we can find (all) LazyEventAPI
+ // instances using LazyEventAPIBase::instance_snapshot. Normally we
+ // wouldn't search; normally we'd just look at each instance in the
+ // loop body.
const MyRegistrar* found = nullptr;
for (const auto& registrar : LL::LazyEventAPIBase::instance_snapshot())
if ((found = dynamic_cast<const MyRegistrar*>(&registrar)))
break;
ensure("Failed to find MyRegistrar via LLInstanceTracker", found);
- ensure_equals("wrong API name", found->mParams.name, "Test");
- ensure_contains("wrong API desc", found->mParams.desc, "test LLEventAPI");
- ensure_equals("wrong API field", found->mParams.field, "op");
- ensure_equals("failed to find operations", found->mOperations.size(), 1);
- ensure_equals("wrong operation name", found->mOperations[0].first, "set");
- ensure_contains("wrong operation desc", found->mOperations[0].second, "set operation");
+
+ ensure_equals("wrong API name", found->getName(), "Test");
+ ensure_contains("wrong API desc", found->getDesc(), "test LLEventAPI");
+ ensure_equals("wrong API field", found->getDispatchKey(), "op");
+ // Normally we'd just iterate over *found. But for test purposes,
+ // actually capture the range of NameDesc pairs in a vector.
+ std::vector<LL::LazyEventAPIBase::NameDesc> ops{ found->begin(), found->end() };
+ ensure_equals("failed to find operations", ops.size(), 1);
+ ensure_equals("wrong operation name", ops[0].first, "set");
+ ensure_contains("wrong operation desc", ops[0].second, "set operation");
+ LLSD metadata{ found->getMetadata(ops[0].first) };
+ ensure_equals("bad metadata name", metadata["name"].asString(), ops[0].first);
+ ensure_equals("bad metadata desc", metadata["desc"].asString(), ops[0].second);
}
} // namespace tut