OSDN Git Service

[automerger skipped] Merge "Reset the IRK after all devices are unpaired" into rvc...
[android-x86/system-bt.git] / gd / stack_manager_unittest.cc
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   std::string ToString() const override {
42     return std::string("TestModuleDep");
43   }
44 };
45
46 const ModuleFactory TestModuleNoDependency::Factory = ModuleFactory([]() { return new TestModuleNoDependency(); });
47
48 TEST(StackManagerTest, get_module_instance) {
49   StackManager stack_manager;
50   ModuleList module_list;
51   module_list.add<TestModuleNoDependency>();
52   os::Thread thread{"test_thread", os::Thread::Priority::NORMAL};
53   stack_manager.StartUp(&module_list, &thread);
54   EXPECT_NE(stack_manager.GetInstance<TestModuleNoDependency>(), nullptr);
55   stack_manager.ShutDown();
56 }
57
58 }  // namespace
59 }  // namespace bluetooth