From 717505daefd9ce6005b607bf985ba4da5643b3f2 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Mon, 14 Mar 2016 16:03:48 +0100 Subject: [PATCH] Test: add a set_button test Which currently fails. Signed-off-by: Benjamin Tissoires --- src/driver-test.c | 11 ++++++++++- test/test-device.c | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/driver-test.c b/src/driver-test.c index 04b5989b..b3447c04 100644 --- a/src/driver-test.c +++ b/src/driver-test.c @@ -122,6 +122,15 @@ test_read_button(struct ratbag_button *button) ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_MACRO); } +static int +test_write_button(struct ratbag_button *button, + const struct ratbag_button_action *action) +{ + /* check if the device is still valid */ + assert(ratbag_get_drv_data(button->profile->device) != NULL); + return 0; +} + static int test_fake_probe(struct ratbag_device *device) { @@ -166,6 +175,6 @@ struct ratbag_driver test_driver = { .write_profile = test_write_profile, .set_active_profile = test_set_active_profile, .read_button = test_read_button, - .write_button = NULL, + .write_button = test_write_button, .write_resolution_dpi = NULL, }; diff --git a/test/test-device.c b/test/test-device.c index 052bffc4..27dc6a65 100644 --- a/test/test-device.c +++ b/test/test-device.c @@ -727,6 +727,30 @@ START_TEST(device_buttons_ref_unref) } END_TEST +START_TEST(device_buttons_set) +{ + struct ratbag *r; + struct ratbag_device *d; + struct ratbag_profile *p; + struct ratbag_button *b; + + struct ratbag_test_device td = sane_device; + td.num_buttons = 10; + + r = ratbag_create_context(&abort_iface, NULL); + d = ratbag_device_new_test_device(r, &td); + p = ratbag_device_get_profile(d, 1); + b = ratbag_profile_get_button(p, 0); + + ratbag_button_set_button(b, 3); + + ratbag_button_unref(b); + ratbag_profile_unref(p); + ratbag_device_unref(d); + ratbag_unref(r); +} +END_TEST + static Suite * test_context_suite(void) { @@ -762,6 +786,7 @@ test_context_suite(void) tc = tcase_create("buttons"); tcase_add_test(tc, device_buttons); tcase_add_test(tc, device_buttons_ref_unref); + tcase_add_test(tc, device_buttons_set); suite_add_tcase(s, tc); return s;