Load libA and check that it exists and that the service it registers exists, also check that the expected events occur and that the storage paths are correct
| 145 | // Load libA and check that it exists and that the service it registers exists, |
| 146 | // also check that the expected events occur and that the storage paths are correct |
| 147 | void frame020a(ModuleContext* mc, TestModuleListener& listener, |
| 148 | SharedLibrary& libA) |
| 149 | { |
| 150 | try |
| 151 | { |
| 152 | libA.Load(); |
| 153 | } |
| 154 | catch (const std::exception& e) |
| 155 | { |
| 156 | US_TEST_FAILED_MSG(<< "Load module exception: " << e.what()) |
| 157 | } |
| 158 | |
| 159 | ModuleSettings::SetStoragePath(std::string("/tmp") + PATH_SEPARATOR); |
| 160 | US_TEST_CONDITION(ModuleSettings::GetStoragePath() == "/tmp", "Test for valid base storage path") |
| 161 | |
| 162 | Module* moduleA = ModuleRegistry::GetModule("TestModuleA"); |
| 163 | US_TEST_CONDITION_REQUIRED(moduleA != nullptr, "Test for existing module TestModuleA") |
| 164 | |
| 165 | US_TEST_CONDITION(moduleA->GetName() == "TestModuleA", "Test module name") |
| 166 | |
| 167 | std::cout << moduleA->GetModuleContext()->GetDataFile("") << std::endl; |
| 168 | std::stringstream ss; |
| 169 | ss << moduleA->GetModuleId(); |
| 170 | const std::string baseStoragePath = std::string("/tmp") + PATH_SEPARATOR + ss.str() + "_TestModuleA" + PATH_SEPARATOR; |
| 171 | US_TEST_CONDITION(moduleA->GetModuleContext()->GetDataFile("") == baseStoragePath, "Test for valid data path") |
| 172 | US_TEST_CONDITION(moduleA->GetModuleContext()->GetDataFile("bla") == baseStoragePath + "bla", "Test for valid data file path") |
| 173 | |
| 174 | // Check if libA registered the expected service |
| 175 | try |
| 176 | { |
| 177 | ServiceReferenceU sr1 = mc->GetServiceReference("us::TestModuleAService"); |
| 178 | InterfaceMap o1 = mc->GetService(sr1); |
| 179 | US_TEST_CONDITION(!o1.empty(), "Test if service object found"); |
| 180 | |
| 181 | try |
| 182 | { |
| 183 | US_TEST_CONDITION(mc->UngetService(sr1), "Test if Service UnGet returns true"); |
| 184 | } |
| 185 | catch (const std::logic_error& le) |
| 186 | { |
| 187 | US_TEST_FAILED_MSG(<< "UnGetService exception: " << le.what()) |
| 188 | } |
| 189 | |
| 190 | // check the listeners for events |
| 191 | std::vector<ModuleEvent> pEvts; |
| 192 | pEvts.push_back(ModuleEvent(ModuleEvent::LOADING, moduleA)); |
| 193 | pEvts.push_back(ModuleEvent(ModuleEvent::LOADED, moduleA)); |
| 194 | |
| 195 | std::vector<ServiceEvent> seEvts; |
| 196 | seEvts.push_back(ServiceEvent(ServiceEvent::REGISTERED, sr1)); |
| 197 | |
| 198 | US_TEST_CONDITION(listener.CheckListenerEvents(pEvts, seEvts), "Test for unexpected events"); |
| 199 | |
| 200 | } |
| 201 | catch (const ServiceException& /*se*/) |
| 202 | { |
| 203 | US_TEST_FAILED_MSG(<< "test module, expected service not found"); |
| 204 | } |
no test coverage detected