Files
oak-editor/tests/gtest/preferences_behavior_tab_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

162 lines
4.9 KiB
C++

#include <gtest/gtest.h>
#include <QApplication>
#include "audio/audiomanager.h"
#include "config/config.h"
#include "dialog/preferences/tabs/preferencesbehaviortab.h"
#include "dialog/preferences/tabs/preferencesgeneraltab.h"
#include "dialog/preferences/tabs/preferencesaudiotab.h"
using namespace olive;
TEST(PreferencesBehaviorTab, TimelineCategoryHasExpectedCheckboxes)
{
PreferencesBehaviorTab tab(PreferencesBehaviorTab::kCategoryTimeline);
// 8 timeline behavior options
EXPECT_EQ(tab.findChildren<QCheckBox *>().size(), 8);
}
TEST(PreferencesBehaviorTab, PlaybackCategoryHasExpectedCheckboxes)
{
PreferencesBehaviorTab tab(PreferencesBehaviorTab::kCategoryPlayback);
EXPECT_EQ(tab.findChildren<QCheckBox *>().size(), 2);
}
TEST(PreferencesBehaviorTab, ProjectCategoryHasExpectedCheckboxes)
{
PreferencesBehaviorTab tab(PreferencesBehaviorTab::kCategoryProject);
EXPECT_EQ(tab.findChildren<QCheckBox *>().size(), 1);
}
TEST(PreferencesBehaviorTab, NodesCategoryHasExpectedCheckboxes)
{
PreferencesBehaviorTab tab(PreferencesBehaviorTab::kCategoryNodes);
EXPECT_EQ(tab.findChildren<QCheckBox *>().size(), 3);
}
TEST(PreferencesBehaviorTab, RenderingCategoryHasGraphicsBackendCombobox)
{
PreferencesBehaviorTab tab(PreferencesBehaviorTab::kCategoryRendering);
EXPECT_FALSE(tab.findChildren<QComboBox *>().isEmpty());
EXPECT_FALSE(tab.findChildren<QCheckBox *>().isEmpty());
}
TEST(PreferencesBehaviorTab, BehaviorPrefTrReturnsExactSourceStrings)
{
// BehaviorPrefTr() provides the shared source strings used by the other
// preference tabs; without a translator installed it returns the source
// text unchanged. Pin the exact strings so accidental edits are caught
// (they would silently change the translation keys and the cross-tab
// lookups that rely on them).
EXPECT_EQ(PreferencesBehaviorTab::BehaviorPrefTr("Behavior"),
QStringLiteral("Behavior"));
EXPECT_EQ(PreferencesBehaviorTab::BehaviorPrefTr("Enable hover focus"),
QStringLiteral("Enable hover focus"));
EXPECT_EQ(PreferencesBehaviorTab::BehaviorPrefTr("Enable slider ladder"),
QStringLiteral("Enable slider ladder"));
EXPECT_EQ(PreferencesBehaviorTab::BehaviorPrefTr(
"Scrolling zooms by default"),
QStringLiteral("Scrolling zooms by default"));
EXPECT_EQ(PreferencesBehaviorTab::BehaviorPrefTr("Enable audio scrubbing"),
QStringLiteral("Enable audio scrubbing"));
}
TEST(PreferencesBehaviorTab, RenderingCategoryContainsDefaultBackend)
{
// Force the config back to the registered default so the selected entry
// is deterministic regardless of test order
const QVariant saved_backend =
Config::Current()[QStringLiteral("GraphicsBackend")];
Config::Current()[QStringLiteral("GraphicsBackend")] =
QStringLiteral("opengl");
{
PreferencesBehaviorTab tab(PreferencesBehaviorTab::kCategoryRendering);
QList<QComboBox *> boxes = tab.findChildren<QComboBox *>();
ASSERT_FALSE(boxes.isEmpty());
QComboBox *backend_box = boxes.first();
// config.cpp registers "opengl" as the default GraphicsBackend
const int opengl_index =
backend_box->findData(QStringLiteral("opengl"));
ASSERT_NE(opengl_index, -1);
EXPECT_EQ(backend_box->itemText(opengl_index),
QStringLiteral("OpenGL"));
EXPECT_EQ(backend_box->currentIndex(), opengl_index);
}
Config::Current()[QStringLiteral("GraphicsBackend")] = saved_backend;
}
TEST(PreferencesGeneralTab, ContainsHoverFocusOption)
{
PreferencesGeneralTab tab;
QList<QCheckBox *> boxes = tab.findChildren<QCheckBox *>();
bool found = false;
foreach (QCheckBox *box, boxes) {
if (box->text() ==
PreferencesBehaviorTab::BehaviorPrefTr("Enable hover focus")) {
found = true;
break;
}
}
EXPECT_TRUE(found);
}
TEST(PreferencesAudioTab, AudioScrubbingCheckboxUsesBehaviorTranslation)
{
AudioManager::CreateInstance();
{
PreferencesAudioTab tab;
QList<QCheckBox *> boxes = tab.findChildren<QCheckBox *>();
bool found = false;
foreach (QCheckBox *box, boxes) {
if (box->text() == PreferencesBehaviorTab::BehaviorPrefTr(
"Enable audio scrubbing")) {
found = true;
break;
}
}
EXPECT_TRUE(found);
}
AudioManager::DestroyInstance();
}
TEST(PreferencesGeneralTab, IncludesBehaviorOptions)
{
PreferencesGeneralTab tab;
QList<QCheckBox *> boxes = tab.findChildren<QCheckBox *>();
EXPECT_GE(boxes.size(), 3);
}
TEST(PreferencesAudioTab, IncludesAudioScrubbingOption)
{
AudioManager::CreateInstance();
{
PreferencesAudioTab tab;
// Locate the scrubbing checkbox by its exact (untranslated) label
QCheckBox *scrubbing = nullptr;
foreach (QCheckBox *box, tab.findChildren<QCheckBox *>()) {
if (box->text() == QStringLiteral("Enable audio scrubbing")) {
scrubbing = box;
break;
}
}
ASSERT_NE(scrubbing, nullptr);
// Its initial state mirrors the AudioScrubbing config entry
EXPECT_EQ(scrubbing->isChecked(),
Config::Current()[QStringLiteral("AudioScrubbing")].toBool());
}
AudioManager::DestroyInstance();
}