Remove testing code from ModuleRegistry
Test: atest --host bluetooth_test_gd
Change-Id: Iafe4a46d4dfc134f4dd9ee1fcbed527a7ec34ed0
diff --git a/gd/module.h b/gd/module.h
index 33e0325..e67ced8 100644
--- a/gd/module.h
+++ b/gd/module.h
@@ -115,20 +115,38 @@
// Stop all running modules in reverse order of start
void StopAll();
- // Helper for dependency injection in test code. DO NOT USE in prod code!
- // Ownership of |instance| is transferred to the registry.
- void inject_test_module(const ModuleFactory* module, Module* instance, os::Thread* thread);
-
- // Helper for dependency injection in test code. DO NOT USE in prod code!
- template <class T>
- T* get_module_under_test() const {
- return static_cast<T*>(Get(&T::Factory));
- }
-
- private:
+ protected:
Module* Get(const ModuleFactory* module) const;
+
std::map<const ModuleFactory*, Module*> started_modules_;
std::vector<const ModuleFactory*> start_order_;
};
+class TestModuleRegistry : public ModuleRegistry {
+ public:
+ void InjectTestModule(const ModuleFactory* module, Module* instance) {
+ start_order_.push_back(module);
+ started_modules_[module] = instance;
+ }
+
+ Module* GetModuleUnderTest(const ModuleFactory* module) const {
+ return Get(module);
+ }
+
+ os::Handler* GetTestModuleHandler() {
+ return new os::Handler(&test_thread);
+ }
+
+ os::Thread& GetTestThread() {
+ return test_thread;
+ }
+
+ template <class T>
+ T* StartTestModule() {
+ return Start<T>(&test_thread);
+ }
+
+ os::Thread test_thread{"test_thread", os::Thread::Priority::NORMAL};
+};
+
} // namespace bluetooth