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
23#include "testdb.h"
24
25
26static const unsigned char params_a[] = { 0xde, 0xad, 0xbe, 0xef, 0x01 };
27static const unsigned char params_b[] = { 0xca, 0xfe, 0xba, 0xbe };
28static const unsigned char blend_a[] = { 0x42, 0x42 };
29
31{
32 (void)state;
33 const int32_t film = testdb_make_film("/testdb/order");
34 const int32_t img = testdb_make_image(film, "a.raw");
35 assert_true(img > 0);
36
37 // no row at all: FALSE, and the out-parameter is left alone -- "no row" must stay
38 // distinguishable from "row with version 0"
39 int version = 12345;
41 assert_int_equal(version, 12345);
44
45 // a built-in order: version only, no serialized list
48 assert_int_equal(version, 5);
51
52 // a custom order carries its list, copied out of the statement
53 assert_true(dt_history_repository_set_module_order(img, 7, "rawprepare,0,exposure,0"));
56 assert_int_equal(row.version, 7);
57 assert_non_null(row.iop_list);
58 assert_string_equal(row.iop_list, "rawprepare,0,exposure,0");
61
62 // and back to a built-in: the list column returns to NULL
65}
66
88
90{
91 (void)state;
92 const int32_t film = testdb_make_film("/testdb/probe");
93 const int32_t img = testdb_make_image(film, "a.raw");
94 assert_true(img > 0);
96 TRUE, blend_a, sizeof(blend_a), 11, 0, ""));
97
98 // byte-identical params date the preset; anything else finds nothing
101 // the group fixture shares one database, so pick an operation NO other test writes --
102 // "exposure" exists here, courtesy of test_history_item_cycle
104}
105
106typedef struct _active_collect_t
107{
108 int count;
110 char op[32];
112
113static void _collect_active(void *user_data, const int num, const char *operation, const char *multi_name)
114{
115 (void)multi_name;
116 _active_collect_t *c = (_active_collect_t *)user_data;
117 if(c->count == 0)
118 {
119 c->first_num = num;
120 g_strlcpy(c->op, operation, sizeof(c->op));
121 }
122 c->count++;
123}
124
126{
127 (void)state;
128 const int32_t film = testdb_make_film("/testdb/active");
129 const int32_t img = testdb_make_image(film, "a.raw");
130 assert_true(img > 0);
131
132 // the same module twice (grouped to one entry at its LOWEST num), plus a disabled one
133 // (not listed at all)
134 assert_true(dt_history_repository_write_item(img, 0, "exposure", params_a, sizeof(params_a), 3,
135 TRUE, blend_a, sizeof(blend_a), 11, 0, ""));
136 assert_true(dt_history_repository_write_item(img, 1, "exposure", params_b, sizeof(params_b), 3,
137 TRUE, blend_a, sizeof(blend_a), 11, 0, ""));
138 assert_true(dt_history_repository_write_item(img, 2, "borders", params_a, sizeof(params_a), 1,
139 FALSE, blend_a, sizeof(blend_a), 11, 0, ""));
140
141 _active_collect_t c = { 0 };
143 assert_int_equal(c.count, 1);
144 assert_int_equal(c.first_num, 0);
145 assert_string_equal(c.op, "exposure");
146}
147
#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.
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)
int main(void)
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