Load libTestModuleB and check that it exists and that the service it registers exists, also check that the expected events occur
| 36 | // Load libTestModuleB and check that it exists and that the service it registers exists, |
| 37 | // also check that the expected events occur |
| 38 | void frame020a(ModuleContext* mc, TestModuleListener& listener, |
| 39 | SharedLibrary& libB) |
| 40 | { |
| 41 | try |
| 42 | { |
| 43 | libB.Load(); |
| 44 | } |
| 45 | catch (const std::exception& e) |
| 46 | { |
| 47 | US_TEST_FAILED_MSG(<< "Load module exception: " << e.what()) |
| 48 | } |
| 49 | |
| 50 | Module* moduleB = ModuleRegistry::GetModule("TestModuleB"); |
| 51 | US_TEST_CONDITION_REQUIRED(moduleB != nullptr, "Test for existing module TestModuleB") |
| 52 | |
| 53 | Module* moduleImportedByB = ModuleRegistry::GetModule("TestModuleImportedByB"); |
| 54 | US_TEST_CONDITION_REQUIRED(moduleImportedByB != nullptr, "Test for existing module TestModuleImportedByB") |
| 55 | |
| 56 | US_TEST_CONDITION(moduleB->GetName() == "TestModuleB", "Test module name") |
| 57 | |
| 58 | // Check if libB registered the expected service |
| 59 | try |
| 60 | { |
| 61 | std::vector<ServiceReferenceU> refs = mc->GetServiceReferences("us::TestModuleBService"); |
| 62 | US_TEST_CONDITION_REQUIRED(refs.size() == 2, "Test that both the service from the shared and imported library are registered"); |
| 63 | |
| 64 | InterfaceMap o1 = mc->GetService(refs.front()); |
| 65 | US_TEST_CONDITION(!o1.empty(), "Test if first service object found"); |
| 66 | |
| 67 | InterfaceMap o2 = mc->GetService(refs.back()); |
| 68 | US_TEST_CONDITION(!o2.empty(), "Test if second service object found"); |
| 69 | |
| 70 | try |
| 71 | { |
| 72 | US_TEST_CONDITION(mc->UngetService(refs.front()), "Test if Service UnGet for first service returns true"); |
| 73 | US_TEST_CONDITION(mc->UngetService(refs.back()), "Test if Service UnGet for second service returns true"); |
| 74 | } |
| 75 | catch (const std::logic_error &le) |
| 76 | { |
| 77 | US_TEST_FAILED_MSG(<< "UnGetService exception: " << le.what()) |
| 78 | } |
| 79 | |
| 80 | // check the listeners for events |
| 81 | std::vector<ModuleEvent> pEvts; |
| 82 | pEvts.push_back(ModuleEvent(ModuleEvent::LOADING, moduleB)); |
| 83 | pEvts.push_back(ModuleEvent(ModuleEvent::LOADED, moduleB)); |
| 84 | pEvts.push_back(ModuleEvent(ModuleEvent::LOADING, moduleImportedByB)); |
| 85 | pEvts.push_back(ModuleEvent(ModuleEvent::LOADED, moduleImportedByB)); |
| 86 | |
| 87 | std::vector<ServiceEvent> seEvts; |
| 88 | seEvts.push_back(ServiceEvent(ServiceEvent::REGISTERED, refs.back())); |
| 89 | seEvts.push_back(ServiceEvent(ServiceEvent::REGISTERED, refs.front())); |
| 90 | |
| 91 | US_TEST_CONDITION(listener.CheckListenerEvents(pEvts, seEvts), "Test for unexpected events"); |
| 92 | |
| 93 | } |
| 94 | catch (const ServiceException& /*se*/) |
| 95 | { |
no test coverage detected