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