ratbagd: add support for test device button types

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2017-07-25 15:33:06 +10:00
committed by Benjamin Tissoires
parent 5f98d8d029
commit 5399d15658
4 changed files with 20 additions and 13 deletions

View File

@@ -200,11 +200,14 @@ static const struct ratbag_test_device ratbagd_test_device_descr = {
.profiles = {
{
.buttons = {
{ .action_type = RATBAG_BUTTON_ACTION_TYPE_BUTTON,
{ .button_type = RATBAG_BUTTON_TYPE_LEFT,
.action_type = RATBAG_BUTTON_ACTION_TYPE_BUTTON,
.button = 0 },
{ .action_type = RATBAG_BUTTON_ACTION_TYPE_KEY,
{ .button_type = RATBAG_BUTTON_TYPE_MIDDLE,
.action_type = RATBAG_BUTTON_ACTION_TYPE_KEY,
.key = KEY_3 },
{ .action_type = RATBAG_BUTTON_ACTION_TYPE_SPECIAL,
{ .button_type = RATBAG_BUTTON_TYPE_RIGHT,
.action_type = RATBAG_BUTTON_ACTION_TYPE_SPECIAL,
.special = RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_CYCLE_UP },
{ .action_type = RATBAG_BUTTON_ACTION_TYPE_MACRO,
.macro = {

View File

@@ -102,6 +102,9 @@ test_read_button(struct ratbag_button *button)
struct ratbag_test_macro_event *e;
int idx;
/* Only take the button types from the first profile */
button->type = d->profiles[0].buttons[button->index].button_type;
switch (b->action_type) {
case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
button->action.type = RATBAG_BUTTON_ACTION_TYPE_BUTTON;

View File

@@ -37,6 +37,7 @@ struct ratbag_test_macro_event {
};
struct ratbag_test_button {
enum ratbag_button_type button_type;
enum ratbag_button_action_type action_type;
union {
int button;

View File

@@ -370,12 +370,12 @@ class TestRatbgagCtlButton(TestRatbagCtl):
def test_button_n_get(self):
self.setProfile(0)
r = self.launch_good_test("button 0 get test_device")
self.assertEqual(r, "Button: 0 type unknown is mapped to 'button 0'")
self.assertEqual(r, "Button: 0 type left is mapped to 'button 0'")
r = self.launch_good_test("button 1 get test_device")
self.assertEqual(r, "Button: 1 type unknown is mapped to 'KEY_3'")
self.assertEqual(r, "Button: 1 type middle is mapped to 'KEY_3'")
r = self.launch_good_test("button 2 get test_device")
# FIXME: special maps to UNKNOWN????
self.assertEqual(r, "Button: 2 type unknown is mapped to UNKNOWN")
self.assertEqual(r, "Button: 2 type right is mapped to UNKNOWN")
r = self.launch_good_test("button 3 get test_device")
self.assertEqual(r, "Button: 3 type unknown is mapped to macro '+KEY_B -KEY_B t300'")
self.launch_fail_test("button 1 get 10 test_device")
@@ -385,7 +385,7 @@ class TestRatbgagCtlButton(TestRatbagCtl):
def test_button_n_action_get(self):
self.setProfile(0)
r = self.launch_good_test("button 0 action get test_device")
self.assertEqual(r, "Button: 0 type unknown is mapped to 'button 0'")
self.assertEqual(r, "Button: 0 type left is mapped to 'button 0'")
self.launch_fail_test("button 1 action get 10 test_device")
self.launch_fail_test("button 10 action get test_device")
self.launch_fail_test("button 1 action get test_device X")
@@ -394,11 +394,11 @@ class TestRatbgagCtlButton(TestRatbagCtl):
self.setProfile(2)
command = "button 2 action set button"
r = self.launch_good_test("button 2 action get test_device")
self.assertEqual(r, "Button: 2 type unknown is mapped to 'button 2'")
self.assertEqual(r, "Button: 2 type right is mapped to 'button 2'")
r = self.launch_good_test(command + " 1 test_device")
self.assertEqual(r, '')
r = self.launch_good_test("button 2 action get test_device")
self.assertEqual(r, "Button: 2 type unknown is mapped to 'button 1'")
self.assertEqual(r, "Button: 2 type right is mapped to 'button 1'")
self.launch_fail_test(command)
self.launch_fail_test(command + " X test_device")
self.launch_fail_test(command + " 100 test_device X")
@@ -412,16 +412,16 @@ class TestRatbgagCtlButton(TestRatbagCtl):
command = "button 2 action set macro "
self.launch_good_test(command + '+KEY_B KEY_A -KEY_B KEY_C test_device')
r = self.launch_good_test("button 2 get test_device")
self.assertEqual(r, "Button: 2 type unknown is mapped to macro '+KEY_B +KEY_A -KEY_A -KEY_B +KEY_C -KEY_C'")
self.assertEqual(r, "Button: 2 type right is mapped to macro '+KEY_B +KEY_A -KEY_A -KEY_B +KEY_C -KEY_C'")
self.launch_good_test(command + 't100 t200 test_device')
r = self.launch_good_test("button 2 get test_device")
self.assertEqual(r, "Button: 2 type unknown is mapped to macro 't100 t200'")
self.assertEqual(r, "Button: 2 type right is mapped to macro 't100 t200'")
self.launch_good_test(command + 'KeY_z test_device')
r = self.launch_good_test("button 2 get test_device")
self.assertEqual(r, "Button: 2 type unknown is mapped to macro '+KEY_Z -KEY_Z'")
self.assertEqual(r, "Button: 2 type right is mapped to macro '+KEY_Z -KEY_Z'")
self.launch_good_test(command + ' test_device')
r = self.launch_good_test("button 2 get test_device")
self.assertEqual(r, "Button: 2 type unknown is mapped to macro ''")
self.assertEqual(r, "Button: 2 type right is mapped to macro ''")
self.launch_fail_test(command)
self.launch_fail_test(command + " KEY_A test_device X")