提交 3d00a7d2 编写于 作者: Y yinjiaming

fix: 实现了musl库net模块中的一些函数接口和相应的测试用例

【背景】
musl库中关于net模块有一些API需要实现,相应的测试用例设计得不是非常合理.

【修改方案】
删去了与实现的API不相关的测试用例,修改了测试用例中一些错误的地方,
修改了测试用例中依赖硬件环境的一些地方。

【影响】
对现有的产品编译不会有影响。

re #I4JQI1
Signed-off-by: Nyinjiaming <yinjiaming@huawei.com>
Change-Id: If57f50b025c84aa79107691efb091dde8e7b2156
上级 95248d44
......@@ -49,7 +49,6 @@ netdb_sources_full = [
"$TEST_UNITTEST_DIR/net/netdb/full/net_netdb_test_010.cpp",
"$TEST_UNITTEST_DIR/net/netdb/full/net_netdb_test_011.cpp",
"$TEST_UNITTEST_DIR/net/netdb/full/net_netdb_test_012.cpp",
"$TEST_UNITTEST_DIR/net/netdb/full/net_netdb_test_014.cpp",
"$TEST_UNITTEST_DIR/net/netdb/full/net_netdb_test_015.cpp",
"$TEST_UNITTEST_DIR/net/netdb/full/net_netdb_test_016.cpp",
"$TEST_UNITTEST_DIR/net/netdb/full/net_netdb_test_017.cpp",
......
......@@ -35,6 +35,17 @@
static int AddrInfoTest(void)
{
// Prerequisite: correct DNS servers must be configured.
char host_file[] = "127.0.0.2 example.com\n", serv_file[] = "ftp 21/tcp\n";
char *pathList[] = {"/etc/hosts", "/etc/services"};
char *streamList[] = {host_file, serv_file};
int streamLen[] = {sizeof(host_file), sizeof(serv_file)};
const int file_number = 2;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct addrinfo *addr = NULL;
int ret = getaddrinfo("example.com", "ftp", NULL, &addr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
......@@ -50,6 +61,7 @@ static int AddrInfoTest(void)
const char *p = gai_strerror(EAI_AGAIN);
ICUNIT_ASSERT_NOT_EQUAL(p, NULL, -1);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -34,8 +34,19 @@
static int GetHostByAddrTest(void)
{
char host_file[] = "127.0.0.1 localhost\n100.0.0.0 example.com example\n";
char *pathList[] = {"/etc/hosts"};
char *streamList[] = {host_file};
int streamLen[] = {sizeof(host_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct in_addr ia;
int length = 4;
int length = 4; // the address length is 4;
ia.s_addr = inet_addr("127.0.0.1");
struct hostent *addr = gethostbyaddr(&ia, sizeof ia, AF_INET);
ICUNIT_ASSERT_NOT_EQUAL(addr, NULL, -1);
......@@ -43,19 +54,18 @@ static int GetHostByAddrTest(void)
ICUNIT_ASSERT_STRING_EQUAL(addr->h_name, "localhost", -1);
ICUNIT_ASSERT_EQUAL(addr->h_length, length, -1);
ia.s_addr = inet_addr("100.109.180.184");
ia.s_addr = inet_addr("100.0.0.0");
addr = gethostbyaddr(&ia, sizeof ia, AF_INET);
ICUNIT_ASSERT_NOT_EQUAL(addr, NULL, -1);
ICUNIT_ASSERT_EQUAL(addr->h_addrtype, AF_INET, addr->h_addrtype);
ICUNIT_ASSERT_STRING_EQUAL(addr->h_name, "szvphisprb93341", -1);
ICUNIT_ASSERT_STRING_EQUAL(addr->h_aliases[0], "szvphisprb93341", -1);
ICUNIT_ASSERT_STRING_EQUAL(addr->h_name, "example.com", -1);
errno = 0;
ia.s_addr = inet_addr("127.0.0.0");
addr = gethostbyaddr(&ia, sizeof ia, AF_INET);
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
return ICUNIT_SUCCESS;
    RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -34,6 +34,16 @@
static int GetHostByNameTest(void)
{
char host_file[] = "127.0.0.1 localhost\n";
char *pathList[] = {"/etc/hosts"};
char *streamList[] = {host_file};
int streamLen[] = {sizeof(host_file)};
int flag = PrepareFileEnv(pathList, streamList, streamLen, 1);
if (flag != 0) {
RecoveryFileEnv(pathList, 1);
return -1;
}
struct hostent *addr = gethostbyname("localhost");
ICUNIT_ASSERT_NOT_EQUAL(addr, NULL, -1);
ICUNIT_ASSERT_EQUAL(strcmp(addr->h_name, "localhost"), 0, -1);
......@@ -49,6 +59,7 @@ static int GetHostByNameTest(void)
addr = gethostbyname("lo");
ICUNIT_ASSERT_EQUAL(addr, NULL, -1);
RecoveryFileEnv(pathList, 1);
return ICUNIT_SUCCESS;
}
......
......@@ -34,6 +34,17 @@
static int GetHostByNameRTest(void)
{
char host_file[] = "127.0.0.1 localhost\n";
char *pathList[] = {"/etc/hosts"};
char *streamList[] = {static_cast<char *>(host_file)};
int streamLen[] = {sizeof(host_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct hostent addr, *result = NULL;
char buf[1024];
char buf1[1];
......@@ -60,6 +71,7 @@ static int GetHostByNameRTest(void)
ret = gethostbyname_r("lo", &addr, buf, sizeof buf, &result, &err);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -34,6 +34,17 @@
static int GetHostByName2Test(void)
{
char host_file[] = "127.0.0.1 localhost\n";
char *pathList[] = {"/etc/hosts"};
char *streamList[] = {static_cast<char *>(host_file)};
int streamLen[] = {sizeof(host_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct hostent *addr = gethostbyname2("localhost", AF_INET);
ICUNIT_ASSERT_NOT_EQUAL(addr, NULL, -1);
ICUNIT_ASSERT_EQUAL(strcmp(addr->h_name, "localhost"), 0, -1);
......@@ -51,6 +62,7 @@ static int GetHostByName2Test(void)
addr = gethostbyname2("localh", AF_INET);
ICUNIT_ASSERT_EQUAL(addr, NULL, -1);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -33,6 +33,17 @@
static int GetHostByName2RTest(void)
{
char host_file[] = "127.0.0.1 localhost\n";
char *pathList[] = {"/etc/hosts"};
char *streamList[] = {host_file};
int streamLen[] = {sizeof(host_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct hostent addr, *result = NULL;
char buf[1024];
char buf1[1];
......@@ -59,6 +70,7 @@ static int GetHostByName2RTest(void)
ret = gethostbyname2_r("lo", AF_INET, &addr, buf, sizeof buf, &result, &err);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -35,16 +35,29 @@
static int GetServByPortTest(void)
{
// refer to the `/etc/services' file.
char serv_file[] = "ssh 22/tcp\n";
char *pathList[] = {"/etc/services"};
char *streamList[] = {static_cast<char *>(serv_file)};
int streamLen[] = {sizeof(serv_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
const int test_port_no = 22; // ssh port number is 22
struct servent *se1 = nullptr;
struct servent *se = getservbyport(htons(22), "tcp");
struct servent *se = getservbyport(htons(test_port_no), "tcp");
ICUNIT_ASSERT_NOT_EQUAL(se, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(se->s_name, "ssh", -1);
ICUNIT_ASSERT_STRING_EQUAL(se->s_proto, "tcp", -1);
ICUNIT_ASSERT_STRING_EQUAL(se->s_aliases[0], "ssh", -1);
se1 = getservbyport(htons(22), "tp");
se1 = getservbyport(htons(test_port_no), "tp");
ICUNIT_ASSERT_EQUAL(se1, nullptr, -1);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -35,26 +35,42 @@
static int GetServByPortRTest(void)
{
// refer to the `/etc/services' file.
char serv_file[] = "ssh 22/tcp\n";
char *pathList[] = {"/etc/services"};
char *streamList[] = {static_cast<char *>(serv_file)};
int streamLen[] = {sizeof(serv_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct servent se, *result = NULL;
char buf[1024];
char buf1[2];
int ret = getservbyport_r(htons(22), "udp", &se, buf, sizeof buf, &result);
const int test_port_no = 22; // ssh port number is 22
int ret = getservbyport_r(htons(test_port_no), "tcp", &se, buf, sizeof buf, &result);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(result, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(se.s_name, "ssh", -1);
ICUNIT_ASSERT_STRING_EQUAL(se.s_proto, "udp", -1);
ICUNIT_ASSERT_STRING_EQUAL(se.s_proto, "tcp", -1);
ICUNIT_ASSERT_STRING_EQUAL(se.s_aliases[0], "ssh", -1);
ICUNIT_ASSERT_STRING_EQUAL(result->s_name, "ssh", -1);
ICUNIT_ASSERT_STRING_EQUAL(result->s_proto, "udp", -1);
ICUNIT_ASSERT_STRING_EQUAL(result->s_proto, "tcp", -1);
ICUNIT_ASSERT_STRING_EQUAL(result->s_aliases[0], "ssh", -1);
ret = getservbyport_r(htons(22), "udp", &se, buf1, sizeof buf1, &result);
ret = getservbyport_r(htons(test_port_no), "udp", &se, buf, sizeof buf, &result);
ICUNIT_ASSERT_EQUAL(ret, ENOENT, -1);
ret = getservbyport_r(htons(test_port_no), "udp", &se, buf1, sizeof buf1, &result);
ICUNIT_ASSERT_EQUAL(ret, ERANGE, ret);
ret = getservbyport_r(htons(22), "ud", &se, buf, sizeof buf, &result);
ret = getservbyport_r(htons(test_port_no), "ud", &se, buf, sizeof buf, &result);
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
/*
* 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 <net/if.h>
static int IfNameIndexTest(void)
{
struct if_nameindex *idx = if_nameindex();
ICUNIT_ASSERT_NOT_EQUAL(idx, NULL, -1);
if_freenameindex(idx);
return ICUNIT_SUCCESS;
}
void NetNetDbTest014(void)
{
TEST_ADD_CASE(__FUNCTION__, IfNameIndexTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION);
}
......@@ -44,10 +44,6 @@ static int IfNameToIndexTest(void)
ICUNIT_ASSERT_NOT_EQUAL(str, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(if_name, "lo", -1);
str = if_indextoname(3, if_name);
ICUNIT_ASSERT_EQUAL(str, nullptr, -1);
ICUNIT_ASSERT_EQUAL(errno, ENXIO, errno);
ret = if_nametoindex("eth1");
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENODEV, errno);
......
......@@ -32,6 +32,23 @@
static int GetServByNameTest(void)
{
char serv_file[] = "echo 7/tcp\n"
"echo 7/udp\n"
"discard 9/tcp sink null\n"
"discard 9/udp sink null\n"
"systat 11/tcp users\n"
"ssh 22/tcp\n";
char *pathList[] = {"/etc/services"};
char *streamList[] = {static_cast<char *>(serv_file)};
int streamLen[] = {sizeof(serv_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct servent *se1 = nullptr;
struct servent *se2 = nullptr;
......@@ -53,6 +70,7 @@ static int GetServByNameTest(void)
se2 = getservbyname("systat", "udp");
ICUNIT_ASSERT_EQUAL(se2, nullptr, -1);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -32,6 +32,17 @@
static int GetServByNameRTest(void)
{
char serv_file[] = "ssh 22/tcp\n";
char *pathList[] = {"/etc/services"};
char *streamList[] = {static_cast<char *>(serv_file)};
int streamLen[] = {sizeof(serv_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct servent se;
struct servent *result = NULL;
char buf1[1024] = { 0 };
......@@ -58,6 +69,7 @@ static int GetServByNameRTest(void)
ret = getservbyname_r("sh", "tcp", &se, buf1, sizeof buf1, &result);
ICUNIT_ASSERT_EQUAL(ret, ENOENT, ret);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -32,6 +32,28 @@
static int GetServEntTest(void)
{
char serv_file[] = "tcpmux 1/tcp # TCP port service multiplexer\n"
"echo 7/tcp\n"
"echo 7/udp\n"
"discard 9/tcp sink null\n"
"ssh 100000/tcp\n"
"ssh /tcp\n"
"ssh 22/";
char *pathList[] = {"/etc/services"};
char *streamList[] = {static_cast<char *>(serv_file)};
int streamLen[] = {sizeof(serv_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
/* tcpmux,echo,discard port number is 1,7,9 */
const int tcpmux_port_no = 1;
const int echo_port_no = 7;
const int discard_port_no = 9;
struct servent *se1 = nullptr;
struct servent *se2 = nullptr;
struct servent *se3 = nullptr;
......@@ -40,7 +62,7 @@ static int GetServEntTest(void)
ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(se1->s_name, "tcpmux", -1);
ICUNIT_ASSERT_STRING_EQUAL(se1->s_proto, "tcp", -1);
ICUNIT_ASSERT_EQUAL(se1->s_port, ntohs(1), -1);
ICUNIT_ASSERT_EQUAL(se1->s_port, ntohs(tcpmux_port_no), -1);
endservent();
se2 = getservent();
......@@ -60,20 +82,28 @@ static int GetServEntTest(void)
ICUNIT_ASSERT_NOT_EQUAL(se3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->s_name, "echo", -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->s_proto, "tcp", -1);
ICUNIT_ASSERT_EQUAL(se3->s_port, ntohs(7), -1);
ICUNIT_ASSERT_EQUAL(se3->s_port, ntohs(echo_port_no), -1);
se3 = getservent();
ICUNIT_ASSERT_NOT_EQUAL(se3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->s_name, "echo", -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->s_proto, "udp", -1);
ICUNIT_ASSERT_EQUAL(se3->s_port, ntohs(7), -1);
ICUNIT_ASSERT_EQUAL(se3->s_port, ntohs(echo_port_no), -1);
se3 = getservent();
ICUNIT_ASSERT_NOT_EQUAL(se3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->s_name, "discard", -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->s_proto, "tcp", -1);
ICUNIT_ASSERT_EQUAL(se3->s_port, ntohs(9), -1);
ICUNIT_ASSERT_EQUAL(se3->s_port, ntohs(discard_port_no), -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->s_aliases[0], "sink", -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->s_aliases[1], "null", -1);
ICUNIT_ASSERT_EQUAL(se3->s_aliases[2], nullptr, -1);
se3 = getservent();
ICUNIT_ASSERT_EQUAL(se3, nullptr, -1);
endservent();
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -29,21 +29,37 @@
*/
#include "lt_net_netdb.h"
#include<arpa/nameser.h>
static int GetHostEntTest(void)
{
char host_file[] = "127.0.0.1 localhost #localhost\n"
"::1 ip6-localhost\n"
"10.0.0.0 example example.com example.cn\n"
"10.0.0.0\n"
"10.0.0 example.com";
char *pathList[] = {"/etc/hosts"};
char *streamList[] = {static_cast<char *>(host_file)};
int streamLen[] = {sizeof(host_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct hostent *se1 = nullptr;
struct hostent *se2 = nullptr;
struct hostent *se3 = nullptr;
int type = 2;
int length1 = 4;
int length2 = 16;
char addr[INET6_ADDRSTRLEN];
se1 = gethostent();
ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(se1->h_name, "localhost", -1);
ICUNIT_ASSERT_EQUAL(se1->h_addrtype, type, -1);
ICUNIT_ASSERT_EQUAL(se1->h_length, length1, -1);
ICUNIT_ASSERT_EQUAL(se1->h_addrtype, AF_INET, -1);
ICUNIT_ASSERT_EQUAL(se1->h_length, INADDRSZ, -1);
ICUNIT_ASSERT_STRING_EQUAL("127.0.0.1", inet_ntop(AF_INET, se1->h_addr_list[0], addr, INET_ADDRSTRLEN), -1);
ICUNIT_ASSERT_EQUAL(se1->h_aliases[0], nullptr, -1);
endhostent();
se2 = gethostent();
......@@ -62,15 +78,24 @@ static int GetHostEntTest(void)
se3 = gethostent();
ICUNIT_ASSERT_NOT_EQUAL(se3, nullptr, -1);
ICUNIT_ASSERT_EQUAL(se3->h_addrtype, AF_INET6, -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->h_name, "localhost", -1);
ICUNIT_ASSERT_EQUAL(se3->h_length, length2, -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->h_name, "ip6-localhost", -1);
ICUNIT_ASSERT_EQUAL(se3->h_length, IN6ADDRSZ, -1);
ICUNIT_ASSERT_STRING_EQUAL("::1", inet_ntop(AF_INET6, se3->h_addr_list[0], addr, INET6_ADDRSTRLEN), -1);
se3 = gethostent();
ICUNIT_ASSERT_NOT_EQUAL(se3, nullptr, -1);
ICUNIT_ASSERT_EQUAL(se3->h_addrtype, AF_INET, -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->h_name, "szvphisprb93341", -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->h_aliases[0], "szvphisprb93341.huawei.com", -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->h_name, "example", -1);
ICUNIT_ASSERT_STRING_EQUAL("10.0.0.0", inet_ntop(AF_INET, se3->h_addr_list[0], addr, INET_ADDRSTRLEN), -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->h_aliases[0], "example.com", -1);
ICUNIT_ASSERT_STRING_EQUAL(se3->h_aliases[1], "example.cn", -1);
ICUNIT_ASSERT_EQUAL(se3->h_aliases[2], nullptr, -1);
se3 = gethostent();
ICUNIT_ASSERT_EQUAL(se3, nullptr, -1);
endhostent();
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -32,6 +32,20 @@
static int GetNetEntTest(void)
{
char network_file[] = "# symbolic names for networks, see networks(5) for more information\n"
"link-local 169.254.0.0\n"
"example 192.168.1.0 network example-network\n"
"test1";
char *pathList[] = {"/etc/networks"};
char *streamList[] = {static_cast<char *>(network_file)};
int streamLen[] = {sizeof(network_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct netent *se1 = nullptr;
struct netent *se2 = nullptr;
struct netent *se3 = nullptr;
......@@ -39,8 +53,9 @@ static int GetNetEntTest(void)
se1 = getnetent();
ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, "link-local", -1);
ICUNIT_ASSERT_EQUAL(se1->n_addrtype, 2, -1);
ICUNIT_ASSERT_EQUAL(se1->n_addrtype, AF_INET, -1);
ICUNIT_ASSERT_EQUAL(se1->n_net, inet_network("169.254.0.0"), -1);
ICUNIT_ASSERT_EQUAL(se1->n_aliases[0], nullptr, -1);
endnetent();
se2 = getnetent();
......@@ -56,6 +71,20 @@ static int GetNetEntTest(void)
ICUNIT_ASSERT_EQUAL(se1->n_addrtype, se3->n_addrtype, -1);
ICUNIT_ASSERT_EQUAL(se1->n_net, se3->n_net, -1);
se1 = getnetent();
ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, "example", -1);
ICUNIT_ASSERT_EQUAL(se1->n_addrtype, AF_INET, -1);
ICUNIT_ASSERT_EQUAL(se1->n_net, inet_network("192.168.1.0"), -1);
ICUNIT_ASSERT_STRING_EQUAL(se1->n_aliases[0], "network", -1);
ICUNIT_ASSERT_STRING_EQUAL(se1->n_aliases[1], "example-network", -1);
ICUNIT_ASSERT_EQUAL(se1->n_aliases[2], nullptr, -1);
se1 = getnetent();
ICUNIT_ASSERT_EQUAL(se1, nullptr, -1);
endnetent();
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -32,6 +32,18 @@
static int GetNetBynametTest(void)
{
char network_file[] = "# symbolic names for networks, see networks(5) for more information\n"
"link-local 169.254.0.0\n";
char *pathList[] = {"/etc/networks"};
char *streamList[] = {static_cast<char *>(network_file)};
int streamLen[] = {sizeof(network_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct netent *se1 = nullptr;
struct netent *se2 = nullptr;
struct netent *se3 = nullptr;
......@@ -39,7 +51,7 @@ static int GetNetBynametTest(void)
se1 = getnetbyname("link-local");
ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, "link-local", -1);
ICUNIT_ASSERT_EQUAL(se1->n_addrtype, 2, -1);
ICUNIT_ASSERT_EQUAL(se1->n_addrtype, AF_INET, -1);
ICUNIT_ASSERT_EQUAL(se1->n_net, inet_network("169.254.0.0"), -1);
se2 = getnetbyname("link");
......@@ -48,6 +60,7 @@ static int GetNetBynametTest(void)
se3 = getnetbyname("hs");
ICUNIT_ASSERT_EQUAL(se3, nullptr, -1);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -32,6 +32,18 @@
static int GetNetByAddrtTest(void)
{
char network_file[] = "# symbolic names for networks, see networks(5) for more information\n"
"link-local 169.254.0.0\n";
char *pathList[] = {"/etc/networks"};
char *streamList[] = {static_cast<char *>(network_file)};
int streamLen[] = {sizeof(network_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct netent *se1 = nullptr;
struct netent *se2 = nullptr;
struct netent *se3 = nullptr;
......@@ -39,7 +51,7 @@ static int GetNetByAddrtTest(void)
se1 = getnetbyaddr(inet_network("169.254.0.0"), AF_INET);
ICUNIT_ASSERT_NOT_EQUAL(se1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(se1->n_name, "link-local", -1);
ICUNIT_ASSERT_EQUAL(se1->n_addrtype, 2, -1);
ICUNIT_ASSERT_EQUAL(se1->n_addrtype, AF_INET, -1);
ICUNIT_ASSERT_EQUAL(se1->n_net, inet_network("169.254.0.0"), -1);
se2 = getnetbyaddr(inet_network("169.254.0.1"), AF_INET);
......@@ -48,6 +60,7 @@ static int GetNetByAddrtTest(void)
se3 = getnetbyaddr(inet_network("169.254.0.1"), AF_INET6);
ICUNIT_ASSERT_EQUAL(se3, nullptr, -1);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -52,7 +52,6 @@ void NetNetDbTest010(void);
void NetNetDbTest011(void);
void NetNetDbTest012(void);
void NetNetDbTest013(void);
void NetNetDbTest014(void);
void NetNetDbTest015(void);
void NetNetDbTest016(void);
void NetNetDbTest017(void);
......
......@@ -72,5 +72,206 @@ HWTEST_F(NetDbTest, NetNetDbTest013, TestSize.Level0)
NetNetDbTest013();
}
#endif
#if defined(LOSCFG_USER_TEST_FULL)
/* *
* @tc.name: NetNetDbTest018
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest018, TestSize.Level0)
{
NetNetDbTest018();
}
/* *
* @tc.name: NetNetDbTest002
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest002, TestSize.Level0)
{
NetNetDbTest002();
}
/* *
* @tc.name: NetNetDbTest003
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest003, TestSize.Level0)
{
NetNetDbTest003();
}
/* *
* @tc.name: NetNetDbTest004
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest004, TestSize.Level0)
{
NetNetDbTest004();
}
/* *
* @tc.name: NetNetDbTest006
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest006, TestSize.Level0)
{
NetNetDbTest006();
}
/* *
* @tc.name: NetNetDbTest007
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest007, TestSize.Level0)
{
NetNetDbTest007();
}
/* *
* @tc.name: NetNetDbTest008
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest008, TestSize.Level0)
{
NetNetDbTest008();
}
/* *
* @tc.name: NetNetDbTest009
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest009, TestSize.Level0)
{
NetNetDbTest009();
}
/* *
* @tc.name: NetNetDbTest010
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest010, TestSize.Level0)
{
NetNetDbTest010();
}
/* *
* @tc.name: NetNetDbTest011
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest011, TestSize.Level0)
{
NetNetDbTest011();
}
/* *
* @tc.name: NetNetDbTest012
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest012, TestSize.Level0)
{
NetNetDbTest012();
}
/* *
* @tc.name: NetNetDbTest015
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest015, TestSize.Level0)
{
NetNetDbTest015();
}
/* *
* @tc.name: NetNetDbTest016
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest016, TestSize.Level0)
{
NetNetDbTest016();
}
/* *
* @tc.name: NetNetDbTest017
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest017, TestSize.Level0)
{
NetNetDbTest017();
}
/* *
* @tc.name: NetNetDbTest019
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest019, TestSize.Level0)
{
NetNetDbTest019();
}
/* *
* @tc.name: NetNetDbTest020
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest020, TestSize.Level0)
{
NetNetDbTest020();
}
/* *
* @tc.name: NetNetDbTest021
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest021, TestSize.Level0)
{
NetNetDbTest021();
}
/* *
* @tc.name: NetNetDbTest022
* @tc.desc: function for NetDbTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(NetDbTest, NetNetDbTest022, TestSize.Level0)
{
NetNetDbTest022();
}
#endif
}
......@@ -34,6 +34,17 @@
static int EtherHosttonTest(void)
{
// suppose "0:0:0:0:0:0 localhost" in `/etc/ethers' file.
char ether_file[] = "0:0:0:0:0:0 localhost";
char *pathList[] = {"/etc/ethers"};
char *streamList[] = {static_cast<char *>(ether_file)};
int streamLen[] = {sizeof(ether_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct ether_addr addr, *eaddr = &addr;
int ret = ether_hostton("localhost", eaddr);
......@@ -45,6 +56,7 @@ static int EtherHosttonTest(void)
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[4], 0x00, eaddr->ether_addr_octet[4]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[5], 0x00, eaddr->ether_addr_octet[5]);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
......@@ -35,6 +35,17 @@
static int EtherNtohostTest(void)
{
// suppose "0:0:0:0:0:0 localhost" in `/etc/ethers' file.
char ether_file[] = "0:0:0:0:0:0 localhost";
char *pathList[] = {"/etc/ethers"};
char *streamList[] = {static_cast<char *>(ether_file)};
int streamLen[] = {sizeof(ether_file)};
const int file_number = 1;
int flag = PrepareFileEnv(pathList, streamList, streamLen, file_number);
if (flag != 0) {
RecoveryFileEnv(pathList, file_number);
return -1;
}
struct ether_addr addr = {{0,0,0,0,0,0}}, *eaddr = &addr;
char buf[100];
int ret = ether_ntohost(buf, eaddr);
......@@ -42,6 +53,7 @@ static int EtherNtohostTest(void)
ICUNIT_ASSERT_EQUAL(ret, 0, -1);
ICUNIT_ASSERT_EQUAL(strcmp("localhost", buf), 0, -1);
RecoveryFileEnv(pathList, file_number);
return ICUNIT_SUCCESS;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册