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.
159 lines
3.7 KiB
C++
159 lines
3.7 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include "cli/cliprogress/cliprogressdialog.h"
|
|
#include "cli/clitask/clitaskdialog.h"
|
|
#include "task/task.h"
|
|
|
|
namespace
|
|
{
|
|
|
|
class DummyTask : public olive::Task {
|
|
public:
|
|
explicit DummyTask(bool succeed)
|
|
: succeed_(succeed)
|
|
{
|
|
set_title(QStringLiteral("Dummy"));
|
|
}
|
|
|
|
protected:
|
|
virtual bool run() override
|
|
{
|
|
emit progress_changed(0.5);
|
|
emit progress_changed(1.0);
|
|
return succeed_;
|
|
}
|
|
|
|
private:
|
|
bool succeed_;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST(CLIProgress, ConstructorPrintsTitleAndZeroPercent)
|
|
{
|
|
testing::internal::CaptureStdout();
|
|
{
|
|
olive::CLIProgressDialog dlg(QStringLiteral("Exporting"));
|
|
}
|
|
const QString out =
|
|
QString::fromStdString(testing::internal::GetCapturedStdout());
|
|
|
|
EXPECT_TRUE(out.contains(QStringLiteral("Exporting")));
|
|
EXPECT_TRUE(out.contains(QStringLiteral("0%")));
|
|
}
|
|
|
|
TEST(CLIProgress, SameProgressValueDoesNotRedraw)
|
|
{
|
|
olive::CLIProgressDialog dlg(QStringLiteral("Job"));
|
|
|
|
testing::internal::CaptureStdout();
|
|
dlg.set_progress(0.0);
|
|
const QString out =
|
|
QString::fromStdString(testing::internal::GetCapturedStdout());
|
|
|
|
EXPECT_TRUE(out.isEmpty());
|
|
}
|
|
|
|
TEST(CLIProgress, ProgressRendersPercentage)
|
|
{
|
|
olive::CLIProgressDialog dlg(QStringLiteral("Job"));
|
|
|
|
testing::internal::CaptureStdout();
|
|
dlg.set_progress(0.25);
|
|
const QString out =
|
|
QString::fromStdString(testing::internal::GetCapturedStdout());
|
|
|
|
EXPECT_TRUE(out.contains(QStringLiteral("25%")));
|
|
}
|
|
|
|
TEST(CLIProgress, LongTitleIsTruncatedWithEllipsis)
|
|
{
|
|
const QString long_title(80, QLatin1Char('a'));
|
|
|
|
testing::internal::CaptureStdout();
|
|
{
|
|
olive::CLIProgressDialog dlg(long_title);
|
|
}
|
|
const QString out =
|
|
QString::fromStdString(testing::internal::GetCapturedStdout());
|
|
|
|
EXPECT_TRUE(out.contains(QStringLiteral("...")));
|
|
EXPECT_FALSE(out.contains(long_title));
|
|
}
|
|
|
|
TEST(CLIProgress, BarFillMatchesProgress)
|
|
{
|
|
olive::CLIProgressDialog dlg(QStringLiteral("Job"));
|
|
|
|
testing::internal::CaptureStdout();
|
|
dlg.set_progress(1.0);
|
|
const QString out =
|
|
QString::fromStdString(testing::internal::GetCapturedStdout());
|
|
|
|
// 80-column layout: bar area is 80/2-7 = 33 columns, all filled at 100%.
|
|
EXPECT_EQ(out.count(QLatin1Char('=')), 33);
|
|
}
|
|
|
|
TEST(CLIProgress, PercentageIsPaddedToThreeColumns)
|
|
{
|
|
olive::CLIProgressDialog dlg(QStringLiteral("Job"));
|
|
|
|
auto pct_field = [&](double p) {
|
|
testing::internal::CaptureStdout();
|
|
dlg.set_progress(p);
|
|
const QString out =
|
|
QString::fromStdString(testing::internal::GetCapturedStdout());
|
|
const int bracket = out.indexOf(QLatin1Char(']'));
|
|
const int percent = out.indexOf(QLatin1Char('%'));
|
|
EXPECT_GE(bracket, 0);
|
|
EXPECT_GT(percent, bracket);
|
|
return out.mid(bracket + 1, percent - bracket - 1);
|
|
};
|
|
|
|
// Single, double and triple digit percentages should all occupy the same
|
|
// field width so the bar stays aligned while progressing.
|
|
EXPECT_EQ(pct_field(0.05), QStringLiteral(" 5"));
|
|
EXPECT_EQ(pct_field(0.5), QStringLiteral(" 50"));
|
|
EXPECT_EQ(pct_field(1.0), QStringLiteral(" 100"));
|
|
}
|
|
|
|
TEST(CLITask, RunReturnsTaskResult)
|
|
{
|
|
{
|
|
DummyTask task(true);
|
|
olive::CLITaskDialog dlg(&task);
|
|
|
|
testing::internal::CaptureStdout();
|
|
const bool ok = dlg.run();
|
|
testing::internal::GetCapturedStdout();
|
|
|
|
EXPECT_TRUE(ok);
|
|
}
|
|
|
|
{
|
|
DummyTask task(false);
|
|
olive::CLITaskDialog dlg(&task);
|
|
|
|
testing::internal::CaptureStdout();
|
|
const bool ok = dlg.run();
|
|
testing::internal::GetCapturedStdout();
|
|
|
|
EXPECT_FALSE(ok);
|
|
}
|
|
}
|
|
|
|
TEST(CLITask, TaskProgressIsForwardedToDisplay)
|
|
{
|
|
DummyTask task(true);
|
|
olive::CLITaskDialog dlg(&task);
|
|
|
|
testing::internal::CaptureStdout();
|
|
dlg.run();
|
|
const QString out =
|
|
QString::fromStdString(testing::internal::GetCapturedStdout());
|
|
|
|
EXPECT_TRUE(out.contains(QStringLiteral("Dummy")));
|
|
EXPECT_TRUE(out.contains(QStringLiteral("50%")));
|
|
EXPECT_TRUE(out.contains(QStringLiteral("100%")));
|
|
}
|