Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_preset_repository.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
28
29#include "testdb.h"
30
31#ifdef _WIN32
32#include "win/main_wrapper.h"
33#endif
34
35
36static const unsigned char params_a[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
37static const unsigned char params_b[] = { 0x0a, 0x0b, 0x0c };
38
40{
41 (void)state;
42 dt_preset_repository_add_module_preset("Q", "exposure", 1, params_a, sizeof(params_a));
43
45 assert_non_null(p);
46 assert_int_equal(p->op_params_size, sizeof(params_a));
47 assert_memory_equal(p->op_params, params_a, sizeof(params_a));
49
50 // stamp a new version onto the row: the blob must survive untouched
52 assert_null(dt_preset_repository_get_module_preset("exposure", 1, "Q"));
53 p = dt_preset_repository_get_module_preset("exposure", 9, "Q");
54 assert_non_null(p);
55 assert_int_equal(p->op_params_size, sizeof(params_a));
56 assert_memory_equal(p->op_params, params_a, sizeof(params_a));
58
59 // the params setter, by contrast, replaces both blob and version
60 dt_preset_repository_update_module_params("exposure", "Q", 10, params_b, sizeof(params_b));
61 p = dt_preset_repository_get_module_preset("exposure", 10, "Q");
62 assert_non_null(p);
63 assert_int_equal(p->op_params_size, sizeof(params_b));
64 assert_memory_equal(p->op_params, params_b, sizeof(params_b));
66}
67
69{
70 (void)state;
71 // the same name at two versions: two distinct rows under the UNIQUE constraint
72 dt_preset_repository_add_module_preset("P", "sharpen", 1, params_a, sizeof(params_a));
73 dt_preset_repository_add_module_preset("P", "sharpen", 2, params_b, sizeof(params_b));
74
75 GList *rows = dt_preset_repository_list_for_upgrade("sharpen");
76 assert_int_equal(g_list_length(rows), 2);
77
78 int seen_v1 = 0, seen_v2 = 0;
79 for(GList *l = rows; l; l = g_list_next(l))
80 {
81 const dt_module_preset_t *p = (const dt_module_preset_t *)l->data;
82 assert_string_equal(p->name, "P");
83 if(p->op_version == 1)
84 {
85 seen_v1++;
86 assert_int_equal(p->op_params_size, sizeof(params_a));
87 assert_memory_equal(p->op_params, params_a, sizeof(params_a));
88 }
89 if(p->op_version == 2)
90 {
91 seen_v2++;
92 assert_int_equal(p->op_params_size, sizeof(params_b));
93 assert_memory_equal(p->op_params, params_b, sizeof(params_b));
94 }
95 }
96 assert_int_equal(seen_v1, 1);
97 assert_int_equal(seen_v2, 1);
98 g_list_free_full(rows, dt_module_preset_free);
99}
100
102{
103 (void)state;
104 dt_preset_repository_add_module_preset("mine", "borders", 1, params_a, sizeof(params_a));
105 dt_preset_repository_add_shipped_preset("shipped", "borders", 1, params_b, sizeof(params_b), 1);
106
108 int mine = 0, shipped = 0;
109 for(GList *l = rows; l; l = g_list_next(l))
110 {
111 const dt_preset_identity_t *p = (const dt_preset_identity_t *)l->data;
112 if(!g_strcmp0(p->operation, "borders"))
113 {
114 if(!g_strcmp0(p->name, "mine")) mine++;
115 if(!g_strcmp0(p->name, "shipped")) shipped++;
116 assert_true(p->rowid > 0);
117 }
118 }
119 assert_int_equal(mine, 1);
120 assert_int_equal(shipped, 0); // writeprotect = 1 must stay out of the editable list
121 g_list_free_full(rows, dt_preset_identity_free);
122}
123
125{
126 (void)state;
127 dt_preset_repository_add_module_preset("treerow", "vignette", 3, params_a, sizeof(params_a));
128
129 GList *rows = dt_preset_repository_list_all();
130 const dt_preset_row_t *found = NULL;
131 for(GList *l = rows; l; l = g_list_next(l))
132 {
133 const dt_preset_row_t *p = (const dt_preset_row_t *)l->data;
134 if(!g_strcmp0(p->operation, "vignette") && !g_strcmp0(p->name, "treerow")) found = p;
135 }
136 assert_non_null(found);
137 assert_false(found->writeprotect);
138 assert_false(found->autoapply); // a menu preset never auto-applies
139 g_list_free_full(rows, dt_preset_row_free);
140}
141
142int main(int argc, char *argv[])
143{
144 const struct CMUnitTest tests[] = {
147 cmocka_unit_test(test_list_editable_excludes_shipped),
148 cmocka_unit_test(test_list_all_carries_the_tree_row),
149 };
150 return cmocka_run_group_tests(tests, testdb_setup, testdb_teardown);
151}
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
void dt_module_preset_free(gpointer data)
Release one dt_module_preset_t. Suits g_list_free_full().
GList * dt_preset_repository_list_all(void)
Every preset, ordered by (operation, name) – the grouping the tree relies on to start a new module no...
void dt_preset_row_free(gpointer data)
Free one dt_preset_row_t. Suits g_list_free_full().
dt_module_preset_t * dt_preset_repository_get_module_preset(const char *operation, const int op_version, const char *name)
One preset by name, or NULL. Free with dt_module_preset_free().
GList * dt_preset_repository_list_editable(void)
Every preset the user may edit (writeprotect = 0), in row order.
GList * dt_preset_repository_list_for_upgrade(const char *operation)
Every preset of operation at any version, with both parameter blobs.
void dt_preset_repository_update_module_params(const char *operation, const char *name, const int op_version, const void *params, const int params_size)
Replace the parameters (and version) of (operation, name).
void dt_preset_identity_free(gpointer data)
Free one dt_preset_identity_t. Suits g_list_free_full().
void dt_preset_repository_add_module_preset(const char *name, const char *operation, const int op_version, const void *params, const int params_size)
Create an empty user preset holding params, as the "new preset" menu item does.
void dt_preset_repository_set_module_version(const char *operation, const char *name, const int op_version)
Set ONLY the version of (operation, name), leaving the parameters alone.
void dt_preset_repository_add_shipped_preset(const char *name, const char *operation, const int op_version, const void *params, const int params_size, const int writeprotect)
Create a preset from code rather than from the menu – the built-in presets a module registers at star...
int main()
Definition prova.c:47
const float uint32_t state[4]
Identity of one preset, for callers listing rather than loading.
One row of the Preferences preset tree, with its auto-apply conditions.
static const unsigned char params_a[]
static const unsigned char params_b[]
static void test_set_module_version_leaves_params_alone(void **state)
static void test_list_editable_excludes_shipped(void **state)
static void test_list_all_carries_the_tree_row(void **state)
static void test_list_for_upgrade_returns_all_versions(void **state)
Shared fixture for the src/database repository tests.
static int testdb_setup(void **state)
Definition testdb.h:55
static int testdb_teardown(void **state)
Definition testdb.h:66