Files
oak-editor/tests/gtest/plugin_smoke_test.cpp
T
Mike-Solar cb1718a103 test: replace fake and duplicate tests with real assertions
Fake tests rewritten to assert real behavior:
- audio_smoke: conversion tests now actually Convert() samples and verify
  output; waveform length/summary assertions tightened to exact values
- plugin_format_conversion: RowBytes/U8ToU16/LoadImageFile now call real
  production code (VideoParams::GetBytesPerPixel, sws scaler, OIIO decode
  of tests/img.png with known pixel values)
- core_color: HSV round trip now verifies fromHsv(toHsv(c)) == c instead
  of comparing toHsv against its own accessors
- core_bezier/node_inputimmediate: expected values replaced with
  independently derived constants instead of re-running the code under test
- common_commandlineparser/common_debug/common_jobtime: capture
  stdout/stderr/qDebug and assert actual output content
- proxy_manager: ProxyFinished test now drives a real proxy job instead of
  emitting the signal itself; proxy_dialog/panel/proxy/preferences/timeruler
  tests assert real widget state
- viewer_smoke/preview_autocacher/render_misc: zero-assertion tests given
  observable-state assertions or removed where nothing is observable

Duplicates removed:
- plugin_smoke_test.cpp: 18 tests duplicated from plugin_paraminstance /
  plugin_support_* / plugin_renderer_readback (751 -> 180 lines)
- module_smoke HumanStrings tests covered precisely by ui_humanstrings_test
- render_misc duplicate kDefaultInterpolation constant check

Removed by policy (skip allowed, never disabled):
- all DISABLED_ prefixes: re-enabled as real offscreen tests or deleted
- ffmpeg_decoder_hw: hardcoded personal path replaced with
  OAK_TEST_HW_DECODE_FILE env var, GTEST_SKIP when unset

Also:
- config_test: restore Config defaults after run (cross-test pollution)
- render_worker_footage: drop /tmp debug-output scaffolding
- previewaudiodevice construction test asserts the real bugfix
2026-07-19 13:58:31 +08:00

204 lines
5.4 KiB
C++

