[autotest/libinput] Add test case for the supported pointer buttons
This commit is contained in:
parent
72d9472674
commit
3aa8dc376e
3 changed files with 67 additions and 1 deletions
|
@ -58,6 +58,8 @@ private Q_SLOTS:
|
|||
void testPointerAcceleration();
|
||||
void testLeftHanded_data();
|
||||
void testLeftHanded();
|
||||
void testSupportedButtons_data();
|
||||
void testSupportedButtons();
|
||||
};
|
||||
|
||||
void TestLibinputDevice::testStaticGetter()
|
||||
|
@ -457,5 +459,47 @@ void TestLibinputDevice::testLeftHanded()
|
|||
QCOMPARE(leftHandedChangedSpy.isEmpty(), (supported && initValue) == expectedValue);
|
||||
}
|
||||
|
||||
void TestLibinputDevice::testSupportedButtons_data()
|
||||
{
|
||||
QTest::addColumn<bool>("isPointer");
|
||||
QTest::addColumn<Qt::MouseButtons>("setButtons");
|
||||
QTest::addColumn<Qt::MouseButtons>("expectedButtons");
|
||||
|
||||
QTest::newRow("left") << true << Qt::MouseButtons(Qt::LeftButton) << Qt::MouseButtons(Qt::LeftButton);
|
||||
QTest::newRow("right") << true << Qt::MouseButtons(Qt::RightButton) << Qt::MouseButtons(Qt::RightButton);
|
||||
QTest::newRow("middle") << true << Qt::MouseButtons(Qt::MiddleButton) << Qt::MouseButtons(Qt::MiddleButton);
|
||||
QTest::newRow("extra1") << true << Qt::MouseButtons(Qt::ExtraButton1) << Qt::MouseButtons(Qt::ExtraButton1);
|
||||
QTest::newRow("extra2") << true << Qt::MouseButtons(Qt::ExtraButton2) << Qt::MouseButtons(Qt::ExtraButton2);
|
||||
QTest::newRow("back") << true << Qt::MouseButtons(Qt::BackButton) << Qt::MouseButtons(Qt::BackButton);
|
||||
QTest::newRow("forward") << true << Qt::MouseButtons(Qt::ForwardButton) << Qt::MouseButtons(Qt::ForwardButton);
|
||||
QTest::newRow("task") << true << Qt::MouseButtons(Qt::TaskButton) << Qt::MouseButtons(Qt::TaskButton);
|
||||
|
||||
QTest::newRow("no pointer/left") << false << Qt::MouseButtons(Qt::LeftButton) << Qt::MouseButtons();
|
||||
QTest::newRow("no pointer/right") << false << Qt::MouseButtons(Qt::RightButton) << Qt::MouseButtons();
|
||||
QTest::newRow("no pointer/middle") << false << Qt::MouseButtons(Qt::MiddleButton) << Qt::MouseButtons();
|
||||
QTest::newRow("no pointer/extra1") << false << Qt::MouseButtons(Qt::ExtraButton1) << Qt::MouseButtons();
|
||||
QTest::newRow("no pointer/extra2") << false << Qt::MouseButtons(Qt::ExtraButton2) << Qt::MouseButtons();
|
||||
QTest::newRow("no pointer/back") << false << Qt::MouseButtons(Qt::BackButton) << Qt::MouseButtons();
|
||||
QTest::newRow("no pointer/forward") << false << Qt::MouseButtons(Qt::ForwardButton) << Qt::MouseButtons();
|
||||
QTest::newRow("no pointer/task") << false << Qt::MouseButtons(Qt::TaskButton) << Qt::MouseButtons();
|
||||
|
||||
QTest::newRow("all") << true
|
||||
<< Qt::MouseButtons(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton | Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::BackButton | Qt::ForwardButton | Qt::TaskButton)
|
||||
<< Qt::MouseButtons(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton | Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::BackButton | Qt::ForwardButton | Qt::TaskButton);
|
||||
}
|
||||
|
||||
void TestLibinputDevice::testSupportedButtons()
|
||||
{
|
||||
libinput_device device;
|
||||
QFETCH(bool, isPointer);
|
||||
device.pointer = isPointer;
|
||||
QFETCH(Qt::MouseButtons, setButtons);
|
||||
device.supportedButtons = setButtons;
|
||||
|
||||
Device d(&device);
|
||||
QCOMPARE(d.isPointer(), isPointer);
|
||||
QTEST(d.supportedButtons(), "expectedButtons");
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestLibinputDevice)
|
||||
#include "device_test.moc"
|
||||
|
|
|
@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <libinput.h>
|
||||
#include "mock_libinput.h"
|
||||
|
||||
#include <linux/input.h>
|
||||
|
||||
int libinput_device_keyboard_has_key(struct libinput_device *device, uint32_t code)
|
||||
{
|
||||
return 0;
|
||||
|
@ -158,7 +160,26 @@ int libinput_device_get_size(struct libinput_device *device, double *width, doub
|
|||
|
||||
int libinput_device_pointer_has_button(struct libinput_device *device, uint32_t code)
|
||||
{
|
||||
return 0;
|
||||
switch (code) {
|
||||
case BTN_LEFT:
|
||||
return device->supportedButtons.testFlag(Qt::LeftButton);
|
||||
case BTN_MIDDLE:
|
||||
return device->supportedButtons.testFlag(Qt::MiddleButton);
|
||||
case BTN_RIGHT:
|
||||
return device->supportedButtons.testFlag(Qt::RightButton);
|
||||
case BTN_SIDE:
|
||||
return device->supportedButtons.testFlag(Qt::ExtraButton1);
|
||||
case BTN_EXTRA:
|
||||
return device->supportedButtons.testFlag(Qt::ExtraButton2);
|
||||
case BTN_BACK:
|
||||
return device->supportedButtons.testFlag(Qt::BackButton);
|
||||
case BTN_FORWARD:
|
||||
return device->supportedButtons.testFlag(Qt::ForwardButton);
|
||||
case BTN_TASK:
|
||||
return device->supportedButtons.testFlag(Qt::TaskButton);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
enum libinput_config_status libinput_device_config_left_handed_set(struct libinput_device *device, int left_handed)
|
||||
|
|
|
@ -47,6 +47,7 @@ struct libinput_device {
|
|||
int setPointerAccelerationReturnValue = 0;
|
||||
bool leftHanded = false;
|
||||
int setLeftHandedReturnValue = 0;
|
||||
Qt::MouseButtons supportedButtons;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue