Hansong Zhang | 0bce6f7 | 2019-06-13 18:31:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "stack_manager.h" |
| 18 | |
| 19 | #include "gtest/gtest.h" |
| 20 | #include "os/thread.h" |
| 21 | |
| 22 | namespace bluetooth { |
| 23 | namespace { |
| 24 | |
| 25 | TEST(StackManagerTest, start_and_shutdown_no_module) { |
| 26 | StackManager stack_manager; |
| 27 | ModuleList module_list; |
| 28 | os::Thread thread{"test_thread", os::Thread::Priority::NORMAL}; |
| 29 | stack_manager.StartUp(&module_list, &thread); |
| 30 | stack_manager.ShutDown(); |
| 31 | } |
| 32 | |
| 33 | class TestModuleNoDependency : public Module { |
| 34 | public: |
| 35 | static const ModuleFactory Factory; |
| 36 | |
| 37 | protected: |
| 38 | void ListDependencies(ModuleList* list) override {} |
| 39 | void Start() override {} |
| 40 | void Stop() override {} |
| 41 | }; |
| 42 | |
| 43 | const ModuleFactory TestModuleNoDependency::Factory = ModuleFactory([]() { return new TestModuleNoDependency(); }); |
| 44 | |
| 45 | TEST(StackManagerTest, get_module_instance) { |
| 46 | StackManager stack_manager; |
| 47 | ModuleList module_list; |
| 48 | module_list.add<TestModuleNoDependency>(); |
| 49 | os::Thread thread{"test_thread", os::Thread::Priority::NORMAL}; |
| 50 | stack_manager.StartUp(&module_list, &thread); |
| 51 | EXPECT_NE(stack_manager.GetInstance<TestModuleNoDependency>(), nullptr); |
| 52 | stack_manager.ShutDown(); |
| 53 | } |
| 54 | |
| 55 | } // namespace |
| 56 | } // namespace bluetooth |