MCPcopy Create free account
hub / github.com/MITK/MITK / TestFindHook

Function TestFindHook

Modules/CppMicroServices/test/usServiceHooksTest.cpp:309–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307}
308
309void TestFindHook()
310{
311 ModuleContext* context = GetModuleContext();
312
313 TestServiceFindHook serviceFindHook1(1);
314 ServiceProperties hookProps1;
315 hookProps1[ServiceConstants::SERVICE_RANKING()] = 0;
316 ServiceRegistration<ServiceFindHook> findHookReg1 =
317 context->RegisterService<ServiceFindHook>(&serviceFindHook1, hookProps1);
318
319 TestServiceFindHook serviceFindHook2(2);
320 ServiceProperties hookProps2;
321 hookProps2[ServiceConstants::SERVICE_RANKING()] = 10;
322 ServiceRegistration<ServiceFindHook> findHookReg2 =
323 context->RegisterService<ServiceFindHook>(&serviceFindHook2, hookProps2);
324
325 std::vector<int> expectedOrdering;
326 US_TEST_CONDITION(serviceFindHook1.ordering == expectedOrdering, "Find hook call order");
327
328 TestServiceListener serviceListener;
329 context->AddServiceListener(&serviceListener, &TestServiceListener::ServiceChanged);
330
331 SharedLibrary libA(LIB_PATH, "TestModuleA");
332 try
333 {
334 libA.Load();
335 }
336 catch (const std::exception& e)
337 {
338 US_TEST_FAILED_MSG(<< "Load module exception: " << e.what())
339 }
340
341 US_TEST_CONDITION(serviceListener.events.size() == 1, "Service registered");
342
343 std::vector<ServiceReferenceU> refs = context->GetServiceReferences("us::TestModuleAService");
344 US_TEST_CONDITION(refs.empty(), "Empty references");
345 ServiceReferenceU ref = context->GetServiceReference("us::TestModuleAService");
346 US_TEST_CONDITION(!ref, "Invalid reference (filtered out)");
347
348 expectedOrdering.push_back(2);
349 expectedOrdering.push_back(1);
350 expectedOrdering.push_back(2);
351 expectedOrdering.push_back(1);
352
353 US_TEST_CONDITION(serviceFindHook1.ordering == expectedOrdering, "Find hook call order");
354
355 findHookReg2.Unregister();
356 findHookReg1.Unregister();
357
358 refs = context->GetServiceReferences("us::TestModuleAService");
359 US_TEST_CONDITION(!refs.empty(), "Non-empty references");
360 ref = context->GetServiceReference("us::TestModuleAService");
361 US_TEST_CONDITION(ref, "Valid reference");
362
363 libA.Unload();
364
365 context->RemoveServiceListener(&serviceListener, &TestServiceListener::ServiceChanged);
366}

Callers 1

usServiceHooksTestFunction · 0.70

Calls 11

GetModuleContextFunction · 0.85
whatMethod · 0.80
GetServiceReferencesMethod · 0.80
AddServiceListenerMethod · 0.45
LoadMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
GetServiceReferenceMethod · 0.45
UnregisterMethod · 0.45
UnloadMethod · 0.45
RemoveServiceListenerMethod · 0.45

Tested by

no test coverage detected