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
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
45typedef struct _seen_t
46{
47 int toasts;
50 gchar *last;
52
54
55static void _record(const dt_metadata_notice_t kind, const char *message)
56{
58 else _seen.messages++;
60 _seen.last = g_strdup(message);
61}
62
63static void _record_tag_change(void)
64{
66}
67
68static int _setup(void **state)
69{
70 (void)state;
71 memset(&_seen, 0, sizeof(_seen));
72 return 0;
73}
74
84
85/* The headless contract: with nothing installed, raising a message must be a silent no-op
86 * rather than a crash. ansel-cli and every unit test run in exactly this state. */
101
102/* The two notice kinds are not interchangeable: one is a transient acknowledgement, the
103 * other the running commentary, and they land in different widgets. */
105{
106 (void)state;
108
109 dt_metadata_notify(DT_METADATA_NOTICE_TOAST, "Rating set to %s for %i image(s)", "three", 12);
112 assert_string_equal(_seen.last, "Rating set to three for 12 image(s)");
113
114 dt_metadata_notify(DT_METADATA_NOTICE_MESSAGE, "no images selected to apply rating");
117 assert_string_equal(_seen.last, "no images selected to apply rating");
118}
119
120/* Removing the handler must actually remove it -- a stale pointer here would outlive the
121 * GUI it belongs to. */
134
135/* The tag-changed notification carries no payload on purpose: every consumer re-reads. */
149
150/* The two channels are independent: installing one must not arm or silence the other. */
167
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
const float uint32_t state[4]
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)
int main(void)
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)