1 /*
2 * Copyright (c) 2021 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 "hctest.h"
17 #include "iot_errno.h"
18 #include "iot_uart.h"
19
20 #define TEST_UART_SIZE 8
21 const unsigned int INIT_UART_BAUD_RATE = 115200;
22 const unsigned int COMPILABILITY_TEST_UART_PORT = 0xFFFFFFFF;
23
24 /**
25 * @tc.desc : this suite is used to test basic flow and interface dependency(Compile overlay)
26 * @param : subsystem name is wifiiot
27 * @param : module name is wifiiotlite
28 * @param : test suit name is UtilsFileFuncTestSuite
29 */
30 LITE_TEST_SUIT(wifiiot, wifiiotlite, IotUartTestSuite);
31
32 /**
33 * @tc.setup : setup for all testcases
34 * @return : setup result, TRUE is success, FALSE is fail
35 */
IotUartTestSuiteSetUp(void)36 static BOOL IotUartTestSuiteSetUp(void)
37 {
38 return TRUE;
39 }
40
41 /**
42 * @tc.teardown : teardown for all testcases
43 * @return : teardown result, TRUE is success, FALSE is fail
44 */
IotUartTestSuiteTearDown(void)45 static BOOL IotUartTestSuiteTearDown(void)
46 {
47 printf("+-------------------------------------------+\n");
48 return TRUE;
49 }
50
51 /**
52 * @tc.number : SUB_UTILS_WIFIIOT_API_5000
53 * @tc.name : UART operation with IoTUartInit
54 * @tc.desc : [C- SOFTWARE -0200]
55 */
56 LITE_TEST_CASE(IotUartTestSuite, testIotUart001, Function | MediumTest | Level1)
57 {
58 IotUartAttribute uartAttr;
59 uartAttr.baudRate = INIT_UART_BAUD_RATE,
60 uartAttr.dataBits = IOT_UART_DATA_BIT_8;
61 uartAttr.stopBits = IOT_UART_STOP_BIT_1;
62 uartAttr.parity = IOT_UART_PARITY_NONE;
63 uartAttr.rxBlock = IOT_UART_BLOCK_STATE_NONE_BLOCK;
64 uartAttr.txBlock = IOT_UART_BLOCK_STATE_NONE_BLOCK;
65 uartAttr.pad ='M'; // Reserved field
66
67 IoTUartInit(COMPILABILITY_TEST_UART_PORT, &uartAttr);
68 };
69
70 /**
71 * @tc.number : SUB_UTILS_WIFIIOT_API_5100
72 * @tc.name : UART operation with IoTUartWrite
73 * @tc.desc : [C- SOFTWARE -0200]
74 */
75 LITE_TEST_CASE(IotUartTestSuite, testIotUart002, Function | MediumTest | Level1)
76 {
77 unsigned char uartWriteBuff[] = "hello uart!";
78 IoTUartWrite(COMPILABILITY_TEST_UART_PORT, uartWriteBuff, sizeof(uartWriteBuff));
79 };
80
81 /**
82 * @tc.number : SUB_UTILS_WIFIIOT_API_5200
83 * @tc.name : UART operation with IoTUartRead
84 * @tc.desc : [C- SOFTWARE -0200]
85 */
86 LITE_TEST_CASE(IotUartTestSuite, testIotUart003, Function | MediumTest | Level1)
87 {
88 unsigned char uartReadBuff[TEST_UART_SIZE] = {0};
89 IoTUartRead(COMPILABILITY_TEST_UART_PORT, uartReadBuff, sizeof(uartReadBuff));
90 };
91
92 /**
93 * @tc.number : SUB_UTILS_WIFIIOT_API_5300
94 * @tc.name : UART operation with IoTUartSetFlowCtrl
95 * @tc.desc : [C- SOFTWARE -0200]
96 */
97 LITE_TEST_CASE(IotUartTestSuite, testIotUart004, Function | MediumTest | Level1)
98 {
99 IoTUartSetFlowCtrl(COMPILABILITY_TEST_UART_PORT, IOT_FLOW_CTRL_NONE);
100 };
101
102 /**
103 * @tc.number : SUB_UTILS_WIFIIOT_API_5400
104 * @tc.name : UART operation with IoTUartDeinit
105 * @tc.desc : [C- SOFTWARE -0200]
106 */
107 LITE_TEST_CASE(IotUartTestSuite, testIotUart005, Function | MediumTest | Level1)
108 {
109 IoTUartDeinit(COMPILABILITY_TEST_UART_PORT);
110 };
111
112 RUN_TEST_SUITE(IotUartTestSuite);
113