Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_metadata_notify.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
26
27#include "metadata/notify.h"
28
29#include <stdarg.h>
30#include <stddef.h>
31// cmocka.h declares `extern jmp_buf global_expect_assert_env' at file scope and does not
32// include <setjmp.h> itself -- it says so at its own line 50. No test names a setjmp
33// symbol, so include-cleaner cannot attribute this one; removing it stops cmocka.h from
34// parsing. The suppression is on the line itself, not NOLINTNEXTLINE above: that form
35// applies to the immediately following line, which a multi-line reason turns into another
36// comment, silently suppressing nothing.
37#include <setjmp.h> // NOLINT(misc-include-cleaner)
38#include <stdint.h>
39#include <cmocka.h>
40
41#include <string.h>
42
43#include <glib.h>
44
45#ifdef _WIN32
46#include "win/main_wrapper.h"
47#endif
48
49typedef struct _seen_t
50{
51 int toasts;
54 gchar *last;
56
58
59static void _record(const dt_metadata_notice_t kind, const char *message)
60{
61 if(kind == DT_METADATA_NOTICE_TOAST) _seen.toasts++;
62 else _seen.messages++;
63 g_free(_seen.last);
64 _seen.last = g_strdup(message);
65}
66
67static void _record_tag_change(void)
68{
69 _seen.tag_changes++;
70}
71
72static int _setup(void **state)
73{
74 (void)state;
75 memset(&_seen, 0, sizeof(_seen));
76 return 0;
77}
78
79static int _teardown(void **state)
80{
81 (void)state;
84 g_free(_seen.last);
85 _seen.last = NULL;
86 return 0;
87}
88
89/* The headless contract: with nothing installed, raising a message must be a silent no-op
90 * rather than a crash. ansel-cli and every unit test run in exactly this state. */
92{
93 (void)state;
96
100
101 assert_int_equal(_seen.toasts, 0);
102 assert_int_equal(_seen.messages, 0);
103 assert_int_equal(_seen.tag_changes, 0);
104}
105
106/* The two notice kinds are not interchangeable: one is a transient acknowledgement, the
107 * other the running commentary, and they land in different widgets. */
109{
110 (void)state;
112
113 dt_metadata_notify(DT_METADATA_NOTICE_TOAST, "Rating set to %s for %i image(s)", "three", 12);
114 assert_int_equal(_seen.toasts, 1);
115 assert_int_equal(_seen.messages, 0);
116 assert_string_equal(_seen.last, "Rating set to three for 12 image(s)");
117
118 dt_metadata_notify(DT_METADATA_NOTICE_MESSAGE, "no images selected to apply rating");
119 assert_int_equal(_seen.toasts, 1);
120 assert_int_equal(_seen.messages, 1);
121 assert_string_equal(_seen.last, "no images selected to apply rating");
122}
123
124/* Removing the handler must actually remove it -- a stale pointer here would outlive the
125 * GUI it belongs to. */
127{
128 (void)state;
131 assert_int_equal(_seen.messages, 1);
132
135 assert_int_equal(_seen.messages, 1);
136 assert_string_equal(_seen.last, "heard");
137}
138
139/* The tag-changed notification carries no payload on purpose: every consumer re-reads. */
141{
142 (void)state;
144
147 assert_int_equal(_seen.tag_changes, 2);
148
151 assert_int_equal(_seen.tag_changes, 2);
152}
153
154/* The two channels are independent: installing one must not arm or silence the other. */
156{
157 (void)state;
159
160 dt_metadata_tags_changed(); // no tags handler yet
161 assert_int_equal(_seen.tag_changes, 0);
162
165
168 assert_int_equal(_seen.toasts, 0);
169 assert_int_equal(_seen.tag_changes, 1);
170}
171
172int main(int argc, char *argv[])
173{
174 const struct CMUnitTest tests[] = {
175 cmocka_unit_test_setup_teardown(test_no_handler_is_silent, _setup, _teardown),
176 cmocka_unit_test_setup_teardown(test_kinds_stay_distinct, _setup, _teardown),
177 cmocka_unit_test_setup_teardown(test_handler_can_be_removed, _setup, _teardown),
178 cmocka_unit_test_setup_teardown(test_tags_changed_fires_each_time, _setup, _teardown),
179 cmocka_unit_test_setup_teardown(test_channels_are_independent, _setup, _teardown),
180 };
181 return cmocka_run_group_tests(tests, NULL, NULL);
182}
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
static const dt_adaptation_t kind
void dt_metadata_set_tags_changed_handler(dt_metadata_tags_changed_handler_t handler)
void dt_metadata_set_notify_handler(dt_metadata_notify_handler_t handler)
Install the handler, or NULL to remove it. Messages raised with none installed are dropped.
void dt_metadata_tags_changed(void)
Raise it. Internal to the module.
void dt_metadata_notify(const dt_metadata_notice_t kind, const char *format,...)
Everything this module says to the outside world: messages for the user, and the fact that the tag vo...
dt_metadata_notice_t
Which affordance the message belongs in. The two are not interchangeable, and the module knows which ...
@ DT_METADATA_NOTICE_TOAST
@ DT_METADATA_NOTICE_MESSAGE
g_free(manifest_path)
int main()
Definition prova.c:47
const float uint32_t state[4]
static int _teardown(void **state __attribute__((unused)))
static int _setup(void **state __attribute__((unused)))
static void _record(const dt_metadata_notice_t kind, const char *message)
static void test_channels_are_independent(void **state)
static void test_no_handler_is_silent(void **state)
static void test_kinds_stay_distinct(void **state)
static int _setup(void **state)
static int _teardown(void **state)
static void _record_tag_change(void)
static void test_tags_changed_fires_each_time(void **state)
static _seen_t _seen
static void test_handler_can_be_removed(void **state)