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
29#include "testdb.h"
30
31
32static const unsigned char params_a[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
33static const unsigned char params_b[] = { 0x0a, 0x0b, 0x0c };
34
36{
37 (void)state;
38 dt_preset_repository_add_module_preset("Q", "exposure", 1, params_a, sizeof(params_a));
39
42 assert_int_equal(p->op_params_size, sizeof(params_a));
43 assert_memory_equal(p->op_params, params_a, sizeof(params_a));
45
46 // stamp a new version onto the row: the blob must survive untouched
49 p = dt_preset_repository_get_module_preset("exposure", 9, "Q");
51 assert_int_equal(p->op_params_size, sizeof(params_a));
52 assert_memory_equal(p->op_params, params_a, sizeof(params_a));
54
55 // the params setter, by contrast, replaces both blob and version
56 dt_preset_repository_update_module_params("exposure", "Q", 10, params_b, sizeof(params_b));
57 p = dt_preset_repository_get_module_preset("exposure", 10, "Q");
59 assert_int_equal(p->op_params_size, sizeof(params_b));
60 assert_memory_equal(p->op_params, params_b, sizeof(params_b));
62}
63
65{
66 (void)state;
67 // the same name at two versions: two distinct rows under the UNIQUE constraint
68 dt_preset_repository_add_module_preset("P", "sharpen", 1, params_a, sizeof(params_a));
69 dt_preset_repository_add_module_preset("P", "sharpen", 2, params_b, sizeof(params_b));
70
73
74 int seen_v1 = 0, seen_v2 = 0;
75 for(GList *l = rows; l; l = g_list_next(l))
76 {
77 const dt_module_preset_t *p = (const dt_module_preset_t *)l->data;
78 assert_string_equal(p->name, "P");
79 if(p->op_version == 1)
80 {
81 seen_v1++;
82 assert_int_equal(p->op_params_size, sizeof(params_a));
83 assert_memory_equal(p->op_params, params_a, sizeof(params_a));
84 }
85 if(p->op_version == 2)
86 {
87 seen_v2++;
88 assert_int_equal(p->op_params_size, sizeof(params_b));
89 assert_memory_equal(p->op_params, params_b, sizeof(params_b));
90 }
91 }
95}
96
98{
99 (void)state;
100 dt_preset_repository_add_module_preset("mine", "borders", 1, params_a, sizeof(params_a));
101 dt_preset_repository_add_shipped_preset("shipped", "borders", 1, params_b, sizeof(params_b), 1);
102
104 int mine = 0, shipped = 0;
105 for(GList *l = rows; l; l = g_list_next(l))
106 {
107 const dt_preset_identity_t *p = (const dt_preset_identity_t *)l->data;
108 if(!g_strcmp0(p->operation, "borders"))
109 {
110 if(!g_strcmp0(p->name, "mine")) mine++;
111 if(!g_strcmp0(p->name, "shipped")) shipped++;
112 assert_true(p->rowid > 0);
113 }
114 }
116 assert_int_equal(shipped, 0); // writeprotect = 1 must stay out of the editable list
118}
119
121{
122 (void)state;
123 dt_preset_repository_add_module_preset("treerow", "vignette", 3, params_a, sizeof(params_a));
124
126 const dt_preset_row_t *found = NULL;
127 for(GList *l = rows; l; l = g_list_next(l))
128 {
129 const dt_preset_row_t *p = (const dt_preset_row_t *)l->data;
130 if(!g_strcmp0(p->operation, "vignette") && !g_strcmp0(p->name, "treerow")) found = p;
131 }
132 assert_non_null(found);
134 assert_false(found->autoapply); // a menu preset never auto-applies
136}
137
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...
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 void test_set_module_version_leaves_params_alone(void **state)
int main(void)
static void test_list_editable_excludes_shipped(void **state)
static void test_list_all_carries_the_tree_row(void **state)
static const unsigned char params_a[]
static const unsigned char params_b[]
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