deskflow/src/test/integtests/platform/MSWindowsKeyStateTests.cpp
Nick Bolton 6f411e4ab8
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 17:51:06 +01:00

149 lines
4.4 KiB
C++

/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2011 Nick Bolton
*
* 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.
*
* 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/>.
*/
// 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"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
// wParam = flags, HIBYTE(lParam) = virtual key, LOBYTE(lParam) = scan code
#define SYNERGY_MSG_FAKE_KEY SYNERGY_HOOK_LAST_MSG + 4
using ::testing::_;
using ::testing::NiceMock;
class MSWindowsKeyStateTests : public ::testing::Test {
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);
}
private:
void updateKeysCB(void *) {}
IScreenSaver *m_screensaver;
MSWindowsHook m_hook;
};
TEST_F(MSWindowsKeyStateTests, disable_eventQueueNotUsed) {
NiceMock<MockEventQueue> eventQueue;
MSWindowsDesks *desks = newDesks(&eventQueue);
MockKeyMap keyMap;
MSWindowsKeyState keyState(
desks, getEventTarget(), &eventQueue, keyMap, {"en"}, true);
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(0);
keyState.disable();
delete desks;
}
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);
bool actual = keyState.testAutoRepeat(true, false, 1);
ASSERT_TRUE(actual);
delete desks;
}
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);
keyState.testAutoRepeat(false, false, 1);
ASSERT_EQ(0, keyState.getLastDown());
delete desks;
}
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;
}
#endif