• 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 #include "display_dumper.h"
18 #include "display_manager_service.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 class DisplayDumperTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp() override;
30     void TearDown() override;
31 };
32 
SetUpTestCase()33 void DisplayDumperTest::SetUpTestCase()
34 {
35 }
36 
TearDownTestCase()37 void DisplayDumperTest::TearDownTestCase()
38 {
39 }
40 
SetUp()41 void DisplayDumperTest::SetUp()
42 {
43 }
44 
TearDown()45 void DisplayDumperTest::TearDown()
46 {
47 }
48 
49 namespace {
50 /**
51  * @tc.name: Dump01
52  * @tc.desc: Dump
53  * @tc.type: FUNC
54  */
55 HWTEST_F(DisplayDumperTest, Dump01, Function | SmallTest | Level1)
56 {
57     sptr<DisplayDumper> displayDumper;
58     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
59         DisplayManagerService::GetInstance().abstractScreenController_,
60         DisplayManagerService::GetInstance().mutex_);
61     int fd = 1;
62     std::vector<std::u16string> args;
63     DMError ret = displayDumper->Dump(fd, args);
64     ASSERT_EQ(ret, DMError::DM_OK);
65 }
66 
67 /**
68  * @tc.name: Dump02
69  * @tc.desc: Dump fd less 0
70  * @tc.type: FUNC
71  */
72 HWTEST_F(DisplayDumperTest, Dump02, Function | SmallTest | Level1)
73 {
74     sptr<DisplayDumper> displayDumper;
75     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
76         DisplayManagerService::GetInstance().abstractScreenController_,
77         DisplayManagerService::GetInstance().mutex_);
78     int fd = -1;
79     std::vector<std::u16string> args;
80     DMError ret = displayDumper->Dump(fd, args);
81     ASSERT_EQ(ret, DMError::DM_ERROR_INVALID_PARAM);
82 }
83 
84 /**
85  * @tc.name: Dump03
86  * @tc.desc: Dump one param with '-h'
87  * @tc.type: FUNC
88  */
89 HWTEST_F(DisplayDumperTest, Dump03, Function | SmallTest | Level1)
90 {
91     sptr<DisplayDumper> displayDumper;
92     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
93         DisplayManagerService::GetInstance().abstractScreenController_,
94         DisplayManagerService::GetInstance().mutex_);
95     int fd = 3;
96     std::vector<std::u16string> args;
97     const std::u16string DUMP_HELP = u"-h";
98     args.emplace_back(DUMP_HELP);
99     DMError ret = displayDumper->Dump(fd, args);
100     ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
101 }
102 
103 /**
104  * @tc.name: Dump04
105  * @tc.desc: Dump one param with '-x'
106  * @tc.type: FUNC
107  */
108 HWTEST_F(DisplayDumperTest, Dump04, Function | SmallTest | Level1)
109 {
110     sptr<DisplayDumper> displayDumper;
111     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
112         DisplayManagerService::GetInstance().abstractScreenController_,
113         DisplayManagerService::GetInstance().mutex_);
114     int fd = 4;
115     std::vector<std::u16string> args;
116     const std::u16string DUMP_HELP = u"-x";
117     args.emplace_back(DUMP_HELP);
118     DMError ret = displayDumper->Dump(fd, args);
119     ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
120 }
121 
122 /**
123  * @tc.name: Dump05
124  * @tc.desc: Dump two param with '-s -a'
125  * @tc.type: FUNC
126  */
127 HWTEST_F(DisplayDumperTest, Dump05, Function | SmallTest | Level1)
128 {
129     sptr<DisplayDumper> displayDumper;
130     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
131         DisplayManagerService::GetInstance().abstractScreenController_,
132         DisplayManagerService::GetInstance().mutex_);
133     int fd = 5;
134     std::vector<std::u16string> args;
135     const std::u16string DUMP_SCREEN = u"-s";
136     const std::u16string DUMP_ALL = u"-a";
137     args.emplace_back(DUMP_SCREEN);
138     args.emplace_back(DUMP_ALL);
139     DMError ret = displayDumper->Dump(fd, args);
140     ASSERT_EQ(ret, DMError::DM_ERROR_UNKNOWN);
141 }
142 
143 /**
144  * @tc.name: Dump06
145  * @tc.desc: Dump two param with '-d -a'
146  * @tc.type: FUNC
147  */
148 HWTEST_F(DisplayDumperTest, Dump06, Function | SmallTest | Level1)
149 {
150     sptr<DisplayDumper> displayDumper;
151     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
152         DisplayManagerService::GetInstance().abstractScreenController_,
153         DisplayManagerService::GetInstance().mutex_);
154     int fd = 6;
155     std::vector<std::u16string> args;
156     const std::u16string DUMP_DISPLAY = u"-d";
157     const std::u16string DUMP_ALL = u"-a";
158     args.emplace_back(DUMP_DISPLAY);
159     args.emplace_back(DUMP_ALL);
160     DMError ret = displayDumper->Dump(fd, args);
161     ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
162 }
163 
164 /**
165  * @tc.name: Dump07
166  * @tc.desc: Dump two param with '-s 1'
167  * @tc.type: FUNC
168  */
169 HWTEST_F(DisplayDumperTest, Dump071, Function | SmallTest | Level1)
170 {
171     sptr<DisplayDumper> displayDumper;
172     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
173         DisplayManagerService::GetInstance().abstractScreenController_,
174         DisplayManagerService::GetInstance().mutex_);
175     int fd = 71;
176     std::vector<std::u16string> args;
177     const std::u16string DUMP_SCREEN = u"-s";
178     const std::u16string DUMP_NUMBER = u"0";
179     args.emplace_back(DUMP_SCREEN);
180     args.emplace_back(DUMP_NUMBER);
181     DMError ret = displayDumper->Dump(fd, args);
182     ASSERT_EQ(ret, DMError::DM_ERROR_UNKNOWN);
183 }
184 
185 /**
186  * @tc.name: Dump07
187  * @tc.desc: Dump two param with '-s -1'
188  * @tc.type: FUNC
189  */
190 HWTEST_F(DisplayDumperTest, Dump07, Function | SmallTest | Level1)
191 {
192     sptr<DisplayDumper> displayDumper;
193     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
194         DisplayManagerService::GetInstance().abstractScreenController_,
195         DisplayManagerService::GetInstance().mutex_);
196     int fd = 7;
197     std::vector<std::u16string> args;
198     const std::u16string DUMP_SCREEN = u"-s";
199     const std::u16string DUMP_NUMBER = u"-1";
200     args.emplace_back(DUMP_SCREEN);
201     args.emplace_back(DUMP_NUMBER);
202     DMError ret = displayDumper->Dump(fd, args);
203     ASSERT_EQ(ret, DMError::DM_ERROR_UNKNOWN);
204 }
205 
206 /**
207  * @tc.name: Dump08
208  * @tc.desc: Dump two param with '-d 1'
209  * @tc.type: FUNC
210  */
211 HWTEST_F(DisplayDumperTest, Dump08, Function | SmallTest | Level1)
212 {
213     sptr<DisplayDumper> displayDumper;
214     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
215         DisplayManagerService::GetInstance().abstractScreenController_,
216         DisplayManagerService::GetInstance().mutex_);
217     int fd = 8;
218     std::vector<std::u16string> args;
219     const std::u16string DUMP_DISPLAY = u"-d";
220     const std::u16string DUMP_NUMBER = u"1";
221     args.emplace_back(DUMP_DISPLAY);
222     args.emplace_back(DUMP_NUMBER);
223     DMError ret = displayDumper->Dump(fd, args);
224     ASSERT_EQ(ret, DMError::DM_ERROR_UNKNOWN);
225 }
226 
227 /**
228  * @tc.name: Dump09
229  * @tc.desc: Dump two param with '-d -1'
230  * @tc.type: FUNC
231  */
232 HWTEST_F(DisplayDumperTest, Dump09, Function | SmallTest | Level1)
233 {
234     sptr<DisplayDumper> displayDumper;
235     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
236         DisplayManagerService::GetInstance().abstractScreenController_,
237         DisplayManagerService::GetInstance().mutex_);
238     int fd = 9;
239     std::vector<std::u16string> args;
240     const std::u16string DUMP_DISPLAY = u"-d";
241     const std::u16string DUMP_NUMBER = u"-1";
242     args.emplace_back(DUMP_DISPLAY);
243     args.emplace_back(DUMP_NUMBER);
244     DMError ret = displayDumper->Dump(fd, args);
245     ASSERT_EQ(ret, DMError::DM_ERROR_UNKNOWN);
246 }
247 
248 /**
249  * @tc.name: Dump10
250  * @tc.desc: Dump three param with '-d -a 1'
251  * @tc.type: FUNC
252  */
253 HWTEST_F(DisplayDumperTest, Dump10, Function | SmallTest | Level1)
254 {
255     sptr<DisplayDumper> displayDumper;
256     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
257         DisplayManagerService::GetInstance().abstractScreenController_,
258         DisplayManagerService::GetInstance().mutex_);
259     int fd = 10;
260     std::vector<std::u16string> args;
261     const std::u16string DUMP_DISPLAY = u"-d";
262     const std::u16string DUMP_ALL = u"-a";
263     const std::u16string DUMP_NUMBER = u"1";
264     args.emplace_back(DUMP_DISPLAY);
265     args.emplace_back(DUMP_ALL);
266     args.emplace_back(DUMP_NUMBER);
267     DMError ret = displayDumper->Dump(fd, args);
268     ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
269 }
270 
271 /**
272  * @tc.name: IsValidDigitString01
273  * @tc.desc: IsValidDigitString "06w"
274  * @tc.type: FUNC
275  */
276 HWTEST_F(DisplayDumperTest, IsValidDigitString01, Function | SmallTest | Level1)
277 {
278     sptr<DisplayDumper> displayDumper;
279     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
280         DisplayManagerService::GetInstance().abstractScreenController_,
281         DisplayManagerService::GetInstance().mutex_);
282     std::string idStr = "06w";
283     bool ret = displayDumper->IsValidDigitString(idStr);
284     ASSERT_EQ(ret, false);
285 }
286 
287 /**
288  * @tc.name: IsValidDigitString02
289  * @tc.desc: IsValidDigitString "96+"
290  * @tc.type: FUNC
291  */
292 HWTEST_F(DisplayDumperTest, IsValidDigitString02, Function | SmallTest | Level1)
293 {
294     sptr<DisplayDumper> displayDumper;
295     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
296         DisplayManagerService::GetInstance().abstractScreenController_,
297         DisplayManagerService::GetInstance().mutex_);
298     std::string idStr = "96+";
299     bool ret = displayDumper->IsValidDigitString(idStr);
300     ASSERT_EQ(ret, false);
301 }
302 
303 /**
304  * @tc.name: IsValidDigitString03
305  * @tc.desc: IsValidDigitString empty
306  * @tc.type: FUNC
307  */
308 HWTEST_F(DisplayDumperTest, IsValidDigitString03, Function | SmallTest | Level1)
309 {
310     sptr<DisplayDumper> displayDumper;
311     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
312         DisplayManagerService::GetInstance().abstractScreenController_,
313         DisplayManagerService::GetInstance().mutex_);
314     std::string idStr;
315     bool ret = displayDumper->IsValidDigitString(idStr);
316     ASSERT_EQ(ret, false);
317 }
318 
319 /**
320  * @tc.name: DumpAllScreenInfo01
321  * @tc.desc: DumpAllScreenInfo
322  * @tc.type: FUNC
323  */
324 HWTEST_F(DisplayDumperTest, DumpAllScreenInfo01, Function | SmallTest | Level1)
325 {
326     sptr<DisplayDumper> displayDumper;
327     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
328         DisplayManagerService::GetInstance().abstractScreenController_,
329         DisplayManagerService::GetInstance().mutex_);
330     std::string dumpInfo;
331     displayDumper->DumpAllScreenInfo(dumpInfo);
332 }
333 
334 /**
335  * @tc.name: GetDisplayInfo01
336  * @tc.desc: GetDisplayInfo
337  * @tc.type: FUNC
338  */
339 HWTEST_F(DisplayDumperTest, GetDisplayInfo01, Function | SmallTest | Level1)
340 {
341     sptr<DisplayDumper> displayDumper;
342     displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
343         DisplayManagerService::GetInstance().abstractScreenController_,
344         DisplayManagerService::GetInstance().mutex_);
345     std::ostringstream oss;
346     displayDumper->GetDisplayInfo(nullptr, oss);
347 }
348 }
349 }
350 }