• 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 <sys/utsname.h>
17 #include <unistd.h>
18 #include "functionalext.h"
19 
20 /**
21  * @tc.name      : getdomainname_0100
22  * @tc.desc      : Verify domain name (valid)
23  * @tc.level     : Level 0
24  */
getdomainname_0100(void)25 void getdomainname_0100(void)
26 {
27     struct utsname u;
28     int ret = uname(&u);
29     EXPECT_EQ("getdomainname_0100", ret, 0);
30 
31     char buf[sizeof(u.domainname)];
32     int result = getdomainname(buf, sizeof(buf));
33     EXPECT_EQ("getdomainname_0100", result, 0);
34     EXPECT_STREQ("getdomainname_0100", u.domainname, buf);
35 }
36 
37 /**
38  * @tc.name      : getdomainname_0200
39  * @tc.desc      : Verify domain name cannot be obtained (len parameter invalid, 0)
40  * @tc.level     : Level 2
41  */
getdomainname_0200(void)42 void getdomainname_0200(void)
43 {
44     struct utsname u;
45     int ret = uname(&u);
46     EXPECT_EQ("getdomainname_0100", ret, 0);
47 
48     char buf[sizeof(u.domainname)];
49     int result = getdomainname(buf, 0);
50     EXPECT_EQ("getdomainname_0200", result, -1);
51 }
52 
53 /**
54  * @tc.name      : getdomainname_0300
55  * @tc.desc      : Failed to obtain domain name (len parameter invalid, less than domain name length)
56  * @tc.level     : Level 2
57  */
getdomainname_0300(void)58 void getdomainname_0300(void)
59 {
60     struct utsname u;
61     int ret = uname(&u);
62     EXPECT_EQ("getdomainname_0100", ret, 0);
63 
64     char buf[sizeof(u.domainname)];
65     int result = getdomainname(buf, 1);
66     EXPECT_EQ("getdomainname_0300", result, -1);
67 }
68 
main(int argc,char * argv[])69 int main(int argc, char *argv[])
70 {
71     getdomainname_0100();
72     getdomainname_0200();
73     getdomainname_0300();
74     return t_status;
75 }