分支昶
wcr 7 months ago
parent fa052b7a28
commit 2bbd81e1bb

@ -2,57 +2,45 @@
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device 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) static int ProtoentTest(void)
{ {
setprotoent(1); setprotoent(1); // 打开协议数据库文件参数1表示重置文件指针到文件开始
// refer to the `/etc/protocols' file. // 引用/etc/protocols文件获取名为"icmp"的协议条目
struct protoent *prot = getprotobyname("icmp"); struct protoent *prot = getprotobyname("icmp");
// 断言:确保获取到的协议条目不为空
ICUNIT_ASSERT_NOT_EQUAL(prot, NULL, -1); ICUNIT_ASSERT_NOT_EQUAL(prot, NULL, -1);
// 断言确保获取到的协议编号是1ICMP协议的编号
ICUNIT_ASSERT_EQUAL(prot->p_proto, 1, prot->p_proto); ICUNIT_ASSERT_EQUAL(prot->p_proto, 1, prot->p_proto);
// 获取编号为1的协议条目也是ICMP协议
prot = getprotobynumber(1); prot = getprotobynumber(1);
// 断言:确保获取到的协议条目不为空
ICUNIT_ASSERT_NOT_EQUAL(prot, NULL, -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(); prot = getprotoent();
// 断言:确保获取到的协议条目不为空
ICUNIT_ASSERT_NOT_EQUAL(prot, NULL, -1); ICUNIT_ASSERT_NOT_EQUAL(prot, NULL, -1);
// 关闭协议数据库文件
endprotoent(); endprotoent();
// 返回测试成功标志
return ICUNIT_SUCCESS; return ICUNIT_SUCCESS;
} }
// 定义一个测试注册函数用于将ProtoentTest测试添加到测试套件中
void NetNetDbTest001(void) void NetNetDbTest001(void)
{ {
// 添加测试用例到测试框架中,包括测试用例名称、测试函数、测试类别、测试协议、测试级别和测试类型
TEST_ADD_CASE(__FUNCTION__, ProtoentTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION); TEST_ADD_CASE(__FUNCTION__, ProtoentTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION);
} }

@ -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) static int HerrorTest(void)
{ {
// 调用hstrerror函数传入一个错误码TRY_AGAIN是一个宏通常代表一个网络相关的错误码
// hstrerror函数用于将错误码转换为对应的错误描述字符串
const char *err = hstrerror(TRY_AGAIN); const char *err = hstrerror(TRY_AGAIN);
// 断言确保hstrerror返回的错误描述字符串不为空
// 如果为空,则测试失败,返回-1作为错误码
ICUNIT_ASSERT_NOT_EQUAL(err, NULL, -1); ICUNIT_ASSERT_NOT_EQUAL(err, NULL, -1);
// 调用herror函数传入hstrerror返回的错误描述字符串
// herror函数通常用于将错误描述打印到标准错误输出stderr
herror(err); herror(err);
// 返回测试成功标志
return ICUNIT_SUCCESS; return ICUNIT_SUCCESS;
} }
// 定义一个测试注册函数用于将HerrorTest测试添加到测试套件中
void NetNetDbTest013(void) void NetNetDbTest013(void)
{ {
// 使用TEST_ADD_CASE宏添加测试用例到测试框架中
// 宏的参数包括测试用例的名称(当前函数名)、测试函数、测试类别、测试协议、测试级别和测试类型
// 这些参数帮助测试框架组织和执行测试用例
TEST_ADD_CASE(__FUNCTION__, HerrorTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION); TEST_ADD_CASE(__FUNCTION__, HerrorTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION);
} }
Loading…
Cancel
Save