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 <gtest/gtest.h>
17
18 #include <libxml/globals.h>
19 #include <libxml/xmlstring.h>
20
21 #include "display_manager_config.h"
22 #include "display_manager_config.cpp"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace Rosen {
29 class DisplayManagerConfigTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 virtual void SetUp() override;
34 virtual void TearDown() override;
35 };
36
SetUpTestCase()37 void DisplayManagerConfigTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void DisplayManagerConfigTest::TearDownTestCase()
42 {
43 }
44
SetUp()45 void DisplayManagerConfigTest::SetUp()
46 {
47 }
48
TearDown()49 void DisplayManagerConfigTest::TearDown()
50 {
51 }
52
53 namespace {
54 /**
55 * @tc.name: IsNumber
56 * @tc.desc: test function : IsNumber
57 * @tc.type: FUNC
58 */
59 HWTEST_F(DisplayManagerConfigTest, IsNumber, Function | SmallTest | Level1)
60 {
61 bool result = DisplayManagerConfig::IsNumber("123");
62 ASSERT_EQ(true, result);
63 result = DisplayManagerConfig::IsNumber("a123");
64 ASSERT_EQ(false, result);
65 }
66
67 /**
68 * @tc.name: GetConfigPath
69 * @tc.desc: test function : GetConfigPath
70 * @tc.type: FUNC
71 */
72 HWTEST_F(DisplayManagerConfigTest, GetConfigPath, Function | SmallTest | Level1)
73 {
74 auto result = DisplayManagerConfig::GetConfigPath("");
75 ASSERT_STRNE("/system/", result.c_str());
76
77 result = DisplayManagerConfig::GetConfigPath("a.xml");
78 ASSERT_STREQ("/system/a.xml", result.c_str());
79 }
80
81 /**
82 * @tc.name: ReadEnableConfigInfo
83 * @tc.desc: test function : ReadEnableConfigInfo
84 * @tc.type: FUNC
85 */
86 HWTEST_F(DisplayManagerConfigTest, ReadEnableConfigInfo, Function | SmallTest | Level1)
87 {
88 DisplayManagerConfig::enableConfig_.clear();
89
90 auto configFilePath = DisplayManagerConfig::GetConfigPath("etc/window/resources/display_manager_config.xml");
91 xmlDocPtr docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS);
92 if (docPtr == nullptr) {
93 return;
94 }
95
96 xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
97 if (rootPtr == nullptr || rootPtr->name == nullptr ||
98 xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
99 xmlFreeDoc(docPtr);
100 return;
101 }
102 for (xmlNodePtr curNodePtr = rootPtr->xmlChildrenNode; curNodePtr != nullptr; curNodePtr = curNodePtr->next) {
103 if (!DisplayManagerConfig::IsValidNode(*curNodePtr)) {
104 continue;
105 }
106
107 auto nodeName = curNodePtr->name;
108 if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("isWaterfallDisplay"))) {
109 DisplayManagerConfig::ReadEnableConfigInfo(curNodePtr);
110 continue;
111 }
112
113 if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("dpi"))) {
114 DisplayManagerConfig::ReadEnableConfigInfo(curNodePtr);
115 continue;
116 }
117 }
118
119 DisplayManagerConfig::DumpConfig();
120 xmlFreeDoc(docPtr);
121 }
122
123 /**
124 * @tc.name: ReadStringConfigInfo
125 * @tc.desc: test function : ReadStringConfigInfo
126 * @tc.type: FUNC
127 */
128 HWTEST_F(DisplayManagerConfigTest, ReadStringConfigInfo, Function | SmallTest | Level1)
129 {
130 DisplayManagerConfig::enableConfig_.clear();
131
132 auto configFilePath = DisplayManagerConfig::GetConfigPath("etc/window/resources/display_manager_config.xml");
133 xmlDocPtr docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS);
134 if (docPtr == nullptr) {
135 return;
136 }
137
138 xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
139 if (rootPtr == nullptr || rootPtr->name == nullptr ||
140 xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
141 xmlFreeDoc(docPtr);
142 return;
143 }
144 for (xmlNodePtr curNodePtr = rootPtr->xmlChildrenNode; curNodePtr != nullptr; curNodePtr = curNodePtr->next) {
145 if (!DisplayManagerConfig::IsValidNode(*curNodePtr)) {
146 continue;
147 }
148
149 auto nodeName = curNodePtr->name;
150 if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("defaultDisplayCutoutPath"))) {
151 DisplayManagerConfig::ReadStringConfigInfo(curNodePtr);
152 continue;
153 }
154
155 if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("dpi"))) {
156 DisplayManagerConfig::ReadStringConfigInfo(curNodePtr);
157 continue;
158 }
159 }
160
161 DisplayManagerConfig::DumpConfig();
162 xmlFreeDoc(docPtr);
163 }
164
165 }
166 } // namespace Rosen
167 } // namespace OHOS