multicast unittest

Signed-off-by: xujie223 <xujie223@huawei.com>
This commit is contained in:
xujie223 2023-10-22 18:29:36 +08:00
parent 85aecad342
commit f43cbddd1e
3 changed files with 158 additions and 0 deletions

View File

@ -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"
]

View File

@ -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" ]
}

View File

@ -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 <cstring>
#include <iostream>
#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