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 "distributed_input_dfx_test.h"
17
18 #include "system_ability_definition.h"
19
20 #include "dinput_errcode.h"
21 #include "hidumper.h"
22 #include "hisysevent_util.h"
23
24 namespace OHOS {
25 namespace DistributedHardware {
26 namespace DistributedInput {
SetUp()27 void DInputDfxUtilsTest::SetUp()
28 {
29 }
30
TearDown()31 void DInputDfxUtilsTest::TearDown()
32 {
33 }
34
SetUpTestCase()35 void DInputDfxUtilsTest::SetUpTestCase()
36 {
37 }
38
TearDownTestCase()39 void DInputDfxUtilsTest::TearDownTestCase()
40 {
41 }
42
43 HWTEST_F(DInputDfxUtilsTest, HiDump_001, testing::ext::TestSize.Level1)
44 {
45 std::vector<std::string> args;
46 std::string result = "";
47 bool ret = HiDumper::GetInstance().HiDump(args, result);
48 EXPECT_EQ(false, ret);
49 }
50
51 HWTEST_F(DInputDfxUtilsTest, HiDump_002, testing::ext::TestSize.Level1)
52 {
53 std::vector<std::string> args;
54 args.push_back("-h");
55 std::string result = "";
56 bool ret = HiDumper::GetInstance().HiDump(args, result);
57 EXPECT_EQ(true, ret);
58
59 args.clear();
60 args.push_back("-nodeinfo");
61 ret = HiDumper::GetInstance().HiDump(args, result);
62 EXPECT_EQ(true, ret);
63
64 args.clear();
65 args.push_back("-sessioninfo");
66 ret = HiDumper::GetInstance().HiDump(args, result);
67 EXPECT_EQ(true, ret);
68
69 args.clear();
70 args.push_back("args_test");
71 ret = HiDumper::GetInstance().HiDump(args, result);
72 EXPECT_EQ(false, ret);
73 }
74
75 HWTEST_F(DInputDfxUtilsTest, GetAllNodeInfos_001, testing::ext::TestSize.Level1)
76 {
77 std::string devId = "umkyu1b165e1be98151891erbe8r91ev";
78 std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8";
79 std::string nodeName = "DistributedInput_123456";
80 HiDumper::GetInstance().SaveNodeInfo(devId, nodeName, dhId);
81 std::string dhId1 = "dhId1_test";
82 std::string devId1 = "devId1_test";
83 HiDumper::GetInstance().SaveNodeInfo(devId, nodeName, dhId1);
84 EXPECT_EQ(2, HiDumper::GetInstance().nodeInfos_.size());
85
86 std::string result = "";
87 int32_t ret = HiDumper::GetInstance().GetAllNodeInfos(result);
88 EXPECT_EQ(DH_SUCCESS, ret);
89
90 HiDumper::GetInstance().DeleteNodeInfo(devId, dhId1);
91 HiDumper::GetInstance().DeleteNodeInfo(devId1, dhId);
92 HiDumper::GetInstance().DeleteNodeInfo(devId1, dhId1);
93 HiDumper::GetInstance().DeleteNodeInfo(devId, dhId);
94 EXPECT_EQ(0, HiDumper::GetInstance().nodeInfos_.size());
95 std::string status = "status_ok";
96 std::string msg = "msg_test";
97 HisyseventUtil::GetInstance().SysEventWriteBehavior(status, msg);
98 HisyseventUtil::GetInstance().SysEventWriteBehavior(status, devId, msg);
99 HisyseventUtil::GetInstance().SysEventWriteBehavior(status, devId, dhId, msg);
100 }
101
102 HWTEST_F(DInputDfxUtilsTest, GetSessionInfo_001, testing::ext::TestSize.Level1)
103 {
104 std::string remoteDevId = "umkyu1b165e1be98151891erbe8r91ev";
105 std::string remoteDevId1 = "remoteDevId_test";
106 int32_t sessionId = 1;
107 std::string mySessionName = "mySessionName_test";
108 std::string peerSessionName = "peerSessionName_test";
109 SessionStatus sessionStatus = static_cast<SessionStatus>(0x04);
110 std::string result = "";
111 HiDumper::GetInstance().CreateSessionInfo(remoteDevId, sessionId, mySessionName, peerSessionName, sessionStatus);
112 EXPECT_EQ(1, HiDumper::GetInstance().sessionInfos_.size());
113 int32_t ret = HiDumper::GetInstance().GetSessionInfo(result);
114 EXPECT_EQ(DH_SUCCESS, ret);
115
116 sessionStatus = SessionStatus::CLOSED;
117 HiDumper::GetInstance().CreateSessionInfo(remoteDevId, sessionId, mySessionName, peerSessionName, sessionStatus);
118 EXPECT_EQ(1, HiDumper::GetInstance().sessionInfos_.size());
119
120 sessionStatus = SessionStatus::CLOSING;
121 HiDumper::GetInstance().SetSessionStatus(remoteDevId1, sessionStatus);
122 HiDumper::GetInstance().SetSessionStatus(remoteDevId, sessionStatus);
123
124 ret = HiDumper::GetInstance().GetSessionInfo(result);
125 EXPECT_EQ(DH_SUCCESS, ret);
126
127 HiDumper::GetInstance().DeleteSessionInfo(remoteDevId);
128 EXPECT_EQ(0, HiDumper::GetInstance().sessionInfos_.size());
129
130 HiDumper::GetInstance().DeleteSessionInfo(remoteDevId1);
131
132 std::string status = "status_ok";
133 std::string msg = "msg_test";
134 int32_t errorCode = 1;
135 std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8";
136 HisyseventUtil::GetInstance().SysEventWriteFault(status, msg);
137 HisyseventUtil::GetInstance().SysEventWriteFault(status, remoteDevId, errorCode, msg);
138 HisyseventUtil::GetInstance().SysEventWriteFault(status, remoteDevId, dhId, errorCode, msg);
139 }
140 } // namespace DistributedInput
141 } // namespace DistributedHardware
142 } // namespace OHOS