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
249 lines
6.7 KiB
C++
249 lines
6.7 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <QDebug>
|
|
#include <QTemporaryDir>
|
|
#include <QTemporaryFile>
|
|
|
|
#include "common/filefunctions.h"
|
|
|
|
namespace
|
|
{
|
|
|
|
// Collects qDebug/qWarning/qCritical output for inspection
|
|
QStringList g_captured_messages;
|
|
|
|
void CaptureMessageHandler(QtMsgType, const QMessageLogContext &,
|
|
const QString &msg)
|
|
{
|
|
g_captured_messages.append(msg);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST(CommonFileFunctions, EnsureFilenameExtension)
|
|
{
|
|
EXPECT_EQ(olive::FileFunctions::EnsureFilenameExtension(
|
|
QStringLiteral("project"), QStringLiteral("ove")),
|
|
QStringLiteral("project.ove"));
|
|
EXPECT_EQ(olive::FileFunctions::EnsureFilenameExtension(
|
|
QStringLiteral("project.ove"), QStringLiteral("ove")),
|
|
QStringLiteral("project.ove"));
|
|
EXPECT_EQ(olive::FileFunctions::EnsureFilenameExtension(
|
|
QStringLiteral("PROJECT"), QStringLiteral("ove")),
|
|
QStringLiteral("PROJECT.ove"));
|
|
EXPECT_TRUE(olive::FileFunctions::EnsureFilenameExtension(
|
|
QString(), QStringLiteral("ove"))
|
|
.isEmpty());
|
|
EXPECT_EQ(olive::FileFunctions::EnsureFilenameExtension(
|
|
QStringLiteral("project"), QString()),
|
|
QStringLiteral("project"));
|
|
}
|
|
|
|
TEST(CommonFileFunctions, GetSafeTemporaryFilename)
|
|
{
|
|
QTemporaryDir dir;
|
|
ASSERT_TRUE(dir.isValid());
|
|
|
|
QString base = dir.filePath(QStringLiteral("test.ove"));
|
|
QString first = olive::FileFunctions::GetSafeTemporaryFilename(base);
|
|
EXPECT_FALSE(QFileInfo::exists(first));
|
|
EXPECT_TRUE(first.contains(QStringLiteral(".tmp0.")));
|
|
|
|
QFile f(first);
|
|
f.open(QIODevice::WriteOnly);
|
|
f.close();
|
|
|
|
QString second = olive::FileFunctions::GetSafeTemporaryFilename(base);
|
|
EXPECT_NE(first, second);
|
|
EXPECT_TRUE(second.contains(QStringLiteral(".tmp1.")));
|
|
}
|
|
|
|
TEST(CommonFileFunctions, DirectoryIsValid)
|
|
{
|
|
QTemporaryDir dir;
|
|
ASSERT_TRUE(dir.isValid());
|
|
|
|
EXPECT_TRUE(
|
|
olive::FileFunctions::DirectoryIsValid(QDir(dir.path()), false));
|
|
|
|
QDir nonexistent(dir.filePath(QStringLiteral("subdir/nested")));
|
|
EXPECT_TRUE(olive::FileFunctions::DirectoryIsValid(nonexistent, true));
|
|
EXPECT_TRUE(nonexistent.exists());
|
|
}
|
|
|
|
TEST(CommonFileFunctions, RenameFileAllowOverwrite)
|
|
{
|
|
QTemporaryDir dir;
|
|
ASSERT_TRUE(dir.isValid());
|
|
|
|
QString from = dir.filePath(QStringLiteral("from.txt"));
|
|
QString to = dir.filePath(QStringLiteral("to.txt"));
|
|
|
|
QFile f(from);
|
|
f.open(QIODevice::WriteOnly);
|
|
f.write("source");
|
|
f.close();
|
|
|
|
QFile t(to);
|
|
t.open(QIODevice::WriteOnly);
|
|
t.write("existing");
|
|
t.close();
|
|
|
|
EXPECT_TRUE(olive::FileFunctions::RenameFileAllowOverwrite(from, to));
|
|
EXPECT_FALSE(QFileInfo::exists(from));
|
|
QFile result(to);
|
|
result.open(QIODevice::ReadOnly);
|
|
EXPECT_EQ(result.readAll(), QByteArray("source"));
|
|
}
|
|
|
|
TEST(CommonFileFunctions, CanCopyDirectoryWithoutOverwriting)
|
|
{
|
|
QTemporaryDir src;
|
|
QTemporaryDir dst;
|
|
ASSERT_TRUE(src.isValid());
|
|
ASSERT_TRUE(dst.isValid());
|
|
|
|
QString src_file = QDir(src.path()).filePath(QStringLiteral("file.txt"));
|
|
QFile f(src_file);
|
|
f.open(QIODevice::WriteOnly);
|
|
f.close();
|
|
|
|
EXPECT_TRUE(olive::FileFunctions::CanCopyDirectoryWithoutOverwriting(
|
|
src.path(), dst.path()));
|
|
|
|
QString dst_file = QDir(dst.path()).filePath(QStringLiteral("file.txt"));
|
|
QFile g(dst_file);
|
|
g.open(QIODevice::WriteOnly);
|
|
g.close();
|
|
|
|
EXPECT_FALSE(olive::FileFunctions::CanCopyDirectoryWithoutOverwriting(
|
|
src.path(), dst.path()));
|
|
}
|
|
|
|
TEST(CommonFileFunctions, CopyDirectory)
|
|
{
|
|
QTemporaryDir src;
|
|
QTemporaryDir dst;
|
|
ASSERT_TRUE(src.isValid());
|
|
ASSERT_TRUE(dst.isValid());
|
|
|
|
QString src_file = QDir(src.path()).filePath(QStringLiteral("file.txt"));
|
|
QFile f(src_file);
|
|
f.open(QIODevice::WriteOnly);
|
|
f.write("copied");
|
|
f.close();
|
|
|
|
QString dst_dir = QDir(dst.path()).filePath(QStringLiteral("copied"));
|
|
olive::FileFunctions::CopyDirectory(src.path(), dst_dir, false);
|
|
|
|
QFile result(QDir(dst_dir).filePath(QStringLiteral("file.txt")));
|
|
EXPECT_TRUE(result.open(QIODevice::ReadOnly));
|
|
EXPECT_EQ(result.readAll(), QByteArray("copied"));
|
|
}
|
|
|
|
TEST(CommonFileFunctions, ReadFileAsString)
|
|
{
|
|
QTemporaryFile f;
|
|
ASSERT_TRUE(f.open());
|
|
f.write("hello world");
|
|
f.close();
|
|
|
|
EXPECT_EQ(olive::FileFunctions::ReadFileAsString(f.fileName()),
|
|
QStringLiteral("hello world"));
|
|
EXPECT_TRUE(olive::FileFunctions::ReadFileAsString(
|
|
QStringLiteral("/nonexistent/path"))
|
|
.isEmpty());
|
|
}
|
|
|
|
TEST(CommonFileFunctions, GetUniqueFileIdentifier)
|
|
{
|
|
QTemporaryFile f;
|
|
ASSERT_TRUE(f.open());
|
|
f.close();
|
|
|
|
QString id1 = olive::FileFunctions::GetUniqueFileIdentifier(f.fileName());
|
|
QString id2 = olive::FileFunctions::GetUniqueFileIdentifier(f.fileName());
|
|
EXPECT_FALSE(id1.isEmpty());
|
|
EXPECT_EQ(id1, id2);
|
|
|
|
EXPECT_TRUE(olive::FileFunctions::GetUniqueFileIdentifier(
|
|
QStringLiteral("/nonexistent"))
|
|
.isEmpty());
|
|
}
|
|
|
|
TEST(CommonFileFunctions, GetConfigurationLocation)
|
|
{
|
|
QString loc = olive::FileFunctions::GetConfigurationLocation();
|
|
EXPECT_FALSE(loc.isEmpty());
|
|
EXPECT_TRUE(QDir(loc).exists());
|
|
}
|
|
|
|
TEST(CommonFileFunctions, GetTempFilePath)
|
|
{
|
|
QString temp = olive::FileFunctions::GetTempFilePath();
|
|
EXPECT_FALSE(temp.isEmpty());
|
|
EXPECT_TRUE(QDir(temp).exists());
|
|
}
|
|
|
|
TEST(CommonFileFunctions, GetAutoRecoveryRoot)
|
|
{
|
|
QString root = olive::FileFunctions::GetAutoRecoveryRoot();
|
|
EXPECT_FALSE(root.isEmpty());
|
|
}
|
|
|
|
TEST(CommonFileFunctions, DirectoryIsValidExisting)
|
|
{
|
|
QTemporaryDir dir;
|
|
ASSERT_TRUE(dir.isValid());
|
|
EXPECT_TRUE(
|
|
olive::FileFunctions::DirectoryIsValid(QDir(dir.path()), false));
|
|
}
|
|
|
|
TEST(CommonFileFunctions, CopyDirectoryWithOverwrite)
|
|
{
|
|
QTemporaryDir src;
|
|
QTemporaryDir dst;
|
|
ASSERT_TRUE(src.isValid());
|
|
ASSERT_TRUE(dst.isValid());
|
|
|
|
QString src_file = QDir(src.path()).filePath(QStringLiteral("file.txt"));
|
|
QFile f(src_file);
|
|
f.open(QIODevice::WriteOnly);
|
|
f.write("new content");
|
|
f.close();
|
|
|
|
QString dst_file = QDir(dst.path()).filePath(QStringLiteral("file.txt"));
|
|
QFile g(dst_file);
|
|
g.open(QIODevice::WriteOnly);
|
|
g.write("old content");
|
|
g.close();
|
|
|
|
olive::FileFunctions::CopyDirectory(src.path(), dst.path(), true);
|
|
|
|
QFile result(dst_file);
|
|
result.open(QIODevice::ReadOnly);
|
|
EXPECT_EQ(result.readAll(), QByteArray("new content"));
|
|
}
|
|
|
|
TEST(CommonFileFunctions, CopyDirectorySourceMissing)
|
|
{
|
|
QTemporaryDir dst;
|
|
ASSERT_TRUE(dst.isValid());
|
|
|
|
// A missing source must log a critical error naming the source and
|
|
// leave the destination untouched
|
|
g_captured_messages.clear();
|
|
QtMessageHandler old = qInstallMessageHandler(CaptureMessageHandler);
|
|
olive::FileFunctions::CopyDirectory(QStringLiteral("/nonexistent/path"),
|
|
dst.path(), false);
|
|
qInstallMessageHandler(old);
|
|
|
|
ASSERT_EQ(g_captured_messages.size(), 1);
|
|
EXPECT_TRUE(g_captured_messages.first().contains(
|
|
QStringLiteral("Failed to copy directory")));
|
|
EXPECT_TRUE(g_captured_messages.first().contains(
|
|
QStringLiteral("/nonexistent/path")));
|
|
EXPECT_TRUE(
|
|
QDir(dst.path()).entryList(QDir::NoDotAndDotDot).isEmpty());
|
|
}
|