From def2ef2a9ff3ea7ce4ffb12e5592a601f41670c1 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sun, 10 Jan 2021 15:28:09 +0200 Subject: [PATCH] gui/test: Add tests for Hotkey serialization via QTextStream --- src/gui/test/HotkeyTests.cpp | 72 ++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) 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"); +}