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#ifdef _WIN32
50#include "win/main_wrapper.h"
51#endif
52
53#define APP_DEFAULT_KEY GDK_KEY_F5
54
56static void _load_config(const char *contents)
57{
58 gchar *path = g_build_filename(g_get_tmp_dir(), "ansel-test-keyboardrc", NULL);
59 gchar *file = g_strconcat("; test GtkAccelMap rc-file\n", contents, NULL);
60 assert_true(g_file_set_contents(path, file, -1, NULL));
61 gtk_accel_map_load(path);
62 g_free(file);
63 g_free(path);
64}
65
67static guint _register_and_read(const char *path, guint default_key)
68{
69 gtk_accel_map_add_entry(path, default_key, 0);
70 GtkAccelKey key = { 0 };
71 assert_true(gtk_accel_map_lookup_entry(path, &key));
72 return key.accel_key;
73}
74
83{
84 (void)state;
85 _load_config("(gtk_accel_path \"<AnselTest1>/known\" \"F1\")\n");
86 assert_int_equal(_register_and_read("<AnselTest1>/absent", APP_DEFAULT_KEY), APP_DEFAULT_KEY);
87}
88
91{
92 (void)state;
93 _load_config("(gtk_accel_path \"<AnselTest2>/cleared\" \"\")\n");
94 assert_int_equal(_register_and_read("<AnselTest2>/cleared", APP_DEFAULT_KEY), 0);
95}
96
99{
100 (void)state;
101 _load_config("(gtk_accel_path \"<AnselTest3>/rebound\" \"<Control>k\")\n");
102 gtk_accel_map_add_entry("<AnselTest3>/rebound", APP_DEFAULT_KEY, 0);
103 GtkAccelKey key = { 0 };
104 assert_true(gtk_accel_map_lookup_entry("<AnselTest3>/rebound", &key));
105 assert_int_equal(key.accel_key, GDK_KEY_k);
106 assert_int_equal(key.accel_mods & GDK_CONTROL_MASK, GDK_CONTROL_MASK);
107}
108
112{
113 (void)state;
114 _load_config("(gtk_accel_path \"<AnselTest4>/cleared\" \"\")\n");
115 assert_int_equal(_register_and_read("<AnselTest4>/cleared", 0), 0);
116 assert_int_equal(_register_and_read("<AnselTest4>/absent", 0), 0);
117}
118
124{
125 (void)state;
126 gtk_accel_map_add_entry("<AnselTest5>/default", APP_DEFAULT_KEY, 0);
127 gtk_accel_map_add_entry("<AnselTest5>/cleared", APP_DEFAULT_KEY, 0);
128 assert_true(gtk_accel_map_change_entry("<AnselTest5>/cleared", 0, 0, TRUE));
129
130 gchar *path = g_build_filename(g_get_tmp_dir(), "ansel-test-keyboardrc-save", NULL);
131 gtk_accel_map_save(path);
132
133 gchar *contents = NULL;
134 assert_true(g_file_get_contents(path, &contents, NULL, NULL));
135 assert_non_null(g_strstr_len(contents, -1, "; (gtk_accel_path \"<AnselTest5>/default\" \"F5\")"));
136 assert_non_null(g_strstr_len(contents, -1, "\n(gtk_accel_path \"<AnselTest5>/cleared\" \"\")"));
137 g_free(contents);
138 g_free(path);
139}
140
141int main(int argc, char *argv[])
142{
143 // The accel map is a plain hash table populated by gtk_init(), and unreachable without it.
144 // The result is deliberately ignored: a headless runner opens no display and answers FALSE,
145 // having initialised everything these tests touch anyway.
146 gtk_init_check(&argc, &argv);
147
148 const struct CMUnitTest tests[] = {
150 cmocka_unit_test(_an_emptied_entry_stays_cleared),
154 };
155
156 return cmocka_run_group_tests(tests, NULL, NULL);
157}
158
159// clang-format off
160// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
161// vim: shiftwidth=2 expandtab tabstop=2 cindent
162// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
163// 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
int main()
Definition prova.c:47
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)
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)