• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *   http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <arpa/inet.h>
17 #include <ctype.h>
18 #include <netinet/in.h>
19 #include <netdb.h>
20 #include <stdio.h>
21 #include <sys/socket.h>
22 #include <stdbool.h>
23 #include "functionalext.h"
24 
25 typedef void (*TEST_FUN)();
26 const int32_t COUNT_ZERO = 0;
27 
28 /**
29  * @tc.name      : gethostbyname_r_0100
30  * @tc.desc      : Verify that the host information can be obtained
31  * @tc.level     : Level 0
32  */
gethostbyname_r_0100(void)33 void gethostbyname_r_0100(void)
34 {
35     bool flag = false;
36     int result = 10;
37     struct hostent h;
38     char buf[1024] = "\0";
39     size_t buflen;
40     struct hostent *res = NULL;
41     int err;
42     result = gethostbyname_r("127.0.0.1", &h, buf, 1024, &res, &err);
43     if (result == 0) {
44         flag = true;
45     }
46     EXPECT_TRUE("gethostbyname_r_0100", flag);
47     EXPECT_STREQ("gethostbyname_r_0100", h.h_name, "127.0.0.1");
48 }
49 
50 /**
51  * @tc.name      : gethostbyname_r_0200
52  * @tc.desc      : The host information cannot be obtained
53  * @tc.level     : Level 2
54  */
gethostbyname_r_0200(void)55 void gethostbyname_r_0200(void)
56 {
57     bool flag = false;
58     int result = 10;
59     struct hostent h;
60     char buf[1024] = "\0";
61     size_t buflen;
62     struct hostent *res = NULL;
63     int err;
64     result = gethostbyname_r("127.0.w.1", &h, buf, 1024, &res, &err);
65     if (result != 0) {
66         flag = true;
67     }
68     EXPECT_TRUE("gethostbyname_r_0200", flag);
69 }
70 
71 TEST_FUN G_Fun_Array[] = {
72     gethostbyname_r_0100,
73     gethostbyname_r_0200,
74 };
75 
main(int argc,char * argv[])76 int main(int argc, char *argv[])
77 {
78     int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
79     for (int pos = 0; pos < num; ++pos) {
80         G_Fun_Array[pos]();
81     }
82     return t_status;
83 }