Skip to content

Commit

Permalink
Separate GuiFont + GuiLinespace tst_shell UTs
Browse files Browse the repository at this point in the history
General code cleanup, in an attempt to improve our test coverage.

Splitting these test will hopefully make them more reliable, and easier
to modify/read in the future.
  • Loading branch information
jgehrig committed Feb 24, 2023
1 parent 2b4cb87 commit cfa6860
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 33 deletions.
4 changes: 3 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ add_xtest(tst_neovimconnector)
add_xtest(tst_callallmethods)
add_xtest(tst_encoding)
add_xtest(tst_msgpackiodevice)
add_xtest_gui(tst_shell ${SRC_SHELL_PLATFORM})
add_xtest_gui(tst_main)
add_xtest_gui(tst_shell
${SRC_SHELL_PLATFORM}
mock_qsettings.cpp)
add_xtest_gui(tst_qsettings
${SRC_SHELL_PLATFORM}
mock_qsettings.cpp)
Expand Down
65 changes: 50 additions & 15 deletions test/tst_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "common.h"
#include "common_gui.h"
#include "mock_qsettings.h"

#if defined(Q_OS_WIN) && defined(USE_STATIC_QT)
#include <QtPlugin>
Expand All @@ -24,11 +25,14 @@ class TestShell : public QObject

private slots:
void initTestCase() noexcept;
void cleanup() noexcept;

void benchStart() noexcept;
void startVarsShellWidget() noexcept;
void startVarsMainWindow() noexcept;
void gviminit() noexcept;
void guiShimCommands() noexcept;
void GuiLinespaceCommand() noexcept;
void GuiFontCommand() noexcept;
void CloseEvent_data() noexcept;
void CloseEvent() noexcept;
void GetClipboard_data() noexcept;
Expand All @@ -48,6 +52,8 @@ static void SignalPrintError(QString msg, const QVariant& err) noexcept

void TestShell::initTestCase() noexcept
{
NeovimQt::MockQSettings::EnableByDefault();

const QStringList fonts{
QStringLiteral("third-party/DejaVuSansMono.ttf"),
QStringLiteral("third-party/DejaVuSansMono-Bold.ttf"),
Expand All @@ -60,6 +66,12 @@ void TestShell::initTestCase() noexcept
}
}

void TestShell::cleanup() noexcept
{
NeovimQt::MockQSettings::ClearAllContents();
}


void TestShell::benchStart() noexcept
{
QBENCHMARK
Expand Down Expand Up @@ -101,28 +113,53 @@ void TestShell::gviminit() noexcept
QCOMPARE(cmd.at(0).at(2).toByteArray(), QByteArray("1"));
}

void TestShell::guiShimCommands() noexcept
void TestShell::GuiLinespaceCommand() noexcept
{
auto cw{ CreateMainWindowWithRuntime() };
NeovimConnector* c{ cw.first };
MainWindow* w{ cw.second };

QObject::connect(c->neovimObject(), &NeovimApi1::err_vim_command_output, SignalPrintError);

QSignalSpy cmd_font(
c->neovimObject()->vim_command_output(c->encode("GuiFont!")), &MsgpackRequest::finished);
QVERIFY(cmd_font.isValid());
QVERIFY2(SPYWAIT(cmd_font), "Waiting for GuiFont");
QSignalSpy cmd_ls{ c->neovimObject()->vim_command_output(c->encode("GuiLinespace")),
&MsgpackRequest::finished };

QSignalSpy cmd_ls(
c->neovimObject()->vim_command_output(c->encode("GuiLinespace")),
&MsgpackRequest::finished);
QVERIFY(cmd_ls.isValid());
QVERIFY2(SPYWAIT(cmd_ls), "Waiting for GuiLinespace");

QSignalSpy spyFontChanged{ w->shell(), &ShellWidget::shellFontChanged };
QSignalSpy spyLineSpace2{ c->neovimObject()->vim_command_output(c->encode("GuiLinespace 2")),
&MsgpackRequest::finished };

QVERIFY(spyFontChanged.isValid());
QVERIFY(SPYWAIT(spyFontChanged));

QSignalSpy spyLineSpaceValue{ c->neovimObject()->vim_command_output(c->encode("GuiLinespace")),
&MsgpackRequest::finished };

QVERIFY(spyLineSpaceValue.isValid());
QVERIFY(SPYWAIT(spyLineSpaceValue));

QByteArray varObserved{ spyLineSpaceValue.at(0).at(2).toByteArray() };
QCOMPARE(varObserved, QByteArray{ "2" });
}

