diff --git a/sa_profile/4809.xml b/sa_profile/4809.xml
new file mode 100644
index 0000000..228a233
--- /dev/null
+++ b/sa_profile/4809.xml
@@ -0,0 +1,27 @@
+
+
+
+ dhardware
+
+ 4809
+ libdinput_source.z.so
+
+
+ true
+ true
+ 1
+
+
diff --git a/sa_profile/4810.xml b/sa_profile/4810.xml
new file mode 100644
index 0000000..7c62437
--- /dev/null
+++ b/sa_profile/4810.xml
@@ -0,0 +1,27 @@
+
+
+
+ dhardware
+
+ 4810
+ libdinput_sink.z.so
+
+
+ true
+ true
+ 1
+
+
diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn
new file mode 100644
index 0000000..1e6afb7
--- /dev/null
+++ b/sa_profile/BUILD.gn
@@ -0,0 +1,32 @@
+# Copyright (c) 2021 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+import("//drivers/adapter/uhdf2/uhdf.gni")
+import("//build/ohos/sa_profile/sa_profile.gni")
+
+ohos_sa_profile("distributed_input_source_sa_profile") {
+ sources = [
+ "4809.xml"
+ ]
+
+ part_name = "distributed_input"
+}
+
+ohos_sa_profile("distributed_input_sink_sa_profile") {
+ sources = [
+ "4810.xml"
+ ]
+
+ part_name = "distributed_input"
+}
\ No newline at end of file
diff --git a/test/BUILD.gn b/test/BUILD.gn
new file mode 100644
index 0000000..ea28b2a
--- /dev/null
+++ b/test/BUILD.gn
@@ -0,0 +1,21 @@
+# Copyright (c) 2021 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+group("test") {
+ testonly = true
+
+ deps = [
+ "system:system",
+ "fuzztest:fuzztest",
+ ]
+}
diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn
new file mode 100644
index 0000000..d42a052
--- /dev/null
+++ b/test/fuzztest/BUILD.gn
@@ -0,0 +1,23 @@
+# Copyright (c) 2022 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+group("fuzztest") {
+ testonly = true
+
+ deps = [
+ "distributedinputkit_fuzzer:fuzztest",
+ "distributedinputclient_fuzzer:fuzztest",
+ "distributedinputsinktransport_fuzzer:fuzztest",
+ "distributedinputsourcetransport_fuzzer:fuzztest",
+ ]
+}
diff --git a/test/fuzztest/distributedinputclient_fuzzer/BUILD.gn b/test/fuzztest/distributedinputclient_fuzzer/BUILD.gn
new file mode 100644
index 0000000..370f939
--- /dev/null
+++ b/test/fuzztest/distributedinputclient_fuzzer/BUILD.gn
@@ -0,0 +1,95 @@
+# Copyright (c) 2021 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#####################hydra-fuzz###################
+import("//build/config/features.gni")
+import("//build/test.gni")
+import("//foundation/distributedhardware/distributedinput/distributedinput.gni")
+
+##############################fuzztest##########################################
+ohos_fuzztest("DistributedInputClientFuzzTest") {
+ module_out_path = "distributedinput_stander/system"
+ # fuzz_config_file = "//foundation/distributedhardware/distributedinput/test/fuzztest/distributedinputclient_fuzzer"
+
+ include_dirs = [
+ "include",
+ "${distributedinput_path}/interfaces/inner_kits/include",
+ "${distributedinput_path}/interfaces/ipc/include",
+ "${distributedinput_path}/services/source/sourcemanager/include",
+ "${distributedinput_path}/services/sink/sinkmanager/include",
+ "${distributedinput_path}/frameworks/include",
+ "${distributedinput_path}/sourcehandler/include",
+ "${distributedinput_path}/sinkhandler/include",
+ "${distributedinput_path}/inputdevicehandler/include",
+ "//foundation/distributedhardware/distributedhardwarefwk/common/utils/include",
+ "//utils/native/base/include",
+ "//utils/system/safwk/native/include",
+ "${service_common}/include",
+ "${common_path}/include",
+ "//third_party/json/include",
+ "//foundation/distributedhardware/distributedhardwarefwk/common/log/include",
+ "//foundation/distributedhardware/distributedhardwarefwk/common/utils/include",
+ "//foundation/distributedhardware/distributedhardwarefwk/utils/include/log",
+ "//foundation/distributedhardware/distributedhardwarefwk/utils/include",
+ ]
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+
+ sources = [
+ "distributed_input_client_fuzzer.cpp",
+ ]
+
+ deps = [
+ "${distributedinput_path}/interfaces/inner_kits:libdinput_sdk",
+ "${distributedinput_path}/services/source/sourcemanager:libdinput_source",
+ "${distributedinput_path}/services/source/inputinject:libdinput_inject",
+ "${distributedinput_path}/services/source/transport:libdinput_source_trans",
+ "${distributedinput_path}/services/sink/sinkmanager:libdinput_sink",
+ "${distributedinput_path}/services/sink/inputcollector:libdinput_collector",
+ "${distributedinput_path}/services/sink/transport:libdinput_sink_trans",
+ "${distributedinput_path}/sourcehandler:libdinput_source_handler",
+ "${distributedinput_path}/sinkhandler:libdinput_sink_handler",
+ "${distributedinput_path}/inputdevicehandler:libdinput_handler",
+ "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
+ "//utils/native/base:utils",
+ ]
+
+ external_deps = [
+ "dsoftbus_standard:softbus_client",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "hiviewdfx_hilog_native:libhilog",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ defines = [
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"DistributedInputClientFuzzTest\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+
+}
+###############################################################################
+group("fuzztest") {
+ testonly = true
+
+ deps = [
+ ":DistributedInputClientFuzzTest",
+ ]
+}
+###############################################################################
diff --git a/test/fuzztest/distributedinputclient_fuzzer/corpus/init b/test/fuzztest/distributedinputclient_fuzzer/corpus/init
new file mode 100644
index 0000000..6b7212c
--- /dev/null
+++ b/test/fuzztest/distributedinputclient_fuzzer/corpus/init
@@ -0,0 +1 @@
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/distributedinputclient_fuzzer/distributed_input_client_fuzzer.cpp b/test/fuzztest/distributedinputclient_fuzzer/distributed_input_client_fuzzer.cpp
new file mode 100644
index 0000000..ae16099
--- /dev/null
+++ b/test/fuzztest/distributedinputclient_fuzzer/distributed_input_client_fuzzer.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "distributed_input_client_fuzzer.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "constants_dinput.h"
+#include "distributed_input_handler.h"
+#include "distributed_input_kit.h"
+#include "distributed_input_sink_handler.h"
+#include "distributed_input_source_handler.h"
+#include "i_distributed_sink_input.h"
+#include "i_distributed_source_input.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class TestRegisterInputCallback : public OHOS::DistributedHardware::RegisterCallback {
+ public:
+ TestRegisterInputCallback() = default;
+ virtual ~TestRegisterInputCallback() = default;
+ virtual int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status,
+ const std::string &data) override {
+ return 0;
+ }
+ };
+
+class TestUnregisterInputCallback : public OHOS::DistributedHardware::UnregisterCallback {
+public:
+ TestUnregisterInputCallback() = default;
+ virtual ~TestUnregisterInputCallback() = default;
+ virtual int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status,
+ const std::string &data) override {
+ return 0;
+ }
+};
+
+void RegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ std::string rDevId(reinterpret_cast(data), size);
+ std::string rDhId(reinterpret_cast(data), size);
+ std::string version(reinterpret_cast(data), size);
+ std::string attrs(reinterpret_cast(data), size);
+ EnableParam enableParam;
+ enableParam.version = version;
+ enableParam.attrs = attrs;
+
+ std::shared_ptr registerCb = std::make_shared();
+ std::shared_ptr unregisterCb = std::make_shared();
+
+ int32_t ret = DistributedInput::DistributedInputSourceHandler::GetInstance().RegisterDistributedHardware(
+ rDevId, rDhId, enableParam, registerCb);
+ ret = DistributedInput::DistributedInputSourceHandler::GetInstance().UnregisterDistributedHardware(
+ rDevId, rDhId, unregisterCb);
+}
+}
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::DistributedHardware::RegisterDistributedHardwareFuzzTest(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/distributedinputclient_fuzzer/distributed_input_client_fuzzer.h b/test/fuzztest/distributedinputclient_fuzzer/distributed_input_client_fuzzer.h
new file mode 100644
index 0000000..15b6c70
--- /dev/null
+++ b/test/fuzztest/distributedinputclient_fuzzer/distributed_input_client_fuzzer.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef DISTRIBUTED_INPUT_CLIENT_FUZZER_H
+#define DISTRIBUTED_INPUT_CLIENT_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "distributedinputclient_fuzzer"
+
+#endif // DISTRIBUTED_INPUT_CLIENT_FUZZER_H
+
diff --git a/test/fuzztest/distributedinputclient_fuzzer/project.xml b/test/fuzztest/distributedinputclient_fuzzer/project.xml
new file mode 100644
index 0000000..85e7ef2
--- /dev/null
+++ b/test/fuzztest/distributedinputclient_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/distributedinputkit_fuzzer/BUILD.gn b/test/fuzztest/distributedinputkit_fuzzer/BUILD.gn
new file mode 100644
index 0000000..1028c1d
--- /dev/null
+++ b/test/fuzztest/distributedinputkit_fuzzer/BUILD.gn
@@ -0,0 +1,95 @@
+# Copyright (c) 2021 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#####################hydra-fuzz###################
+import("//build/config/features.gni")
+import("//build/test.gni")
+import("//foundation/distributedhardware/distributedinput/distributedinput.gni")
+
+##############################fuzztest##########################################
+ohos_fuzztest("DistributedInputKitFuzzTest") {
+ module_out_path = "distributedinput_stander/system"
+ # fuzz_config_file = "//foundation/distributedhardware/distributedinput/test/fuzztest/distributedinputkit_fuzzer"
+
+ include_dirs = [
+ "include",
+ "${distributedinput_path}/interfaces/inner_kits/include",
+ "${distributedinput_path}/interfaces/ipc/include",
+ "${distributedinput_path}/services/source/sourcemanager/include",
+ "${distributedinput_path}/services/sink/sinkmanager/include",
+ "${distributedinput_path}/frameworks/include",
+ "${distributedinput_path}/sourcehandler/include",
+ "${distributedinput_path}/sinkhandler/include",
+ "${distributedinput_path}/inputdevicehandler/include",
+ "//foundation/distributedhardware/distributedhardwarefwk/common/utils/include",
+ "//utils/native/base/include",
+ "//utils/system/safwk/native/include",
+ "${service_common}/include",
+ "${common_path}/include",
+ "//third_party/json/include",
+ "//foundation/distributedhardware/distributedhardwarefwk/common/log/include",
+ "//foundation/distributedhardware/distributedhardwarefwk/common/utils/include",
+ "//foundation/distributedhardware/distributedhardwarefwk/utils/include/log",
+ "//foundation/distributedhardware/distributedhardwarefwk/utils/include",
+ ]
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+
+ sources = [
+ "distributed_input_kit_fuzzer.cpp",
+ ]
+
+ deps = [
+ "${distributedinput_path}/interfaces/inner_kits:libdinput_sdk",
+ "${distributedinput_path}/services/source/sourcemanager:libdinput_source",
+ "${distributedinput_path}/services/source/inputinject:libdinput_inject",
+ "${distributedinput_path}/services/source/transport:libdinput_source_trans",
+ "${distributedinput_path}/services/sink/sinkmanager:libdinput_sink",
+ "${distributedinput_path}/services/sink/inputcollector:libdinput_collector",
+ "${distributedinput_path}/services/sink/transport:libdinput_sink_trans",
+ "${distributedinput_path}/sourcehandler:libdinput_source_handler",
+ "${distributedinput_path}/sinkhandler:libdinput_sink_handler",
+ "${distributedinput_path}/inputdevicehandler:libdinput_handler",
+ "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
+ "//utils/native/base:utils",
+ ]
+
+ external_deps = [
+ "dsoftbus_standard:softbus_client",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "hiviewdfx_hilog_native:libhilog",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ defines = [
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"DistributedInputKitFuzzTest\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+
+}
+###############################################################################
+group("fuzztest") {
+ testonly = true
+
+ deps = [
+ ":DistributedInputKitFuzzTest",
+ ]
+}
+###############################################################################
diff --git a/test/fuzztest/distributedinputkit_fuzzer/corpus/init b/test/fuzztest/distributedinputkit_fuzzer/corpus/init
new file mode 100644
index 0000000..6b7212c
--- /dev/null
+++ b/test/fuzztest/distributedinputkit_fuzzer/corpus/init
@@ -0,0 +1 @@
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp
new file mode 100644
index 0000000..a0e3f13
--- /dev/null
+++ b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "distributed_input_kit_fuzzer.h"
+
+#include
+#include
+
+#include "i_distributed_sink_input.h"
+#include "i_distributed_source_input.h"
+#include "distributed_input_kit.h"
+#include "distributed_input_sink_handler.h"
+#include "distributed_input_source_handler.h"
+#include "distributed_input_handler.h"
+
+#include "prepare_d_input_call_back_stub.h"
+#include "unprepare_d_input_call_back_stub.h"
+#include "start_d_input_call_back_stub.h"
+#include "stop_d_input_call_back_stub.h"
+
+#include "constants_dinput.h"
+
+#include
+#include
+#include
+#include
+
+namespace OHOS {
+namespace DistributedHardware {
+class TestPrepareDInputCallback :
+public OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub {
+public:
+ TestPrepareDInputCallback() = default;
+ virtual ~TestPrepareDInputCallback() = default;
+ void OnResult(const std::string& deviceId, const int32_t& status) {};
+};
+
+class TestUnprepareDInputCallback :
+public OHOS::DistributedHardware::DistributedInput::UnprepareDInputCallbackStub {
+public:
+ TestUnprepareDInputCallback() = default;
+ virtual ~TestUnprepareDInputCallback() = default;
+ void OnResult(const std::string& deviceId, const int32_t& status) {};
+};
+
+class TestStartDInputCallback :
+public OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub {
+public:
+ void OnResult(const std::string& devId, const uint32_t& inputTypes, const int32_t& status) {};
+};
+
+class TestStopDInputCallback :
+public OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub {
+public:
+ TestStopDInputCallback() = default;
+ virtual ~TestStopDInputCallback() = default;
+ void OnResult(const std::string& devId, const uint32_t& inputTypes, const int32_t& status) {};
+};
+
+void PrepareInputFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ std::string networkId(reinterpret_cast(data), size);
+
+ OHOS::sptr prepareCb = new(std::nothrow) TestPrepareDInputCallback();
+ OHOS::sptr unprepareCb = new(std::nothrow) TestUnprepareDInputCallback();
+ DistributedInput::DistributedInputKit::PrepareRemoteInput(networkId, prepareCb);
+ DistributedInput::DistributedInputKit::UnprepareRemoteInput(networkId, unprepareCb);
+}
+
+void StartRemoteInputFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ std::string dhId(reinterpret_cast(data), size);
+ uint32_t inputTypes = *(reinterpret_cast(data));
+
+ OHOS::sptr startCb = new(std::nothrow) TestStartDInputCallback();
+ OHOS::sptr stopCb = new(std::nothrow) TestStopDInputCallback();
+ DistributedInput::DistributedInputKit::StartRemoteInput(dhId, inputTypes, startCb);
+ DistributedInput::DistributedInputKit::StopRemoteInput(dhId, inputTypes, stopCb);
+}
+
+void IsNeedFilterOutFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ std::string deviceId(reinterpret_cast(data), size);
+ int32_t pressedKey = *(reinterpret_cast(data));
+ int32_t keyCode = *(reinterpret_cast(data));
+ int32_t keyAction = *(reinterpret_cast(data));
+ DistributedInput::BusinessEvent event;
+ event.pressedKeys.push_back(pressedKey);
+ event.keyAction = keyCode;
+ event.keyAction = keyAction;
+
+ DistributedInput::DistributedInputKit::IsNeedFilterOut(deviceId, event);
+}
+}
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::DistributedHardware::PrepareInputFuzzTest(data, size);
+ OHOS::DistributedHardware::StartRemoteInputFuzzTest(data, size);
+ OHOS::DistributedHardware::IsNeedFilterOutFuzzTest(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.h b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.h
new file mode 100644
index 0000000..c886b58
--- /dev/null
+++ b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef DISTRIBUTED_INPUT_KIT_FUZZER_H
+#define DISTRIBUTED_INPUT_KIT_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "distributedinputkit_fuzzer"
+
+#endif // DISTRIBUTED_INPUT_KIT_FUZZER_H
+
diff --git a/test/fuzztest/distributedinputkit_fuzzer/project.xml b/test/fuzztest/distributedinputkit_fuzzer/project.xml
new file mode 100644
index 0000000..85e7ef2
--- /dev/null
+++ b/test/fuzztest/distributedinputkit_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/distributedinputsinktransport_fuzzer/BUILD.gn b/test/fuzztest/distributedinputsinktransport_fuzzer/BUILD.gn
new file mode 100644
index 0000000..d60a61b
--- /dev/null
+++ b/test/fuzztest/distributedinputsinktransport_fuzzer/BUILD.gn
@@ -0,0 +1,79 @@
+# Copyright (c) 2021 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#####################hydra-fuzz###################
+import("//build/config/features.gni")
+import("//build/test.gni")
+import("//foundation/distributedhardware/distributedinput/distributedinput.gni")
+
+##############################fuzztest##########################################
+ohos_fuzztest("DistributedInputSinkTransportFuzzTest") {
+ module_out_path = "distributedinput_stander/system"
+ # fuzz_config_file = "//foundation/distributedhardware/distributedinput/test/fuzztest/distributedinputsinktransport_fuzzer"
+
+ include_dirs = [
+ "//foundation/distributedhardware/distributedinput/services/sink/transport/include",
+ "//utils/native/base/include",
+ "//utils/system/safwk/native/include",
+ "${common_path}/include",
+ "${fwk_common_path}/log/include",
+ "${fwk_common_path}/utils/include",
+ "${fwk_utils_path}/include/log",
+ "${fwk_utils_path}/include",
+ "${service_common}/include",
+ "//third_party/json/include",
+ ]
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources = [
+ "//foundation/distributedhardware/distributedinput/services/sink/transport/src/distributed_input_sink_switch.cpp",
+ "//foundation/distributedhardware/distributedinput/services/sink/transport/src/distributed_input_sink_transport.cpp",
+ "distributed_input_sink_transport_fuzzer.cpp",
+ ]
+
+ deps = [
+ "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
+ "//utils/native/base:utils",
+ "${fwk_utils_path}:distributedhardwareutils",
+ "//foundation/communication/dsoftbus/sdk:softbus_client",
+ ]
+
+ external_deps = [
+ "dsoftbus_standard:softbus_client",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "hiviewdfx_hilog_native:libhilog",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ defines = [
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"DistributedInputSinkTransportFuzzTest\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+
+}
+###############################################################################
+group("fuzztest") {
+ testonly = true
+
+ deps = [
+ ":DistributedInputSinkTransportFuzzTest",
+ ]
+}
+###############################################################################
diff --git a/test/fuzztest/distributedinputsinktransport_fuzzer/corpus/init b/test/fuzztest/distributedinputsinktransport_fuzzer/corpus/init
new file mode 100644
index 0000000..6b7212c
--- /dev/null
+++ b/test/fuzztest/distributedinputsinktransport_fuzzer/corpus/init
@@ -0,0 +1 @@
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/distributedinputsinktransport_fuzzer/distributed_input_sink_transport_fuzzer.cpp b/test/fuzztest/distributedinputsinktransport_fuzzer/distributed_input_sink_transport_fuzzer.cpp
new file mode 100644
index 0000000..c76cd9c
--- /dev/null
+++ b/test/fuzztest/distributedinputsinktransport_fuzzer/distributed_input_sink_transport_fuzzer.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "distributed_input_sink_transport_fuzzer.h"
+#include "distributed_input_sink_transport.h"
+
+#include
+#include
+#include
+#include
+
+#include "constants_dinput.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+void RespPrepareRemoteInputFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ int32_t sessionId = *(reinterpret_cast(data));
+ std::string smsg(reinterpret_cast(data), size);
+
+ DistributedInput::DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg);
+ DistributedInput::DistributedInputSinkTransport::GetInstance().RespUnprepareRemoteInput(sessionId, smsg);
+}
+
+void RespStartRemoteInputFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ int32_t sessionId = *(reinterpret_cast(data));
+ std::string smsg(reinterpret_cast(data), size);
+
+ DistributedInput::DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsg);
+ DistributedInput::DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg);
+}
+
+void OnSessionOpenedFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ int32_t sessionId = *(reinterpret_cast(data));
+ int32_t result = *(reinterpret_cast(data));
+
+ DistributedInput::DistributedInputSinkTransport::GetInstance().OnSessionOpened(sessionId, result);
+ DistributedInput::DistributedInputSinkTransport::GetInstance().OnSessionClosed(sessionId);
+}
+
+void OnBytesReceivedFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ int32_t sessionId = *(reinterpret_cast(data));
+ const char *msg = reinterpret_cast(data);
+ uint16_t dataLen = *(reinterpret_cast(data));
+ DistributedInput::DistributedInputSinkTransport::GetInstance().OnBytesReceived(sessionId, msg, dataLen);
+}
+}
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::DistributedHardware::RespPrepareRemoteInputFuzzTest(data, size);
+ OHOS::DistributedHardware::RespStartRemoteInputFuzzTest(data, size);
+ OHOS::DistributedHardware::OnSessionOpenedFuzzTest(data, size);
+ OHOS::DistributedHardware::OnBytesReceivedFuzzTest(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/distributedinputsinktransport_fuzzer/distributed_input_sink_transport_fuzzer.h b/test/fuzztest/distributedinputsinktransport_fuzzer/distributed_input_sink_transport_fuzzer.h
new file mode 100644
index 0000000..49a3467
--- /dev/null
+++ b/test/fuzztest/distributedinputsinktransport_fuzzer/distributed_input_sink_transport_fuzzer.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef DISTRIBUTED_INPUT_SINK_TRANSPORT_FUZZER_H
+#define DISTRIBUTED_INPUT_SINK_TRANSPORT_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "distributedinputsinktransport_fuzzer"
+
+#endif // DISTRIBUTED_INPUT_SINK_TRANSPORT_FUZZER_H
+
diff --git a/test/fuzztest/distributedinputsinktransport_fuzzer/project.xml b/test/fuzztest/distributedinputsinktransport_fuzzer/project.xml
new file mode 100644
index 0000000..85e7ef2
--- /dev/null
+++ b/test/fuzztest/distributedinputsinktransport_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/distributedinputsourcetransport_fuzzer/BUILD.gn b/test/fuzztest/distributedinputsourcetransport_fuzzer/BUILD.gn
new file mode 100644
index 0000000..bf0970c
--- /dev/null
+++ b/test/fuzztest/distributedinputsourcetransport_fuzzer/BUILD.gn
@@ -0,0 +1,81 @@
+# Copyright (c) 2021 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#####################hydra-fuzz###################
+import("//build/config/features.gni")
+import("//build/test.gni")
+import("//foundation/distributedhardware/distributedinput/distributedinput.gni")
+
+##############################fuzztest##########################################
+ohos_fuzztest("DistributedInputSourceTransportFuzzTest") {
+ module_out_path = "distributedinput_stander/system"
+ # fuzz_config_file = "//foundation/distributedhardware/distributedinput/test/fuzztest/distributedinputsourcetransport_fuzzer"
+
+ include_dirs = [
+ "//foundation/distributedhardware/distributedinput/services/source/transport/include",
+ "//utils/native/base/include",
+ "//utils/system/safwk/native/include",
+ "${common_path}/include",
+ "//utils/native/base/include",
+ "${fwk_common_path}/log/include",
+ "${fwk_common_path}/utils/include",
+ "${fwk_utils_path}/include/log",
+ "${fwk_utils_path}/include",
+ "${service_common}/include",
+ "//third_party/json/include",
+ "//foundation/distributedhardware/distributedinput/services/source/transport/test/sourcetransunittest/mock",
+ ]
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+
+ sources = [
+ "//foundation/distributedhardware/distributedinput/services/source/transport/src/distributed_input_source_transport.cpp",
+ "distributed_input_source_transport_fuzzer.cpp",
+ ]
+
+ deps = [
+ "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
+ "//utils/native/base:utils",
+ "${fwk_utils_path}:distributedhardwareutils",
+ "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
+ ]
+
+ external_deps = [
+ "dsoftbus_standard:softbus_client",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "hiviewdfx_hilog_native:libhilog",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ defines = [
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"DistributedInputSourceTransportFuzzTest\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+
+}
+###############################################################################
+group("fuzztest") {
+ testonly = true
+
+ deps = [
+ ":DistributedInputSourceTransportFuzzTest",
+ ]
+}
+###############################################################################
diff --git a/test/fuzztest/distributedinputsourcetransport_fuzzer/corpus/init b/test/fuzztest/distributedinputsourcetransport_fuzzer/corpus/init
new file mode 100644
index 0000000..6b7212c
--- /dev/null
+++ b/test/fuzztest/distributedinputsourcetransport_fuzzer/corpus/init
@@ -0,0 +1 @@
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/distributedinputsourcetransport_fuzzer/distributed_input_source_transport_fuzzer.cpp b/test/fuzztest/distributedinputsourcetransport_fuzzer/distributed_input_source_transport_fuzzer.cpp
new file mode 100644
index 0000000..64d99dc
--- /dev/null
+++ b/test/fuzztest/distributedinputsourcetransport_fuzzer/distributed_input_source_transport_fuzzer.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "distributed_input_source_transport_fuzzer.h"
+#include "distributed_input_source_transport.h"
+
+#include
+#include
+
+#include "constants_dinput.h"
+
+#include
+#include
+#include
+#include
+
+namespace OHOS {
+namespace DistributedHardware {
+void OpenInputSoftbusFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ std::string remoteDevId(reinterpret_cast(data), size);
+ std::string hwId(reinterpret_cast(data), size);
+
+ DistributedInput::DistributedInputSourceTransport::GetInstance().OpenInputSoftbus(remoteDevId, hwId);
+ DistributedInput::DistributedInputSourceTransport::GetInstance().CloseInputSoftbus(remoteDevId, hwId);
+}
+
+void OnSessionOpenedFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ int32_t sessionId = *(reinterpret_cast(data));
+ int32_t result = *(reinterpret_cast(data));
+
+ DistributedInput::DistributedInputSourceTransport::GetInstance().OnSessionOpened(sessionId, result);
+ DistributedInput::DistributedInputSourceTransport::GetInstance().OnSessionClosed(sessionId);
+}
+
+void OnBytesReceivedFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ int32_t sessionId = *(reinterpret_cast(data));
+ const char *msg = reinterpret_cast(data);
+ uint16_t dataLen = *(reinterpret_cast(data));
+ DistributedInput::DistributedInputSourceTransport::GetInstance().OnBytesReceived(sessionId, msg, dataLen);
+}
+}
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::DistributedHardware::OpenInputSoftbusFuzzTest(data, size);
+ OHOS::DistributedHardware::OnSessionOpenedFuzzTest(data, size);
+ OHOS::DistributedHardware::OnBytesReceivedFuzzTest(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/distributedinputsourcetransport_fuzzer/distributed_input_source_transport_fuzzer.h b/test/fuzztest/distributedinputsourcetransport_fuzzer/distributed_input_source_transport_fuzzer.h
new file mode 100644
index 0000000..4997564
--- /dev/null
+++ b/test/fuzztest/distributedinputsourcetransport_fuzzer/distributed_input_source_transport_fuzzer.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef DISTRIBUTED_INPUT_SOURCE_TRANSPORT_FUZZER_H
+#define DISTRIBUTED_INPUT_SOURCE_TRANSPORT_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "distributedinputsourcetransport_fuzzer"
+
+#endif // DISTRIBUTED_INPUT_SOURCE_TRANSPORT_FUZZER_H
+
diff --git a/test/fuzztest/distributedinputsourcetransport_fuzzer/project.xml b/test/fuzztest/distributedinputsourcetransport_fuzzer/project.xml
new file mode 100644
index 0000000..85e7ef2
--- /dev/null
+++ b/test/fuzztest/distributedinputsourcetransport_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/system/BUILD.gn b/test/system/BUILD.gn
new file mode 100644
index 0000000..a54f5d4
--- /dev/null
+++ b/test/system/BUILD.gn
@@ -0,0 +1,98 @@
+# Copyright (c) 2021 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/test.gni")
+import("//foundation/distributedhardware/distributedinput/distributedinput.gni")
+module_out_path = "distributedinput_stander/system"
+
+group("system") {
+ testonly = true
+
+ deps = [
+ ":distributed_input_test",
+ ]
+}
+
+## UnitTest distributed_input_test {{{
+ohos_unittest("distributed_input_test") {
+ module_out_path = module_out_path
+
+ include_dirs = [
+ "include",
+ "${distributedinput_path}/interfaces/inner_kits/include",
+ "${distributedinput_path}/interfaces/inner_kits/src",
+ "${distributedinput_path}/interfaces/ipc/include",
+ "${distributedinput_path}/interfaces/ipc/src",
+ "${distributedinput_path}/services/source/sourcemanager/include",
+ "${distributedinput_path}/services/sink/sinkmanager/include",
+ "${distributedinput_path}/frameworks/include",
+ "${distributedinput_path}/sourcehandler/include",
+ "${distributedinput_path}/sinkhandler/include",
+ "${distributedinput_path}/inputdevicehandler/include",
+ "//utils/native/base/include",
+ "//utils/system/safwk/native/include",
+ "${service_common}/include",
+ "${common_path}/include",
+ "${fwk_common_path}/log/include",
+ "${fwk_common_path}/utils/include",
+ "${fwk_utils_path}/include/log",
+ "${fwk_utils_path}/include",
+ "//third_party/json/include",
+ ]
+
+ sources = [
+ "src/distributed_input_test.cpp",
+ ]
+
+ cflags = [
+ "-Wall",
+ "-Werror",
+ "-g3",
+ "-Dprivate=public",
+ "-Dprotected=public",
+ ]
+
+ defines = [
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"distributedinpututtest\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+
+ deps = [
+ "${distributedinput_path}/interfaces/inner_kits:libdinput_sdk",
+ "${distributedinput_path}/services/source/sourcemanager:libdinput_source",
+ "${distributedinput_path}/services/source/inputinject:libdinput_inject",
+ "${distributedinput_path}/services/source/transport:libdinput_source_trans",
+ "${distributedinput_path}/services/sink/sinkmanager:libdinput_sink",
+ "${distributedinput_path}/services/sink/inputcollector:libdinput_collector",
+ "${distributedinput_path}/services/sink/transport:libdinput_sink_trans",
+ "${distributedinput_path}/sourcehandler:libdinput_source_handler",
+ "${distributedinput_path}/sinkhandler:libdinput_sink_handler",
+ "${distributedinput_path}/inputdevicehandler:libdinput_handler",
+ "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
+ "//utils/native/base:utils",
+ "${fwk_utils_path}:distributedhardwareutils",
+ ]
+
+ external_deps = [
+ "dsoftbus_standard:softbus_client",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "hiviewdfx_hilog_native:libhilog",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ cflags_cc = [ "-DHILOG_ENABLE" ]
+}
+
+## UnitTest distributed_input_test }}}
\ No newline at end of file
diff --git a/test/system/include/distributed_input_test.h b/test/system/include/distributed_input_test.h
new file mode 100644
index 0000000..7b379fe
--- /dev/null
+++ b/test/system/include/distributed_input_test.h
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DISRIBUTED_INPUT_TEST_H
+#define DISRIBUTED_INPUT_TEST_H
+
+#include "i_distributed_sink_input.h"
+#include "i_distributed_source_input.h"
+#include "distributed_input_kit.h"
+#include "distributed_input_sink_handler.h"
+#include "distributed_input_source_handler.h"
+#include "distributed_input_handler.h"
+
+#include "prepare_d_input_call_back_stub.h"
+#include "unprepare_d_input_call_back_stub.h"
+#include "start_d_input_call_back_stub.h"
+#include "stop_d_input_call_back_stub.h"
+
+#include "constants_dinput.h"
+
+#include
+#include
+#include
+#include
+#include
+
+namespace OHOS {
+namespace DistributedHardware {
+namespace DistributedInput {
+class DistributedInputTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ virtual void SetUp() override;
+ virtual void TearDown() override;
+
+ void StartSourceSa();
+ void StartSinkSa();
+ void GetHardWhereInfo();
+ void GetDeviceInfo();
+ void RegisterDistributedHardware();
+ void UnregisterDistributedHardware();
+ void PrepareRemoteInput();
+ void UnprepareRemoteInput();
+ void StartRemoteInput();
+ void StopRemoteInput();
+ void IsStartDistributedInput();
+ void IsNeedFilterOut();
+ void StopSourceSa();
+ void StopSinkSa();
+ void Help();
+ void SwitchCase(int32_t in);
+
+ class TestRegisterInputCallback : public OHOS::DistributedHardware::RegisterCallback {
+ public:
+ TestRegisterInputCallback() = default;
+ virtual ~TestRegisterInputCallback() = default;
+ virtual int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status,
+ const std::string &data) override;
+ };
+
+ class TestUnregisterInputCallback : public OHOS::DistributedHardware::UnregisterCallback {
+ public:
+ TestUnregisterInputCallback() = default;
+ virtual ~TestUnregisterInputCallback() = default;
+ virtual int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status,
+ const std::string &data) override;
+ };
+
+ class TestPluginListener : public OHOS::DistributedHardware::PluginListener {
+ public:
+ TestPluginListener() = default;
+ virtual ~TestPluginListener() = default;
+ virtual void PluginHardware(const std::string &dhId, const std::string &attrs) override;
+ virtual void UnPluginHardware(const std::string &dhId) override;
+ };
+
+ class TestPrepareDInputCallback :
+ public OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub {
+ public:
+ TestPrepareDInputCallback() = default;
+ virtual ~TestPrepareDInputCallback() = default;
+ void OnResult(const std::string& deviceId, const int32_t& status);
+ };
+
+ class TestUnprepareDInputCallback :
+ public OHOS::DistributedHardware::DistributedInput::UnprepareDInputCallbackStub {
+ public:
+ TestUnprepareDInputCallback() = default;
+ virtual ~TestUnprepareDInputCallback() = default;
+ void OnResult(const std::string& deviceId, const int32_t& status);
+ };
+
+ class TestStartDInputCallback :
+ public OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub {
+ public:
+ void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status);
+ };
+
+ class TestStopDInputCallback :
+ public OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub {
+ public:
+ TestStopDInputCallback() = default;
+ virtual ~TestStopDInputCallback() = default;
+ void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status);
+ };
+
+ OHOS::DistributedHardware::EnableParam enableParam;
+
+ std::shared_ptr registerCb = nullptr;
+ std::shared_ptr unregisterCb = nullptr;
+ std::shared_ptr pluginListener;
+ OHOS::sptr prepareCb;
+ OHOS::sptr unprepareCb;
+ OHOS::sptr startCb;
+ OHOS::sptr stopCb;
+};
+} // namespace DistributedInput
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // DISRIBUTED_INPUT_TEST_H
diff --git a/test/system/src/distributed_input_test.cpp b/test/system/src/distributed_input_test.cpp
new file mode 100644
index 0000000..603eace
--- /dev/null
+++ b/test/system/src/distributed_input_test.cpp
@@ -0,0 +1,557 @@
+/*
+ * Copyright (c) 2021 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "distributed_input_test.h"
+#include "idistributed_hardware_source.h"
+#include "ipc_skeleton.h"
+#include "softbus_bus_center.h"
+#include "nlohmann/json.hpp"
+
+#include
+#include
+#include
+
+using namespace testing::ext;
+using namespace OHOS::DistributedHardware::DistributedInput;
+using namespace std;
+
+namespace OHOS {
+namespace DistributedHardware {
+namespace DistributedInput {
+namespace {
+ const int32_t TEST_START_SINK = 1;
+ const int32_t TEST_START_SOURCE = 2;
+ const int32_t TEST_GET_DEVICEINFO = 3;
+ const int32_t TEST_GET_HARDWAREINFO = 4;
+ const int32_t TEST_IS_START_INPUT = 5;
+ const int32_t TEST_IS_NEED_FILTEROUT = 6;
+ const int32_t TEST_STOP_SINK = 7;
+ const int32_t TEST_STOP_SOURCE = 8;
+ const int32_t TEST_HELP = 9;
+ const int32_t TEST_REGISTERHARDWARE = 11;
+ const int32_t TEST_PREPAREREMOTE = 12;
+ const int32_t TEST_STARTREMOTE = 13;
+ const int32_t TEST_STOPREMOTE = 14;
+ const int32_t TEST_UN_PREPAREREMOTE = 15;
+ const int32_t TEST_UN_REGISTERHARDWARE = 16;
+}
+void DistributedInputTest::SetUp()
+{
+}
+
+void DistributedInputTest::TearDown()
+{
+}
+
+void DistributedInputTest::SetUpTestCase()
+{
+}
+
+void DistributedInputTest::TearDownTestCase()
+{
+}
+
+void DistributedInputTest::TestPluginListener::PluginHardware(
+ const std::string &dhId, const std::string &attrs)
+{
+ std::cout << std::endl;
+ std::cout << "TestPluginListener::PluginHardware " << std::endl;
+ std::cout << "dhId::" << dhId < items = DistributedInputHandler::GetInstance().Query();
+ int index = 0;
+ for (auto item : items) {
+ std::cout << "dhId :: " << std::endl;
+ std::cout << item.dhId << std::endl;
+ std::cout << "attrs:: " << std::endl;
+ index = 0;
+ while ((index = item.attrs.find(' ', index)) != string::npos) {
+ item.attrs.erase(index, 1);
+ }
+ std::cout << item.attrs << std::endl;
+ }
+ std::cout << "GetHardWhereInfo::end " << std::endl;
+}
+
+void DistributedInputTest::GetDeviceInfo()
+{
+ std::cout << "GetDeviceInfo::start " << std::endl;
+
+ NodeBasicInfo *info = NULL;
+ int32_t infoNum = 0;
+ GetAllNodeDeviceInfo("ohos.distributedhardware.devicemanager", &info, &infoNum);
+ std::cout << "DeviceInfo::" << std::endl;
+ for (int32_t i = 0; i < infoNum; i++) {
+ std::cout << "networkId::" << std::endl;
+ std::cout << info->networkId << std::endl;
+ std::cout << "deviceName::" << std::endl;
+ std::cout << info->deviceName << std::endl;
+ std::cout << std::endl;
+ info++;
+ }
+ std::cout << "GetDeviceInfo::end " << std::endl;
+}
+
+void DistributedInputTest::IsStartDistributedInput()
+{
+ std::cout << "IsStartDistributedInput::start " << std::endl;
+
+ uint32_t inputType = 0;
+ std::cout << "inputType::";
+ std::cin >> inputType;
+
+ DInputServerType type = DistributedInputKit::IsStartDistributedInput(inputType);
+ if (type == DInputServerType::SOURCE_SERVER_TYPE) {
+ std::cout << "The inputed type is using in source sa! " << std::endl;
+ } else if (type == DInputServerType::SINK_SERVER_TYPE) {
+ std::cout << "The inputed type is using in sink sa! " << std::endl;
+ } else {
+ std::cout << "No sa is using! " << std::endl;
+ }
+
+ std::cout << "IsStartDistributedInput::end " << std::endl;
+}
+
+void DistributedInputTest::IsNeedFilterOut()
+{
+ std::cout << "IsNeedFilterOut::start " << std::endl;
+
+ string deviceId = "";
+ int32_t pressedKey1 = 0;
+ int32_t pressedKey2 = 0;
+ int32_t keyCode = 0;
+ int32_t keyAction = 0;
+ BusinessEvent event;
+
+ std::cout << "deviceId::";
+ std::cin >> deviceId;
+ std::cout << "BusinessEvent::" << std::endl;
+ std::cout << "pressedKey1::";
+ std::cin >> pressedKey1;
+ std::cout << "pressedKey2::";
+ std::cin >> pressedKey2;
+ std::cout << "keyCode::";
+ std::cin >> keyCode;
+ std::cout << "keyAction::";
+ std::cin >> keyAction;
+
+ event.pressedKeys.push_back(pressedKey1);
+ event.pressedKeys.push_back(pressedKey2);
+ event.keyCode = keyCode;
+ event.keyAction = keyAction;
+
+ bool ret = DistributedInputKit::IsNeedFilterOut(deviceId, event);
+ if (ret == true) {
+ std::cout << " Result::true ! " << std::endl;
+ std::cout << " The businessEvent is not in the white list ! " << std::endl;
+ std::cout << " The businessEvent take effect at the source! " << std::endl;
+ } else {
+ std::cout << " Result::false ! " << std::endl;
+ std::cout << " The businessEvent is in the white list ! " << std::endl;
+ std::cout << " The businessEvent don`t take effect at the source! " << std::endl;
+ }
+
+ std::cout << "IsNeedFilterOut::end " << std::endl;
+}
+
+void DistributedInputTest::RegisterDistributedHardware()
+{
+ std::cout << "RegisterDistributedHardware::start " << std::endl;
+
+ string rDevId = "";
+ string rDhId = "";
+ string attrs = "";
+
+ std::cout << "devId::";
+ std::cin >> rDevId;
+ std::cout << "dhId::";
+ std::cin >> rDhId;
+ std::cout << "params::";
+ std::cin >> attrs;
+
+ enableParam.version = "1.0";
+ enableParam.attrs = attrs;
+
+ registerCb = std::make_shared();
+ int32_t ret = DistributedInputSourceHandler::GetInstance().RegisterDistributedHardware(
+ rDevId, rDhId, enableParam, registerCb);
+ if (ret == SUCCESS) {
+ std::cout << "RegisterDistributedHardware is succese! " << std::endl;
+ } else {
+ std::cout << "RegisterDistributedHardware is fall! " << std::endl;
+ }
+
+ std::cout << "RegisterDistributedHardware::end " << std::endl;
+}
+
+void DistributedInputTest::PrepareRemoteInput()
+{
+ std::cout << "PrepareRemoteInput::start " << std::endl;
+
+ string rDevId = "";
+
+ std::cout << "devId::";
+ std::cin >> rDevId;
+
+ prepareCb = new(std::nothrow) TestPrepareDInputCallback();
+ int32_t ret = DistributedInputKit::PrepareRemoteInput(rDevId, prepareCb);
+ if (ret == SUCCESS) {
+ std::cout << "PrepareRemoteInput is succese! " << std::endl;
+ } else {
+ std::cout << "PrepareRemoteInput is fall! " << std::endl;
+ }
+
+ std::cout << "PrepareRemoteInput::end " << std::endl;
+}
+
+void DistributedInputTest::UnprepareRemoteInput()
+{
+ std::cout << "UnprepareRemoteInput::start " << std::endl;
+
+ string rDevId = "";
+
+ std::cout << "devId::";
+ std::cin >> rDevId;
+
+ unprepareCb = new(std::nothrow) TestUnprepareDInputCallback();
+ int32_t ret = DistributedInputKit::UnprepareRemoteInput(rDevId, unprepareCb);
+ if (ret == SUCCESS) {
+ std::cout << "UnprepareRemoteInput is succese! " << std::endl;
+ } else {
+ std::cout << "UnprepareRemoteInput is fall! " << std::endl;
+ }
+ std::cout << "UnprepareRemoteInput::end " << std::endl;
+}
+
+void DistributedInputTest::StartRemoteInput()
+{
+ std::cout << "StartRemoteInput::start " << std::endl;
+ std::cout << "You can input 1 ~ 7" << std::endl;
+ std::cout << "1:mouse " << std::endl;
+ std::cout << "2:keyboard " << std::endl;
+ std::cout << "4:touch " << std::endl;
+ std::cout << "7:all " << std::endl;
+
+ string rDevId = "";
+ uint32_t rInputType = 0;
+ std::cout << "inputType::";
+ std::cin >> rInputType;
+ std::cout << "devId::";
+ std::cin >> rDevId;
+
+ startCb = new(std::nothrow) TestStartDInputCallback();
+ int32_t ret = DistributedInputKit::StartRemoteInput(rDevId, rInputType, startCb);
+ if (ret == SUCCESS) {
+ std::cout << "StartRemoteInput is succese! " << std::endl;
+ } else {
+ std::cout << "StartRemoteInput is fall! " << std::endl;
+ }
+
+ std::cout << "StartRemoteInput::end " << std::endl;
+}
+
+void DistributedInputTest::StopRemoteInput()
+{
+ std::cout << "StopRemoteInput::start " << std::endl;
+ std::cout << "You can input 1 ~ 7" << std::endl;
+ std::cout << "1:mouse " << std::endl;
+ std::cout << "2:keyboard " << std::endl;
+ std::cout << "4:touch " << std::endl;
+ std::cout << "7:all " << std::endl;
+
+ string rDevId = "";
+ uint32_t rInputType = 0;
+
+ std::cout << "devId::";
+ std::cin >> rDevId;
+
+ std::cout << "inputType::";
+ std::cin >> rInputType;
+
+ stopCb = new(std::nothrow) TestStopDInputCallback();
+ int32_t ret = DistributedInputKit::StopRemoteInput(rDevId, rInputType, stopCb);
+ if (ret == SUCCESS) {
+ std::cout << "StopRemoteInput is succese! " << std::endl;
+ } else {
+ std::cout << "StopRemoteInput is fall! " << std::endl;
+ }
+
+ std::cout << "StopRemoteInput::end " << std::endl;
+}
+
+void DistributedInputTest::UnregisterDistributedHardware()
+{
+ std::cout << "UnregisterDistributedHardware::start " << std::endl;
+
+ string rDevId = "";
+ string rDhId = "";
+ string attrs = "";
+
+ std::cout << "devId::";
+ std::cin >> rDevId;
+ std::cout << "dhId::";
+ std::cin >> rDhId;
+
+ unregisterCb = std::make_shared();
+ int32_t ret = DistributedInputSourceHandler::GetInstance().UnregisterDistributedHardware(
+ rDevId, rDhId, unregisterCb);
+ if (ret == SUCCESS) {
+ std::cout << "UnregisterDistributedHardware is succese! " << std::endl;
+ } else {
+ std::cout << "UnregisterDistributedHardware is fall! " << std::endl;
+ }
+
+ std::cout << "UnregisterDistributedHardware::end " << std::endl;
+}
+
+void DistributedInputTest::StopSourceSa()
+{
+ std::cout << "StopSourceSa::start " << std::endl;
+ int ret = DistributedInputSourceHandler::GetInstance().ReleaseSource();
+ if (ret == SUCCESS) {
+ std::cout << "StopSourceSa is succese! " << std::endl;
+ } else {
+ std::cout << "StopSourceSa is fall! " << std::endl;
+ }
+
+ std::cout << "StopSourceSa::end " << std::endl;
+}
+
+void DistributedInputTest::StopSinkSa()
+{
+ std::cout << "StopSinkSa::start " << std::endl;
+ int ret = DistributedInputSinkHandler::GetInstance().ReleaseSink();
+ if (ret == SUCCESS) {
+ std::cout << "StopSinkSa is succese! " << std::endl;
+ } else {
+ std::cout << "StopSinkSa is fall! " << std::endl;
+ }
+ std::cout << "StopSinkSa::end " << std::endl;
+}
+
+void DistributedInputTest::Help()
+{
+ std::cout << "************************************************************" << std::endl;
+ std::cout << "Welcome to the dinput source test demo!" << std::endl;
+ std::cout << "1 ::StartSinkSa " << std::endl;
+ std::cout << "2 ::StartSourceSa " << std::endl;
+ std::cout << "3 ::GetDeviceInfo " << std::endl;
+ std::cout << "4 ::GetHardWhereInfo " << std::endl;
+ std::cout << "5 ::IsStartDistributedInput " << std::endl;
+ std::cout << "6 ::IsNeedFilterOut " << std::endl;
+ std::cout << "7 ::StopSinkSa " << std::endl;
+ std::cout << "8 ::StopSourceSa " << std::endl;
+ std::cout << "9 ::Help " << std::endl;
+ std::cout << "0 ::Exit " << std::endl;
+ std::cout << "11::RegisterDistributedHardware " << std::endl;
+ std::cout << "12::PrepareRemoteInput " << std::endl;
+ std::cout << "13::StartRemoteInput " << std::endl;
+ std::cout << "14::StopRemoteInput " << std::endl;
+ std::cout << "15::UnprepareRemoteInput " << std::endl;
+ std::cout << "16::UnregisterDistributedHardware " << std::endl;
+ std::cout << "************************************************************" << std::endl;
+}
+
+void DistributedInputTest::SwitchCase(int32_t in)
+{
+ switch (in) {
+ case TEST_START_SINK:
+ StartSinkSa();
+ break;
+ case TEST_START_SOURCE:
+ StartSourceSa();
+ break;
+ case TEST_GET_DEVICEINFO:
+ GetDeviceInfo();
+ break;
+ case TEST_GET_HARDWAREINFO:
+ GetHardWhereInfo();
+ break;
+ case TEST_IS_START_INPUT:
+ IsStartDistributedInput();
+ break;
+ case TEST_IS_NEED_FILTEROUT:
+ IsNeedFilterOut();
+ break;
+ case TEST_STOP_SINK:
+ StopSinkSa();
+ break;
+ case TEST_STOP_SOURCE:
+ StopSourceSa();
+ break;
+ case TEST_HELP:
+ Help();
+ break;
+ case TEST_REGISTERHARDWARE:
+ RegisterDistributedHardware();
+ break;
+ case TEST_PREPAREREMOTE:
+ PrepareRemoteInput();
+ break;
+ case TEST_STARTREMOTE:
+ StartRemoteInput();
+ break;
+ case TEST_STOPREMOTE:
+ StopRemoteInput();
+ break;
+ case TEST_UN_PREPAREREMOTE:
+ UnprepareRemoteInput();
+ break;
+ case TEST_UN_REGISTERHARDWARE:
+ UnregisterDistributedHardware();
+ break;
+ default:
+ break;
+ }
+}
+
+HWTEST_F(DistributedInputTest, SystemTest01, testing::ext::TestSize.Level0)
+{
+ Help();
+ pluginListener = std::make_shared();
+ DistributedInputHandler::GetInstance().RegisterPluginListener(pluginListener);
+
+ int32_t in;
+ while (true) {
+ std::cout << std::endl;
+ std::cout << "Enter the case No : " << std::endl;
+ std::cin >> in;
+ if (in == 0) {
+ registerCb = nullptr;
+ unregisterCb = nullptr;
+ prepareCb = nullptr;
+ unprepareCb = nullptr;
+ startCb = nullptr;
+ stopCb = nullptr;
+ break;
+ }
+ SwitchCase(in);
+ }
+}
+} // namespace DistributedInput
+} // namespace DistributedHardware
+} // namespace OHOS