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.
181 lines
5.2 KiB
C++
181 lines
5.2 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <QUuid>
|
|
#include <QXmlStreamReader>
|
|
#include <QXmlStreamWriter>
|
|
|
|
#include "node/project.h"
|
|
|
|
TEST(NodeProject, DefaultsAfterConstruction)
|
|
{
|
|
olive::Project project;
|
|
|
|
EXPECT_EQ(project.filename(), QString());
|
|
EXPECT_EQ(project.name(), QStringLiteral("(untitled)"));
|
|
EXPECT_EQ(project.pretty_filename(), QStringLiteral("(untitled)"));
|
|
EXPECT_TRUE(project.is_new());
|
|
EXPECT_FALSE(project.is_modified());
|
|
EXPECT_TRUE(project.has_autorecovery_been_saved());
|
|
EXPECT_FALSE(project.get_uuid().isNull());
|
|
EXPECT_NE(project.color_manager(), nullptr);
|
|
EXPECT_EQ(project.root(), nullptr);
|
|
EXPECT_TRUE(project.nodes().isEmpty());
|
|
}
|
|
|
|
TEST(NodeProject, FilenameAndNameUpdate)
|
|
{
|
|
olive::Project project;
|
|
|
|
const QString filename = QStringLiteral("test_project.ove");
|
|
project.set_filename(filename);
|
|
EXPECT_EQ(project.filename(), filename);
|
|
EXPECT_EQ(project.name(), QStringLiteral("test_project"));
|
|
EXPECT_EQ(project.pretty_filename(), filename);
|
|
EXPECT_FALSE(project.is_new());
|
|
}
|
|
|
|
TEST(NodeProject, ModifiedState)
|
|
{
|
|
olive::Project project;
|
|
|
|
project.set_modified(true);
|
|
EXPECT_TRUE(project.is_modified());
|
|
EXPECT_FALSE(project.has_autorecovery_been_saved());
|
|
|
|
project.set_modified(false);
|
|
EXPECT_FALSE(project.is_modified());
|
|
EXPECT_TRUE(project.has_autorecovery_been_saved());
|
|
}
|
|
|
|
TEST(NodeProject, SettingsRoundTrip)
|
|
{
|
|
olive::Project project;
|
|
|
|
project.set_setting(
|
|
olive::Project::k_cache_location_setting_key,
|
|
QString::number(olive::Project::k_cache_store_alongside_project));
|
|
EXPECT_EQ(project.get_cache_location_setting(),
|
|
olive::Project::k_cache_store_alongside_project);
|
|
|
|
project.set_custom_cache_path(QStringLiteral("/tmp/cache"));
|
|
EXPECT_EQ(project.get_custom_cache_path(), QStringLiteral("/tmp/cache"));
|
|
|
|
project.set_color_config_filename(QStringLiteral("config.ocio"));
|
|
EXPECT_EQ(project.get_color_config_filename(), QStringLiteral("config.ocio"));
|
|
|
|
project.set_default_input_color_space(QStringLiteral("ACEScg"));
|
|
EXPECT_EQ(project.get_default_input_color_space(), QStringLiteral("ACEScg"));
|
|
|
|
project.set_color_reference_space(QStringLiteral("ACES - ACEScg"));
|
|
EXPECT_EQ(project.get_color_reference_space(),
|
|
QStringLiteral("ACES - ACEScg"));
|
|
}
|
|
|
|
TEST(NodeProject, InitializeCreatesRoot)
|
|
{
|
|
olive::Project project;
|
|
EXPECT_EQ(project.root(), nullptr);
|
|
|
|
project.initialize();
|
|
EXPECT_NE(project.root(), nullptr);
|
|
EXPECT_EQ(project.root()->get_label(), QStringLiteral("Root"));
|
|
}
|
|
|
|
TEST(NodeProject, UuidCanBeRegenerated)
|
|
{
|
|
olive::Project project;
|
|
const QUuid original = project.get_uuid();
|
|
|
|
project.regenerate_uuid();
|
|
EXPECT_FALSE(project.get_uuid().isNull());
|
|
EXPECT_NE(project.get_uuid(), original);
|
|
}
|
|
|
|
TEST(NodeProject, GetProjectFromObject)
|
|
{
|
|
olive::Project project;
|
|
olive::ColorManager *cm = project.color_manager();
|
|
EXPECT_EQ(olive::Project::get_project_from_object(cm), &project);
|
|
}
|
|
|
|
TEST(NodeProject, SaveProducesXml)
|
|
{
|
|
olive::Project project;
|
|
project.initialize();
|
|
|
|
QByteArray xml;
|
|
QXmlStreamWriter writer(&xml);
|
|
writer.writeStartDocument();
|
|
writer.writeStartElement(QStringLiteral("project"));
|
|
project.save(&writer);
|
|
writer.writeEndElement();
|
|
writer.writeEndDocument();
|
|
|
|
EXPECT_FALSE(xml.isEmpty());
|
|
|
|
// Parse the document and assert the serialized structure instead of
|
|
// relying on substring matching
|
|
QXmlStreamReader reader(xml);
|
|
ASSERT_TRUE(reader.readNextStartElement());
|
|
EXPECT_EQ(reader.name(), QStringLiteral("project"));
|
|
EXPECT_EQ(reader.attributes().value(QStringLiteral("version")).toString(),
|
|
QStringLiteral("1"));
|
|
|
|
bool saw_uuid = false;
|
|
QString uuid_text;
|
|
bool saw_nodes = false;
|
|
bool in_nodes = false;
|
|
int node_count = 0;
|
|
QString first_node_id;
|
|
bool in_settings = false;
|
|
bool saw_settings_root = false;
|
|
|
|
while (!reader.atEnd()) {
|
|
const QXmlStreamReader::TokenType token = reader.readNext();
|
|
if (token == QXmlStreamReader::StartElement) {
|
|
const QStringView name = reader.name();
|
|
if (name == QStringLiteral("uuid")) {
|
|
saw_uuid = true;
|
|
uuid_text = reader.readElementText();
|
|
} else if (name == QStringLiteral("nodes")) {
|
|
saw_nodes = true;
|
|
in_nodes = true;
|
|
} else if (in_nodes && name == QStringLiteral("node")) {
|
|
++node_count;
|
|
if (first_node_id.isEmpty()) {
|
|
first_node_id =
|
|
reader.attributes().value(QStringLiteral("id")).toString();
|
|
}
|
|
} else if (name == QStringLiteral("settings")) {
|
|
in_settings = true;
|
|
} else if (in_settings && name == QStringLiteral("root")) {
|
|
saw_settings_root = true;
|
|
}
|
|
} else if (token == QXmlStreamReader::EndElement) {
|
|
if (reader.name() == QStringLiteral("nodes")) {
|
|
in_nodes = false;
|
|
} else if (reader.name() == QStringLiteral("settings")) {
|
|
in_settings = false;
|
|
} else if (reader.name() == QStringLiteral("project")) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
ASSERT_FALSE(reader.hasError()) << reader.errorString().toStdString();
|
|
|
|
// The project uuid round-trips as a valid uuid
|
|
EXPECT_TRUE(saw_uuid);
|
|
EXPECT_EQ(uuid_text, project.get_uuid().toString());
|
|
EXPECT_FALSE(QUuid(uuid_text).isNull());
|
|
|
|
// Initialize() created a root folder, so at least one node is serialized
|
|
// and the first one is that root
|
|
EXPECT_TRUE(saw_nodes);
|
|
EXPECT_GE(node_count, 1);
|
|
EXPECT_EQ(first_node_id, project.root()->id());
|
|
|
|
// The root pointer is persisted in the settings block
|
|
EXPECT_TRUE(saw_settings_root);
|
|
}
|