• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_policy_utils_test.h"
17 
18 #include <gtest/gtest.h>
19 
20 #include "config_policy_utils.h"
21 
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 class ConfigPolicyUtilsTest : public testing::Test {};
26 
TestGetCfgFile(const char * testPathSuffix,int type,const char * extra)27 bool TestGetCfgFile(const char *testPathSuffix, int type, const char *extra)
28 {
29     CfgFiles *cfgFiles = GetCfgFilesEx(testPathSuffix, type, extra);
30     EXPECT_TRUE(cfgFiles != NULL);
31     bool flag = false;
32     char *filePath = nullptr;
33     for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) {
34         filePath = cfgFiles->paths[i];
35         if (filePath && *filePath != '\0') {
36             std::cout << "type: " << type << ", filePath: " << filePath << std::endl;
37             flag = true;
38         }
39     }
40     FreeCfgFiles(cfgFiles);
41     char buf[MAX_PATH_LEN] = {0};
42     filePath = GetOneCfgFileEx(testPathSuffix, buf, MAX_PATH_LEN, type, extra);
43     if (filePath && *filePath != '\0') {
44         std::cout << "type: " << type << ", one filePath: " << filePath << std::endl;
45         flag = flag && true;
46     }
47     return flag;
48 }
49 
50 /**
51  * @tc.name: CfgPolicyUtilsFuncTest001
52  * @tc.desc: Test GetOneCfgFile & GetCfgFiles function, none file case.
53  * @tc.type: FUNC
54  * @tc.require: issueI5NYDH
55  */
56 HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest001, TestSize.Level1)
57 {
58     const char *testPathSuffix = "custxmltest/none.xml";
59     EXPECT_FALSE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_FOLLOW, NULL));
60 }
61 
62 /**
63  * @tc.name: CfgPolicyUtilsFuncTest002
64  * @tc.desc: Test GetOneCfgFile & GetCfgFiles function, system file case.
65  * @tc.type: FUNC
66  * @tc.require: issueI5NYDH
67  */
68 HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest002, TestSize.Level1)
69 {
70     const char *testPathSuffix = "custxmltest/system.xml";
71     EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_FOLLOW, NULL));
72 }
73 
74 /**
75  * @tc.name: CfgPolicyUtilsFuncTest003
76  * @tc.desc: Test GetOneCfgFile & GetCfgFiles function, user file case.
77  * @tc.type: FUNC
78  * @tc.require: issueI5NYDH
79  */
80 HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest003, TestSize.Level1)
81 {
82     const char *testPathSuffix = "custxmltest/user.xml";
83     EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_FOLLOW, NULL));
84 }
85 
86 /**
87  * @tc.name: CfgPolicyUtilsFuncTest004
88  * @tc.desc: Test GetOneCfgFile & GetCfgFiles function, both files case.
89  * @tc.type: FUNC
90  * @tc.require: issueI5NYDH
91  */
92 HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest004, TestSize.Level1)
93 {
94     const char *testPathSuffix = "custxmltest/both.xml";
95     EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_NO_FOLLOW, NULL));
96 }
97 
98 /**
99  * @tc.name: CfgPolicyUtilsFuncTest005
100  * @tc.desc: Test struct CfgDir *GetCfgDirList(void) function.
101  * @tc.type: FUNC
102  * @tc.require: issueI5NYDH
103  */
104 HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest005, TestSize.Level1)
105 {
106     CfgDir *cfgDir = GetCfgDirList();
107     EXPECT_TRUE(cfgDir != NULL);
108     bool flag = false;
109     for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) {
110         char *filePath = cfgDir->paths[i];
111         if (filePath && *filePath != '\0') {
112             std::cout << "filePath: " << filePath << std::endl;
113             flag = true;
114         }
115     }
116     FreeCfgDirList(cfgDir);
117     EXPECT_TRUE(flag);
118 }
119 
120 /**
121  * @tc.name: CfgPolicyUtilsFuncTest006
122  * @tc.desc: Test GetOneCfgFile & GetCfgFiles function, follow default sim rule.
123  * @tc.type: FUNC
124  * @tc.require: issueI5NYDH
125  */
126 HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest006, TestSize.Level1)
127 {
128     const char *testPathSuffix = "custxmltest/user.xml";
129     EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_SIM_DEFAULT, NULL));
130 }
131 
132 /**
133  * @tc.name: CfgPolicyUtilsFuncTest007
134  * @tc.desc: Test GetOneCfgFile & GetCfgFiles function, follow sim1 rule.
135  * @tc.type: FUNC
136  * @tc.require: issueI5NYDH
137  */
138 HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest007, TestSize.Level1)
139 {
140     const char *testPathSuffix = "custxmltest/user.xml";
141     EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_SIM_1, NULL));
142 }
143 
144 /**
145  * @tc.name: CfgPolicyUtilsFuncTest008
146  * @tc.desc: Test GetOneCfgFile & GetCfgFiles function, follow sim1 rule.
147  * @tc.type: FUNC
148  * @tc.require: issueI5NYDH
149  */
150 HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest008, TestSize.Level1)
151 {
152     const char *testPathSuffix = "custxmltest/user.xml";
153     EXPECT_TRUE(TestGetCfgFile(testPathSuffix, FOLLOWX_MODE_SIM_2, NULL));
154 }
155 
156 /**
157  * @tc.name: CfgPolicyUtilsFuncTest009
158  * @tc.desc: Test GetOneCfgFile & GetCfgFiles function, follow default x rule rule.
159  * @tc.type: FUNC
160  * @tc.require: issueI5NYDH
161  */
162 HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest009, TestSize.Level1)
163 {
164     EXPECT_TRUE(TestGetCfgFile("custxmltest/user.xml", FOLLOWX_MODE_DEFAULT, NULL));
165     EXPECT_TRUE(TestGetCfgFile("custxmltest/both.xml", FOLLOWX_MODE_DEFAULT, NULL));
166 }
167 
168 /**
169  * @tc.name: CfgPolicyUtilsFuncTest010
170  * @tc.desc: Test GetOneCfgFile & GetCfgFiles function, follow default x rule rule.
171  * @tc.type: FUNC
172  * @tc.require: issueI5NYDH
173  */
174 HWTEST_F(ConfigPolicyUtilsTest, CfgPolicyUtilsFuncTest010, TestSize.Level1)
175 {
176     const char *extra = "etc/carrier/${persist.telephony.opkey1:-46060},etc/carrier/${persist.telephony.opkey0}/"
177                         "${testkey:-custxmltest}";
178     EXPECT_TRUE(TestGetCfgFile("custxmltest/user.xml", FOLLOWX_MODE_USER_DEFINE, extra));
179     EXPECT_TRUE(TestGetCfgFile("custxmltest/both.xml", FOLLOWX_MODE_USER_DEFINE, extra));
180 }
181 } // namespace OHOS
182