- 创建基本项目结构和目录 - 添加CMake构建系统 - 实现基础的配置解析功能 - 添加YOLO推理框架支持 - 集成RTSP和视频流处理功能 - 添加性能监控和日志系统
106 lines
2.9 KiB
C++
106 lines
2.9 KiB
C++
#include <gtest/gtest.h>
|
|
#include <thread>
|
|
#include <opencv2/imgproc.hpp>
|
|
#include "pipeline/input/frame_queue.hpp"
|
|
|
|
using namespace pipeline;
|
|
|
|
class FrameQueueTest : public ::testing::Test {
|
|
protected:
|
|
void SetUp() override {
|
|
// 创建测试用的帧
|
|
test_frame_ = cv::Mat::zeros(100, 100, CV_8UC3);
|
|
cv::rectangle(test_frame_, cv::Point(25, 25), cv::Point(75, 75), cv::Scalar(0, 255, 0), -1);
|
|
}
|
|
|
|
cv::Mat test_frame_;
|
|
};
|
|
|
|
// 测试基本操作
|
|
TEST_F(FrameQueueTest, BasicOperations) {
|
|
FrameQueue queue(2); // 最大容量为2的队列
|
|
cv::Mat frame;
|
|
|
|
// 初始状态检查
|
|
EXPECT_TRUE(queue.empty());
|
|
EXPECT_FALSE(queue.full());
|
|
EXPECT_EQ(queue.size(), 0);
|
|
EXPECT_EQ(queue.capacity(), 2);
|
|
|
|
// 推入一帧
|
|
EXPECT_TRUE(queue.push(test_frame_));
|
|
EXPECT_FALSE(queue.empty());
|
|
EXPECT_FALSE(queue.full());
|
|
EXPECT_EQ(queue.size(), 1);
|
|
|
|
// 推入第二帧
|
|
EXPECT_TRUE(queue.push(test_frame_));
|
|
EXPECT_FALSE(queue.empty());
|
|
EXPECT_TRUE(queue.full());
|
|
EXPECT_EQ(queue.size(), 2);
|
|
|
|
// 尝试推入第三帧(应该失败)
|
|
EXPECT_FALSE(queue.push(test_frame_, std::chrono::milliseconds(10)));
|
|
|
|
// 弹出一帧
|
|
EXPECT_TRUE(queue.pop(frame));
|
|
EXPECT_FALSE(frame.empty());
|
|
EXPECT_EQ(frame.size(), test_frame_.size());
|
|
EXPECT_EQ(queue.size(), 1);
|
|
|
|
// 清空队列
|
|
queue.clear();
|
|
EXPECT_TRUE(queue.empty());
|
|
EXPECT_EQ(queue.size(), 0);
|
|
}
|
|
|
|
// 测试多线程操作
|
|
TEST_F(FrameQueueTest, ThreadedOperations) {
|
|
FrameQueue queue(5);
|
|
const int num_frames = 10;
|
|
bool producer_done = false;
|
|
|
|
// 生产者线程
|
|
std::thread producer([&]() {
|
|
for (int i = 0; i < num_frames; ++i) {
|
|
EXPECT_TRUE(queue.push(test_frame_));
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
}
|
|
producer_done = true;
|
|
});
|
|
|
|
// 消费者线程
|
|
std::thread consumer([&]() {
|
|
int frames_received = 0;
|
|
cv::Mat frame;
|
|
while (frames_received < num_frames) {
|
|
if (queue.pop(frame)) {
|
|
EXPECT_FALSE(frame.empty());
|
|
EXPECT_EQ(frame.size(), test_frame_.size());
|
|
frames_received++;
|
|
}
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
}
|
|
});
|
|
|
|
producer.join();
|
|
consumer.join();
|
|
|
|
EXPECT_TRUE(producer_done);
|
|
EXPECT_TRUE(queue.empty());
|
|
}
|
|
|
|
// 测试超时行为
|
|
TEST_F(FrameQueueTest, TimeoutBehavior) {
|
|
FrameQueue queue(1);
|
|
cv::Mat frame;
|
|
|
|
// 测试空队列弹出超时
|
|
EXPECT_FALSE(queue.pop(frame, std::chrono::milliseconds(100)));
|
|
|
|
// 填满队列
|
|
EXPECT_TRUE(queue.push(test_frame_));
|
|
|
|
// 测试满队列推入超时
|
|
EXPECT_FALSE(queue.push(test_frame_, std::chrono::milliseconds(100)));
|
|
}
|