test: expand gtest coverage for common/core utilities

Add unit tests for:
- CommandLineParser, Debug handler, Decibel, Digit, JobTime, FFmpegUtils
- Core StringUtils, Timecode, TimeRange, Bezier, Color
- Extend Frame tests to cover pixel access, interlace, conversion

Coverage improvements (app + ext/core):
- commandlineparser.cpp: 0% -> 93%
- debug.cpp: 0% -> 85%
- decibel.h: 25% -> 88%
- digit.h: 0% -> 100%
- ffmpegutils.cpp: 29% -> 90%
- frame.cpp: 53% -> 97%
- bezier.cpp: 16% -> 98%
- color.cpp: 13% -> 71%
- Overall line coverage: 17% -> 19%
This commit is contained in:
2026-07-13 10:19:30 +08:00
parent 748c53ac5c
commit c57608b8f8
13 changed files with 1159 additions and 0 deletions
+130
View File
@@ -54,3 +54,133 @@ TEST(CodecFrame, DestroyDeallocatesData)
EXPECT_FALSE(frame->is_allocated());
EXPECT_EQ(frame->data(), nullptr);
}
TEST(CodecFrame, AllocateInvalidParamsFails)
{
olive::Frame frame;
EXPECT_FALSE(frame.allocate());
}
TEST(CodecFrame, DoubleAllocateReturnsTrue)
{
olive::VideoParams params(8, 8, olive::core::PixelFormat::U8,
olive::VideoParams::kRGBAChannelCount);
olive::FramePtr frame = olive::Frame::Create();
frame->set_video_params(params);
EXPECT_TRUE(frame->allocate());
EXPECT_TRUE(frame->allocate());
}
TEST(CodecFrame, ContainsPixel)
{
olive::VideoParams params(8, 8, olive::core::PixelFormat::U8,
olive::VideoParams::kRGBAChannelCount);
olive::FramePtr frame = olive::Frame::Create();
frame->set_video_params(params);
EXPECT_FALSE(frame->contains_pixel(0, 0));
frame->allocate();
EXPECT_TRUE(frame->contains_pixel(0, 0));
EXPECT_TRUE(frame->contains_pixel(7, 7));
EXPECT_FALSE(frame->contains_pixel(8, 0));
EXPECT_FALSE(frame->contains_pixel(0, 8));
EXPECT_FALSE(frame->contains_pixel(-1, 0));
}
TEST(CodecFrame, GetPixelOutOfBoundsReturnsBlack)
{
olive::VideoParams params(8, 8, olive::core::PixelFormat::U8,
olive::VideoParams::kRGBAChannelCount);
olive::FramePtr frame = olive::Frame::Create();
frame->set_video_params(params);
frame->allocate();
olive::core::Color c = frame->get_pixel(-1, 0);
EXPECT_FLOAT_EQ(c.red(), 0.0f);
}
TEST(CodecFrame, SetAndGetPixel)
{
olive::VideoParams params(8, 8, olive::core::PixelFormat::U8,
olive::VideoParams::kRGBAChannelCount);
olive::FramePtr frame = olive::Frame::Create();
frame->set_video_params(params);
frame->allocate();
olive::core::Color red(1.0f, 0.0f, 0.0f, 1.0f);
frame->set_pixel(3, 3, red);
olive::core::Color got = frame->get_pixel(3, 3);
EXPECT_NEAR(got.red(), 1.0f, 0.01f);
EXPECT_NEAR(got.green(), 0.0f, 0.01f);
EXPECT_NEAR(got.blue(), 0.0f, 0.01f);
}
TEST(CodecFrame, TimestampRoundTrip)
{
olive::FramePtr frame = olive::Frame::Create();
frame->set_timestamp(olive::core::rational(5, 1));
EXPECT_EQ(frame->timestamp(), olive::core::rational(5, 1));
}
TEST(CodecFrame, GenerateLineSizeBytes)
{
EXPECT_EQ(olive::Frame::generate_linesize_bytes(
64, olive::core::PixelFormat::U8,
olive::VideoParams::kRGBAChannelCount),
64 * 4);
}
TEST(CodecFrame, InterlaceFrames)
{
olive::VideoParams params(4, 4, olive::core::PixelFormat::U8,
olive::VideoParams::kRGBAChannelCount);
olive::FramePtr top = olive::Frame::Create();
top->set_video_params(params);
top->allocate();
memset(top->data(), 0xFF, top->allocated_size());
olive::FramePtr bottom = olive::Frame::Create();
bottom->set_video_params(params);
bottom->allocate();
memset(bottom->data(), 0x00, bottom->allocated_size());
olive::FramePtr interlaced = olive::Frame::Interlace(top, bottom);
ASSERT_NE(interlaced, nullptr);
EXPECT_EQ(interlaced->width(), 4);
EXPECT_EQ(interlaced->height(), 4);
}
TEST(CodecFrame, InterlaceIncompatibleReturnsNull)
{
olive::FramePtr top = olive::Frame::Create();
top->set_video_params(olive::VideoParams(
4, 4, olive::core::PixelFormat::U8, olive::VideoParams::kRGBAChannelCount));
top->allocate();
olive::FramePtr bottom = olive::Frame::Create();
bottom->set_video_params(olive::VideoParams(
8, 8, olive::core::PixelFormat::U8, olive::VideoParams::kRGBAChannelCount));
bottom->allocate();
EXPECT_EQ(olive::Frame::Interlace(top, bottom), nullptr);
}
TEST(CodecFrame, ConvertU8ToU16)
{
olive::VideoParams params(4, 4, olive::core::PixelFormat::U8,
olive::VideoParams::kRGBAChannelCount);
olive::FramePtr frame = olive::Frame::Create();
frame->set_video_params(params);
frame->allocate();
olive::FramePtr converted =
frame->convert(olive::core::PixelFormat::U16);
ASSERT_NE(converted, nullptr);
EXPECT_EQ(converted->format(), olive::core::PixelFormat::U16);
EXPECT_EQ(converted->width(), 4);
EXPECT_EQ(converted->height(), 4);
}