• 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 <fcntl.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <sys/uio.h>
20 #include <unistd.h>
21 #include "test.h"
22 
23 /**
24  * @tc.name      : writev_0100
25  * @tc.desc      : Writes iovcnt buffers of data described by iov to the file associated with fd
26  * @tc.level     : Level 0
27  */
writev_0100(void)28 void writev_0100(void)
29 {
30     char *str0 = "test ";
31     char *str1 = "writev\n";
32     struct iovec iov[2];
33 
34     iov[0].iov_base = str0;
35     iov[0].iov_len = strlen(str0) + 1;
36     iov[1].iov_base = str1;
37     iov[1].iov_len = strlen(str1) + 1;
38 
39     ssize_t result = writev(STDOUT_FILENO, iov, 2);
40     if (result != (iov[0].iov_len + iov[1].iov_len)) {
41         t_error("%s writev falied", __func__);
42     }
43 }
44 
45 /**
46  * @tc.name      : writev_0200
47  * @tc.desc      : When iovlen is equal to 0, the data in the structure iov will not be read
48  * @tc.level     : Level 1
49  */
writev_0200(void)50 void writev_0200(void)
51 {
52     char *str0 = "test ";
53     char *str1 = "writev\n";
54     struct iovec iov[2];
55 
56     iov[0].iov_base = str0;
57     iov[0].iov_len = 0;
58     iov[1].iov_base = str1;
59     iov[1].iov_len = strlen(str1) + 1;
60 
61     ssize_t result = writev(STDOUT_FILENO, iov, 2);
62     if (result != (iov[0].iov_len + iov[1].iov_len)) {
63         t_error("%s writev falied", __func__);
64     }
65 }
66 
67 /**
68  * @tc.name      : writev_0300
69  * @tc.desc      : Invalid parameter input
70  * @tc.level     : Level 2
71  */
writev_0300(void)72 void writev_0300(void)
73 {
74     ssize_t result = writev(-1, NULL, -1);
75     if (result != -1) {
76         t_error("%s writev should falied", __func__);
77     }
78 }
79 
main(int argc,char * argv[])80 int main(int argc, char *argv[])
81 {
82     writev_0100();
83     writev_0200();
84     writev_0300();
85     return t_status;
86 }