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

Function testDefaultAutoLoadPath

Modules/CppMicroServices/test/usModuleAutoLoadTest.cpp:38–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36#endif
37
38void testDefaultAutoLoadPath(bool autoLoadEnabled)
39{
40 ModuleContext* mc = GetModuleContext();
41 assert(mc);
42 TestModuleListener listener;
43
44 ModuleListenerRegistrationHelper<TestModuleListener> listenerReg(mc, &listener, &TestModuleListener::ModuleChanged);
45
46 SharedLibrary libAL(LIB_PATH, "TestModuleAL");
47
48 try
49 {
50 libAL.Load();
51 }
52 catch (const std::exception& e)
53 {
54 US_TEST_FAILED_MSG(<< "Load module exception: " << e.what())
55 }
56
57 Module* moduleAL = ModuleRegistry::GetModule("TestModuleAL");
58 US_TEST_CONDITION_REQUIRED(moduleAL != nullptr, "Test for existing module TestModuleAL")
59
60 US_TEST_CONDITION(moduleAL->GetName() == "TestModuleAL", "Test module name")
61
62 // check the listeners for events
63 std::vector<ModuleEvent> pEvts;
64 pEvts.push_back(ModuleEvent(ModuleEvent::LOADING, moduleAL));
65
66 Any loadedModules = moduleAL->GetProperty(Module::PROP_AUTOLOADED_MODULES());
67 Module* moduleAL_1 = ModuleRegistry::GetModule("TestModuleAL_1");
68 if (autoLoadEnabled)
69 {
70 US_TEST_CONDITION_REQUIRED(moduleAL_1 != nullptr, "Test for existing auto-loaded module TestModuleAL_1")
71 US_TEST_CONDITION(moduleAL_1->GetName() == "TestModuleAL_1", "Test module name")
72 US_TEST_CONDITION_REQUIRED(!loadedModules.Empty(), "Test for PROP_AUTOLOADED_MODULES property")
73 US_TEST_CONDITION_REQUIRED(loadedModules.Type() == typeid(std::vector<std::string>), "Test for PROP_AUTOLOADED_MODULES property type")
74 std::vector<std::string> loadedModulesVec = any_cast<std::vector<std::string> >(loadedModules);
75 US_TEST_CONDITION_REQUIRED(loadedModulesVec.size() == 1, "Test for PROP_AUTOLOADED_MODULES vector size")
76 US_TEST_CONDITION_REQUIRED(loadedModulesVec[0] == moduleAL_1->GetLocation(), "Test for PROP_AUTOLOADED_MODULES vector content")
77
78 pEvts.push_back(ModuleEvent(ModuleEvent::LOADING, moduleAL_1));
79 pEvts.push_back(ModuleEvent(ModuleEvent::LOADED, moduleAL_1));
80 }
81 else
82 {
83 US_TEST_CONDITION_REQUIRED(moduleAL_1 == nullptr, "Test for non-existing auto-loaded module TestModuleAL_1")
84 US_TEST_CONDITION_REQUIRED(loadedModules.Empty(), "Test for empty PROP_AUTOLOADED_MODULES property")
85 }
86
87 pEvts.push_back(ModuleEvent(ModuleEvent::LOADED, moduleAL));
88
89 US_TEST_CONDITION(listener.CheckListenerEvents(pEvts), "Test for unexpected events");
90
91 mc->RemoveModuleListener(&listener, &TestModuleListener::ModuleChanged);
92
93 libAL.Unload();
94}
95

Callers 1

usModuleAutoLoadTestFunction · 0.85

Calls 13

GetModuleContextFunction · 0.85
whatMethod · 0.80
EmptyMethod · 0.80
CheckListenerEventsMethod · 0.80
ModuleEventClass · 0.50
LoadMethod · 0.45
GetNameMethod · 0.45
GetPropertyMethod · 0.45
TypeMethod · 0.45
sizeMethod · 0.45
GetLocationMethod · 0.45
RemoveModuleListenerMethod · 0.45

Tested by

no test coverage detected