• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "plugin_manager_test.h"
17 #include <ipc_skeleton.h>
18 #include <iservice_registry.h>
19 #include "func_code_utils.h"
20 #include "plugin_manager.h"
21 #include "string_ex.h"
22 #include "system_ability_definition.h"
23 
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace OHOS::EDM;
27 
28 namespace OHOS {
29 namespace EDM {
30 namespace TEST {
SetUp()31 void PluginManagerTest::SetUp()
32 {
33     PluginManager::GetInstance()->AddPlugin(std::make_shared<TestPlugin>());
34 }
35 
TearDown()36 void PluginManagerTest::TearDown()
37 {
38     PluginManager::GetInstance().reset();
39 }
40 
41 /**
42  * @tc.name: TestGetInstance
43  * @tc.desc: Test PluginManager GetInstance func.
44  * @tc.type: FUNC
45  */
46 HWTEST_F(PluginManagerTest, TestGetInstance, TestSize.Level1)
47 {
48     ASSERT_TRUE(PluginManager::GetInstance() != nullptr);
49     ASSERT_TRUE(PluginManager::GetInstance().get() != nullptr);
50 }
51 
52 /**
53  * @tc.name: TestGetPluginByFuncCode
54  * @tc.desc: Test PluginManager GetPluginByFuncCode func.
55  * @tc.type: FUNC
56  */
57 HWTEST_F(PluginManagerTest, TestGetPluginByFuncCode, TestSize.Level1)
58 {
59     std::shared_ptr<IPlugin> plugin = PluginManager::GetInstance()->GetPluginByFuncCode(
60         POLICY_FUNC_CODE((uint32_t)FuncOperateType::SET, 0));
61     ASSERT_TRUE(plugin != nullptr);
62     ASSERT_TRUE(plugin->GetPolicyName() == "TestPlugin");
63     ASSERT_TRUE(PluginManager::GetInstance()->GetPluginByFuncCode(
64         POLICY_FUNC_CODE((uint32_t)FuncOperateType::SET, 100000)) == nullptr);
65 }
66 
67 /**
68  * @tc.name: TestGetPluginByPolicyName
69  * @tc.desc: Test PluginManager GetPluginByPolicyName func.
70  * @tc.type: FUNC
71  */
72 HWTEST_F(PluginManagerTest, TestGetPluginByPolicyName, TestSize.Level1)
73 {
74     std::shared_ptr<IPlugin> plugin = PluginManager::GetInstance()->GetPluginByPolicyName("TestPlugin");
75     ASSERT_TRUE(plugin != nullptr);
76     ASSERT_TRUE(plugin->GetCode() == 0);
77     ASSERT_TRUE(PluginManager::GetInstance()->GetPluginByPolicyName("XXXXExamplePlugin") == nullptr);
78 }
79 } // namespace TEST
80 } // namespace EDM
81 } // namespace OHOS
82