1/* 2 * Copyright (c) 2022-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 "dinput_context_test.h" 17 18#include "dinput_context.h" 19#include "dinput_errcode.h" 20#include "dinput_utils_tool.h" 21#include "dinput_softbus_define.h" 22 23using namespace testing::ext; 24using namespace OHOS::DistributedHardware::DistributedInput; 25using namespace std; 26 27namespace OHOS { 28namespace DistributedHardware { 29namespace DistributedInput { 30constexpr uint32_t SIZE_AFTER_GET = 1; 31constexpr uint32_t HEIGHT = 1080; 32 33void DInputContextTest::SetUp() 34{ 35} 36 37void DInputContextTest::TearDown() 38{ 39} 40 41void DInputContextTest::SetUpTestCase() 42{ 43} 44 45void DInputContextTest::TearDownTestCase() 46{ 47} 48 49HWTEST_F(DInputContextTest, GetSourceWindId001, testing::ext::TestSize.Level0) 50{ 51 std::string devId = "hello"; 52 uint64_t sourceWinId = 1; 53 std::string ret = DInputContext::GetInstance().GetScreenInfoKey(devId, sourceWinId); 54 EXPECT_EQ("hello###1", ret); 55} 56 57HWTEST_F(DInputContextTest, RemoveSinkScreenInfo001, testing::ext::TestSize.Level0) 58{ 59 std::string sourceWinId = "hello"; 60 int32_t ret = DInputContext::GetInstance().RemoveSinkScreenInfo(sourceWinId); 61 EXPECT_EQ(DH_SUCCESS, ret); 62} 63 64HWTEST_F(DInputContextTest, UpdateSinkScreenInfo001, testing::ext::TestSize.Level0) 65{ 66 std::string sourceWinId = "hello"; 67 SinkScreenInfo sinkScreenInfo; 68 int32_t ret = DInputContext::GetInstance().UpdateSinkScreenInfo(sourceWinId, sinkScreenInfo); 69 EXPECT_EQ(ERR_DH_INPUT_CONTEXT_KEY_NOT_EXIST, ret); 70} 71 72HWTEST_F(DInputContextTest, UpdateSinkScreenInfo002, testing::ext::TestSize.Level0) 73{ 74 std::string sourceWinId = "hello"; 75 SinkScreenInfo sinkScreenInfo = DInputContext::GetInstance().GetSinkScreenInfo(sourceWinId); 76 int32_t ret = DInputContext::GetInstance().UpdateSinkScreenInfo(sourceWinId, sinkScreenInfo); 77 EXPECT_EQ(DH_SUCCESS, ret); 78 DInputContext::GetInstance().RemoveSinkScreenInfo(sourceWinId); 79} 80 81HWTEST_F(DInputContextTest, GetSinkScreenInfo001, testing::ext::TestSize.Level0) 82{ 83 std::string sourceWinId = "hello"; 84 SinkScreenInfo sinkScreenInfo = DInputContext::GetInstance().GetSinkScreenInfo(sourceWinId); 85 EXPECT_EQ(SIZE_AFTER_GET, DInputContext::GetInstance().sinkScreenInfoMap_.size()); 86 DInputContext::GetInstance().RemoveSinkScreenInfo(sourceWinId); 87} 88 89HWTEST_F(DInputContextTest, GetSinkScreenInfo002, testing::ext::TestSize.Level0) 90{ 91 std::string sourceWinId = "hello"; 92 SinkScreenInfo sinkScreenInfo1; 93 sinkScreenInfo1.sinkPhyHeight = HEIGHT; 94 DInputContext::GetInstance().sinkScreenInfoMap_[sourceWinId] = sinkScreenInfo1; 95 SinkScreenInfo sinkScreenInfo = DInputContext::GetInstance().GetSinkScreenInfo(sourceWinId); 96 EXPECT_EQ(HEIGHT, sinkScreenInfo.sinkPhyHeight); 97 DInputContext::GetInstance().RemoveSinkScreenInfo(sourceWinId); 98} 99 100HWTEST_F(DInputContextTest, RemoveSrcScreenInfo001, testing::ext::TestSize.Level0) 101{ 102 std::string sourceWinId = "hello"; 103 int32_t ret = DInputContext::GetInstance().RemoveSrcScreenInfo(sourceWinId); 104 EXPECT_EQ(DH_SUCCESS, ret); 105} 106 107HWTEST_F(DInputContextTest, UpdateSrcScreenInfo001, testing::ext::TestSize.Level0) 108{ 109 std::string sourceWinId = "hello"; 110 SrcScreenInfo srcScreenInfo; 111 int32_t ret = DInputContext::GetInstance().UpdateSrcScreenInfo(sourceWinId, srcScreenInfo); 112 EXPECT_EQ(ERR_DH_INPUT_CONTEXT_KEY_NOT_EXIST, ret); 113} 114 115HWTEST_F(DInputContextTest, UpdateSrcScreenInfo002, testing::ext::TestSize.Level0) 116{ 117 std::string sourceWinId = "hello"; 118 SrcScreenInfo srcScreenInfo = DInputContext::GetInstance().GetSrcScreenInfo(sourceWinId); 119 int32_t ret = DInputContext::GetInstance().UpdateSrcScreenInfo(sourceWinId, srcScreenInfo); 120 EXPECT_EQ(DH_SUCCESS, ret); 121 DInputContext::GetInstance().RemoveSrcScreenInfo(sourceWinId); 122} 123 124HWTEST_F(DInputContextTest, GetSrcScreenInfo001, testing::ext::TestSize.Level0) 125{ 126 std::string sourceWinId = "hello"; 127 SrcScreenInfo srcScreenInfo = DInputContext::GetInstance().GetSrcScreenInfo(sourceWinId); 128 EXPECT_EQ(SIZE_AFTER_GET, DInputContext::GetInstance().srcScreenInfoMap_.size()); 129 DInputContext::GetInstance().RemoveSrcScreenInfo(sourceWinId); 130} 131 132HWTEST_F(DInputContextTest, GetSrcScreenInfo002, testing::ext::TestSize.Level0) 133{ 134 std::string sourceWinId = "hello"; 135 SrcScreenInfo srcScreenInfo1; 136 srcScreenInfo1.sourcePhyHeight = HEIGHT; 137 DInputContext::GetInstance().srcScreenInfoMap_[sourceWinId] = srcScreenInfo1; 138 SrcScreenInfo srcScreenInfo = DInputContext::GetInstance().GetSrcScreenInfo(sourceWinId); 139 EXPECT_EQ(HEIGHT, srcScreenInfo.sourcePhyHeight); 140 DInputContext::GetInstance().RemoveSrcScreenInfo(sourceWinId); 141} 142 143HWTEST_F(DInputContextTest, SetGetLocalTouchScreenInfo001, testing::ext::TestSize.Level0) 144{ 145 LocalTouchScreenInfo localTouchScreenInfo; 146 localTouchScreenInfo.sinkShowWidth = HEIGHT; 147 DInputContext::GetInstance().SetLocalTouchScreenInfo(localTouchScreenInfo); 148 EXPECT_EQ(HEIGHT, DInputContext::GetInstance().GetLocalTouchScreenInfo().sinkShowWidth); 149} 150 151HWTEST_F(DInputContextTest, CalculateTransformInfo001, testing::ext::TestSize.Level0) 152{ 153 SinkScreenInfo sinkScreenInfo; 154 int32_t ret = DInputContext::GetInstance().CalculateTransformInfo(sinkScreenInfo); 155 EXPECT_EQ(ERR_DH_INPUT_CONTEXT_CALCULATE_FAIL, ret); 156} 157 158HWTEST_F(DInputContextTest, CalculateTransformInfo002, testing::ext::TestSize.Level0) 159{ 160 SinkScreenInfo sinkScreenInfo; 161 sinkScreenInfo.sinkPhyHeight = 1080; 162 sinkScreenInfo.sinkPhyWidth = 960; 163 sinkScreenInfo.sinkShowHeight = 1080; 164 sinkScreenInfo.sinkShowWidth = 960; 165 int32_t ret = DInputContext::GetInstance().CalculateTransformInfo(sinkScreenInfo); 166 EXPECT_EQ(ERR_DH_INPUT_CONTEXT_CALCULATE_FAIL, ret); 167} 168 169HWTEST_F(DInputContextTest, CalculateTransformInfo003, testing::ext::TestSize.Level0) 170{ 171 SinkScreenInfo sinkScreenInfo; 172 sinkScreenInfo.sinkPhyHeight = 1080; 173 sinkScreenInfo.sinkPhyWidth = 960; 174 sinkScreenInfo.sinkShowHeight = 1080; 175 sinkScreenInfo.sinkShowWidth = 960; 176 sinkScreenInfo.sinkProjShowHeight = 640; 177 sinkScreenInfo.sinkProjShowWidth = 480; 178 int32_t ret = DInputContext::GetInstance().CalculateTransformInfo(sinkScreenInfo); 179 EXPECT_EQ(DH_SUCCESS, ret); 180} 181 182HWTEST_F(DInputContextTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Level1) 183{ 184 DevInfo devInfo = GetLocalDeviceInfo(); 185 EXPECT_NE(0, devInfo.networkId.size()); 186} 187 188HWTEST_F(DInputContextTest, GetLocalNetworkId_001, testing::ext::TestSize.Level1) 189{ 190 std::string ret = GetLocalNetworkId(); 191 EXPECT_NE(0, ret.size()); 192} 193 194HWTEST_F(DInputContextTest, GetUUIDBySoftBus_001, testing::ext::TestSize.Level1) 195{ 196 std::string networkId = ""; 197 std::string ret = GetUUIDBySoftBus(networkId); 198 EXPECT_EQ(0, ret.size()); 199 200 networkId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; 201 ret = GetUUIDBySoftBus(networkId); 202 EXPECT_EQ(0, ret.size()); 203} 204 205HWTEST_F(DInputContextTest, GetCurrentTime_001, testing::ext::TestSize.Level1) 206{ 207 uint64_t ret = GetCurrentTimeUs(); 208 EXPECT_NE(0, ret); 209} 210 211HWTEST_F(DInputContextTest, SetAnonyId_001, testing::ext::TestSize.Level1) 212{ 213 std::string message = ""; 214 std::string ret = SetAnonyId(message); 215 EXPECT_EQ(0, ret.size()); 216} 217 218HWTEST_F(DInputContextTest, SetAnonyId_002, testing::ext::TestSize.Level1) 219{ 220 nlohmann::json jsonObj; 221 std::string deviceId = "deviceId_test"; 222 std::string inputData = "inputData_data"; 223 std::string vecDhId = "dhId_123.dhId_456.dhId_789"; 224 std::string srcDevId = "srcDevId_test"; 225 std::string sinkDevId = "sinkDevId_test"; 226 jsonObj[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; 227 jsonObj[DINPUT_SOFTBUS_KEY_INPUT_DATA] = inputData; 228 jsonObj[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = vecDhId; 229 jsonObj[DINPUT_SOFTBUS_KEY_SRC_DEV_ID] = srcDevId; 230 jsonObj[DINPUT_SOFTBUS_KEY_SINK_DEV_ID] = sinkDevId; 231 std::string ret = SetAnonyId(jsonObj.dump()); 232 EXPECT_NE(0, ret.size()); 233} 234 235HWTEST_F(DInputContextTest, GetNodeDesc_001, testing::ext::TestSize.Level1) 236{ 237 std::string parameters = ""; 238 std::string ret = GetNodeDesc(parameters); 239 EXPECT_EQ(0, ret.size()); 240} 241 242HWTEST_F(DInputContextTest, JointDhIds_001, testing::ext::TestSize.Level1) 243{ 244 std::vector<std::string> dhids; 245 std::string ret = JointDhIds(dhids); 246 EXPECT_EQ("", ret); 247} 248 249} // namespace DistributedInput 250} // namespace DistributedHardware 251} // namespace OHOS 252