• 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_switch_test.h"
17 
18 using namespace std;
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 namespace ResourceSchedule {
23 const string TEST_PREFIX_SWITCH_PATH = "/data/test/resource/resschedfwk/parseswitch/";
24 
SetUpTestCase()25 void PluginSwitchTest::SetUpTestCase() {}
26 
TearDownTestCase()27 void PluginSwitchTest::TearDownTestCase() {}
28 
SetUp()29 void PluginSwitchTest::SetUp()
30 {
31     /**
32      * @tc.setup: initialize the member variable pluginSwitch_
33      */
34     pluginSwitch_ = make_shared<PluginSwitch>();
35 }
36 
TearDown()37 void PluginSwitchTest::TearDown()
38 {
39     /**
40      * @tc.teardown: clear pluginSwitch_
41      */
42     pluginSwitch_ = nullptr;
43 }
44 
45 /**
46  * @tc.name: Init plugin Switch LoadConfig001
47  * @tc.desc: Verify if can Init the plugin correctly
48  * @tc.type: FUNC
49  * @tc.require: SR000GGUUN AR000GH1JN
50  * @tc.author:xukuan
51  */
52 HWTEST_F(PluginSwitchTest, LoadConfig001, TestSize.Level1)
53 {
54     pluginSwitch_ = make_unique<PluginSwitch>();
55     bool ret = pluginSwitch_->LoadFromConfigFile(TEST_PREFIX_SWITCH_PATH + "fileNotExist");
56     EXPECT_TRUE(!ret);
57 }
58 
59 /**
60  * @tc.name: Init plugin Switch LoadConfig002
61  * @tc.desc: Verify if can load file while xml does not have pluginlist node
62  * @tc.type: FUNC
63  * @tc.require: SR000GGUUN AR000GH1JN
64  * @tc.author:xukuan
65  */
66 HWTEST_F(PluginSwitchTest, LoadConfig002, TestSize.Level1)
67 {
68     pluginSwitch_ = make_unique<PluginSwitch>();
69     bool ret = pluginSwitch_->LoadFromConfigFile(TEST_PREFIX_SWITCH_PATH + "not_exist_plugin.xml");
70     EXPECT_TRUE(!ret);
71 }
72 
73 /**
74  * @tc.name: Init plugin Switch LoadConfig003
75  * @tc.desc: Verify if can load file invalid format config file
76  * @tc.type: FUNC
77  * @tc.require: SR000GGUUN AR000GH1JN
78  * @tc.author:xukuan
79  */
80 HWTEST_F(PluginSwitchTest, LoadConfig003, TestSize.Level1)
81 {
82     bool ret = pluginSwitch_->LoadFromConfigFile(TEST_PREFIX_SWITCH_PATH + "invalid_format.xml");
83     EXPECT_TRUE(!ret);
84 }
85 
86 /**
87  * @tc.name: Init plugin Switch LoadConfig004
88  * @tc.desc: Verify if can load wrong root element config
89  * @tc.type: FUNC
90  * @tc.require: SR000GGUUN AR000GH1JN
91  * @tc.author:xukuan
92  */
93 HWTEST_F(PluginSwitchTest, LoadConfig004, TestSize.Level1)
94 {
95     bool ret = pluginSwitch_->LoadFromConfigFile(TEST_PREFIX_SWITCH_PATH + "root_element_wrong.xml");
96     EXPECT_TRUE(!ret);
97 }
98 } // namespace ResourceSchedule
99 } // namespace OHOS
100