Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_accel_map_defaults.c
Go to the documentation of this file.
1/*
2 This file is part of Ansel,
3 Copyright (C) 2026 Aurélien PIERRE.
4
5 Ansel is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Ansel is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Ansel. If not, see <http://www.gnu.org/licenses/>.
17*/
18
39#include <gtk/gtk.h>
40
41#include <stdarg.h>
42#include <stddef.h>
43// cmocka.h declares `extern jmp_buf global_expect_assert_env' at file scope without including
44// <setjmp.h> itself. Same suppression as the other tests here, and for the same reason.
45#include <setjmp.h> // NOLINT(misc-include-cleaner)
46#include <stdint.h>
47#include <cmocka.h>
48
49#define APP_DEFAULT_KEY GDK_KEY_F5
50
52static void _load_config(const char *contents)
53{
54 gchar *path = g_build_filename(g_get_tmp_dir(), "ansel-test-keyboardrc", NULL);
55 gchar *file = g_strconcat("; test GtkAccelMap rc-file\n", contents, NULL);
56 assert_true(g_file_set_contents(path, file, -1, NULL));
57 gtk_accel_map_load(path);
58 g_free(file);
59 g_free(path);
60}
61
63static guint _register_and_read(const char *path, guint default_key)
64{
65 gtk_accel_map_add_entry(path, default_key, 0);
66 GtkAccelKey key = { 0 };
67 assert_true(gtk_accel_map_lookup_entry(path, &key));
68 return key.accel_key;
69}
70
79{
80 (void)state;
81 _load_config("(gtk_accel_path \"<AnselTest1>/known\" \"F1\")\n");
82 assert_int_equal(_register_and_read("<AnselTest1>/absent", APP_DEFAULT_KEY), APP_DEFAULT_KEY);
83}
84
87{
88 (void)state;
89 _load_config("(gtk_accel_path \"<AnselTest2>/cleared\" \"\")\n");
90 assert_int_equal(_register_and_read("<AnselTest2>/cleared", APP_DEFAULT_KEY), 0);
91}
92
95{
96 (void)state;
97 _load_config("(gtk_accel_path \"<AnselTest3>/rebound\" \"<Control>k\")\n");
98 gtk_accel_map_add_entry("<AnselTest3>/rebound", APP_DEFAULT_KEY, 0);
99 GtkAccelKey key = { 0 };
100 assert_true(gtk_accel_map_lookup_entry("<AnselTest3>/rebound", &key));
101 assert_int_equal(key.accel_key, GDK_KEY_k);
102 assert_int_equal(key.accel_mods & GDK_CONTROL_MASK, GDK_CONTROL_MASK);
103}
104
108{
109 (void)state;
110 _load_config("(gtk_accel_path \"<AnselTest4>/cleared\" \"\")\n");
111 assert_int_equal(_register_and_read("<AnselTest4>/cleared", 0), 0);
112 assert_int_equal(_register_and_read("<AnselTest4>/absent", 0), 0);
113}
114
120{
121 (void)state;
122 gtk_accel_map_add_entry("<AnselTest5>/default", APP_DEFAULT_KEY, 0);
123 gtk_accel_map_add_entry("<AnselTest5>/cleared", APP_DEFAULT_KEY, 0);
124 assert_true(gtk_accel_map_change_entry("<AnselTest5>/cleared", 0, 0, TRUE));
125
126 gchar *path = g_build_filename(g_get_tmp_dir(), "ansel-test-keyboardrc-save", NULL);
127 gtk_accel_map_save(path);
128
129 gchar *contents = NULL;
130 assert_true(g_file_get_contents(path, &contents, NULL, NULL));
131 assert_non_null(g_strstr_len(contents, -1, "; (gtk_accel_path \"<AnselTest5>/default\" \"F5\")"));
132 assert_non_null(g_strstr_len(contents, -1, "\n(gtk_accel_path \"<AnselTest5>/cleared\" \"\")"));
133 g_free(contents);
134 g_free(path);
135}
136
137int main(void)
138{
139 // The accel map is a plain hash table populated by gtk_init(), and unreachable without it.
140 // The result is deliberately ignored: a headless runner opens no display and answers FALSE,
141 // having initialised everything these tests touch anyway.
142 int argc = 0;
143 char **argv = NULL;
144 gtk_init_check(&argc, &argv);
145
146 const struct CMUnitTest tests[] = {
148 cmocka_unit_test(_an_emptied_entry_stays_cleared),
152 };
153
154 return cmocka_run_group_tests(tests, NULL, NULL);
155}
156
157// clang-format off
158// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
159// vim: shiftwidth=2 expandtab tabstop=2 cindent
160// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
161// clang-format on
#define TRUE
Definition ashift_lsd.c:162
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
char * key
const float uint32_t state[4]
static void _a_zero_default_cannot_tell_absent_from_cleared(void **state)
#define APP_DEFAULT_KEY
static void _saving_marks_defaults_as_comments_and_changes_as_lines(void **state)
int main(void)
static void _an_absent_path_takes_the_app_default(void **state)
static void _an_emptied_entry_stays_cleared(void **state)
static void _load_config(const char *contents)
static void _a_user_binding_wins_over_the_default(void **state)
static guint _register_and_read(const char *path, guint default_key)