Files
feedbackd/tests/test-fbd-dev-led.c
T
Dylan Van Assche e43126b007 fbd-dev-led: Rework color API
Drop has_color API since supported colors are set during probing
and can be handled completely separately from the classes for
each type of hardware.

Rename set_color to set_supported_color because the usage
of this API is to check if the color is supported, but not
setting it. Setting the color is also separated from
start_periodic API to re-use multicolor across multiple LED types
with a set_color API. Multicolor LEDs are actually the same as
regular LEDs but they require a few additional sysfs entries to
actually set the color. Single color LEDs only have a single color
so the set_color method just returns TRUE for these LEDs.

Supported colors are advertised through the supports_color API now.
This way, each LED driver define which colors are supported
through supports_color API. RGB multicolor LEDs will report only fixed colors
like red, blue, green and white until the kernel can expose if a diffusor
is present to mix these colors.
2024-06-09 11:21:19 +02:00

84 lines
2.4 KiB
C

/*
* Copyright (C) 2024 The Phosh Developers
* SPDX-License-Identifier: GPL-3.0+
*
* Author: Guido Günther <agx@sigxcpu.org>
*/
#include "fbd-feedback-led.h"
#include "fbd-dev-led.h"
#include "fbd-dev-led-multicolor.h"
#include "testlib.h"
static void
test_fbd_dev_led_simple (FbdUmockdevFixture *fixture, gconstpointer unused)
{
GUdevClient *client;
g_autolist (GUdevDevice) leds = NULL;
FbdDevLed *led;
g_autoptr (GError) err = NULL;
GUdevDevice *dev;
client = g_udev_client_new ((const char *const []){ "leds", NULL});
leds = g_udev_client_query_by_subsystem (client, "leds");
/* There should be a single device only */
g_assert_cmpint (g_list_length (leds), ==, 1);
dev = G_UDEV_DEVICE (leds->data);
g_assert_cmpstr (g_udev_device_get_property (dev, "FEEDBACKD_TYPE"), ==, "led");
led = fbd_dev_led_new (dev, &err);
g_assert_no_error (err);
g_assert_cmpint (fbd_dev_led_get_max_brightness (led), ==, 255);
g_assert_true (fbd_dev_led_supports_color (led, FBD_FEEDBACK_LED_COLOR_BLUE));
g_assert_true (fbd_dev_led_start_periodic (led, 50, 50));
g_assert_finalize_object (led);
}
static void
test_fbd_dev_led_multicolor (FbdUmockdevFixture *fixture, gconstpointer unused)
{
GUdevClient *client;
g_autolist (GUdevDevice) leds = NULL;
FbdDevLed *led;
g_autoptr (GError) err = NULL;
GUdevDevice *dev;
client = g_udev_client_new ((const char *const []){ "leds", NULL});
leds = g_udev_client_query_by_subsystem (client, "leds");
/* There should be a single device only */
g_assert_cmpint (g_list_length (leds), ==, 1);
dev = G_UDEV_DEVICE (leds->data);
g_assert_cmpstr (g_udev_device_get_property (dev, "FEEDBACKD_TYPE"), ==, "led");
led = fbd_dev_led_multicolor_new (dev, &err);
g_assert_no_error (err);
g_assert_cmpint (fbd_dev_led_get_max_brightness (led), ==, 248);
g_assert_true (fbd_dev_led_supports_color (led, FBD_FEEDBACK_LED_COLOR_RGB));
g_assert_true (fbd_dev_led_start_periodic (led, 50, 50));
g_assert_finalize_object (led);
}
gint
main (gint argc, gchar *argv[])
{
g_test_init (&argc, &argv, NULL);
FBD_UMOCKDEV_TEST_ADD ("/feedbackd/fbd/dev/led/simple",
test_fbd_dev_led_simple,
"led-simple");
FBD_UMOCKDEV_TEST_ADD ("/feedbackd/fbd/dev/led/multicolor",
test_fbd_dev_led_multicolor,
"led-multicolor");
return g_test_run();
}