Compare commits
1 Commits
main
...
test_20260
| Author | SHA1 | Date |
|---|---|---|
|
|
5fd8d9c8b2 |
|
|
@ -0,0 +1,25 @@
|
||||||
|
cmake_minimum_required(VERSION 3.10.0)
|
||||||
|
project(test_net_env_project)
|
||||||
|
include(FetchContent)
|
||||||
|
if (MSVC)
|
||||||
|
add_compile_options(/utf-8)
|
||||||
|
endif()
|
||||||
|
FetchContent_Declare(
|
||||||
|
googletest
|
||||||
|
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
||||||
|
)
|
||||||
|
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||||
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
add_executable(test_net_env_project test_app.cpp ../src/dau.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(test_net_env_project gtest gmock gtest_main)
|
||||||
|
include(GoogleTest)
|
||||||
|
gtest_discover_tests(test_net_env_project)
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include "app.hpp"
|
||||||
|
#include <string>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
using namespace dau;
|
||||||
|
|
||||||
|
class DAUTest : public ::testing::Test {
|
||||||
|
protected:
|
||||||
|
void SetUp() override {
|
||||||
|
DAU_SetSleep(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(DAUTest, testDAUProcessNormalInput) {
|
||||||
|
RawDataFrame input{};
|
||||||
|
input.len = 8;
|
||||||
|
for(int i=0; i<8; ++i) input.data[i] = i;
|
||||||
|
input.timestamp = 12345;
|
||||||
|
input.busType = 1;
|
||||||
|
|
||||||
|
ValidData output{};
|
||||||
|
std::string errorLog;
|
||||||
|
|
||||||
|
uint32_t initialLoad = DAU_GetBusLoad();
|
||||||
|
bool result = DAU_Process(input, output, errorLog);
|
||||||
|
|
||||||
|
EXPECT_TRUE(result);
|
||||||
|
EXPECT_EQ(output.dataLen, 8);
|
||||||
|
EXPECT_EQ(output.timestamp, 12345);
|
||||||
|
EXPECT_EQ(output.sourceBus, 1);
|
||||||
|
EXPECT_EQ(DAU_GetBusLoad(), initialLoad + 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DAUTest, testDAUProcessZeroLength) {
|
||||||
|
RawDataFrame input{};
|
||||||
|
input.len = 0;
|
||||||
|
ValidData output{};
|
||||||
|
std::string errorLog;
|
||||||
|
|
||||||
|
bool result = DAU_Process(input, output, errorLog);
|
||||||
|
EXPECT_FALSE(result);
|
||||||
|
EXPECT_NE(errorLog.find("Invalid data length"), std::string::npos);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DAUTest, testDAUProcessMaxLength) {
|
||||||
|
RawDataFrame input{};
|
||||||
|
input.len = 64;
|
||||||
|
for(int i=0; i<64; ++i) input.data[i] = 0x01;
|
||||||
|
ValidData output{};
|
||||||
|
std::string errorLog;
|
||||||
|
|
||||||
|
bool result = DAU_Process(input, output, errorLog);
|
||||||
|
EXPECT_TRUE(result);
|
||||||
|
EXPECT_EQ(output.dataLen, 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DAUTest, testDAUProcessExceedMaxLength) {
|
||||||
|
RawDataFrame input{};
|
||||||
|
input.len = 65;
|
||||||
|
ValidData output{};
|
||||||
|
std::string errorLog;
|
||||||
|
|
||||||
|
bool result = DAU_Process(input, output, errorLog);
|
||||||
|
EXPECT_FALSE(result);
|
||||||
|
EXPECT_NE(errorLog.find("Invalid data length"), std::string::npos);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DAUTest, testDAUProcessErrorFrame) {
|
||||||
|
RawDataFrame input{};
|
||||||
|
input.len = 8;
|
||||||
|
memset(input.data, 0xFF, 8);
|
||||||
|
ValidData output{};
|
||||||
|
std::string errorLog;
|
||||||
|
|
||||||
|
bool result = DAU_Process(input, output, errorLog);
|
||||||
|
EXPECT_FALSE(result);
|
||||||
|
EXPECT_NE(errorLog.find("Error frame detected"), std::string::npos);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DAUTest, testDAUProcessSleepMode) {
|
||||||
|
DAU_SetSleep(true);
|
||||||
|
RawDataFrame input{};
|
||||||
|
input.len = 8;
|
||||||
|
ValidData output{};
|
||||||
|
std::string errorLog;
|
||||||
|
|
||||||
|
bool result = DAU_Process(input, output, errorLog);
|
||||||
|
EXPECT_FALSE(result);
|
||||||
|
EXPECT_NE(errorLog.find("Sleep mode"), std::string::npos);
|
||||||
|
|
||||||
|
DAU_SetSleep(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DAUTest, testDAUSetSleepAndGetBusLoad) {
|
||||||
|
DAU_SetSleep(false);
|
||||||
|
uint32_t load1 = DAU_GetBusLoad();
|
||||||
|
|
||||||
|
RawDataFrame input{};
|
||||||
|
input.len = 1;
|
||||||
|
input.data[0] = 0x01;
|
||||||
|
ValidData output{};
|
||||||
|
std::string errorLog;
|
||||||
|
DAU_Process(input, output, errorLog);
|
||||||
|
|
||||||
|
uint32_t load2 = DAU_GetBusLoad();
|
||||||
|
EXPECT_EQ(load2, load1 + 5);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue