Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_image_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
27#include "testdb.h"
28
29
30// an arbitrary flag bit with no side meaning in these tests
31#define TEST_FLAG 2048
32
34{
35 (void)state;
36 const int32_t film = testdb_make_film("/testdb/filmroll");
37 assert_true(film > 0);
38 const int32_t a = testdb_make_image(film, "a.raw");
39 const int32_t b = testdb_make_image(film, "b.raw");
40 const int32_t c = testdb_make_image(film, "c.raw");
41 assert_true(a > 0 && b > 0 && c > 0);
42
45
46 // set the flag on TWO images at once -- the case the old IN (?) binding silently dropped
48
54
55 // a single-element list keeps working (the only case the old binding handled)
61
62 // an empty set asks about nothing
64
68}
69
70static void test_full_paths(void **state)
71{
72 (void)state;
73 const int32_t film = testdb_make_film("/testdb/paths");
74 const int32_t a = testdb_make_image(film, "a.raw");
75 const int32_t b = testdb_make_image(film, "b.raw");
76 assert_true(a > 0 && b > 0);
77
81 assert_string_equal((const char *)paths->data, "/testdb/paths/a.raw");
82 assert_string_equal((const char *)paths->next->data, "/testdb/paths/b.raw");
84 g_list_free(ids);
85}
86
87static void test_id_range(void **state)
88{
89 (void)state;
90 const int32_t film = testdb_make_film("/testdb/range");
91 const int32_t a = testdb_make_image(film, "a.raw");
92 const int32_t b = testdb_make_image(film, "b.raw");
93 const int32_t c = testdb_make_image(film, "c.raw");
94 assert_true(a > 0 && c > a);
95
99}
100
102{
103 (void)state;
104 const int32_t film = testdb_make_film("/testdb/ts");
105 const int32_t a = testdb_make_image(film, "a.raw");
106 assert_true(a > 0);
107
108 // 2100-01-01: overflows a 32-bit time_t. The caller this setter replaced bound the
109 // timestamp with sqlite3_bind_int(), which truncates in 2038.
110 const int64_t year2100 = 4102444800LL;
113}
114
115static void test_group_member_rows(void **state)
116{
117 (void)state;
118 const int32_t film = testdb_make_film("/testdb/group");
119 const int32_t a = testdb_make_image(film, "a.raw");
120 const int32_t b = testdb_make_image(film, "b.raw");
121 assert_true(a > 0 && b > 0);
124
127 const dt_image_group_member_t *first = (const dt_image_group_member_t *)members->data;
128 const dt_image_group_member_t *second = (const dt_image_group_member_t *)members->next->data;
129 assert_int_equal(first->imgid, a);
130 assert_string_equal(first->filename, "a.raw");
131 assert_int_equal(second->imgid, b);
132 assert_string_equal(second->filename, "b.raw");
134}
135
137{
138 (void)state;
139 const int32_t film = testdb_make_film("/testdb/distinct");
140 const int32_t a = testdb_make_image(film, "a.raw");
141 const int32_t b = testdb_make_image(film, "b.raw");
142 assert_true(a > 0 && b > 0);
143
147
148 assert_int_equal(counts[DT_IMAGE_FIELD_FILM_ROLL], 1); // same film -> agree
149 assert_int_equal(counts[DT_IMAGE_FIELD_FILENAME], 2); // different names -> disagree
150 assert_int_equal(counts[DT_IMAGE_FIELD_IMGID], 2); // ids differ by definition
151 assert_int_equal(counts[DT_IMAGE_FIELD_VERSION], 1); // both imported at version 0
152
153 free(counts);
154 g_list_free(ids);
155
156 // the empty set answers nothing rather than something
158}
159
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
int dt_image_repository_count_in_id_range(const int32_t min_imgid, const int32_t max_imgid)
How many images have an id in [min_imgid, max_imgid]. -1 when unreadable.
GList * dt_image_repository_get_ids_with_flag_among(GList *imgids, const int flag)
Of the images in imgids, those whose flags carry flag, in row order.
int64_t dt_image_repository_get_write_timestamp(const int32_t imgid)
main.images.write_timestamp for imgid, or 0.
gboolean dt_image_repository_set_group(const int32_t imgid, const int32_t group_id)
Set imgid's group_id.
gboolean dt_image_repository_set_write_timestamp(const int32_t imgid, const int64_t timestamp)
Set write_timestamp of imgid to timestamp (seconds since the epoch). Bound as a 64-bit integer; the c...
void dt_image_group_member_free(gpointer data)
Free one dt_image_group_member_t. Suits g_list_free_full().
GList * dt_image_repository_get_group_member_rows(const int32_t group_id)
Every member of group_id, in row order, named. Free with g_list_free_full(list, dt_image_group_member...
gboolean dt_image_repository_set_flag_among(GList *imgids, const int flag)
Set flag on every image in imgids.
GList * dt_image_repository_get_full_paths(GList *imgids)
"<folder>/<filename>" for every image in imgids, distinct, in row order. Caller owns the strings.
int * dt_image_repository_count_distinct_fields(GList *imgids)
How many DISTINCT values each dt_image_field_t takes over imgids.
@ DT_IMAGE_FIELD_VERSION
@ DT_IMAGE_FIELD_FILENAME
@ DT_IMAGE_FIELD_FILM_ROLL
@ DT_IMAGE_FIELD_IMGID
const float uint32_t state[4]
One member of a group, with what a tooltip needs to name it.
static void test_flag_among_multi_image(void **state)
static void test_write_timestamp_is_64bit(void **state)
static void test_group_member_rows(void **state)
int main(void)
static void test_count_distinct_fields(void **state)
static void test_full_paths(void **state)
static void test_id_range(void **state)
#define TEST_FLAG
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