deskflow/src/test/integtests/platform/MSWindowsKeyStateTests.cpp

150 lines
4.4 KiB
C++
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* synergy -- mouse and keyboard sharing utility
2016-09-07 14:24:00 +00:00
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2011 Nick Bolton
*
2012-06-10 16:50:54 +00:00
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
2012-06-10 16:50:54 +00:00
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Restore integtests and add to CI as warning comment on failure (#7404) * Add coverage for both targets * Use var for test bins * Disable cmake-format comment fiddling * Refactor GUI source config * Use bin var for tests * Remove unused member * Add integration tests to CI * Use modern cmake args * Use max threads for build * Use better var name for CPU core count * Split build and configure steps * Combine tests into action and add a PR comment * Fixed yaml indentation in action * Pass GITHUB_TOKEN * Update coverage paths for SonarCloud * Don't ignore return codes * Add shell * Run Valgrind on integ tests * Use header for tests * Save test results in table * Move setup step outside of action * Change logic of creating PR comment * Remove header formatting * Use emojis for simplicity * Run build wrapper in build dir * Use default make target * Pass secrets * Fixed SonarScanner warnings * Don't allow unit tests to fail * Fixed typo * Update sonar scanner paths * Fixed line endings * Use step output * Improve exclusion glob * Exclude files from coverage * Restore simpler pattern * Set temp file path * Coverage tests * Re-create comment at start of job * Append table header * Add setup action * Checkout before action * Re-add projectBaseDir * Restore original sonar scanner * Use bash syntax for if * Remove unused `shell` * Add missing shell for valgrind action * Restore new sonar scanner config * Add missing shell * Run only MainWindowTests * Test with big change * More changes * Move to correct dir * Remove test code * Disable broken integ tests * Switch coverage to front of filename * Remove filter * Refactor status step * Disable segfault test * Fixed: No status showing * Add link to workflows * Add test code for coverage * Revert "Add test code for coverage" This reverts commit c42309349b64f7828f2ca89149b30c5b0f93478a. * Get workflow run URL * Add missing shell * Use dynamic URL in valgrind comment * Revert "Revert "Add test code for coverage"" This reverts commit 9cff58b7ea5c581681ae6d6660c073bd76ba99aa. * Test with commented out code * Reintroduce 6 lines for coverage * Test code to pass scanner * Test code to pass scanner (take 2) * Simplify to 2 new lines * Add another line * Trim changes to only 3 lines * Add task for all tests * Surface warning on failure * Simplify build-wrapper step and move settings from web UI to CI * Add missing line delims * Also run tests action on Windows and macOS * Add names to action steps * Add timeout for test steps * Add failure warning for integ tests * Remove space * Disable failing test on macOS * Disable problem matcher * Simplify names * Disable freezing test on Windows * Disable failing integ test on Windows * Add build-kill task * Ignore kill result on Windows * Delete test code * Update ChangeLog * Move timeout to workflow step
2024-07-18 16:51:06 +00:00
// TODO: fix Assertion failed: s_instance != nullptr
#if 0
#define TEST_ENV
#include "base/TMethodJob.h"
#include "platform/MSWindowsDesks.h"
#include "platform/MSWindowsKeyState.h"
#include "platform/MSWindowsScreen.h"
#include "platform/MSWindowsScreenSaver.h"
#include "test/mock/synergy/MockEventQueue.h"
#include "test/mock/synergy/MockKeyMap.h"
Solve SonarCloud security hotspots and bugs (#7383) * Test: allocLockCursorToScreenInfo_withState_setsState * Merge remote-tracking branch 'origin/master' into S1-1717-sonarcloud-issues * Remove header wrappers for gmock/gtest * Convenience wrapper script for tests * Use `std::copy` instead of `strcpy` * Use `std::ranges::copy` instead of `stdcpy` * Delete dead code * Add guitests VS Code config and test wrapper * Revert "Delete dead code" This reverts commit aa40f5cd35a22b4b69acfd1876aceea053088060. * Build guitests with CMake * Run all tests * Don't use --gtest_filter for Qt tests * Undo skip for GUI tests * Coverage for `IpcClient::sendCommand` * Remove provider and proxy * Use lamda for StreamProvider to reduce boilerplate * Restore version checker tests * Remove activation souces * Tasks for current/all tests * Change command for tasks * Mock QNetworkAccessManager * Create core app to satisfy Qt assertations * Use `std::copy` instead of `std::ranges::copy` * Remove integtests * Merge guitests into unittests * Use std::string::length * Remove include (resolves to root) * Fix memory leaks * Disable sigsegv tests * Fixed formatting * Remove guitests from CI * New MainWindowTests * Passing test for MainWindowTests * Use alternative to strlen in MainWindow::checkSecureSocket * Passing test for Log::print * Fixed dtor call order * Fixed var name typo * Use proxy instead of `#define protected public` * Add args test for log * Add license ctor * Fixed log test for release * Add error log test * Init qt with -platform offscreen * Back-out initQt function * Use QT_QPA_PLATFORM * Try QT_QPA_PLATFORM=offscreen * Use more readable env node * Set QT_QPA_PLATFORM in CI and CodeQL * Remove env not needed * Modernize Log::print * Calculate the length of the format string fmt during the initial scan loop * More direct and efficient alterative to `strlen` * Fixed major maint issues in AppConfig * New clang and cmake rules * Set `max_pargs_hwrap` to 4 * Undo clang format for now * Fix missing `Setting::` * Fixed missing `m_S` on Windows * Re-add accidental dep resolution (fix later) * Fixed missing buffer position increment * Turn on errors * Fixed tests and improve error message * Fixed segfault on log refactor * Extract log time to function * Copyright date * Update ChangeLog
2024-07-16 08:30:35 +00:00
#include <gmock/gmock.h>
#include <gtest/gtest.h>
2012-06-10 16:50:54 +00:00
// wParam = flags, HIBYTE(lParam) = virtual key, LOBYTE(lParam) = scan code
#define SYNERGY_MSG_FAKE_KEY SYNERGY_HOOK_LAST_MSG + 4
2012-06-10 16:50:54 +00:00
using ::testing::_;
using ::testing::NiceMock;
class MSWindowsKeyStateTests : public ::testing::Test {
2012-06-10 16:50:54 +00:00
protected:
virtual void SetUp() {
m_hook.loadLibrary();
m_screensaver = new MSWindowsScreenSaver();
}
virtual void TearDown() { delete m_screensaver; }
MSWindowsDesks *newDesks(IEventQueue *eventQueue) {
return new MSWindowsDesks(
true, false, m_screensaver, eventQueue,
new TMethodJob<MSWindowsKeyStateTests>(
this, &MSWindowsKeyStateTests::updateKeysCB),
false);
}
void *getEventTarget() const {
return const_cast<MSWindowsKeyStateTests *>(this);
}
2012-06-10 16:50:54 +00:00
private:
void updateKeysCB(void *) {}
IScreenSaver *m_screensaver;
MSWindowsHook m_hook;
2012-06-10 16:50:54 +00:00
};
TEST_F(MSWindowsKeyStateTests, disable_eventQueueNotUsed) {
NiceMock<MockEventQueue> eventQueue;
MSWindowsDesks *desks = newDesks(&eventQueue);
MockKeyMap keyMap;
MSWindowsKeyState keyState(
desks, getEventTarget(), &eventQueue, keyMap, {"en"}, true);
2012-06-10 16:50:54 +00:00
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(0);
2012-06-10 16:50:54 +00:00
keyState.disable();
delete desks;
2012-06-10 16:50:54 +00:00
}
TEST_F(
MSWindowsKeyStateTests,
testAutoRepeat_noRepeatAndButtonIsZero_resultIsTrue) {
NiceMock<MockEventQueue> eventQueue;
MSWindowsDesks *desks = newDesks(&eventQueue);
MockKeyMap keyMap;
MSWindowsKeyState keyState(
desks, getEventTarget(), &eventQueue, keyMap, {"en"}, true);
keyState.setLastDown(1);
2012-06-10 16:50:54 +00:00
bool actual = keyState.testAutoRepeat(true, false, 1);
2012-06-10 16:50:54 +00:00
ASSERT_TRUE(actual);
delete desks;
2012-06-10 16:50:54 +00:00
}
TEST_F(MSWindowsKeyStateTests, testAutoRepeat_pressFalse_lastDownIsZero) {
NiceMock<MockEventQueue> eventQueue;
MSWindowsDesks *desks = newDesks(&eventQueue);
MockKeyMap keyMap;
MSWindowsKeyState keyState(
desks, getEventTarget(), &eventQueue, keyMap, {"en"}, true);
keyState.setLastDown(1);
2012-06-10 16:50:54 +00:00
keyState.testAutoRepeat(false, false, 1);
2012-06-10 16:50:54 +00:00
ASSERT_EQ(0, keyState.getLastDown());
delete desks;
2012-06-10 16:50:54 +00:00
}
TEST_F(MSWindowsKeyStateTests, saveModifiers_noModifiers_savedModifiers0) {
NiceMock<MockEventQueue> eventQueue;
MSWindowsDesks *desks = newDesks(&eventQueue);
MockKeyMap keyMap;
MSWindowsKeyState keyState(
desks, getEventTarget(), &eventQueue, keyMap, {"en"}, true);
keyState.saveModifiers();
ASSERT_EQ(0, keyState.getSavedModifiers());
delete desks;
}
TEST_F(
MSWindowsKeyStateTests, testKoreanLocale_inputModeKey_resultCorrectKeyID) {
NiceMock<MockEventQueue> eventQueue;
MSWindowsDesks *desks = newDesks(&eventQueue);
MockKeyMap keyMap;
MSWindowsKeyState keyState(
desks, getEventTarget(), &eventQueue, keyMap, {"en"}, true);
keyState.setKeyLayout((HKL)0x00000412u); // for ko-KR local ID
ASSERT_EQ(
0xEF31, keyState.getKeyID(0x15u, 0x1f2u)); // VK_HANGUL from Hangul key
ASSERT_EQ(
0xEF34, keyState.getKeyID(0x19u, 0x1f1u)); // VK_HANJA from Hanja key
ASSERT_EQ(
0xEF31, keyState.getKeyID(0x15u, 0x11du)); // VK_HANGUL from R-Alt key
ASSERT_EQ(
0xEF34, keyState.getKeyID(0x19u, 0x138u)); // VK_HANJA from R-Ctrl key
keyState.setKeyLayout((HKL)0x00000411); // for ja-jp locale ID
ASSERT_EQ(0xEF26, keyState.getKeyID(0x15u, 0x1du)); // VK_KANA
ASSERT_EQ(0xEF2A, keyState.getKeyID(0x19u, 0x38u)); // VK_KANJI
delete desks;
}
Restore integtests and add to CI as warning comment on failure (#7404) * Add coverage for both targets * Use var for test bins * Disable cmake-format comment fiddling * Refactor GUI source config * Use bin var for tests * Remove unused member * Add integration tests to CI * Use modern cmake args * Use max threads for build * Use better var name for CPU core count * Split build and configure steps * Combine tests into action and add a PR comment * Fixed yaml indentation in action * Pass GITHUB_TOKEN * Update coverage paths for SonarCloud * Don't ignore return codes * Add shell * Run Valgrind on integ tests * Use header for tests * Save test results in table * Move setup step outside of action * Change logic of creating PR comment * Remove header formatting * Use emojis for simplicity * Run build wrapper in build dir * Use default make target * Pass secrets * Fixed SonarScanner warnings * Don't allow unit tests to fail * Fixed typo * Update sonar scanner paths * Fixed line endings * Use step output * Improve exclusion glob * Exclude files from coverage * Restore simpler pattern * Set temp file path * Coverage tests * Re-create comment at start of job * Append table header * Add setup action * Checkout before action * Re-add projectBaseDir * Restore original sonar scanner * Use bash syntax for if * Remove unused `shell` * Add missing shell for valgrind action * Restore new sonar scanner config * Add missing shell * Run only MainWindowTests * Test with big change * More changes * Move to correct dir * Remove test code * Disable broken integ tests * Switch coverage to front of filename * Remove filter * Refactor status step * Disable segfault test * Fixed: No status showing * Add link to workflows * Add test code for coverage * Revert "Add test code for coverage" This reverts commit c42309349b64f7828f2ca89149b30c5b0f93478a. * Get workflow run URL * Add missing shell * Use dynamic URL in valgrind comment * Revert "Revert "Add test code for coverage"" This reverts commit 9cff58b7ea5c581681ae6d6660c073bd76ba99aa. * Test with commented out code * Reintroduce 6 lines for coverage * Test code to pass scanner * Test code to pass scanner (take 2) * Simplify to 2 new lines * Add another line * Trim changes to only 3 lines * Add task for all tests * Surface warning on failure * Simplify build-wrapper step and move settings from web UI to CI * Add missing line delims * Also run tests action on Windows and macOS * Add names to action steps * Add timeout for test steps * Add failure warning for integ tests * Remove space * Disable failing test on macOS * Disable problem matcher * Simplify names * Disable freezing test on Windows * Disable failing integ test on Windows * Add build-kill task * Ignore kill result on Windows * Delete test code * Update ChangeLog * Move timeout to workflow step
2024-07-18 16:51:06 +00:00
#endif