diff --git a/test/test_develop.md b/test/test_develop.md index 4219680..fadb9ed 100644 --- a/test/test_develop.md +++ b/test/test_develop.md @@ -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 diff --git a/test/utils/UartDevice/src/UartDevice_Test.cpp b/test/utils/UartDevice/src/UartDevice_Test.cpp index e51da3b..d1e8cd3 100644 --- a/test/utils/UartDevice/src/UartDevice_Test.cpp +++ b/test/utils/UartDevice/src/UartDevice_Test.cpp @@ -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); diff --git a/test/utils/UartDevice/src_mock/UartDevice_Mock_Test.cpp b/test/utils/UartDevice/src_mock/UartDevice_Mock_Test.cpp index 3c72f22..fac8849 100644 --- a/test/utils/UartDevice/src_mock/UartDevice_Mock_Test.cpp +++ b/test/utils/UartDevice/src_mock/UartDevice_Mock_Test.cpp @@ -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', diff --git a/test/utils/UartDevice/tool/include/UartDeviceTestTool.h b/test/utils/UartDevice/tool/include/UartDeviceTestTool.h index be73c22..1a04c82 100644 --- a/test/utils/UartDevice/tool/include/UartDeviceTestTool.h +++ b/test/utils/UartDevice/tool/include/UartDeviceTestTool.h @@ -28,13 +28,13 @@ public: * @param mock * @param uart */ - void RegisterUartDevice(std::shared_ptr &mock, const uart_info &uart); + void RegisterUartDevice(std::shared_ptr &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 &mock, const uart_info &uart, const ssize_t &length); + void SetSendApiOnce(std::shared_ptr &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 &mock, const uart_info &uart, void *recvBuff, const ssize_t &length); + void SetRecvApiOnce(std::shared_ptr &mock, const UartInfo &uart, void *recvBuff, const ssize_t &length); private: std::map mDeviceMap; diff --git a/test/utils/UartDevice/tool/src/UartDeviceTestTool.cpp b/test/utils/UartDevice/tool/src/UartDeviceTestTool.cpp index 144851e..98bed5f 100644 --- a/test/utils/UartDevice/tool/src/UartDeviceTestTool.cpp +++ b/test/utils/UartDevice/tool/src/UartDeviceTestTool.cpp @@ -16,7 +16,7 @@ #include "ILog.h" #include static size_t WRITE_COUNT = -1; -void UartDeviceTestTool::RegisterUartDevice(std::shared_ptr &mock, const uart_info &uart) +void UartDeviceTestTool::RegisterUartDevice(std::shared_ptr &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 &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::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 &mock, const uart_info &uart, const ssize_t &length) +void UartDeviceTestTool::SetSendApiOnce(std::shared_ptr &mock, const UartInfo &uart, const ssize_t &length) { std::map::iterator iter; iter = mDeviceMap.find(uart.mDevice); @@ -64,7 +64,7 @@ void UartDeviceTestTool::SetSendApiOnce(std::shared_ptr &mock, const .WillOnce(DoAll(Return(length))) .WillRepeatedly(DoAll(SaveArg<2>(&WRITE_COUNT), ReturnPointee(&WRITE_COUNT))); } -void UartDeviceTestTool::SetRecvApiOnce(std::shared_ptr &mock, const uart_info &uart, void *recvBuff, +void UartDeviceTestTool::SetRecvApiOnce(std::shared_ptr &mock, const UartInfo &uart, void *recvBuff, const ssize_t &length) { std::map::iterator iter; diff --git a/utils/UartDevice/include/UartDevice.h b/utils/UartDevice/include/UartDevice.h index 0a61094..05a8488 100644 --- a/utils/UartDevice/include/UartDevice.h +++ b/utils/UartDevice/include/UartDevice.h @@ -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 }