UartDevice:backup.

This commit is contained in:
Fancy code 2024-01-30 02:40:26 -08:00
parent 6e11dc58f6
commit c1a5ad44a9
6 changed files with 70 additions and 14 deletions

View File

@ -3,7 +3,22 @@
  便于对测试用例进行管理,指定测试用例开发规范。
## 1.1. 命名规则
* 测试用例命名:
### 1.1.1. 基本概念
**单元测试**单元测试指对单一功能接口的测试一般不需要或少量使用gtest的mock功能即可完成测试不需要实际链接外部接口对模块内部代码功能进行有效验证
**用例所属模块**:测试时锁定目标测试用例的作用;
**集成测试**集成测试指对复杂业务进行测试往往需要跨多层级多模块需要大量使用gtest的mock功能才能完成的复杂逻辑测试一般不针对代码本身而是针对产品定义的功能进行有效验证
**测试用例**
1. EXAMPLE:对模块接口进行使用演示的测试用例;
2. AUTO:自动化运行的测试用例;
3. STRESS:压力测试用例,一般不在单次测试中执行;
### 1.1.2. 测试用例命名:
1. 测试用例类型含单元测试UNIT和集成测试INTEGRATION
2. 用例所属模块:大小驼峰;
3. 测试用例属性EXAMPLE/AUTO/STRESS
@ -11,13 +26,15 @@
示例:
该测试用例标识属于SharedData模块的单元测试作为example具有演示接口使用规范的作用测试用例名为Deme7。
```
TEST(SharedDataTest, UNIT_SharedData_EXAMPLE_Demo7)
{
// TODO:
}
```
* 测试源码文件命名:
### 1.1.3. 测试源码文件命名:
1. 每个测试可执行文件都有一个标准mian函数文件名统一为mainTest.cpp;
```
#include <gmock/gmock.h>

View File

@ -45,7 +45,7 @@ TEST(UartDeviceTest, UNIT_UartDevice_EXAMPLE_Demo)
{
CreateLogModule();
ILogInit(LOG_INSTANCE_TYPE_END);
uart_info device = {
UartInfo device = {
"dev/s1",
};
void *object = CreateUartDevice(device);

View File

@ -22,7 +22,7 @@
namespace UartDeviceMockTest
{
const char *gDeviceName = "dev/s1";
static uart_info gUartDevice = {
static UartInfo gUartDevice = {
gDeviceName,
1152000,
'N',
@ -85,7 +85,7 @@ TEST_F(UartDeviceMockTest, UNIT_UartDevice_EXAMPLE_AUTO_Demo)
TEST_F(UartDeviceMockTest, UNIT_UartDevice_AUTO_ParameterEarror)
{
char *deviceName = nullptr;
static uart_info uartDevice = {
static UartInfo uartDevice = {
deviceName,
1152000,
'N',
@ -111,7 +111,7 @@ TEST_F(UartDeviceMockTest, UNIT_UartDevice_AUTO_ParameterEarror2)
// const char *SEND_BUF = "TEST";
// char *deviceName = (char *)malloc(strlen(SEND_BUF) + 1);
// memset(deviceName, 0, strlen(SEND_BUF) + 1);
// static uart_info uartDevice = {
// static UartInfo uartDevice = {
// "deviceName",
// 1152000,
// 'N',

View File

@ -28,13 +28,13 @@ public:
* @param mock
* @param uart
*/
void RegisterUartDevice(std::shared_ptr<LinuxTest> &mock, const uart_info &uart);
void RegisterUartDevice(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart);
/**
* @brief
*
* @param uart
*/
void UnregisterUartDevice(const uart_info &uart);
void UnregisterUartDevice(const UartInfo &uart);
/**
* @brief Set the Send Api object
*
@ -42,7 +42,7 @@ public:
* @param uart
* @param length
*/
void SetSendApiOnce(std::shared_ptr<LinuxTest> &mock, const uart_info &uart, const ssize_t &length);
void SetSendApiOnce(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart, const ssize_t &length);
/**
* @brief Set the Recv Api Once object
*
@ -51,7 +51,7 @@ public:
* @param recvBuff
* @param length
*/
void SetRecvApiOnce(std::shared_ptr<LinuxTest> &mock, const uart_info &uart, void *recvBuff, const ssize_t &length);
void SetRecvApiOnce(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart, void *recvBuff, const ssize_t &length);
private:
std::map<const char *, int> mDeviceMap;

View File

@ -16,7 +16,7 @@
#include "ILog.h"
#include <thread>
static size_t WRITE_COUNT = -1;
void UartDeviceTestTool::RegisterUartDevice(std::shared_ptr<LinuxTest> &mock, const uart_info &uart)
void UartDeviceTestTool::RegisterUartDevice(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart)
{
if (nullptr == uart.mDevice) {
LogError("Parament error, nullptr == uartInfo.mDevice\n");
@ -42,7 +42,7 @@ void UartDeviceTestTool::RegisterUartDevice(std::shared_ptr<LinuxTest> &mock, co
EXPECT_CALL(*mock.get(), fx_read(uartFd, _, _)).WillRepeatedly(DoAll(Return(READ_NOTHING)));
mDeviceMap[uart.mDevice] = uartFd;
}
void UartDeviceTestTool::UnregisterUartDevice(const uart_info &uart)
void UartDeviceTestTool::UnregisterUartDevice(const UartInfo &uart)
{
std::map<const char *, int>::iterator iter;
iter = mDeviceMap.find(uart.mDevice);
@ -52,7 +52,7 @@ void UartDeviceTestTool::UnregisterUartDevice(const uart_info &uart)
}
LogError("Can't found the uart device[%s].\n", uart.mDevice);
}
void UartDeviceTestTool::SetSendApiOnce(std::shared_ptr<LinuxTest> &mock, const uart_info &uart, const ssize_t &length)
void UartDeviceTestTool::SetSendApiOnce(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart, const ssize_t &length)
{
std::map<const char *, int>::iterator iter;
iter = mDeviceMap.find(uart.mDevice);
@ -64,7 +64,7 @@ void UartDeviceTestTool::SetSendApiOnce(std::shared_ptr<LinuxTest> &mock, const
.WillOnce(DoAll(Return(length)))
.WillRepeatedly(DoAll(SaveArg<2>(&WRITE_COUNT), ReturnPointee(&WRITE_COUNT)));
}
void UartDeviceTestTool::SetRecvApiOnce(std::shared_ptr<LinuxTest> &mock, const uart_info &uart, void *recvBuff,
void UartDeviceTestTool::SetRecvApiOnce(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart, void *recvBuff,
const ssize_t &length)
{
std::map<const char *, int>::iterator iter;

View File

@ -28,11 +28,50 @@ typedef struct uart_info
const int mStopBits;
const int mParity;
} UartInfo;
/**
* @brief Create a serial port object instance.
*
* @param info Serial port information
* @return void*
*/
void *CreateUartDevice(const UartInfo info);
/**
* @brief Open the serial port.
*
* @param object Serial port object pointer.
* @return const StatusCode
*/
const StatusCode IUartOpen(void *object);
/**
* @brief Send data using a serial port.
*
* @param object Serial port object pointer.
* @param buff The data to be sent.
* @param buffLength The length of data to be sent.
* @return const size_t
*/
const size_t IUartSend(void *object, const char *buff, const size_t buffLength);
/**
* @brief Use a serial port to receive data.
*
* @param object Serial port object pointer.
* @param buff The cache area for receiving data.
* @param buffLength The size of the cache area for receiving data.
* @param timeoutMs The timeout time in milliseconds.
* @return const size_t
*/
const size_t IUartRecv(void *object, char *buff, const size_t buffLength, const unsigned int timeoutMs);
/**
* @brief Clear the serial port cache data.
*
* @param object Serial port object pointer.
*/
void IUartTcflush(void *object);
/**
* @brief Destroy a serial object instance.
*
* @param object Serial port object pointer.
*/
void IUartDeviceFree(void *object);
#ifdef __cplusplus
}