diff --git a/src/gui/test/HotkeyTests.cpp b/src/gui/test/HotkeyTests.cpp index 9df9c209..be8741c3 100644 --- a/src/gui/test/HotkeyTests.cpp +++ b/src/gui/test/HotkeyTests.cpp @@ -20,6 +20,7 @@ #include "Utils.h" #include +#include 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"); +}