• 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 <resolv.h>
17 #include "functionalext.h"
18 
19 /**
20  * @tc.name      : dn_comp_0100
21  * @tc.desc      : Verify domain name compression (all parameters are valid)
22  * @tc.level     : Level 0
23  */
dn_comp_0100(void)24 void dn_comp_0100(void)
25 {
26     char name[1024] = "www.baidu.com";
27     unsigned char buf[1024] = "\0";
28     int result = dn_comp(name, buf, 1024, NULL, NULL);
29     EXPECT_EQ("dn_comp_0100", result, 15);
30 }
31 
32 /**
33  * @tc.name      : dn_comp_0200
34  * @tc.desc      : Verify that the domain name cannot be compressed (SRC parameter invalid, length 1)
35  * @tc.level     : Level 1
36  */
dn_comp_0200(void)37 void dn_comp_0200(void)
38 {
39     char name[1024] = ".";
40     unsigned char buf[1024] = "\0";
41     int result = dn_comp(name, buf, 1024, NULL, NULL);
42     EXPECT_EQ("dn_comp_0200", result, 1);
43 }
44 
45 /**
46  * @tc.name      : dn_comp_0300
47  * @tc.desc      : Verify that the domain name cannot be compressed (SRC parameter invalid, length greater than 253)
48  * @tc.level     : Level 2
49  */
dn_comp_0300(void)50 void dn_comp_0300(void)
51 {
52     char name[1024];
53     for (int i = 0; i < 260; i++) {
54         name[i] = 'w';
55     }
56     unsigned char buf[1024] = "\0";
57     int result = dn_comp(name, buf, 1024, NULL, NULL);
58     EXPECT_EQ("dn_comp_0300", result, -1);
59 }
60 
61 /**
62  * @tc.name      : dn_comp_0400
63  * @tc.desc      : Verify that the domain name cannot be compressed (the space parameter is invalid, equal to 0)
64  * @tc.level     : Level 2
65  */
dn_comp_0400(void)66 void dn_comp_0400(void)
67 {
68     char name[1024] = "www.baidu.com";
69     unsigned char buf[1024] = "\0";
70     int result = dn_comp(name, buf, 0, NULL, NULL);
71     EXPECT_EQ("dn_comp_0400", result, -1);
72 }
73 
74 /**
75  * @tc.name      : dn_comp_0500
76  * @tc.desc      : Verify that the domain name cannot be compressed (space argument is invalid, less than 0)
77  * @tc.level     : Level 2
78  */
dn_comp_0500(void)79 void dn_comp_0500(void)
80 {
81     char name[1024] = "www.baidu.com";
82     unsigned char buf[1024] = "\0";
83     int result = dn_comp(name, buf, -1, NULL, NULL);
84     EXPECT_EQ("dn_comp_0500", result, -1);
85 }
86 
87 /**
88  * @tc.name      : dn_comp_0600
89  * @tc.desc      : Verify that the domain name cannot be compressed (space argument is invalid, equal to 1)
90  * @tc.level     : Level 2
91  */
dn_comp_0600(void)92 void dn_comp_0600(void)
93 {
94     char name[1024] = "www.baidu.com";
95     unsigned char buf[1024] = "\0";
96     int result = dn_comp(name, buf, 1, NULL, NULL);
97     EXPECT_EQ("dn_comp_0600", result, -1);
98 }
99 
main(int argc,char * argv[])100 int main(int argc, char *argv[])
101 {
102     dn_comp_0100();
103     dn_comp_0200();
104     dn_comp_0300();
105     dn_comp_0400();
106     dn_comp_0500();
107     dn_comp_0600();
108     return t_status;
109 }