• 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 <errno.h>
17 #include <termios.h>
18 
19 #include "test.h"
20 
21 const cc_t veof = (cc_t)0x07;
22 
23 /**
24  * @tc.name      : tcsetattr_0100
25  * @tc.desc      : set terminal attributes
26  * @tc.level     : Level 0
27  */
tcsetattr_0100(void)28 void tcsetattr_0100(void)
29 {
30     struct termios tio = {};
31     tio.c_cc[VEOF] = veof;
32     int result = tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio);
33     if (result != 0) {
34         t_error("%s failed: result = %d\n", __func__, result);
35     }
36 
37     result = tcgetattr(STDIN_FILENO, &tio);
38     if (result != 0) {
39         t_error("%s failed: result = %d\n", __func__, result);
40     }
41 
42     if (tio.c_cc[VEOF] != veof) {
43         t_error("%s failed: tio.c_cc[%d] = %#x\n", __func__, VEOF, tio.c_cc[VEOF]);
44     }
45 }
46 
47 /**
48  * @tc.name      : tcsetattr_0200
49  * @tc.desc      : set terminal attributes with invalid parameters
50  * @tc.level     : Level 2
51  */
tcsetattr_0200(void)52 void tcsetattr_0200(void)
53 {
54     errno = 0;
55     int result = tcsetattr(-1, -1, NULL);
56     if (result == 0) {
57         t_error("%s failed: result = %d\n", __func__, result);
58     }
59 
60     if (errno == 0) {
61         t_error("%s failed: errno = %d\n", __func__, errno);
62     }
63 }
64 
main(int argc,char * argv[])65 int main(int argc, char *argv[])
66 {
67     tcsetattr_0100();
68     tcsetattr_0200();
69 
70     return t_status;
71 }
72