* 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
219 lines
No EOL
5.9 KiB
C++
219 lines
No EOL
5.9 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 `s_instance != nullptr' failed.
|
|
#if 0
|
|
|
|
#define TEST_ENV
|
|
|
|
#include "test/mock/synergy/MockEventQueue.h"
|
|
#include "test/mock/synergy/MockKeyMap.h"
|
|
|
|
#include "base/Log.h"
|
|
#include "platform/XWindowsKeyState.h"
|
|
|
|
#define XK_LATIN1
|
|
#define XK_MISCELLANY
|
|
#include <X11/keysymdef.h>
|
|
|
|
#if HAVE_XKB_EXTENSION
|
|
#include <X11/XKBlib.h>
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
class XWindowsKeyStateTests : public ::testing::Test {
|
|
protected:
|
|
XWindowsKeyStateTests() : m_display(NULL) {}
|
|
|
|
~XWindowsKeyStateTests() {
|
|
if (m_display != NULL) {
|
|
LOG((CLOG_DEBUG "closing display"));
|
|
XCloseDisplay(m_display);
|
|
}
|
|
}
|
|
|
|
virtual void SetUp() {
|
|
// open the display only once for the entire test suite
|
|
if (this->m_display == NULL) {
|
|
LOG((CLOG_DEBUG "opening display"));
|
|
this->m_display = XOpenDisplay(NULL);
|
|
|
|
ASSERT_TRUE(this->m_display != NULL)
|
|
<< "unable to open display: " << errno;
|
|
}
|
|
}
|
|
|
|
virtual void TearDown() {}
|
|
|
|
Display *m_display;
|
|
};
|
|
|
|
TEST_F(XWindowsKeyStateTests, setActiveGroup_pollAndSet_groupIsZero) {
|
|
MockKeyMap keyMap;
|
|
MockEventQueue eventQueue;
|
|
XWindowsKeyState keyState(m_display, true, &eventQueue, keyMap);
|
|
|
|
keyState.setActiveGroup(XWindowsKeyState::kGroupPollAndSet);
|
|
|
|
ASSERT_EQ(0, keyState.group());
|
|
}
|
|
|
|
TEST_F(XWindowsKeyStateTests, setActiveGroup_poll_groupIsNotSet) {
|
|
MockKeyMap keyMap;
|
|
MockEventQueue eventQueue;
|
|
XWindowsKeyState keyState(m_display, true, &eventQueue, keyMap);
|
|
|
|
keyState.setActiveGroup(XWindowsKeyState::kGroupPoll);
|
|
|
|
ASSERT_LE(-1, keyState.group());
|
|
}
|
|
|
|
TEST_F(XWindowsKeyStateTests, setActiveGroup_customGroup_groupWasSet) {
|
|
MockKeyMap keyMap;
|
|
MockEventQueue eventQueue;
|
|
XWindowsKeyState keyState(m_display, true, &eventQueue, keyMap);
|
|
|
|
keyState.setActiveGroup(1);
|
|
|
|
ASSERT_EQ(1, keyState.group());
|
|
}
|
|
|
|
TEST_F(XWindowsKeyStateTests, mapModifiersFromX_zeroState_zeroMask) {
|
|
MockKeyMap keyMap;
|
|
MockEventQueue eventQueue;
|
|
XWindowsKeyState keyState(m_display, true, &eventQueue, keyMap);
|
|
|
|
int mask = keyState.mapModifiersFromX(0);
|
|
|
|
ASSERT_EQ(0, mask);
|
|
}
|
|
|
|
TEST_F(XWindowsKeyStateTests, mapModifiersToX_zeroMask_resultIsTrue) {
|
|
MockKeyMap keyMap;
|
|
MockEventQueue eventQueue;
|
|
XWindowsKeyState keyState(m_display, true, &eventQueue, keyMap);
|
|
|
|
unsigned int modifiers = 0;
|
|
bool result = keyState.mapModifiersToX(0, modifiers);
|
|
|
|
ASSERT_TRUE(result);
|
|
}
|
|
|
|
TEST_F(XWindowsKeyStateTests, fakeCtrlAltDel_default_returnsFalse) {
|
|
MockKeyMap keyMap;
|
|
MockEventQueue eventQueue;
|
|
XWindowsKeyState keyState(m_display, true, &eventQueue, keyMap);
|
|
|
|
bool result = keyState.fakeCtrlAltDel();
|
|
|
|
ASSERT_FALSE(result);
|
|
}
|
|
|
|
TEST_F(XWindowsKeyStateTests, pollActiveModifiers_defaultState_returnsZero) {
|
|
MockKeyMap keyMap;
|
|
MockEventQueue eventQueue;
|
|
XWindowsKeyState keyState(m_display, true, &eventQueue, keyMap);
|
|
|
|
KeyModifierMask actual = keyState.pollActiveModifiers();
|
|
|
|
ASSERT_EQ(0, actual);
|
|
}
|
|
|
|
#if 0 // TODO: fix, causes sigsegv
|
|
TEST_F(XWindowsKeyStateTests, pollActiveModifiers_shiftKeyDownThenUp_masksAreCorrect)
|
|
{
|
|
MockKeyMap keyMap;
|
|
MockEventQueue eventQueue;
|
|
XWindowsKeyState keyState(
|
|
m_display, true, &eventQueue, keyMap);
|
|
|
|
// set mock modifier mapping
|
|
std::fill(keyState.modifierFromX().begin(), keyState.modifierFromX().end(), 0);
|
|
keyState.modifierFromX()[ShiftMapIndex] = KeyModifierShift;
|
|
|
|
KeyCode key = XKeysymToKeycode(m_display, XK_Shift_L);
|
|
|
|
// fake shift key down (without using synergy)
|
|
XTestFakeKeyEvent(m_display, key, true, CurrentTime);
|
|
|
|
// function under test (1st call)
|
|
KeyModifierMask modDown = keyState.pollActiveModifiers();
|
|
|
|
// fake shift key up (without using synergy)
|
|
XTestFakeKeyEvent(m_display, key, false, CurrentTime);
|
|
|
|
// function under test (2nd call)
|
|
KeyModifierMask modUp = keyState.pollActiveModifiers();
|
|
|
|
EXPECT_TRUE((modDown & KeyModifierShift) == KeyModifierShift)
|
|
<< "shift key not in mask - key was not pressed";
|
|
|
|
EXPECT_TRUE((modUp & KeyModifierShift) == 0)
|
|
<< "shift key still in mask - make sure no keys are being held down";
|
|
}
|
|
#endif
|
|
|
|
TEST_F(XWindowsKeyStateTests, pollActiveGroup_defaultState_returnsZero) {
|
|
MockKeyMap keyMap;
|
|
MockEventQueue eventQueue;
|
|
XWindowsKeyState keyState(m_display, true, &eventQueue, keyMap);
|
|
|
|
SInt32 actual = keyState.pollActiveGroup();
|
|
|
|
ASSERT_EQ(0, actual);
|
|
}
|
|
|
|
TEST_F(XWindowsKeyStateTests, pollActiveGroup_positiveGroup_returnsGroup) {
|
|
MockKeyMap keyMap;
|
|
MockEventQueue eventQueue;
|
|
XWindowsKeyState keyState(m_display, true, &eventQueue, keyMap);
|
|
|
|
keyState.group(3);
|
|
|
|
SInt32 actual = keyState.pollActiveGroup();
|
|
|
|
ASSERT_EQ(3, actual);
|
|
}
|
|
|
|
TEST_F(XWindowsKeyStateTests, pollActiveGroup_xkb_areEqual) {
|
|
#if HAVE_XKB_EXTENSION
|
|
MockKeyMap keyMap;
|
|
MockEventQueue eventQueue;
|
|
XWindowsKeyState keyState(m_display, true, &eventQueue, keyMap);
|
|
|
|
// reset the group
|
|
keyState.group(-1);
|
|
|
|
XkbStateRec state;
|
|
|
|
// compare pollActiveGroup() with XkbGetState()
|
|
if (XkbGetState(m_display, XkbUseCoreKbd, &state) == Success) {
|
|
SInt32 actual = keyState.pollActiveGroup();
|
|
|
|
ASSERT_EQ(state.group, actual);
|
|
} else {
|
|
FAIL() << "XkbGetState() returned error " << errno;
|
|
}
|
|
#else
|
|
SUCCEED() << "Xkb extension not installed";
|
|
#endif
|
|
}
|
|
#endif |