• 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 "config_reader_test.h"
17 
18 using namespace std;
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 namespace ResourceSchedule {
23 namespace {
24     const string PLUGIN_NAME = "demo";
25     const string CONFIG_NAME = "sample";
26     const string TEST_PREFIX_RES_PATH = "/data/test/resource/resschedfwk/parseconfig/";
27 }
28 
SetUpTestCase()29 void ConfigReaderTest::SetUpTestCase() {}
30 
TearDownTestCase()31 void ConfigReaderTest::TearDownTestCase() {}
32 
SetUp()33 void ConfigReaderTest::SetUp()
34 {
35     /**
36      * @tc.setup: initialize the member variable configReader_
37      */
38     configReader_ = make_shared<ConfigReader>();
39 }
40 
TearDown()41 void ConfigReaderTest::TearDown()
42 {
43     /**
44      * @tc.teardown: clear configReader_
45      */
46     configReader_ = nullptr;
47 }
48 
ParseConfigFile(const string & fileName)49 bool ConfigReaderTest::ParseConfigFile(const string& fileName)
50 {
51     bool ret = configReader_->LoadFromCustConfigFile(TEST_PREFIX_RES_PATH + fileName);
52     return ret;
53 }
54 
55 /**
56  * @tc.name: Load Config File 001
57  * @tc.desc: Verify if can load not exist file.
58  * @tc.type: FUNC
59  * @tc.require: issueI798UT
60  * @tc.author:xukuan
61  */
62 HWTEST_F(ConfigReaderTest, LoadConfigFile001, TestSize.Level1)
63 {
64     /**
65      * @tc.steps: step1. load not exist config file
66      * @tc.expected: step1. return false when load not exist file
67      */
68     bool ret = configReader_->LoadFromCustConfigFile("fileNotExist");
69     EXPECT_TRUE(!ret);
70 }
71 
72 /**
73  * @tc.name: Load Config File 002
74  * @tc.desc: Verify if can load invalid format config file.
75  * @tc.type: FUNC
76  * @tc.require: issueI798UT
77  * @tc.author:xukuan
78  */
79 HWTEST_F(ConfigReaderTest, LoadConfigFile002, TestSize.Level1)
80 {
81     bool ret = ParseConfigFile("invalid_format.xml");
82     EXPECT_TRUE(!ret);
83 }
84 
85 /**
86  * @tc.name: Load Config File 003
87  * @tc.desc: Verify if can load wrong root element config file.
88  * @tc.type: FUNC
89  * @tc.require: issueI798UT
90  * @tc.author:xukuan
91  */
92 HWTEST_F(ConfigReaderTest, LoadConfigFile003, TestSize.Level1)
93 {
94     bool ret = ParseConfigFile("root_element_wrong.xml");
95     EXPECT_TRUE(!ret);
96 }
97 
98 /**
99  * @tc.name: Load Config File 004
100  * @tc.desc: Verify if can load wrong plugin tag config file.
101  * @tc.type: FUNC
102  * @tc.require: issueI798UT
103  * @tc.author:xukuan
104  */
105 HWTEST_F(ConfigReaderTest, LoadConfigFile004, TestSize.Level1)
106 {
107     bool ret = ParseConfigFile("plugin_tag_wrong.xml");
108     EXPECT_TRUE(!ret);
109 }
110 
111 /**
112  * @tc.name: Load Config File 005
113  * @tc.desc: Verify if can load config file with comment.
114  * @tc.type: FUNC
115  * @tc.require: issueI798UT
116  * @tc.author:xukuan
117  */
118 HWTEST_F(ConfigReaderTest, LoadConfigFile005, TestSize.Level1)
119 {
120     bool ret = ParseConfigFile("res_sched_config_comments.xml");
121     EXPECT_TRUE(ret);
122 }
123 
124 /**
125  * @tc.name: Get Config 001
126  * @tc.desc: Verify if can load config with wrong pluginName or configName.
127  * @tc.type: FUNC
128  * @tc.require: issueI5WWV3
129  * @tc.author:lice
130  */
131 HWTEST_F(ConfigReaderTest, GetConfig001, TestSize.Level1)
132 {
133     PluginConfig config = configReader_->GetConfig("error.xml", "");
134     EXPECT_TRUE(config.itemList.empty());
135 
136     config = configReader_->GetConfig("res_sched_config_comments.xml", "error.xml");
137     EXPECT_TRUE(config.itemList.empty());
138 }
139 } // namespace ResourceSchedule
140 } // namespace OHOS
141