Details: imageRPC for now assumed to have 4 fields: width,height of type int (4 signed bytes) type (enum BGR,RGBA,DEPTH) and raw vector of data tests written by opencode + gemini flash TG-8 TG-7
92 lines
2.6 KiB
C++
92 lines
2.6 KiB
C++
//
|
|
// Created by vptyp on 12.03.2026.
|
|
//
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <cloud_point/imageFactory.h>
|
|
|
|
class ImageTest : public ::testing::Test {
|
|
protected:
|
|
void SetUp() override {}
|
|
void TearDown() override {}
|
|
};
|
|
|
|
TEST_F(ImageTest, DefaultConstructor) {
|
|
score::Image image;
|
|
cv::Mat mat = image.get();
|
|
EXPECT_TRUE(mat.empty());
|
|
}
|
|
|
|
TEST_F(ImageTest, ConstructorWithMat) {
|
|
cv::Mat input = cv::Mat::zeros(5, 5, CV_8UC1);
|
|
score::Image image(input);
|
|
cv::Mat output = image.get();
|
|
EXPECT_EQ(output.rows, 5);
|
|
EXPECT_EQ(output.cols, 5);
|
|
EXPECT_EQ(output.type(), CV_8UC1);
|
|
}
|
|
|
|
TEST_F(ImageTest, PixelTypeMapping) {
|
|
EXPECT_EQ(score::ImageFactory::pixelType(score::ImageRPC::Type::BGR),
|
|
CV_8UC3);
|
|
EXPECT_EQ(score::ImageFactory::pixelType(score::ImageRPC::Type::RGBA),
|
|
CV_8UC4);
|
|
EXPECT_EQ(score::ImageFactory::pixelType(score::ImageRPC::Type::DEPTH),
|
|
CV_64FC1);
|
|
EXPECT_THROW(score::ImageFactory::pixelType(score::ImageRPC::Type::UNKNOWN),
|
|
std::runtime_error);
|
|
}
|
|
|
|
TEST_F(ImageTest, CreateBGR) {
|
|
score::ImageRPC rpc;
|
|
rpc.width = 10;
|
|
rpc.height = 20;
|
|
rpc.type = score::ImageRPC::Type::BGR;
|
|
rpc.data.resize(rpc.width * rpc.height * 3, 128);
|
|
|
|
score::Image image = score::ImageFactory::create(rpc);
|
|
cv::Mat mat = image.get();
|
|
|
|
EXPECT_EQ(mat.rows, 10);
|
|
EXPECT_EQ(mat.cols, 20);
|
|
EXPECT_EQ(mat.type(), CV_8UC3);
|
|
EXPECT_EQ(mat.at<cv::Vec3b>(0, 0)[0], 128);
|
|
}
|
|
|
|
TEST_F(ImageTest, CreateRGBA) {
|
|
score::ImageRPC rpc;
|
|
rpc.width = 15;
|
|
rpc.height = 25;
|
|
rpc.type = score::ImageRPC::Type::RGBA;
|
|
rpc.data.resize(rpc.width * rpc.height * 4, 255);
|
|
|
|
score::Image image = score::ImageFactory::create(rpc);
|
|
cv::Mat mat = image.get();
|
|
|
|
EXPECT_EQ(mat.rows, 15);
|
|
EXPECT_EQ(mat.cols, 25);
|
|
EXPECT_EQ(mat.type(), CV_8UC4);
|
|
EXPECT_EQ(mat.at<cv::Vec4b>(0, 0)[0], 255);
|
|
}
|
|
|
|
TEST_F(ImageTest, CreateDepth) {
|
|
score::ImageRPC rpc;
|
|
rpc.width = 5;
|
|
rpc.height = 10;
|
|
rpc.type = score::ImageRPC::Type::DEPTH;
|
|
rpc.data.resize(rpc.width * rpc.height * sizeof(double));
|
|
auto *dataPtr = reinterpret_cast<double *>(rpc.data.data());
|
|
for (int i = 0; i < 50; ++i)
|
|
dataPtr[i] = static_cast<double>(i);
|
|
|
|
score::Image image = score::ImageFactory::create(rpc);
|
|
cv::Mat mat = image.get();
|
|
|
|
EXPECT_EQ(mat.rows, 5);
|
|
EXPECT_EQ(mat.cols, 10);
|
|
EXPECT_EQ(mat.type(), CV_64FC1);
|
|
EXPECT_DOUBLE_EQ(mat.at<double>(0, 0), 0.0);
|
|
EXPECT_DOUBLE_EQ(mat.at<double>(4, 9), 49.0);
|
|
}
|