| 123 | } |
| 124 | |
| 125 | void 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 |
no test coverage detected