From f43cbddd1eee0793846954b206619bb78c4e0ec3 Mon Sep 17 00:00:00 2001 From: xujie223 Date: Sun, 22 Oct 2023 18:29:36 +0800 Subject: [PATCH] multicast unittest Signed-off-by: xujie223 --- bundle.json | 1 + test/unittest/socket/BUILD.gn | 73 +++++++++++++++++++++++++ test/unittest/socket/SocketTest.cpp | 84 +++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 test/unittest/socket/BUILD.gn create mode 100644 test/unittest/socket/SocketTest.cpp diff --git a/bundle.json b/bundle.json index 5226fa51..897196e6 100644 --- a/bundle.json +++ b/bundle.json @@ -91,6 +91,7 @@ "//foundation/communication/netstack/test/unittest/http:unittest", "//foundation/communication/netstack/test/unittest/http/cache:unittest", "//foundation/communication/netstack/test/unittest/http_client:unittest", + "//foundation/communication/netstack/test/unittest/socket:unittest", "//foundation/communication/netstack/test/unittest/tlssocket:unittest", "//foundation/communication/netstack/test/unittest/utils/common_utils:unittest" ] diff --git a/test/unittest/socket/BUILD.gn b/test/unittest/socket/BUILD.gn new file mode 100644 index 00000000..069bdf4b --- /dev/null +++ b/test/unittest/socket/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2023 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("//build/test.gni") +import("//foundation/communication/netstack/netstack_config.gni") + +SOCKET_NAPI = "$NETSTACK_DIR/frameworks/js/napi/socket" + +utils_include = [ + "$SUBSYSTEM_DIR/netstack/utils/common_utils/include", + "$SUBSYSTEM_DIR/netstack/utils/log/include", + "$SUBSYSTEM_DIR/netstack/utils/napi_utils/include", + "$THIRD_PARTY_ROOT/curl/include", +] + +common_external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "napi:ace_napi", +] + +ohos_unittest("socket_unittest") { + module_out_path = "netstack/socket_unittest" + + include_dirs = [ + "$NETSTACK_DIR/utils/napi_utils/include", + "$SOCKET_NAPI/async_context/include", + "$SOCKET_NAPI/async_work/include", + "$SOCKET_NAPI/constant/include", + "$SOCKET_NAPI/options/include", + "$SOCKET_NAPI/socket_exec/include", + "$SOCKET_NAPI/socket_module/include", + ] + include_dirs += utils_include + + sources = [ + "$SOCKET_NAPI/async_context/src/multicast_get_loopback_context.cpp", + "$SOCKET_NAPI/async_context/src/multicast_get_ttl_context.cpp", + "$SOCKET_NAPI/async_context/src/multicast_membership_context.cpp", + "$SOCKET_NAPI/async_context/src/multicast_set_loopback_context.cpp", + "$SOCKET_NAPI/async_context/src/multicast_set_ttl_context.cpp", + "$SOCKET_NAPI/options/src/net_address.cpp", + "$SOCKET_NAPI/options/src/socket_remote_info.cpp", + "$SOCKET_NAPI/socket_exec/src/socket_exec.cpp", + "SocketTest.cpp", + ] + + deps = [ + "$NETSTACK_DIR/frameworks/js/napi/socket:socket", + "$NETSTACK_DIR/utils/napi_utils:napi_utils", + ] + + external_deps = common_external_deps + + part_name = "netstack" + subsystem_name = "communication" +} + +group("unittest") { + testonly = true + deps = [ ":socket_unittest" ] +} diff --git a/test/unittest/socket/SocketTest.cpp b/test/unittest/socket/SocketTest.cpp new file mode 100644 index 00000000..280dc68a --- /dev/null +++ b/test/unittest/socket/SocketTest.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2023 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 "netstack_log.h" +#include "gtest/gtest.h" +#include +#include + +#include "multicast_get_loopback_context.h" +#include "multicast_get_ttl_context.h" +#include "multicast_membership_context.h" +#include "multicast_set_loopback_context.h" +#include "multicast_set_ttl_context.h" +#include "socket_exec.h" + +class SocketTest : public testing::Test { +public: + static void SetUpTestCase() {} + + static void TearDownTestCase() {} + + virtual void SetUp() {} + + virtual void TearDown() {} +}; + +namespace { +using namespace testing::ext; +using namespace OHOS::NetStack::Socket; + +HWTEST_F(SocketTest, MulticastTest001, TestSize.Level1) +{ + MulticastMembershipContext context(nullptr, nullptr); + bool ret = SocketExec::ExecUdpAddMembership(&context); + EXPECT_EQ(ret, false); +} + +HWTEST_F(SocketTest, MulticastTest002, TestSize.Level1) +{ + MulticastMembershipContext context(nullptr, nullptr); + bool ret = SocketExec::ExecUdpDropMembership(&context); + EXPECT_EQ(ret, false); +} + +HWTEST_F(SocketTest, MulticastTest003, TestSize.Level1) +{ + MulticastSetTTLContext context(nullptr, nullptr); + bool ret = SocketExec::ExecSetMulticastTTL(&context); + EXPECT_EQ(ret, false); +} + +HWTEST_F(SocketTest, MulticastTest004, TestSize.Level1) +{ + MulticastGetTTLContext context(nullptr, nullptr); + bool ret = SocketExec::ExecGetMulticastTTL(&context); + EXPECT_EQ(ret, false); +} + +HWTEST_F(SocketTest, MulticastTest005, TestSize.Level1) +{ + MulticastSetLoopbackContext context(nullptr, nullptr); + bool ret = SocketExec::ExecSetLoopbackMode(&context); + EXPECT_EQ(ret, false); +} + +HWTEST_F(SocketTest, MulticastTest006, TestSize.Level1) +{ + MulticastGetLoopbackContext context(nullptr, nullptr); + bool ret = SocketExec::ExecGetLoopbackMode(&context); + EXPECT_EQ(ret, false); +} +} // namespace \ No newline at end of file