test: fix a bunch of checks for a given switch
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 28 May 2020 05:25:02 +0000 (15:25 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 3 Jun 2020 22:32:56 +0000 (22:32 +0000)
The has_switch() function returns -1 if the device doesn't have the switch
capability - which is the same as "true" and how we used this so far. Fix the
checks.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test/test-switch.c

index 29212e8d42208c5d94cd90d6ebfe37acbf5c4029..16838a86fd20b19b8fff08da8d08a9973499aef6 100644 (file)
@@ -33,14 +33,14 @@ static inline bool
 switch_has_lid(struct litest_device *dev)
 {
        return libinput_device_switch_has_switch(dev->libinput_device,
-                                                LIBINPUT_SWITCH_LID);
+                                                LIBINPUT_SWITCH_LID) > 0;
 }
 
 static inline bool
 switch_has_tablet_mode(struct litest_device *dev)
 {
        return libinput_device_switch_has_switch(dev->libinput_device,
-                                                LIBINPUT_SWITCH_TABLET_MODE);
+                                                LIBINPUT_SWITCH_TABLET_MODE) > 0;
 }
 
 START_TEST(switch_has_cap)
@@ -91,7 +91,7 @@ START_TEST(switch_toggle)
        litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
        libinput_dispatch(li);
 
-       if (libinput_device_switch_has_switch(dev->libinput_device, sw)) {
+       if (libinput_device_switch_has_switch(dev->libinput_device, sw) > 0) {
                event = libinput_get_event(li);
                litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_ON);
                libinput_event_destroy(event);
@@ -102,7 +102,7 @@ START_TEST(switch_toggle)
        litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_OFF);
        libinput_dispatch(li);
 
-       if (libinput_device_switch_has_switch(dev->libinput_device, sw)) {
+       if (libinput_device_switch_has_switch(dev->libinput_device, sw) > 0) {
                event = libinput_get_event(li);
                litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_OFF);
                libinput_event_destroy(event);
@@ -119,7 +119,7 @@ START_TEST(switch_toggle_double)
        struct libinput_event *event;
        enum libinput_switch sw = _i; /* ranged test */
 
-       if (!libinput_device_switch_has_switch(dev->libinput_device, sw))
+       if (libinput_device_switch_has_switch(dev->libinput_device, sw) <= 0)
                return;
 
        litest_drain_events(li);
@@ -163,7 +163,7 @@ START_TEST(switch_down_on_init)
        struct libinput_event *event;
        enum libinput_switch sw = _i; /* ranged test */
 
-       if (!libinput_device_switch_has_switch(dev->libinput_device, sw))
+       if (libinput_device_switch_has_switch(dev->libinput_device, sw) <= 0)
                return;
 
        if (sw == LIBINPUT_SWITCH_LID && !lid_switch_is_reliable(dev))
@@ -207,7 +207,7 @@ START_TEST(switch_not_down_on_init)
        struct libinput_event *event;
        enum libinput_switch sw = LIBINPUT_SWITCH_LID;
 
-       if (!libinput_device_switch_has_switch(dev->libinput_device, sw))
+       if (libinput_device_switch_has_switch(dev->libinput_device, sw) <= 0)
                return;
 
        if (sw == LIBINPUT_SWITCH_LID && lid_switch_is_reliable(dev))
@@ -248,7 +248,7 @@ START_TEST(switch_disable_touchpad)
        struct libinput *li = sw->libinput;
        enum libinput_switch which = _i; /* ranged test */
 
-       if (!libinput_device_switch_has_switch(sw->libinput_device, which))
+       if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
                return;
 
        touchpad = switch_init_paired_touchpad(li);
@@ -284,7 +284,7 @@ START_TEST(switch_disable_touchpad_during_touch)
        struct libinput *li = sw->libinput;
        enum libinput_switch which = _i; /* ranged test */
 
-       if (!libinput_device_switch_has_switch(sw->libinput_device, which))
+       if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
                return;
 
        touchpad = switch_init_paired_touchpad(li);
@@ -313,7 +313,7 @@ START_TEST(switch_disable_touchpad_edge_scroll)
        struct libinput *li = sw->libinput;
        enum libinput_switch which = _i; /* ranged test */
 
-       if (!libinput_device_switch_has_switch(sw->libinput_device, which))
+       if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
                return;
 
        touchpad = switch_init_paired_touchpad(li);
@@ -351,7 +351,7 @@ START_TEST(switch_disable_touchpad_edge_scroll_interrupt)
        struct libinput_event *event;
        enum libinput_switch which = _i; /* ranged test */
 
-       if (!libinput_device_switch_has_switch(sw->libinput_device, which))
+       if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
                return;
 
        touchpad = switch_init_paired_touchpad(li);
@@ -390,7 +390,7 @@ START_TEST(switch_disable_touchpad_already_open)
        struct libinput *li = sw->libinput;
        enum libinput_switch which = _i; /* ranged test */
 
-       if (!libinput_device_switch_has_switch(sw->libinput_device, which))
+       if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
                return;
 
        touchpad = switch_init_paired_touchpad(li);
@@ -424,7 +424,7 @@ START_TEST(switch_dont_resume_disabled_touchpad)
        struct libinput *li = sw->libinput;
        enum libinput_switch which = _i; /* ranged test */
 
-       if (!libinput_device_switch_has_switch(sw->libinput_device, which))
+       if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
                return;
 
        touchpad = switch_init_paired_touchpad(li);
@@ -462,7 +462,7 @@ START_TEST(switch_dont_resume_disabled_touchpad_external_mouse)
        struct libinput *li = sw->libinput;
        enum libinput_switch which = _i; /* ranged test */
 
-       if (!libinput_device_switch_has_switch(sw->libinput_device, which))
+       if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
                return;
 
        touchpad = switch_init_paired_touchpad(li);