From 950ba39eec5941c118a0b5474a18f24a3d0a15fc Mon Sep 17 00:00:00 2001 From: yang123 Date: Mon, 5 Aug 2024 11:39:15 +0000 Subject: [PATCH] add EnumeratorTest unittest Signed-off-by: yang123 --- .../input_adapter/include/input_adapter.h | 48 +++++++++++++++++++ .../input_adapter/src/input_adapter.cpp | 48 ------------------- .../test/unittest/src/input_adapter_test.cpp | 17 +++++++ .../test/src/cooperate_server_test.cpp | 19 ++++++++ .../intentiontest/src/socket_session_test.cpp | 13 +++++ 5 files changed, 97 insertions(+), 48 deletions(-) diff --git a/intention/adapters/input_adapter/include/input_adapter.h b/intention/adapters/input_adapter/include/input_adapter.h index 11c4e4942..c7ab56110 100644 --- a/intention/adapters/input_adapter/include/input_adapter.h +++ b/intention/adapters/input_adapter/include/input_adapter.h @@ -20,6 +20,8 @@ #include "i_input_adapter.h" +#include "i_input_event_consumer.h" +#include "i_input_event_filter.h" namespace OHOS { namespace Msdp { namespace DeviceStatus { @@ -51,6 +53,52 @@ public: int32_t AddVirtualInputDevice(std::shared_ptr device, int32_t &deviceId) override; int32_t RemoveVirtualInputDevice(int32_t deviceId) override; }; + +class PointerFilter : public MMI::IInputEventFilter { +public: + explicit PointerFilter(std::function)> filter) + : filter_(filter) {} + + bool OnInputEvent(std::shared_ptr pointerEvent) const override + { + return (filter_ != nullptr ? filter_(pointerEvent) : false); + } + + bool OnInputEvent(std::shared_ptr keyEvent) const override + { + return false; + } + +private: + std::function)> filter_; +}; + +class InterceptorConsumer : public MMI::IInputEventConsumer { +public: + InterceptorConsumer(std::function)> pointerCb, + std::function)> keyCb) + : pointerCb_(pointerCb), keyCb_(keyCb) {} + + void OnInputEvent(std::shared_ptr keyEvent) const override + { + if (keyCb_ != nullptr) { + keyCb_(keyEvent); + } + } + + void OnInputEvent(std::shared_ptr pointerEvent) const override + { + if (pointerCb_ != nullptr) { + pointerCb_(pointerEvent); + } + } + + void OnInputEvent(std::shared_ptr axisEvent) const override {} + +private: + std::function)> pointerCb_; + std::function)> keyCb_; +}; } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/intention/adapters/input_adapter/src/input_adapter.cpp b/intention/adapters/input_adapter/src/input_adapter.cpp index 57c82a674..d7ba7b220 100644 --- a/intention/adapters/input_adapter/src/input_adapter.cpp +++ b/intention/adapters/input_adapter/src/input_adapter.cpp @@ -16,8 +16,6 @@ #include "input_adapter.h" #include "input_manager.h" -#include "i_input_event_consumer.h" -#include "i_input_event_filter.h" #include "devicestatus_define.h" @@ -28,52 +26,6 @@ namespace OHOS { namespace Msdp { namespace DeviceStatus { -class PointerFilter : public MMI::IInputEventFilter { -public: - explicit PointerFilter(std::function)> filter) - : filter_(filter) {} - - bool OnInputEvent(std::shared_ptr pointerEvent) const override - { - return (filter_ != nullptr ? filter_(pointerEvent) : false); - } - - bool OnInputEvent(std::shared_ptr keyEvent) const override - { - return false; - } - -private: - std::function)> filter_; -}; - -class InterceptorConsumer : public MMI::IInputEventConsumer { -public: - InterceptorConsumer(std::function)> pointerCb, - std::function)> keyCb) - : pointerCb_(pointerCb), keyCb_(keyCb) {} - - void OnInputEvent(std::shared_ptr keyEvent) const override - { - if (keyCb_ != nullptr) { - keyCb_(keyEvent); - } - } - - void OnInputEvent(std::shared_ptr pointerEvent) const override - { - if (pointerCb_ != nullptr) { - pointerCb_(pointerEvent); - } - } - - void OnInputEvent(std::shared_ptr axisEvent) const override {} - -private: - std::function)> pointerCb_; - std::function)> keyCb_; -}; - int32_t InputAdapter::AddMonitor(std::function)> callback) { int32_t monitorId = MMI::InputManager::GetInstance()->AddMonitor(callback); diff --git a/intention/adapters/test/unittest/src/input_adapter_test.cpp b/intention/adapters/test/unittest/src/input_adapter_test.cpp index d567884e8..22f8d7d4a 100644 --- a/intention/adapters/test/unittest/src/input_adapter_test.cpp +++ b/intention/adapters/test/unittest/src/input_adapter_test.cpp @@ -335,6 +335,23 @@ HWTEST_F(InputAdapterTest, TestKeyAddMonitor1, TestSize.Level1) RemovePermission(); } +/** + * @tc.name: TestAddKeyEventInterceptor1 + * @tc.desc: Test AddKeyEventInterceptor1 + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputAdapterTest, AddKeyEventInterceptor1, TestSize.Level1) +{ + CALL_TEST_DEBUG; + SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0])); + std::shared_ptr inputAdapter = std::make_shared(); + int32_t interceptorId = inputAdapter->AddInterceptor(nullptr, nullptr); + ASSERT_EQ(interceptorId, RET_ERR); + inputAdapter->RemoveInterceptor(interceptorId); + RemovePermission(); +} + /** * @tc.name: TestAddKeyEventInterceptor1 * @tc.desc: Test AddKeyEventInterceptor1 diff --git a/intention/cooperate/test/src/cooperate_server_test.cpp b/intention/cooperate/test/src/cooperate_server_test.cpp index aaa8552ac..3de45ed42 100644 --- a/intention/cooperate/test/src/cooperate_server_test.cpp +++ b/intention/cooperate/test/src/cooperate_server_test.cpp @@ -604,6 +604,25 @@ HWTEST_F(CooperateServerTest, ControlTest1, TestSize.Level0) ASSERT_NO_FATAL_FAILURE(cooperateServer_->Control( context, CooperateRequestID::UNKNOWN_COOPERATE_ACTION, data, reply)); } + +/** + * @tc.name: RemovePermissionTest + * @tc.desc: Test func named RemovePermission + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CooperateServerTest, RemovePermissionTest, TestSize.Level0) +{ + CALL_TEST_DEBUG; + RemovePermission(); + CallingContext context { + .intention = intention_, + .tokenId = IPCSkeleton::GetCallingTokenID(), + .uid = IPCSkeleton::GetCallingUid(), + .pid = IPCSkeleton::GetCallingPid(), + }; +cooperateServer_->Disable(context, datas, reply); +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/intentiontest/src/socket_session_test.cpp b/test/unittest/intentiontest/src/socket_session_test.cpp index a0692b64b..b69fb2316 100644 --- a/test/unittest/intentiontest/src/socket_session_test.cpp +++ b/test/unittest/intentiontest/src/socket_session_test.cpp @@ -626,6 +626,19 @@ HWTEST_F(SocketSessionTest, SocketSessionTest31, TestSize.Level0) CALL_TEST_DEBUG; ASSERT_NO_FATAL_FAILURE(g_socketSessionManager->RegisterApplicationState()); } + +/** + * @tc.name: SocketSessionTest32 + * @tc.desc: Drag Drawing + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SocketSessionTest, SocketSessionTest32, TestSize.Level0) +{ + CALL_TEST_DEBUG; + int32_t pid = IPCSkeleton::GetCallingPid(), + ASSERT_NO_FATAL_FAILURE(g_socketSessionManager->ReleaseSessionByPid(pid)); +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS