Files
oak-editor/tests/gtest/codec_frame_test.cpp
T
Mike-Solar bb40b4923e style: unify identifier naming per updated conventions
Automated with clang-tidy readability-identifier-naming (config added to
.clang-tidy) plus scripted passes, per the updated rules now documented
in CONTRIBUTING.md:

- types (class/struct/enum/alias/template params): PascalCase
- functions, variables, members: snake_case (incl. rational -> Rational)
- private/protected members: trailing underscore; static member
  variables likewise (instance_, available_themes_)
- constants and enum values: snake_case (kLinear -> k_linear,
  F32P -> f32p); ALL_CAPS reserved for macros
- macros: OAK_ prefix (OLIVE_ADD_TEST/OLIVE_ASSERT/OLIVE_CONFIG ->
  OAK_ADD_TEST/OAK_ASSERT/OAK_CONFIG, GL_PREAMBLE -> OAK_GL_PREAMBLE,
  include guards -> OAK_*)
- file names: all lowercase (Current/Plugin/OliveHost/OliveClip/
  OlivePluginInstance -> current/plugin/olivehost/oliveclip/
  oliveplugininstance)
- getters share the member name sans underscore, setters set_foo()
- Qt and third-party (OpenFX) virtual overrides and framework callbacks
  keep their original names (exempt in .clang-tidy)

Manual follow-ups required where automation could not reach:
- string-based QMetaObject/SIGNAL/SLOT references updated to renamed
  methods (AddTask, CreatedFile, DeleteSpecificFile, moveSelectionUp, ...)
- macro bodies referencing renamed methods (OLIVE_CONFIG,
  NODE_DEFAULT_DESTRUCTOR, MANAGEDDISPLAYWIDGET_*)
- self-shadowing locals renamed where signals/methods became same-named
  (size_changed, worker_count, selected_items, import param, filters)
- third_party OFX member/namespace usages restored (OFX::Host::*,
  _created, _clipPrefsDirty, createInstance, clearPersistentMessage)
- STL protocol aliases restored (const_iterator) with .clang-tidy
  ignore rules; qHash overloads restored

Full build and test suite pass: ctest 4/4, ~1960 gtest cases green.
2026-07-19 16:10:54 +08:00

187 lines
5.3 KiB
C++

#include <gtest/gtest.h>
#include "codec/frame.h"
TEST(CodecFrame, DefaultState)
{
olive::Frame frame;
EXPECT_EQ(frame.width(), 0);
EXPECT_EQ(frame.height(), 0);
EXPECT_EQ(frame.format(), olive::core::PixelFormat::invalid);
EXPECT_FALSE(frame.is_allocated());
EXPECT_EQ(frame.data(), nullptr);
}
TEST(CodecFrame, CreateAllocatesForParams)
{
olive::VideoParams params(64, 32, olive::core::PixelFormat::u8,
olive::VideoParams::k_rgba_channel_count);
olive::FramePtr frame = olive::Frame::create();
frame->set_video_params(params);
frame->allocate();
EXPECT_TRUE(frame->is_allocated());
EXPECT_NE(frame->data(), nullptr);
EXPECT_EQ(frame->width(), 64);
EXPECT_EQ(frame->height(), 32);
EXPECT_EQ(frame->format(), olive::core::PixelFormat::u8);
}
TEST(CodecFrame, AllocateMatchesLineSize)
{
olive::VideoParams params(64, 32, olive::core::PixelFormat::u8,
olive::VideoParams::k_rgba_channel_count);
olive::FramePtr frame = olive::Frame::create();
frame->set_video_params(params);
frame->allocate();
EXPECT_EQ(frame->linesize_bytes(), 64 * 4);
EXPECT_EQ(frame->allocated_size(), 64 * 4 * 32);
}
TEST(CodecFrame, DestroyDeallocatesData)
{
olive::FramePtr frame = olive::Frame::create();
frame->set_video_params(
olive::VideoParams(8, 8, olive::core::PixelFormat::u8,
olive::VideoParams::k_rgba_channel_count));
frame->allocate();
EXPECT_TRUE(frame->is_allocated());
frame->destroy();
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::k_rgba_channel_count);
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::k_rgba_channel_count);
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::k_rgba_channel_count);
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::k_rgba_channel_count);
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::k_rgba_channel_count),
64 * 4);
}
TEST(CodecFrame, InterlaceFrames)
{
olive::VideoParams params(4, 4, olive::core::PixelFormat::u8,
olive::VideoParams::k_rgba_channel_count);
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::k_rgba_channel_count));
top->allocate();
olive::FramePtr bottom = olive::Frame::create();
bottom->set_video_params(
olive::VideoParams(8, 8, olive::core::PixelFormat::u8,
olive::VideoParams::k_rgba_channel_count));
bottom->allocate();
EXPECT_EQ(olive::Frame::interlace(top, bottom), nullptr);
}
TEST(CodecFrame, ConvertU8ToU16)
{
olive::VideoParams params(4, 4, olive::core::PixelFormat::u8,
olive::VideoParams::k_rgba_channel_count);
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);
}