From 11c31591a2431935bacf21642f99abc293e3d559 Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Wed, 10 Apr 2024 17:40:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- common/include/input_hub.cpp | 5 ++--- common/include/test/whitelistunittest/white_list_test.h | 6 +++--- common/test/mock/socket_mock.cpp | 4 +++- .../test/unittest/distributed_input_inner_test.h | 6 +++--- interfaces/ipc/src/distributed_input_sink_stub.cpp | 2 +- .../distributed_input_collector_test.h | 6 +++--- .../distributed_input_sinkmanager_test.h | 6 +++--- .../test/sinkmanagerunittest/mock/mock_process.cpp | 6 +++--- .../transport/src/distributed_input_sink_transport.cpp | 8 +++++++- .../sinktransunittest/distributed_input_sinktrans_test.h | 6 +++--- .../distributed_input_sourceinject_test.h | 4 ++-- .../distributed_input_sourcemanager_test.h | 6 +++--- .../distributed_input_sourcetrans_test.h | 6 +++--- .../test/unittest/distributed_input_sinkhandler_test.h | 6 +++--- .../test/unittest/distributed_input_sourcehandler_test.h | 6 +++--- utils/test/unittest/dinput_context_test.h | 6 +++--- 16 files changed, 48 insertions(+), 41 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index f6190e4..8a4a287 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -42,6 +42,7 @@ namespace DistributedInput { namespace { const uint32_t SLEEP_TIME_US = 100 * 1000; const std::string MOUSE_NODE_KEY = "mouse"; +const int32_t SPACE_LENGTH = 1024; } InputHub::InputHub(bool isPluginMonitor) : epollFd_(-1), iNotifyFd_(-1), inputWd_(-1), @@ -915,9 +916,7 @@ int32_t InputHub::QueryLocalTouchScreenInfo(int fd, std::unique_ptr &dev std::string InputHub::StringPrintf(const char *format, ...) const { - static const int kSpaceLength = 1024; - char space[kSpaceLength]; - + char space[SPACE_LENGTH] = {0}; va_list ap; va_start(ap, format); std::string result; diff --git a/common/include/test/whitelistunittest/white_list_test.h b/common/include/test/whitelistunittest/white_list_test.h index 029aaed..eca804d 100644 --- a/common/include/test/whitelistunittest/white_list_test.h +++ b/common/include/test/whitelistunittest/white_list_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,8 +25,8 @@ class WhiteListTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; + void SetUp() override; + void TearDown() override; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/common/test/mock/socket_mock.cpp b/common/test/mock/socket_mock.cpp index 31dac24..ba4a271 100644 --- a/common/test/mock/socket_mock.cpp +++ b/common/test/mock/socket_mock.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,6 +15,7 @@ #include "socket.h" +namespace { int32_t Socket(SocketInfo info) { (void)info; @@ -85,4 +86,5 @@ int32_t EvaluateQos(const char *peerNetworkId, TransDataType dataType, const Qos (void)qos; (void)qosCount; return 0; +} } \ No newline at end of file diff --git a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h index 2060897..f23ce61 100644 --- a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h +++ b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -46,8 +46,8 @@ class DistributedInputInnerTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; + void SetUp() override; + void TearDown() override; int CheckSourceProxy() const; int CheckSinkProxy() const; diff --git a/interfaces/ipc/src/distributed_input_sink_stub.cpp b/interfaces/ipc/src/distributed_input_sink_stub.cpp index dfc0694..32789b5 100644 --- a/interfaces/ipc/src/distributed_input_sink_stub.cpp +++ b/interfaces/ipc/src/distributed_input_sink_stub.cpp @@ -123,8 +123,8 @@ int32_t DistributedInputSinkStub::NotifyStartDScreenInner(MessageParcel &data, M GetAnonyString(sourcePhyId).c_str(), sourcePhyFd, sourcePhyWidth, sourcePhyHeight); SrcScreenInfo srcScreenInfo = { .devId = devId, - .sessionId = sessionId, .uuid = uuid, + .sessionId = sessionId, .sourceWinId = sourceWinId, .sourceWinWidth = sourceWinWidth, .sourceWinHeight = sourceWinHeight, diff --git a/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.h b/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.h index e48f879..fabfe58 100644 --- a/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.h +++ b/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -30,8 +30,8 @@ class DistributedInputCollectorTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; + void SetUp() override; + void TearDown() override; class DInputSinkCollectorEventHandler : public AppExecFwk::EventHandler { public: diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.h b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.h index 4abf048..b730a3c 100644 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.h +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -36,8 +36,8 @@ class DistributedInputSinkManagerTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; + void SetUp() override; + void TearDown() override; class TestGetSinkScreenInfosCb : public OHOS::DistributedHardware::DistributedInput::GetSinkScreenInfosCallbackStub { diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/mock/mock_process.cpp b/services/sink/sinkmanager/test/sinkmanagerunittest/mock/mock_process.cpp index 05c4750..e5796b3 100644 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/mock/mock_process.cpp +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/mock/mock_process.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,7 +23,7 @@ namespace DistributedHardware { namespace DistributedInput { void MockProcess::MockDinputProcess(const char* processName) { - static const char *PERMS[] = { + static const char *perms[] = { "ohos.permission.DISTRIBUTED_DATASYNC" }; uint64_t tokenId; @@ -32,7 +32,7 @@ void MockProcess::MockDinputProcess(const char* processName) .permsNum = 1, .aclsNum = 0, .dcaps = nullptr, - .perms = PERMS, + .perms = perms, .acls = nullptr, .processName = processName, .aplStr = "system_core", diff --git a/services/sink/transport/src/distributed_input_sink_transport.cpp b/services/sink/transport/src/distributed_input_sink_transport.cpp index f1f2dfd..b755822 100644 --- a/services/sink/transport/src/distributed_input_sink_transport.cpp +++ b/services/sink/transport/src/distributed_input_sink_transport.cpp @@ -253,7 +253,7 @@ void DistributedInputSinkTransport::SendKeyStateNodeMsgBatch(const int32_t sessi void DistributedInputSinkTransport::DoSendMsgBatch(const int32_t sessionId, const std::vector &events) { - int64_t currentTimeNs = GetCurrentTimeUs() * 1000LL; + int64_t currentTimeNs = static_cast(GetCurrentTimeUs()) * 1000LL; std::shared_ptr eventsJsonArr = std::make_shared(); for (const auto &ev : events) { nlohmann::json tmpJson; @@ -582,6 +582,12 @@ void DistributedInputSinkTransport::DInputSinkEventHandler::RecordEventLog( { for (nlohmann::json::const_iterator iter = events->cbegin(); iter != events->cend(); ++iter) { nlohmann::json event = *iter; + if (!IsInt32(event, INPUT_KEY_TYPE) || !IsInt64(event, INPUT_KEY_WHEN) || + !IsUInt32(event, INPUT_KEY_CODE) || !IsInt32(event, INPUT_KEY_VALUE) || + !IsString(event, INPUT_KEY_PATH)) { + DHLOGE("The key is invaild."); + continue; + } std::string eventType = ""; int32_t evType = event[INPUT_KEY_TYPE]; switch (evType) { diff --git a/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.h b/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.h index 46d44bc..4571221 100644 --- a/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.h +++ b/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -33,8 +33,8 @@ class DistributedInputSinkTransTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; + void SetUp() override; + void TearDown() override; private: nlohmann::json jsonStr_; nlohmann::json jsonStr1_; diff --git a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.h b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.h index c97fab4..3f59f4a 100644 --- a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.h +++ b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.h @@ -36,8 +36,8 @@ class DistributedInputSourceInjectTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; + void SetUp() override; + void TearDown() override; class TestInputNodeListener : public OHOS::DistributedHardware::DistributedInput::InputNodeListenerStub { public: TestInputNodeListener() = default; diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h index c47d5e0..d1001d3 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -48,8 +48,8 @@ class DistributedInputSourceManagerTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; + void SetUp() override; + void TearDown() override; class TestPrepareDInputCallback : public OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub { diff --git a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.h b/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.h index 7b44288..eaa0fa2 100644 --- a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.h +++ b/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -33,8 +33,8 @@ class DistributedInputSourceTransTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; + void SetUp() override; + void TearDown() override; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/sinkhandler/test/unittest/distributed_input_sinkhandler_test.h b/sinkhandler/test/unittest/distributed_input_sinkhandler_test.h index 0a3577b..c69afe2 100644 --- a/sinkhandler/test/unittest/distributed_input_sinkhandler_test.h +++ b/sinkhandler/test/unittest/distributed_input_sinkhandler_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -35,8 +35,8 @@ class DistributedInputSinkHandlerTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; + void SetUp() override; + void TearDown() override; int32_t CheckSystemAbility(); }; } // namespace DistributedInput diff --git a/sourcehandler/test/unittest/distributed_input_sourcehandler_test.h b/sourcehandler/test/unittest/distributed_input_sourcehandler_test.h index 9060f83..105e0b6 100644 --- a/sourcehandler/test/unittest/distributed_input_sourcehandler_test.h +++ b/sourcehandler/test/unittest/distributed_input_sourcehandler_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -40,8 +40,8 @@ class DistributedInputSourceHandlerTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; + void SetUp() override; + void TearDown() override; int32_t CheckSystemAbility(); class TestRegisterDInputCallback : public OHOS::DistributedHardware::RegisterCallback { diff --git a/utils/test/unittest/dinput_context_test.h b/utils/test/unittest/dinput_context_test.h index 0a471de..d8d5370 100644 --- a/utils/test/unittest/dinput_context_test.h +++ b/utils/test/unittest/dinput_context_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,8 +25,8 @@ class DInputContextTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; + void SetUp() override; + void TearDown() override; }; } // namespace DistributedInput } // namespace DistributedHardware -- Gitee