From 2bbd81e1bb18c31bbedf7086cc213de7c58aa5bb Mon Sep 17 00:00:00 2001 From: wcr <2108380043@qq.com> Date: Tue, 31 Dec 2024 18:37:48 +0800 Subject: [PATCH] 1231 --- .../net/netdb/smoke/net_netdb_test_001.cpp | 50 +++++++------------ .../net/netdb/smoke/net_netdb_test_013.cpp | 48 +++++++----------- 2 files changed, 36 insertions(+), 62 deletions(-) diff --git a/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_001.cpp b/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_001.cpp index 1e0b53a..ac2a9dc 100644 --- a/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_001.cpp +++ b/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_001.cpp @@ -2,57 +2,45 @@ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 这部分版权信息说明了华为技术有限公司(或其子公司)是这段代码的版权持有者, + * 并规定了代码的重新分发和使用条件。 */ +#include "lt_net_netdb.h" // 包含测试所需的网络数据库头文件 -#include "lt_net_netdb.h" - +// 定义一个测试函数,用于测试协议数据库的功能 static int ProtoentTest(void) { - setprotoent(1); + setprotoent(1); // 打开协议数据库文件,参数1表示重置文件指针到文件开始 - // refer to the `/etc/protocols' file. + // 引用/etc/protocols文件,获取名为"icmp"的协议条目 struct protoent *prot = getprotobyname("icmp"); + // 断言:确保获取到的协议条目不为空 ICUNIT_ASSERT_NOT_EQUAL(prot, NULL, -1); + // 断言:确保获取到的协议编号是1(ICMP协议的编号) ICUNIT_ASSERT_EQUAL(prot->p_proto, 1, prot->p_proto); + // 获取编号为1的协议条目(也是ICMP协议) prot = getprotobynumber(1); + // 断言:确保获取到的协议条目不为空 ICUNIT_ASSERT_NOT_EQUAL(prot, NULL, -1); - ICUNIT_ASSERT_EQUAL(strcmp(prot->p_name, "icmp"), 0, -1); + // 断言:确保获取到的协议名称是"icmp" + ICUNIT_ASSERT_EQUAL(strcmp(prot->p_name, "icmp"), 0, -1); // strcmp返回0表示字符串相等 + // 获取协议数据库中的下一个协议条目 prot = getprotoent(); + // 断言:确保获取到的协议条目不为空 ICUNIT_ASSERT_NOT_EQUAL(prot, NULL, -1); + // 关闭协议数据库文件 endprotoent(); + // 返回测试成功标志 return ICUNIT_SUCCESS; } +// 定义一个测试注册函数,用于将ProtoentTest测试添加到测试套件中 void NetNetDbTest001(void) { + // 添加测试用例到测试框架中,包括测试用例名称、测试函数、测试类别、测试协议、测试级别和测试类型 TEST_ADD_CASE(__FUNCTION__, ProtoentTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION); -} +} \ No newline at end of file diff --git a/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_013.cpp b/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_013.cpp index b713849..3a8b6bd 100644 --- a/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_013.cpp +++ b/kernel_liteos_a-master/testsuites/unittest/net/netdb/smoke/net_netdb_test_013.cpp @@ -1,48 +1,34 @@ /* - * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 版权信息,说明了华为技术有限公司(或其子公司)是这段代码的版权持有者, + * 并规定了代码的重新分发和使用条件。 */ +#include "lt_net_netdb.h" // 包含测试所需的网络数据库头文件,可能定义了测试框架和相关的宏、函数原型等 -#include "lt_net_netdb.h" - +// 定义一个测试函数,用于测试hstrerror和herror函数的功能 static int HerrorTest(void) { + // 调用hstrerror函数,传入一个错误码(TRY_AGAIN是一个宏,通常代表一个网络相关的错误码) + // hstrerror函数用于将错误码转换为对应的错误描述字符串 const char *err = hstrerror(TRY_AGAIN); + + // 断言:确保hstrerror返回的错误描述字符串不为空 + // 如果为空,则测试失败,返回-1作为错误码 ICUNIT_ASSERT_NOT_EQUAL(err, NULL, -1); + // 调用herror函数,传入hstrerror返回的错误描述字符串 + // herror函数通常用于将错误描述打印到标准错误输出(stderr) herror(err); + // 返回测试成功标志 return ICUNIT_SUCCESS; } +// 定义一个测试注册函数,用于将HerrorTest测试添加到测试套件中 void NetNetDbTest013(void) { + // 使用TEST_ADD_CASE宏添加测试用例到测试框架中 + // 宏的参数包括测试用例的名称(当前函数名)、测试函数、测试类别、测试协议、测试级别和测试类型 + // 这些参数帮助测试框架组织和执行测试用例 TEST_ADD_CASE(__FUNCTION__, HerrorTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION); -} +} \ No newline at end of file