/*
* Oak Video Editor - Plugin Subsystem Smoke Tests
* Copyright (C) 2025 Olive CE Team
*
* Smoke tests for the OFX plugin subsystem covering:
* - Plugin host initialization
* - Plugin job execution
* - Concurrent image allocation
*
* Parameter instance, clip, image and renderer coverage lives in the
* dedicated plugin_paraminstance_test.cpp, plugin_support_param_test.cpp,
* plugin_support_clip_test.cpp, plugin_support_image_test.cpp and
* plugin_renderer_readback_test.cpp files.
*/
#include <gtest/gtest.h>
#include <atomic>
#include <thread>
#include <QCoreApplication>
#include <QThread>
// OFX headers
#include "ofxCore.h"
#include "ofxImageEffect.h"
#include "ofxhClip.h"
#include "ofxhImageEffect.h"
// Plugin support headers
#include "pluginSupport/OliveHost.h"
#include "pluginSupport/OliveClip.h"
#include "pluginSupport/OlivePluginInstance.h"
#include "pluginSupport/image.h"
// Node and render headers
#include "render/job/pluginjob.h"
#include "render/videoparams.h"
#include "render/texture.h"
#include "node/value.h"
#include "common/ffmpegutils.h"
namespace olive
{
namespace plugin
{
namespace test
{
// ============================================================================
// Helper Functions
// ============================================================================
static VideoParams MakeVideoParams(int width, int height,
core::PixelFormat format, int channels,
bool premultiplied = false)
{
VideoParams params;
params.set_width(width);
params.set_height(height);
params.set_format(format);
params.set_channel_count(channels);
params.set_premultiplied_alpha(premultiplied);
params.set_pixel_aspect_ratio(core::rational(1, 1));
params.set_frame_rate(core::rational(30, 1));
return params;
}
static TexturePtr CreateTestTexture(const VideoParams &params,
uint8_t fill_value = 0x7f)
{
AVFramePtr frame = CreateAVFramePtr();
frame->set_format(FFmpegUtils::GetFFmpegPixelFormat(params.format(),
params.channel_count()));
frame->set_width(params.width());
frame->set_height(params.height());
if (frame->format() == FB_PIX_FMT_NONE) {
return nullptr;
}
if (frame->get_buffer(0) < 0) {
return nullptr;
}
if (frame->make_writable() < 0) {
return nullptr;
}
const int linesize = frame->linesize(0);
for (int y = 0; y < frame->height(); ++y) {
std::memset(frame->data(0) + y * linesize, fill_value, linesize);
}
TexturePtr texture = std::make_shared<Texture>(params);
texture->handleFrame(frame);
return texture;
}
// ============================================================================
// Smoke Test: Plugin Host
// ============================================================================
TEST(PluginSmoke, HostSingletonExists)
{
// Verify that the plugin cache can be accessed
auto *cache = OFX::Host::PluginCache::getPluginCache();
EXPECT_NE(cache, nullptr);
}
TEST(PluginSmoke, LoadPluginsEmptyPathNoCrash)
{
// Loading plugins from empty path should not crash
EXPECT_NO_THROW({ loadPlugins(QString()); });
}
TEST(PluginSmoke, LoadPluginsNonExistentPathNoCrash)
{
// Loading plugins from non-existent path should not crash
EXPECT_NO_THROW(
{ loadPlugins(QStringLiteral("/nonexistent/path/to/plugins")); });
}
// ============================================================================
// Smoke Test: Plugin Job
// ============================================================================
TEST(PluginSmokeJob, JobConstruction)
{
NodeValueRow row;
PluginJob job(nullptr, nullptr, row);
EXPECT_EQ(job.pluginInstance(), nullptr);
EXPECT_EQ(job.node(), nullptr);
EXPECT_DOUBLE_EQ(job.time_seconds(), 0.0);
}
TEST(PluginSmokeJob, JobWithTime)
{
NodeValueRow row;
core::rational time(5, 1); // 5 seconds
PluginJob job(nullptr, nullptr, row, time);
EXPECT_DOUBLE_EQ(job.time_seconds(), 5.0);
}
TEST(PluginSmokeJob, JobWithTextureValue)
{
VideoParams params(64, 64, core::PixelFormat::U8, 4);
TexturePtr tex = CreateTestTexture(params, 0x80);
ASSERT_NE(tex, nullptr);
NodeValueRow row;
row.insert(QStringLiteral("source"), NodeValue(NodeValue::kTexture, tex));
PluginJob job(nullptr, nullptr, row);
// Job should have the values inserted
EXPECT_FALSE(job.GetValues().isEmpty());
}
// ============================================================================
// Smoke Test: Thread Safety
// ============================================================================
TEST(PluginSmokeThread, ConcurrentImageAllocation)
{
const int num_threads = 4;
const int num_allocs_per_thread = 10;
std::vector<std::thread> threads;
std::atomic<int> success_count{ 0 };
for (int t = 0; t < num_threads; ++t) {
threads.emplace_back([&success_count, num_allocs_per_thread, t]() {
for (int i = 0; i < num_allocs_per_thread; ++i) {
OFX::Host::ImageEffect::ClipDescriptor desc(
kOfxImageEffectOutputClipName);
VideoParams params = MakeVideoParams(
32 + t, 32 + i, core::PixelFormat::U8, 4, false);
OliveClipInstance clip(nullptr, desc, params);
Image image(clip);
OfxRectI bounds = { 0, 0, 32 + t, 32 + i };
OfxRectI rod = bounds;
image.AllocateFromParams(params, bounds, rod, true);
if (image.data() != nullptr && image.width() == 32 + t &&
image.height() == 32 + i) {
success_count++;
}
}
});
}
for (auto &t : threads) {
t.join();
}
EXPECT_EQ(success_count.load(), num_threads * num_allocs_per_thread);
}
} // namespace test
} // namespace plugin
} // namespace olive