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 #include "hctest.h"
16 #include "iot_errno.h"
17 #ifdef CONFIG_I2C_SUPPORT
18 #include "iot_i2c.h"
19 #endif
20
21 const unsigned int INIT_BAUD_RATE = 115200;
22 const unsigned int COMPILABILITY_TEST_I2C_DEVICE = 0xFFFFFFFF;
23 const unsigned short COMPILABILITY_TEST_I2C_DEVICE_ADDR = 0xFFFF;
24 #define DATA_LEN 3
25
26
27 /**
28 * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
29 * @param : subsystem name is wifiiot
30 * @param : module name is wifiiotlite
31 * @param : test suit name is UtilsFileFuncTestSuite
32 */
33 LITE_TEST_SUIT(wifiiot, wifiiotlite, IotI2cTestSuite);
34
35 #ifdef CONFIG_I2C_SUPPORT
36
37 /**
38 * @tc.setup : setup for all testcases
39 * @return : setup result, TRUE is success, FALSE is fail
40 */
IotI2cTestSuiteSetUp(void)41 static BOOL IotI2cTestSuiteSetUp(void)
42 {
43 return TRUE;
44 }
45
46 /**
47 * @tc.teardown : teardown for all testcases
48 * @return : teardown result, TRUE is success, FALSE is fail
49 */
IotI2cTestSuiteTearDown(void)50 static BOOL IotI2cTestSuiteTearDown(void)
51 {
52 printf("+-------------------------------------------+\n");
53 return TRUE;
54 }
55
IOT_ResetFunc(void)56 void IOT_ResetFunc(void)
57 {
58 printf("Abnormal callback function\n");
59 }
60
61 /**
62 * @tc.number : SUB_UTILS_WIFIIOT_API_3100
63 * @tc.name : I2C operation with IoTI2cInit
64 * @tc.desc : [C- SOFTWARE -0200]
65 */
66 LITE_TEST_CASE(IotI2cTestSuite, testIotI2C001, Function | MediumTest | Level1)
67 {
68 unsigned int ret;
69 ret = IoTI2cInit(COMPILABILITY_TEST_I2C_DEVICE, INIT_BAUD_RATE);
70 };
71
72 /**
73 * @tc.number : SUB_UTILS_WIFIIOT_API_3200
74 * @tc.name : I2C operation with IoTI2cWrite
75 * @tc.desc : [C- SOFTWARE -0200]
76 */
77 LITE_TEST_CASE(IotI2cTestSuite, testIotI2C002, Function | MediumTest | Level1)
78 {
79 unsigned int ret;
80 unsigned char senddata[DATA_LEN] = {0};
81
82 senddata[0] = 0x0;
83 senddata[1] = 0x3;
84 ret = IoTI2cWrite(COMPILABILITY_TEST_I2C_DEVICE,
85 COMPILABILITY_TEST_I2C_DEVICE_ADDR,
86 (unsigned char*)&senddata,
87 DATA_LEN);
88 };
89
90 /**
91 * @tc.number : SUB_UTILS_WIFIIOT_API_3300
92 * @tc.name : I2C operation with IoTI2cRead
93 * @tc.desc : [C- SOFTWARE -0200]
94 */
95 LITE_TEST_CASE(IotI2cTestSuite, testIotI2C003, Function | MediumTest | Level1)
96 {
97 unsigned int ret;
98 unsigned char recvdata[DATA_LEN] = {0};
99
100 ret = IoTI2cRead(COMPILABILITY_TEST_I2C_DEVICE,
101 COMPILABILITY_TEST_I2C_DEVICE_ADDR,
102 (unsigned char*)&recvdata,
103 DATA_LEN);
104 };
105
106 /**
107 * @tc.number : SUB_UTILS_WIFIIOT_API_3400
108 * @tc.name : I2C operation with IoTI2cSetBaudrate
109 * @tc.desc : [C- SOFTWARE -0200]
110 */
111 LITE_TEST_CASE(IotI2cTestSuite, testIotI2C004, Function | MediumTest | Level1)
112 {
113 unsigned int ret;
114 ret = IoTI2cSetBaudrate(COMPILABILITY_TEST_I2C_DEVICE, INIT_BAUD_RATE);
115 };
116
117 /**
118 * @tc.number : SUB_UTILS_WIFIIOT_API_3500
119 * @tc.name : I2C operation with IoTI2cDeinit
120 * @tc.desc : [C- SOFTWARE -0200]
121 */
122 LITE_TEST_CASE(IotI2cTestSuite, testIotI2C005, Function | MediumTest | Level1)
123 {
124 unsigned int ret;
125 ret = IoTI2cDeinit(COMPILABILITY_TEST_I2C_DEVICE);
126 };
127 #endif
128
129 RUN_TEST_SUITE(IotI2cTestSuite);
130