Files
oak-editor/tests/gtest/common_commandlineparser_test.cpp
Mike-Solar bb40b4923e style: unify identifier naming per updated conventions
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.
2026-07-19 16:10:54 +08:00

129 lines
3.9 KiB
C++

#include <gtest/gtest.h>
#include <QDebug>
#include "common/commandlineparser.h"
namespace
{
// Collects qDebug/qWarning/qCritical output for inspection
QStringList g_captured_messages;
void capture_message_handler(QtMsgType, const QMessageLogContext &,
const QString &msg)
{
g_captured_messages.append(msg);
}
} // namespace
TEST(CommonCommandLineParser, OptionWithoutArgument)
{
CommandLineParser parser;
const CommandLineParser::Option *opt =
parser.add_option({ QStringLiteral("help"), QStringLiteral("h") },
QStringLiteral("Show help"), false);
parser.process({ QStringLiteral("app"), QStringLiteral("-help") });
EXPECT_TRUE(opt->is_set());
}
TEST(CommonCommandLineParser, ShortOption)
{
CommandLineParser parser;
const CommandLineParser::Option *opt =
parser.add_option({ QStringLiteral("help"), QStringLiteral("h") },
QStringLiteral("Show help"), false);
parser.process({ QStringLiteral("app"), QStringLiteral("-h") });
EXPECT_TRUE(opt->is_set());
}
TEST(CommonCommandLineParser, OptionWithArgument)
{
CommandLineParser parser;
const CommandLineParser::Option *opt = parser.add_option(
{ QStringLiteral("project") }, QStringLiteral("Project file"), true,
QStringLiteral("file"));
parser.process({ QStringLiteral("app"), QStringLiteral("-project"),
QStringLiteral("test.ove") });
EXPECT_TRUE(opt->is_set());
EXPECT_EQ(opt->get_setting(), QStringLiteral("test.ove"));
}
TEST(CommonCommandLineParser, PositionalArgument)
{
CommandLineParser parser;
const CommandLineParser::PositionalArgument *arg =
parser.add_positional_argument(QStringLiteral("filename"),
QStringLiteral("Project file"), true);
parser.process({ QStringLiteral("app"), QStringLiteral("test.ove") });
EXPECT_EQ(arg->get_setting(), QStringLiteral("test.ove"));
}
TEST(CommonCommandLineParser, UnknownOptionWarning)
{
CommandLineParser parser;
parser.add_option({ QStringLiteral("known") }, QStringLiteral("Known"));
g_captured_messages.clear();
QtMessageHandler old = qInstallMessageHandler(capture_message_handler);
parser.process({ QStringLiteral("app"), QStringLiteral("-unknown") });
qInstallMessageHandler(old);
// The warning must name the offending option
ASSERT_EQ(g_captured_messages.size(), 1);
EXPECT_TRUE(g_captured_messages.first().contains(
QStringLiteral("Unknown parameter:")));
EXPECT_TRUE(
g_captured_messages.first().contains(QStringLiteral("-unknown")));
}
TEST(CommonCommandLineParser, UnknownPositionalWarning)
{
CommandLineParser parser;
g_captured_messages.clear();
QtMessageHandler old = qInstallMessageHandler(capture_message_handler);
parser.process({ QStringLiteral("app"), QStringLiteral("extra") });
qInstallMessageHandler(old);
// The warning must name the offending positional argument
ASSERT_EQ(g_captured_messages.size(), 1);
EXPECT_TRUE(g_captured_messages.first().contains(
QStringLiteral("Unknown parameter:")));
EXPECT_TRUE(
g_captured_messages.first().contains(QStringLiteral("extra")));
}
TEST(CommonCommandLineParser, HiddenOptionExcludedFromHelp)
{
CommandLineParser parser;
parser.add_option({ QStringLiteral("visible") }, QStringLiteral("Visible"));
parser.add_option({ QStringLiteral("hidden") }, QStringLiteral("Hidden"),
false, QString(), true);
parser.add_positional_argument(QStringLiteral("file"),
QStringLiteral("Input file"));
// PrintHelp writes to stdout via printf
testing::internal::CaptureStdout();
parser.print_help("/usr/bin/app");
std::string help = testing::internal::GetCapturedStdout();
// Visible option and positional argument must be listed
EXPECT_NE(help.find("-visible"), std::string::npos);
EXPECT_NE(help.find("Visible"), std::string::npos);
EXPECT_NE(help.find("[file]"), std::string::npos);
// Hidden option must not appear anywhere in the help text
EXPECT_EQ(help.find("-hidden"), std::string::npos);
EXPECT_EQ(help.find("Hidden"), std::string::npos);
}