tests: coverage for common utils, cli, timeline undo, tasks, codec, ui

- common: Html doc<->HTML conversion (17), OIIOUtils (6)
- cli: CLIProgressDialog rendering and CLITaskDialog (8)
- timeline: undo commands for pointer/ripple/split/track/workarea (43)
  and general commands (22)
- task: project import/load, import error dialog, cache tasks (13)
- codec: OIIO decoder/encoder, planar file device, FFmpeg encoder (15)
- ui: HumanStrings (6), icons (4), StyleManager (4)
This commit is contained in:
2026-07-17 13:07:56 +08:00
parent dd7427f51a
commit 807e02614b
14 changed files with 4025 additions and 0 deletions
+124
View File
@@ -0,0 +1,124 @@
#include <gtest/gtest.h>
#include <OpenImageIO/imagebuf.h>
#include "codec/frame.h"
#include "common/oiioutils.h"
TEST(CommonOIIOUtils, BaseTypeFromPixelFormat)
{
using olive::core::PixelFormat;
EXPECT_EQ(olive::OIIOUtils::GetOIIOBaseTypeFromFormat(PixelFormat::U8),
OIIO::TypeDesc::UINT8);
EXPECT_EQ(olive::OIIOUtils::GetOIIOBaseTypeFromFormat(PixelFormat::U16),
OIIO::TypeDesc::UINT16);
EXPECT_EQ(olive::OIIOUtils::GetOIIOBaseTypeFromFormat(PixelFormat::F16),
OIIO::TypeDesc::HALF);
EXPECT_EQ(olive::OIIOUtils::GetOIIOBaseTypeFromFormat(PixelFormat::F32),
OIIO::TypeDesc::FLOAT);
EXPECT_EQ(olive::OIIOUtils::GetOIIOBaseTypeFromFormat(PixelFormat::U10),
OIIO::TypeDesc::UNKNOWN);
EXPECT_EQ(olive::OIIOUtils::GetOIIOBaseTypeFromFormat(PixelFormat::INVALID),
OIIO::TypeDesc::UNKNOWN);
}
TEST(CommonOIIOUtils, PixelFormatFromBaseType)
{
using olive::core::PixelFormat;
EXPECT_EQ(olive::OIIOUtils::GetFormatFromOIIOBasetype(OIIO::TypeDesc::UINT8),
PixelFormat::U8);
EXPECT_EQ(
olive::OIIOUtils::GetFormatFromOIIOBasetype(OIIO::TypeDesc::UINT16),
PixelFormat::U16);
EXPECT_EQ(olive::OIIOUtils::GetFormatFromOIIOBasetype(OIIO::TypeDesc::HALF),
PixelFormat::F16);
EXPECT_EQ(olive::OIIOUtils::GetFormatFromOIIOBasetype(OIIO::TypeDesc::FLOAT),
PixelFormat::F32);
EXPECT_EQ(
olive::OIIOUtils::GetFormatFromOIIOBasetype(OIIO::TypeDesc::UNKNOWN),
PixelFormat::INVALID);
EXPECT_EQ(olive::OIIOUtils::GetFormatFromOIIOBasetype(OIIO::TypeDesc::DOUBLE),
PixelFormat::INVALID);
EXPECT_EQ(olive::OIIOUtils::GetFormatFromOIIOBasetype(OIIO::TypeDesc::STRING),
PixelFormat::INVALID);
}
TEST(CommonOIIOUtils, FormatRoundTripIsSymmetric)
{
using olive::core::PixelFormat;
for (PixelFormat fmt :
{ PixelFormat::U8, PixelFormat::U16, PixelFormat::F16,
PixelFormat::F32 }) {
EXPECT_EQ(olive::OIIOUtils::GetFormatFromOIIOBasetype(
olive::OIIOUtils::GetOIIOBaseTypeFromFormat(fmt)),
fmt);
}
}
TEST(CommonOIIOUtils, PixelAspectRatioDefaultsToOne)
{
OIIO::ImageSpec spec(16, 16, 4, OIIO::TypeDesc::FLOAT);
const olive::core::rational par =
olive::OIIOUtils::GetPixelAspectRatioFromOIIO(spec);
EXPECT_EQ(par, olive::core::rational(1, 1));
}
TEST(CommonOIIOUtils, PixelAspectRatioIsReadFromAttribute)
{
OIIO::ImageSpec spec(16, 16, 4, OIIO::TypeDesc::FLOAT);
spec.attribute("PixelAspectRatio", 2.0f);
const olive::core::rational par =
olive::OIIOUtils::GetPixelAspectRatioFromOIIO(spec);
EXPECT_EQ(par, olive::core::rational(2, 1));
}
TEST(CommonOIIOUtils, FrameBufferRoundTripPreservesPixels)
{
using olive::core::PixelFormat;
const olive::VideoParams params(8, 8, PixelFormat::F32,
olive::VideoParams::kRGBAChannelCount);
auto frame = olive::Frame::Create();
frame->set_video_params(params);
frame->allocate();
frame->set_pixel(0, 0, olive::Color(0.1f, 0.2f, 0.3f, 1.0f));
frame->set_pixel(7, 7, olive::Color(0.9f, 0.8f, 0.7f, 0.6f));
OIIO::ImageSpec spec(params.effective_width(), params.effective_height(),
params.channel_count(),
olive::OIIOUtils::GetOIIOBaseTypeFromFormat(
params.format()));
OIIO::ImageBuf buf(spec);
ASSERT_TRUE(buf.initialized());
olive::OIIOUtils::FrameToBuffer(frame.get(), &buf);
auto out = olive::Frame::Create();
out->set_video_params(params);
out->allocate();
// Poison the output so a failed transfer is visible.
std::memset(out->data(), 0xFF, out->allocated_size());
olive::OIIOUtils::BufferToFrame(&buf, out.get());
const olive::Color a = out->get_pixel(0, 0);
EXPECT_NEAR(a.red(), 0.1f, 1e-5f);
EXPECT_NEAR(a.green(), 0.2f, 1e-5f);
EXPECT_NEAR(a.blue(), 0.3f, 1e-5f);
EXPECT_NEAR(a.alpha(), 1.0f, 1e-5f);
const olive::Color b = out->get_pixel(7, 7);
EXPECT_NEAR(b.red(), 0.9f, 1e-5f);
EXPECT_NEAR(b.green(), 0.8f, 1e-5f);
EXPECT_NEAR(b.blue(), 0.7f, 1e-5f);
EXPECT_NEAR(b.alpha(), 0.6f, 1e-5f);
}