• 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 <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     uint32_t readCount = 0;
103     for (xmlNodePtr curNodePtr = rootPtr->xmlChildrenNode; curNodePtr != nullptr; curNodePtr = curNodePtr->next) {
104         if (!DisplayManagerConfig::IsValidNode(*curNodePtr)) {
105             continue;
106         }
107 
108         auto nodeName = curNodePtr->name;
109         if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("isWaterfallDisplay"))) {
110             DisplayManagerConfig::ReadEnableConfigInfo(curNodePtr);
111             readCount++;
112             continue;
113         }
114 
115         if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("dpi"))) {
116             DisplayManagerConfig::ReadEnableConfigInfo(curNodePtr);
117             readCount++;
118             continue;
119         }
120     }
121 
122     ASSERT_LE(DisplayManagerConfig::enableConfig_.size(), readCount);
123 
124     DisplayManagerConfig::DumpConfig();
125     xmlFreeDoc(docPtr);
126 }
127 
128 /**
129  * @tc.name: ReadStringConfigInfo
130  * @tc.desc: test function : ReadStringConfigInfo
131  * @tc.type: FUNC
132  */
133 HWTEST_F(DisplayManagerConfigTest, ReadStringConfigInfo, Function | SmallTest | Level1)
134 {
135     DisplayManagerConfig::enableConfig_.clear();
136 
137     auto configFilePath = DisplayManagerConfig::GetConfigPath("etc/window/resources/display_manager_config.xml");
138     xmlDocPtr docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS);
139     if (docPtr == nullptr) {
140         return;
141     }
142 
143     xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
144     if (rootPtr == nullptr || rootPtr->name == nullptr ||
145         xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
146         xmlFreeDoc(docPtr);
147         return;
148     }
149     uint32_t readCount = 0;
150     for (xmlNodePtr curNodePtr = rootPtr->xmlChildrenNode; curNodePtr != nullptr; curNodePtr = curNodePtr->next) {
151         if (!DisplayManagerConfig::IsValidNode(*curNodePtr)) {
152             continue;
153         }
154 
155         auto nodeName = curNodePtr->name;
156         if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("defaultDisplayCutoutPath"))) {
157             DisplayManagerConfig::ReadStringConfigInfo(curNodePtr);
158             readCount++;
159             continue;
160         }
161 
162         if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("dpi"))) {
163             DisplayManagerConfig::ReadStringConfigInfo(curNodePtr);
164             readCount++;
165             continue;
166         }
167     }
168 
169     ASSERT_LE(DisplayManagerConfig::stringConfig_.size(), readCount);
170     DisplayManagerConfig::DumpConfig();
171     xmlFreeDoc(docPtr);
172 }
173 
174 }
175 } // namespace Rosen
176 } // namespace OHOS