UartDevice:backup.
This commit is contained in:
parent
6e11dc58f6
commit
c1a5ad44a9
|
@ -3,7 +3,22 @@
|
||||||
  便于对测试用例进行管理,指定测试用例开发规范。
|
  便于对测试用例进行管理,指定测试用例开发规范。
|
||||||
|
|
||||||
## 1.1. 命名规则
|
## 1.1. 命名规则
|
||||||
* 测试用例命名:
|
|
||||||
|
### 1.1.1. 基本概念
|
||||||
|
|
||||||
|
**单元测试**:单元测试指对单一功能接口的测试,一般不需要或少量使用gtest的mock功能即可完成测试,不需要实际链接外部接口,对模块内部代码功能进行有效验证;
|
||||||
|
|
||||||
|
**用例所属模块**:测试时锁定目标测试用例的作用;
|
||||||
|
|
||||||
|
**集成测试**:集成测试指对复杂业务进行测试,往往需要跨多层级多模块,需要大量使用gtest的mock功能才能完成的复杂逻辑测试,一般不针对代码本身而是针对产品定义的功能进行有效验证;
|
||||||
|
|
||||||
|
**测试用例**:
|
||||||
|
|
||||||
|
1. EXAMPLE:对模块接口进行使用演示的测试用例;
|
||||||
|
2. AUTO:自动化运行的测试用例;
|
||||||
|
3. STRESS:压力测试用例,一般不在单次测试中执行;
|
||||||
|
|
||||||
|
### 1.1.2. 测试用例命名:
|
||||||
1. 测试用例类型:含单元测试(UNIT)和集成测试(INTEGRATION);
|
1. 测试用例类型:含单元测试(UNIT)和集成测试(INTEGRATION);
|
||||||
2. 用例所属模块:大小驼峰;
|
2. 用例所属模块:大小驼峰;
|
||||||
3. 测试用例属性:EXAMPLE/AUTO/STRESS
|
3. 测试用例属性:EXAMPLE/AUTO/STRESS
|
||||||
|
@ -11,13 +26,15 @@
|
||||||
|
|
||||||
示例:
|
示例:
|
||||||
|
|
||||||
|
该测试用例标识属于SharedData模块的单元测试,作为example具有演示接口使用规范的作用,测试用例名为Deme7。
|
||||||
|
|
||||||
```
|
```
|
||||||
TEST(SharedDataTest, UNIT_SharedData_EXAMPLE_Demo7)
|
TEST(SharedDataTest, UNIT_SharedData_EXAMPLE_Demo7)
|
||||||
{
|
{
|
||||||
// TODO:
|
// TODO:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
* 测试源码文件命名:
|
### 1.1.3. 测试源码文件命名:
|
||||||
1. 每个测试可执行文件都有一个标准mian函数,文件名统一为:mainTest.cpp;
|
1. 每个测试可执行文件都有一个标准mian函数,文件名统一为:mainTest.cpp;
|
||||||
```
|
```
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
|
|
|
@ -45,7 +45,7 @@ TEST(UartDeviceTest, UNIT_UartDevice_EXAMPLE_Demo)
|
||||||
{
|
{
|
||||||
CreateLogModule();
|
CreateLogModule();
|
||||||
ILogInit(LOG_INSTANCE_TYPE_END);
|
ILogInit(LOG_INSTANCE_TYPE_END);
|
||||||
uart_info device = {
|
UartInfo device = {
|
||||||
"dev/s1",
|
"dev/s1",
|
||||||
};
|
};
|
||||||
void *object = CreateUartDevice(device);
|
void *object = CreateUartDevice(device);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
namespace UartDeviceMockTest
|
namespace UartDeviceMockTest
|
||||||
{
|
{
|
||||||
const char *gDeviceName = "dev/s1";
|
const char *gDeviceName = "dev/s1";
|
||||||
static uart_info gUartDevice = {
|
static UartInfo gUartDevice = {
|
||||||
gDeviceName,
|
gDeviceName,
|
||||||
1152000,
|
1152000,
|
||||||
'N',
|
'N',
|
||||||
|
@ -85,7 +85,7 @@ TEST_F(UartDeviceMockTest, UNIT_UartDevice_EXAMPLE_AUTO_Demo)
|
||||||
TEST_F(UartDeviceMockTest, UNIT_UartDevice_AUTO_ParameterEarror)
|
TEST_F(UartDeviceMockTest, UNIT_UartDevice_AUTO_ParameterEarror)
|
||||||
{
|
{
|
||||||
char *deviceName = nullptr;
|
char *deviceName = nullptr;
|
||||||
static uart_info uartDevice = {
|
static UartInfo uartDevice = {
|
||||||
deviceName,
|
deviceName,
|
||||||
1152000,
|
1152000,
|
||||||
'N',
|
'N',
|
||||||
|
@ -111,7 +111,7 @@ TEST_F(UartDeviceMockTest, UNIT_UartDevice_AUTO_ParameterEarror2)
|
||||||
// const char *SEND_BUF = "TEST";
|
// const char *SEND_BUF = "TEST";
|
||||||
// char *deviceName = (char *)malloc(strlen(SEND_BUF) + 1);
|
// char *deviceName = (char *)malloc(strlen(SEND_BUF) + 1);
|
||||||
// memset(deviceName, 0, strlen(SEND_BUF) + 1);
|
// memset(deviceName, 0, strlen(SEND_BUF) + 1);
|
||||||
// static uart_info uartDevice = {
|
// static UartInfo uartDevice = {
|
||||||
// "deviceName",
|
// "deviceName",
|
||||||
// 1152000,
|
// 1152000,
|
||||||
// 'N',
|
// 'N',
|
||||||
|
|
|
@ -28,13 +28,13 @@ public:
|
||||||
* @param mock
|
* @param mock
|
||||||
* @param uart
|
* @param uart
|
||||||
*/
|
*/
|
||||||
void RegisterUartDevice(std::shared_ptr<LinuxTest> &mock, const uart_info &uart);
|
void RegisterUartDevice(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart);
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* @param uart
|
* @param uart
|
||||||
*/
|
*/
|
||||||
void UnregisterUartDevice(const uart_info &uart);
|
void UnregisterUartDevice(const UartInfo &uart);
|
||||||
/**
|
/**
|
||||||
* @brief Set the Send Api object
|
* @brief Set the Send Api object
|
||||||
*
|
*
|
||||||
|
@ -42,7 +42,7 @@ public:
|
||||||
* @param uart
|
* @param uart
|
||||||
* @param length
|
* @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
|
* @brief Set the Recv Api Once object
|
||||||
*
|
*
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
* @param recvBuff
|
* @param recvBuff
|
||||||
* @param length
|
* @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:
|
private:
|
||||||
std::map<const char *, int> mDeviceMap;
|
std::map<const char *, int> mDeviceMap;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
static size_t WRITE_COUNT = -1;
|
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) {
|
if (nullptr == uart.mDevice) {
|
||||||
LogError("Parament error, nullptr == uartInfo.mDevice\n");
|
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)));
|
EXPECT_CALL(*mock.get(), fx_read(uartFd, _, _)).WillRepeatedly(DoAll(Return(READ_NOTHING)));
|
||||||
mDeviceMap[uart.mDevice] = uartFd;
|
mDeviceMap[uart.mDevice] = uartFd;
|
||||||
}
|
}
|
||||||
void UartDeviceTestTool::UnregisterUartDevice(const uart_info &uart)
|
void UartDeviceTestTool::UnregisterUartDevice(const UartInfo &uart)
|
||||||
{
|
{
|
||||||
std::map<const char *, int>::iterator iter;
|
std::map<const char *, int>::iterator iter;
|
||||||
iter = mDeviceMap.find(uart.mDevice);
|
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);
|
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;
|
std::map<const char *, int>::iterator iter;
|
||||||
iter = mDeviceMap.find(uart.mDevice);
|
iter = mDeviceMap.find(uart.mDevice);
|
||||||
|
@ -64,7 +64,7 @@ void UartDeviceTestTool::SetSendApiOnce(std::shared_ptr<LinuxTest> &mock, const
|
||||||
.WillOnce(DoAll(Return(length)))
|
.WillOnce(DoAll(Return(length)))
|
||||||
.WillRepeatedly(DoAll(SaveArg<2>(&WRITE_COUNT), ReturnPointee(&WRITE_COUNT)));
|
.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)
|
const ssize_t &length)
|
||||||
{
|
{
|
||||||
std::map<const char *, int>::iterator iter;
|
std::map<const char *, int>::iterator iter;
|
||||||
|
|
|
@ -28,11 +28,50 @@ typedef struct uart_info
|
||||||
const int mStopBits;
|
const int mStopBits;
|
||||||
const int mParity;
|
const int mParity;
|
||||||
} UartInfo;
|
} UartInfo;
|
||||||
|
/**
|
||||||
|
* @brief Create a serial port object instance.
|
||||||
|
*
|
||||||
|
* @param info Serial port information
|
||||||
|
* @return void*
|
||||||
|
*/
|
||||||
void *CreateUartDevice(const UartInfo info);
|
void *CreateUartDevice(const UartInfo info);
|
||||||
|
/**
|
||||||
|
* @brief Open the serial port.
|
||||||
|
*
|
||||||
|
* @param object Serial port object pointer.
|
||||||
|
* @return const StatusCode
|
||||||
|
*/
|
||||||
const StatusCode IUartOpen(void *object);
|
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);
|
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);
|
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);
|
void IUartTcflush(void *object);
|
||||||
|
/**
|
||||||
|
* @brief Destroy a serial object instance.
|
||||||
|
*
|
||||||
|
* @param object Serial port object pointer.
|
||||||
|
*/
|
||||||
void IUartDeviceFree(void *object);
|
void IUartDeviceFree(void *object);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user