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

Function TestEventHook

Modules/CppMicroServices/test/usModuleHooksTest.cpp:125–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125void TestEventHook()
126{
127 TestModuleListener moduleListener;
128 GetModuleContext()->AddModuleListener(&moduleListener, &TestModuleListener::ModuleChanged);
129
130 SharedLibrary libA(LIB_PATH, "TestModuleA");
131 try
132 {
133 libA.Load();
134 }
135 catch (const std::exception& e)
136 {
137 US_TEST_FAILED_MSG(<< "Load module exception: " << e.what())
138 }
139 US_TEST_CONDITION_REQUIRED(moduleListener.events.size() == 2, "Test for received load module events")
140
141 libA.Unload();
142 US_TEST_CONDITION_REQUIRED(moduleListener.events.size() == 4, "Test for received unload module events")
143
144 TestModuleEventHook eventHook;
145 ServiceRegistration<ModuleEventHook> eventHookReg = GetModuleContext()->RegisterService<ModuleEventHook>(&eventHook);
146
147 moduleListener.events.clear();
148 try
149 {
150 libA.Load();
151 }
152 catch (const std::exception& e)
153 {
154 US_TEST_FAILED_MSG(<< "Load module exception: " << e.what())
155 }
156
157 US_TEST_CONDITION_REQUIRED(moduleListener.events.size() == 1, "Test for filtered load module events")
158 US_TEST_CONDITION_REQUIRED(moduleListener.events[0].GetType() == ModuleEvent::LOADED, "Test for LOADED event")
159
160 libA.Unload();
161 US_TEST_CONDITION_REQUIRED(moduleListener.events.size() == 2, "Test for filtered unload module events")
162 US_TEST_CONDITION_REQUIRED(moduleListener.events[1].GetType() == ModuleEvent::UNLOADED, "Test for UNLOADED event")
163
164 eventHookReg.Unregister();
165 GetModuleContext()->RemoveModuleListener(&moduleListener, &TestModuleListener::ModuleChanged);
166}
167
168} // end unnamed namespace
169

Callers 1

usModuleHooksTestFunction · 0.85

Calls 10

GetModuleContextFunction · 0.85
whatMethod · 0.80
AddModuleListenerMethod · 0.45
LoadMethod · 0.45
UnloadMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
GetTypeMethod · 0.45
UnregisterMethod · 0.45
RemoveModuleListenerMethod · 0.45

Tested by

no test coverage detected