Recursively load themes
Themes (other than the default theme) can specify a `parent-name` in the json file. This theme will be used as a base for the theme. Events and profiles of the children override those in the parents. For this we move the lookup code into it's separate class and also add tests. Closes: #38
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name" : "custom",
|
||||
"parent-name": "default",
|
||||
"profiles" : [
|
||||
{
|
||||
"name" : "full",
|
||||
"feedbacks" : [
|
||||
{
|
||||
"event-name" : "test-dummy-0",
|
||||
"type" : "Dummy",
|
||||
"duration" : 0x10
|
||||
},
|
||||
{
|
||||
"event-name" : "test-dummy-2",
|
||||
"type" : "Dummy",
|
||||
"duration" : 0x30
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name" : "$device",
|
||||
"parent-name": "default"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name" : "default",
|
||||
"profiles" : [
|
||||
{
|
||||
"name" : "full",
|
||||
"feedbacks" : [
|
||||
{
|
||||
"event-name" : "test-dummy-0",
|
||||
"type" : "Dummy"
|
||||
},
|
||||
{
|
||||
"event-name" : "test-dummy-1",
|
||||
"type" : "Dummy"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "quiet",
|
||||
"feedbacks" : [
|
||||
{
|
||||
"event-name" : "test-dummy-0",
|
||||
"type" : "Dummy"
|
||||
},
|
||||
{
|
||||
"event-name" : "test-dummy-1",
|
||||
"type" : "Dummy"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name" : "$device",
|
||||
"parent-name": "default",
|
||||
"profiles" : [
|
||||
{
|
||||
"name" : "full",
|
||||
"feedbacks" : [
|
||||
{
|
||||
"event-name" : "test-dummy-0",
|
||||
"type" : "Dummy",
|
||||
"duration" : 0x10
|
||||
},
|
||||
{
|
||||
"event-name" : "test-dummy-2",
|
||||
"type" : "Dummy",
|
||||
"duration" : 0x20
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
+7
-3
@@ -11,7 +11,7 @@ test_env.set('MALLOC_CHECK_', '2')
|
||||
test_env.set('XDG_CONFIG_HOME', meson.current_source_dir())
|
||||
test_env.set('XDG_CONFIG_DIRS', meson.current_source_dir())
|
||||
|
||||
# Shared lfbrary Unit tests
|
||||
# Shared library Unit tests
|
||||
|
||||
test_lfb_cflags = [
|
||||
'-DTEST_APP_ID="org.sigxcpu.feedbackd_test"',
|
||||
@@ -52,10 +52,13 @@ endforeach
|
||||
# Daemon Unit tests
|
||||
if get_option('daemon')
|
||||
|
||||
test_env_fbd = test_env
|
||||
test_env_fbd.set('XDG_DATA_DIRS', meson.current_source_dir() / 'data' / 'xdg-data')
|
||||
|
||||
test_fbd_cflags = [
|
||||
'-DTEST_APP_ID="org.sigxcpu.feedbackd_test"',
|
||||
'-DTEST_DATA_DIR="@0@"'.format(join_paths(meson.current_source_dir(), 'data')),
|
||||
]
|
||||
]
|
||||
|
||||
test_fbd_link_args = [
|
||||
'-fPIC',
|
||||
@@ -69,6 +72,7 @@ fbd_tests = [
|
||||
'fbd-feedback-profile',
|
||||
'fbd-feedback-theme',
|
||||
'fbd-event',
|
||||
'fbd-theme-expander',
|
||||
]
|
||||
|
||||
foreach test : fbd_tests
|
||||
@@ -79,7 +83,7 @@ foreach test : fbd_tests
|
||||
link_args : test_fbd_link_args,
|
||||
include_directories : fbd_inc,
|
||||
dependencies : test_fbd_deps)
|
||||
test(test, t, env : test_env)
|
||||
test(test, t, env : test_env_fbd)
|
||||
endforeach
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Guido Günther <agx@sigxcpu.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0+
|
||||
*/
|
||||
|
||||
#include "fbd-feedback-dummy.h"
|
||||
#include "fbd-theme-expander.h"
|
||||
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
|
||||
static void
|
||||
test_fbd_theme_expander_object (void)
|
||||
{
|
||||
g_autoptr (FbdThemeExpander) expander = g_object_new (FBD_TYPE_THEME_EXPANDER, NULL);
|
||||
|
||||
g_assert_null (fbd_theme_expander_get_theme_file (expander));
|
||||
g_assert_null (fbd_theme_expander_get_compatibles (expander));
|
||||
}
|
||||
|
||||
static void
|
||||
test_fbd_theme_expander_device (void)
|
||||
{
|
||||
g_autoptr (GError) err = NULL;
|
||||
const char *compatibles[] = { NULL, NULL };
|
||||
FbdFeedbackProfile *profile;
|
||||
FbdThemeExpander *expander;
|
||||
FbdFeedbackTheme *theme;
|
||||
FbdFeedbackBase *fb;
|
||||
const char *const *compatibles2;
|
||||
|
||||
/* just the default profile */
|
||||
compatibles[0] = "doesnotexist";
|
||||
expander = fbd_theme_expander_new (compatibles, NULL);
|
||||
theme = fbd_theme_expander_load_theme_files (expander, &err);
|
||||
compatibles2 = fbd_theme_expander_get_compatibles (expander);
|
||||
g_assert_cmpstrv (compatibles2, compatibles);
|
||||
g_assert_no_error (err);
|
||||
profile = fbd_feedback_theme_get_profile (theme, "silent");
|
||||
g_assert_null (profile);
|
||||
profile = fbd_feedback_theme_get_profile (theme, "quiet");
|
||||
g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
|
||||
profile = fbd_feedback_theme_get_profile (theme, "full");
|
||||
g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
|
||||
g_assert_finalize_object (theme);
|
||||
g_assert_finalize_object (expander);
|
||||
|
||||
/* Empty device theme that just chains up */
|
||||
compatibles[0] = "chainup";
|
||||
expander = fbd_theme_expander_new (compatibles, NULL);
|
||||
compatibles2 = fbd_theme_expander_get_compatibles (expander);
|
||||
g_assert_cmpstrv (compatibles2, compatibles);
|
||||
theme = fbd_theme_expander_load_theme_files (expander, &err);
|
||||
g_assert_no_error (err);
|
||||
profile = fbd_feedback_theme_get_profile (theme, "silent");
|
||||
g_assert_null (profile);
|
||||
profile = fbd_feedback_theme_get_profile (theme, "quiet");
|
||||
g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
|
||||
profile = fbd_feedback_theme_get_profile (theme, "full");
|
||||
g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
|
||||
g_assert_finalize_object (theme);
|
||||
g_assert_finalize_object (expander);
|
||||
|
||||
/* Replace an existing event */
|
||||
compatibles[0] = "replace";
|
||||
expander = fbd_theme_expander_new (compatibles, NULL);
|
||||
compatibles2 = fbd_theme_expander_get_compatibles (expander);
|
||||
g_assert_cmpstrv (compatibles2, compatibles);
|
||||
theme = fbd_theme_expander_load_theme_files (expander, &err);
|
||||
g_assert_no_error (err);
|
||||
profile = fbd_feedback_theme_get_profile (theme, "full");
|
||||
g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
|
||||
fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-0");
|
||||
g_assert_cmpstr ("test-dummy-0", ==, fbd_feedback_get_event_name (fb));
|
||||
g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x10);
|
||||
g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
|
||||
fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-2");
|
||||
g_assert_cmpstr ("test-dummy-2", ==, fbd_feedback_get_event_name (fb));
|
||||
g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x20);
|
||||
g_assert_finalize_object (theme);
|
||||
g_assert_finalize_object (expander);
|
||||
}
|
||||
|
||||
|
||||
gint
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func("/feedbackd/fbd/theme-expander/object", test_fbd_theme_expander_object);
|
||||
g_test_add_func("/feedbackd/fbd/theme-expander/device", test_fbd_theme_expander_device);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
Reference in New Issue
Block a user