![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
#include <gtk/gtk.h>#include <stdarg.h>#include <stddef.h>#include <setjmp.h>#include <stdint.h>#include <cmocka.h>
Include dependency graph for test_accel_map_defaults.c:Go to the source code of this file.
Macros | |
| #define | APP_DEFAULT_KEY GDK_KEY_F5 |
Functions | |
| static void | _load_config (const char *contents) |
| static guint | _register_and_read (const char *path, guint default_key) |
| static void | _an_absent_path_takes_the_app_default (void **state) |
| static void | _an_emptied_entry_stays_cleared (void **state) |
| static void | _a_user_binding_wins_over_the_default (void **state) |
| static void | _a_zero_default_cannot_tell_absent_from_cleared (void **state) |
| static void | _saving_marks_defaults_as_comments_and_changes_as_lines (void **state) |
| int | main (void) |
| #define APP_DEFAULT_KEY GDK_KEY_F5 |
The GtkAccelMap contract _insert_accel() (widgets/accelerators.c) is built on.
Shortcuts are reconciled between three sources: the app default declared in the code, the user's keyboardrc, and the GtkAccelMap that sits between them. dt_accels_load_user_config() reads the file first, then every shortcut registers its accel path, and only the difference between the two decides whether a shortcut is at its default, was rebound, or was cleared.
That difference is only legible if the app default is registered AS the accel_map entry's default. Registering (path, 0, 0) instead – what the code did until the purple-label bug – makes "this config predates the shortcut" and "the user cleared this shortcut" arrive identically, as key 0, and _update_shortcut_state() then reads both as a deliberate user override. _a_zero_default_cannot_tell_absent_from_cleared() pins that failure so the reason for the current spelling stays visible.
These tests exercise GTK, not Ansel code: they state what accelerators.c assumes, so a GTK whose bookkeeping changed is caught here rather than as shortcuts going quietly dead. Each test uses accel pathes of its own – the GtkAccelMap is process-global with no reset call, and gtk_accel_map_load() merges into whatever is already there.
Definition at line 49 of file test_accel_map_defaults.c.
A shortcut the user rebound keeps the user's keys, not the app's.
Definition at line 94 of file test_accel_map_defaults.c.
References _load_config(), APP_DEFAULT_KEY, key, state, and void().
Referenced by main().
Why the default is registered rather than (0, 0): with (0, 0) the two cases above are the same value, and the one that must win cannot be told from the one that must not.
Definition at line 107 of file test_accel_map_defaults.c.
References _load_config(), _register_and_read(), state, and void().
Referenced by main().
A shortcut whose path the config never mentions must come up at its app default.
This is the whole bug: a shortcut added by a new version, or one whose accel path moved because the translated menu label it is built from changed, is absent from every config written before it existed. F5 for the purple colour label was lost this way when the French catalogue translated "Purple" as "Violet".
Definition at line 78 of file test_accel_map_defaults.c.
References _load_config(), _register_and_read(), APP_DEFAULT_KEY, state, and void().
Referenced by main().
A shortcut the user cleared must stay cleared, and says so with a live empty entry.
Definition at line 86 of file test_accel_map_defaults.c.
References _load_config(), _register_and_read(), APP_DEFAULT_KEY, state, and void().
Referenced by main().
|
static |
Write a keyboardrc holding the given lines, and load it the way the app does.
Definition at line 52 of file test_accel_map_defaults.c.
Referenced by _a_user_binding_wins_over_the_default(), _a_zero_default_cannot_tell_absent_from_cleared(), _an_absent_path_takes_the_app_default(), and _an_emptied_entry_stays_cleared().
|
static |
The key the map holds for a path once its shortcut has registered its own default.
Definition at line 63 of file test_accel_map_defaults.c.
References key.
Referenced by _a_zero_default_cannot_tell_absent_from_cleared(), _an_absent_path_takes_the_app_default(), and _an_emptied_entry_stays_cleared().
The other half of the contract, on the way out: gtk_accel_map_save() comments out an entry still sitting at its default and writes every other one as a live line. That is what makes a cleared shortcut survive the next start – it is saved as a real (path "") line, which is what _an_emptied_entry_stays_cleared() reads back.
Definition at line 119 of file test_accel_map_defaults.c.
References APP_DEFAULT_KEY, state, TRUE, and void().
Referenced by main().
| int main | ( | void | ) |