void TestShell::GuiFontCommand() noexcept
{
auto cw{ CreateMainWindowWithRuntime() };
NeovimConnector* c{ cw.first };
MainWindow* w{ cw.second };

QObject::connect(c->neovimObject(), &NeovimApi1::err_vim_command_output, SignalPrintError);

QSignalSpy spyGuiFontNoArgs{ c->neovimObject()->vim_command_output(c->encode("GuiFont")),
&MsgpackRequest::finished };
QVERIFY(spyGuiFontNoArgs.isValid());
QVERIFY2(SPYWAIT(spyGuiFontNoArgs), "Waiting for GuiFont");

// Test font attributes
const QString cmdFontSize14{ QStringLiteral("GuiFont! %1:h14").arg(GetPlatformTestFont()) };
const QString expectedFontSize14{ QStringLiteral("%1:h14").arg(GetPlatformTestFont()) };
const QString cmdFontSize14{ QStringLiteral("GuiFont! DejaVu Sans Mono:h14") };
const QString expectedFontSize14{ QStringLiteral("DejaVu Sans Mono:h14") };
QSignalSpy cmd_gf{ c->neovimObject()->vim_command_output(c->encode(cmdFontSize14)),
&MsgpackRequest::finished };
QVERIFY(cmd_gf.isValid());
Expand All @@ -136,10 +173,8 @@ void TestShell::guiShimCommands() noexcept
QCOMPARE(w->shell()->fontDesc(), expectedFontSize14);

// Normalization removes the :b attribute
const QString cmdFontBoldRemoved{
QStringLiteral("GuiFont! %1:h16:b:l").arg(GetPlatformTestFont())
};
const QString expectedFontBoldRemoved{ QStringLiteral("%1:h16:l").arg(GetPlatformTestFont()) };
const QString cmdFontBoldRemoved{ QStringLiteral("GuiFont! DejaVu Sans Mono:h16:b:l") };
const QString expectedFontBoldRemoved{ QStringLiteral("DejaVu Sans Mono:h16:l") };
QSignalSpy spy_fontchange2(w->shell(), &ShellWidget::shellFontChanged);
QSignalSpy cmd_gf2{ c->neovimObject()->vim_command_output(c->encode(cmdFontBoldRemoved)),
&MsgpackRequest::finished };
Expand Down
2 changes: 0 additions & 2 deletions test/tst_shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace NeovimQt {

QClipboard::Mode GetClipboardMode(char reg) noexcept;

QString GetPlatformTestFont() noexcept;

QStringList BinaryAndArgumentsNoForkWithCommand(const QString& command) noexcept;

void AddPlatformSpecificExitCodeCases() noexcept;
Expand Down
5 changes: 0 additions & 5 deletions test/tst_shell_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ QClipboard::Mode GetClipboardMode(char /*reg*/) noexcept
return QClipboard::Clipboard;
}

QString GetPlatformTestFont() noexcept
{
return QStringLiteral("Monaco");
}

QStringList BinaryAndArgumentsNoForkWithCommand(const QString& command) noexcept
{
return { NVIM_QT_BINARY, "--nofork", "--", "-c", command };
Expand Down
5 changes: 0 additions & 5 deletions test/tst_shell_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ QClipboard::Mode GetClipboardMode(char reg) noexcept
return QClipboard::Clipboard;
}

QString GetPlatformTestFont() noexcept
{
return QStringLiteral("DejaVu Sans Mono");
}

QStringList BinaryAndArgumentsNoForkWithCommand(const QString& command) noexcept
{
return { NVIM_QT_BINARY, "--nofork", "--", "-c", command };
Expand Down
5 changes: 0 additions & 5 deletions test/tst_shell_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ QClipboard::Mode GetClipboardMode(char /*reg*/) noexcept
return QClipboard::Clipboard;
}

QString GetPlatformTestFont() noexcept
{
return QStringLiteral("Consolas");
}

QStringList BinaryAndArgumentsNoForkWithCommand(const QString& command) noexcept
{
return { NVIM_QT_BINARY, "--", "-c", command };
Expand Down

0 comments on commit cfa6860

Please sign in to comment.