• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 "dscreen_hidumper_test.h"
17 #include "dscreen_hidumper.h"
18 
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 namespace DistributedHardware {
23 
DumpScreenData(std::string & result)24 int32_t DscreenHidumper::DumpScreenData(std::string &result)
25 {
26     return DH_SUCCESS;
27 }
28 
ReDumpScreenData(std::string & result)29 int32_t DscreenHidumper::ReDumpScreenData(std::string &result)
30 {
31     return DH_SUCCESS;
32 }
33 
ShowIllegalInfomation(std::string & result)34 int32_t DscreenHidumper::ShowIllegalInfomation(std::string &result)
35 {
36     return DH_SUCCESS;
37 }
38 
SetUpTestCase(void)39 void DScreenHidumperTest::SetUpTestCase(void) {}
40 
TearDownTestCase(void)41 void DScreenHidumperTest::TearDownTestCase(void) {}
42 
SetUp()43 void DScreenHidumperTest::SetUp() {}
44 
TearDown()45 void DScreenHidumperTest::TearDown() {}
46 
47 /**
48  * @tc.name: Dump_001
49  * @tc.desc: Verify the Dump function.
50  * @tc.type: FUNC
51  * @tc.require: Issue Number
52  */
53 HWTEST_F(DScreenHidumperTest, Dump_001, TestSize.Level1)
54 {
55     std::string result;
56     std::string helpStr;
57     std::vector<std::string> argsStr;
58     DscreenHidumper::GetInstance().ShowHelp(helpStr);
59     bool ret = DscreenHidumper::GetInstance().Dump(argsStr, result);
60     EXPECT_EQ(true, ret);
61     EXPECT_EQ(helpStr, result);
62 }
63 
64 /**
65  * @tc.name: Dump_002
66  * @tc.desc: Verify the Dump function.
67  * @tc.type: FUNC
68  * @tc.require: Issue Number
69  */
70 HWTEST_F(DScreenHidumperTest, Dump_002, TestSize.Level1)
71 {
72     std::string result;
73     std::vector<std::string> argsStr = {"arg1", "arg2"};
74     bool ret = DscreenHidumper::GetInstance().Dump(argsStr, result);
75     EXPECT_EQ(true, ret);
76     EXPECT_EQ("unknown command, -h for help.", result);
77 }
78 
79 /**
80  * @tc.name: Dump_003
81  * @tc.desc: Verify the Dump function.
82  * @tc.type: FUNC
83  * @tc.require: Issue Number
84  */
85 HWTEST_F(DScreenHidumperTest, Dump_003, TestSize.Level1)
86 {
87     std::string result;
88     std::string helpStr;
89     std::vector<std::string> argsStr = {"-h"};
90     DscreenHidumper::GetInstance().ShowHelp(helpStr);
91     bool ret = DscreenHidumper::GetInstance().Dump(argsStr, result);
92     EXPECT_EQ(true, ret);
93     EXPECT_EQ(helpStr, result);
94 }
95 
96 /**
97  * @tc.name: ProcessDump_001
98  * @tc.desc: Verify the ProcessDump function with HidumpFlag::DUMP_SCREEN_DATA.
99  * @tc.type: FUNC
100  * @tc.require: Issue Number
101  */
102 HWTEST_F(DScreenHidumperTest, ProcessDump_001, TestSize.Level1)
103 {
104     std::string result;
105     std::string argsStr = "--dump";
106     int32_t ret = DscreenHidumper::GetInstance().ProcessDump(argsStr, result);
107     EXPECT_EQ(DH_SUCCESS, ret);
108 }
109 
110 /**
111  * @tc.name: ProcessDump_002
112  * @tc.desc: Verify the ProcessDump function with HidumpFlag::DUMP_SCREEN_DATA_RESTART.
113  * @tc.type: FUNC
114  * @tc.require: Issue Number
115  */
116 HWTEST_F(DScreenHidumperTest, ProcessDump_002, TestSize.Level1)
117 {
118     std::string result;
119     std::string argsStr = "--redump";
120     int32_t ret = DscreenHidumper::GetInstance().ProcessDump(argsStr, result);
121     EXPECT_EQ(DH_SUCCESS, ret);
122 }
123 
124 /**
125  * @tc.name: ProcessDump_003
126  * @tc.desc: Verify the ProcessDump function with HidumpFlag::DUMP_SCREEN_DATA_STOP.
127  * @tc.type: FUNC
128  * @tc.require: Issue Number
129  */
130 HWTEST_F(DScreenHidumperTest, ProcessDump_003, TestSize.Level1)
131 {
132     std::string result;
133     std::string argsStr = "--stopdump";
134     int32_t ret = DscreenHidumper::GetInstance().ProcessDump(argsStr, result);
135     EXPECT_EQ(DH_SUCCESS, ret);
136 }
137 
138 /**
139  * @tc.name: ProcessDump_004
140  * @tc.desc: Verify the ProcessDump function with an unknown command.
141  * @tc.type: FUNC
142  * @tc.require: Issue Number
143  */
144 HWTEST_F(DScreenHidumperTest, ProcessDump_004, TestSize.Level1)
145 {
146     std::string result;
147     std::string argsStr = "unknown_command";
148     int32_t ret = DscreenHidumper::GetInstance().ProcessDump(argsStr, result);
149     EXPECT_EQ(DH_SUCCESS, ret);
150 }
151 } // namespace DistributedHardware
152 } // namespace OHOS