gui/test: Add tests for Hotkey serialization via QTextStream

This commit is contained in:
Povilas Kanapickas 2021-01-10 15:28:09 +02:00
parent 7befd121d4
commit def2ef2a9f
1 changed files with 72 additions and 0 deletions

View File

@ -20,6 +20,7 @@
#include "Utils.h"
#include <QtCore/QSettings>
#include <QtCore/QTextStream>
struct TestAction
{
@ -146,6 +147,14 @@ namespace {
}
return hotkey;
}
std::string hotkeyToStringViaTextStream(const Hotkey& hotkey)
{
QString result;
QTextStream stream{&result};
stream << hotkey;
return result.toStdString();
}
} // namespace
void doHotkeyLoadSaveTest(const TestHotKey& test_hotkey)
@ -246,3 +255,66 @@ TEST(HotkeyLoadSaveTests, KeysMultipleAction)
};
doHotkeyLoadSaveTest(hotkey);
}
TEST(HotkeyToTexStreamTests, Empty)
{
TestHotKey hotkey;
ASSERT_EQ(hotkeyToStringViaTextStream(createHotkey(hotkey)), "");
}
TEST(HotkeyToTexStreamTests, KeysNoActions)
{
TestHotKey hotkey = {
{
{Qt::Key_A, Qt::NoModifier},
{Qt::Key_B, Qt::NoModifier}
},
{}
};
ASSERT_EQ(hotkeyToStringViaTextStream(createHotkey(hotkey)), "");
}
TEST(HotkeyToTexStreamTests, KeysSingleAction)
{
TestHotKey hotkey = {
{
{Qt::Key_A, Qt::NoModifier},
{Qt::Key_B, Qt::NoModifier}
},
{}
};
ASSERT_EQ(hotkeyToStringViaTextStream(createHotkey(hotkey)), "");
}
TEST(HotkeyToTexStreamTests, KeysCommaSingleAction)
{
TestHotKey hotkey = {
{
{Qt::Key_A, Qt::NoModifier},
{Qt::Key_Comma, Qt::NoModifier},
{Qt::Key_B, Qt::NoModifier}
},
{
TestAction::createKeyDown({{Qt::Key_Z, Qt::NoModifier}})
}
};
ASSERT_EQ(hotkeyToStringViaTextStream(createHotkey(hotkey)),
"\tkeystroke(a+,+b) = keyDown(z,*)\n");
}
TEST(HotkeyToTexStreamTests, KeysMultipleAction)
{
TestHotKey hotkey = {
{
{Qt::Key_A, Qt::NoModifier},
{Qt::Key_B, Qt::NoModifier}
},
{
TestAction::createKeyDown({{Qt::Key_Z, Qt::NoModifier}}),
TestAction::createSwitchToScreen("test_screen")
}
};
ASSERT_EQ(hotkeyToStringViaTextStream(createHotkey(hotkey)),
"\tkeystroke(a+b) = keyDown(z,*)\n\tkeystroke(a+b) = switchToScreen(test_screen)\n");
}