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 #include "test.h"
19
20 /**
21 * @tc.name : cfsetospeed_0100
22 * @tc.desc : Verify information that can set output baud rate (parameter valid).
23 * @tc.level : Level 0
24 */
cfsetospeed_0100(void)25 void cfsetospeed_0100(void)
26 {
27 struct termios t = {};
28 int result = cfsetospeed(&t, B1200);
29 if (result != 0) {
30 t_error("%s cfsetospeed failed\n", __func__);
31 }
32
33 speed_t ret = cfgetospeed(&t);
34 if (ret != (speed_t)(B1200)) {
35 t_error("%s cfgetospeed failed\n", __func__);
36 }
37 }
38
39 /**
40 * @tc.name : cfsetospeed_0200
41 * @tc.desc : Verify that the output baud rate cannot be set (the speed parameter is invalid).
42 * @tc.level : Level 2
43 */
cfsetospeed_0200(void)44 void cfsetospeed_0200(void)
45 {
46 struct termios t = {};
47 errno = 0;
48
49 int result = cfsetospeed(&t, 1200);
50 if (result != -1) {
51 t_error("%s cfsetospeed should be failed\n", __func__);
52 }
53 if (errno != EINVAL) {
54 t_error("%s errno should be EINVAL", __func__);
55 }
56 }
57
main(int argc,char * argv[])58 int main(int argc, char *argv[])
59 {
60 cfsetospeed_0100();
61 cfsetospeed_0200();
62 return t_status;
63 }