Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_history_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
22
23#include "testdb.h"
24
25#ifdef _WIN32
26#include "win/main_wrapper.h"
27#endif
28
29
30static const unsigned char params_a[] = { 0xde, 0xad, 0xbe, 0xef, 0x01 };
31static const unsigned char params_b[] = { 0xca, 0xfe, 0xba, 0xbe };
32static const unsigned char blend_a[] = { 0x42, 0x42 };
33
35{
36 (void)state;
37 const int32_t film = testdb_make_film("/testdb/order");
38 const int32_t img = testdb_make_image(film, "a.raw");
39 assert_true(img > 0);
40
41 // no row at all: FALSE, and the out-parameter is left alone -- "no row" must stay
42 // distinguishable from "row with version 0"
43 int version = 12345;
44 assert_false(dt_history_repository_get_module_order_version(img, &version));
45 assert_int_equal(version, 12345);
48
49 // a built-in order: version only, no serialized list
50 assert_true(dt_history_repository_set_module_order(img, 5, NULL));
51 assert_true(dt_history_repository_get_module_order_version(img, &version));
52 assert_int_equal(version, 5);
55
56 // a custom order carries its list, copied out of the statement
57 assert_true(dt_history_repository_set_module_order(img, 7, "rawprepare,0,exposure,0"));
60 assert_int_equal(row.version, 7);
61 assert_non_null(row.iop_list);
62 assert_string_equal(row.iop_list, "rawprepare,0,exposure,0");
65
66 // and back to a built-in: the list column returns to NULL
67 assert_true(dt_history_repository_set_module_order(img, 5, NULL));
69}
70
71static void test_history_item_cycle(void **state)
72{
73 (void)state;
74 const int32_t film = testdb_make_film("/testdb/items");
75 const int32_t img = testdb_make_image(film, "a.raw");
76 assert_true(img > 0);
77
78 assert_int_equal(dt_history_repository_count_items(img), 0);
79 assert_int_equal(dt_history_repository_get_next_num(img), 0);
80 assert_false(dt_history_repository_module_exists(img, "exposure"));
81
82 assert_true(dt_history_repository_write_item(img, 0, "exposure", params_a, sizeof(params_a), 3,
83 TRUE, blend_a, sizeof(blend_a), 11, 0, ""));
84 assert_int_equal(dt_history_repository_count_items(img), 1);
85 assert_int_equal(dt_history_repository_get_next_num(img), 1);
86 assert_true(dt_history_repository_module_exists(img, "exposure"));
87 assert_false(dt_history_repository_module_exists(img, "filmic"));
88
89 assert_true(dt_history_repository_set_end(img, 1));
90 assert_int_equal(dt_history_repository_get_end(img), 1);
91}
92
94{
95 (void)state;
96 const int32_t film = testdb_make_film("/testdb/probe");
97 const int32_t img = testdb_make_image(film, "a.raw");
98 assert_true(img > 0);
99 assert_true(dt_history_repository_write_item(img, 0, "sharpen", params_a, sizeof(params_a), 4,
100 TRUE, blend_a, sizeof(blend_a), 11, 0, ""));
101
102 // byte-identical params date the preset; anything else finds nothing
103 assert_int_equal(dt_history_repository_find_version_for_params("sharpen", params_a, sizeof(params_a)), 4);
104 assert_int_equal(dt_history_repository_find_version_for_params("sharpen", params_b, sizeof(params_b)), 0);
105 // the group fixture shares one database, so pick an operation NO other test writes --
106 // "exposure" exists here, courtesy of test_history_item_cycle
107 assert_int_equal(dt_history_repository_find_version_for_params("filmic", params_a, sizeof(params_a)), 0);
108}
109
110typedef struct _active_collect_t
111{
112 int count;
114 char op[32];
116
117static void _collect_active(void *user_data, const int num, const char *operation, const char *multi_name)
118{
119 (void)multi_name;
120 _active_collect_t *c = (_active_collect_t *)user_data;
121 if(c->count == 0)
122 {
123 c->first_num = num;
124 g_strlcpy(c->op, operation, sizeof(c->op));
125 }
126 c->count++;
127}
128
130{
131 (void)state;
132 const int32_t film = testdb_make_film("/testdb/active");
133 const int32_t img = testdb_make_image(film, "a.raw");
134 assert_true(img > 0);
135
136 // the same module twice (grouped to one entry at its LOWEST num), plus a disabled one
137 // (not listed at all)
138 assert_true(dt_history_repository_write_item(img, 0, "exposure", params_a, sizeof(params_a), 3,
139 TRUE, blend_a, sizeof(blend_a), 11, 0, ""));
140 assert_true(dt_history_repository_write_item(img, 1, "exposure", params_b, sizeof(params_b), 3,
141 TRUE, blend_a, sizeof(blend_a), 11, 0, ""));
142 assert_true(dt_history_repository_write_item(img, 2, "borders", params_a, sizeof(params_a), 1,
143 FALSE, blend_a, sizeof(blend_a), 11, 0, ""));
144
145 _active_collect_t c = { 0 };
147 assert_int_equal(c.count, 1);
148 assert_int_equal(c.first_num, 0);
149 assert_string_equal(c.op, "exposure");
150}
151
152int main(int argc, char *argv[])
153{
154 const struct CMUnitTest tests[] = {
155 cmocka_unit_test(test_module_order_absent_vs_zero),
156 cmocka_unit_test(test_history_item_cycle),
157 cmocka_unit_test(test_find_version_for_params),
158 cmocka_unit_test(test_foreach_active_module),
159 };
160 return cmocka_run_group_tests(tests, testdb_setup, testdb_teardown);
161}
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
static const int row
gboolean dt_history_repository_get_module_order(const int32_t imgid, dt_module_order_row_t *row)
Read imgid's row. FALSE when there is none, and row is then left zeroed.
gboolean dt_history_repository_write_item(const int32_t imgid, const int num, const char *operation, const void *op_params, const int op_params_size, const int module_version, const gboolean enabled, const void *blendop_params, const int blendop_params_size, const int blendop_version, const int multi_priority, const char *multi_name)
gboolean dt_history_repository_module_exists(const int32_t imgid, const char *operation)
void dt_module_order_row_cleanup(dt_module_order_row_t *row)
Release what dt_history_repository_get_module_order() allocated.
gboolean dt_history_repository_set_module_order(const int32_t imgid, const int version, const char *iop_list)
Store imgid's order: version, and iop_list serialized or NULL.
int dt_history_repository_find_version_for_params(const char *operation, const void *op_params, const int op_params_size)
The module version some image's history recorded for this exact parameter blob.
int dt_history_repository_count_items(const int32_t imgid)
gboolean dt_history_repository_set_end(const int32_t imgid, const int32_t history_end)
gboolean dt_history_repository_has_custom_module_order(const int32_t imgid)
Whether imgid's row stores a serialized list, i.e. iop_list IS NOT NULL.
gboolean dt_history_repository_get_module_order_version(const int32_t imgid, int *version)
imgid's stored order version.
gboolean dt_history_repository_has_module_order(const int32_t imgid)
Whether imgid has a main.module_order row at all, whatever it says.
int32_t dt_history_repository_get_end(const int32_t imgid)
int32_t dt_history_repository_get_next_num(const int32_t imgid)
void dt_history_repository_foreach_active_module(const int32_t imgid, dt_history_repository_active_module_cb cb, void *user_data)
Every module an image has enabled, once each, in the order they run.
int main()
Definition prova.c:47
const float uint32_t state[4]
One main.module_order row.
static void test_find_version_for_params(void **state)
static void test_module_order_absent_vs_zero(void **state)
static const unsigned char blend_a[]
static void _collect_active(void *user_data, const int num, const char *operation, const char *multi_name)
static void test_foreach_active_module(void **state)
static void test_history_item_cycle(void **state)
static const unsigned char params_a[]
static const unsigned char params_b[]
Shared fixture for the src/database repository tests.
static int testdb_setup(void **state)
Definition testdb.h:55
static int32_t testdb_make_film(const char *folder)
Definition testdb.h:85
static int testdb_teardown(void **state)
Definition testdb.h:66
static int32_t testdb_make_image(const int32_t film_id, const char *filename)
Definition testdb.h:92