32#include <glib/gstdio.h>
46 assert_true(film > 0);
50 assert_true(a > 0 && b > 0 && c > 0);
52 GList *two = g_list_append(g_list_append(NULL, GINT_TO_POINTER(a)), GINT_TO_POINTER(b));
53 GList *all = g_list_append(g_list_copy(two), GINT_TO_POINTER(c));
59 assert_int_equal(g_list_length(flagged), 2);
60 assert_int_equal(GPOINTER_TO_INT(flagged->data), a);
61 assert_int_equal(GPOINTER_TO_INT(flagged->next->data), b);
65 GList *one = g_list_append(NULL, GINT_TO_POINTER(a));
67 assert_int_equal(g_list_length(flagged), 1);
68 assert_int_equal(GPOINTER_TO_INT(flagged->data), a);
89 assert_true(film > 0);
94 const int owned_a = 1 << 4;
95 const int owned_b = 1 << 5;
96 const int mask = owned_a | owned_b;
98 GList *one = g_list_append(NULL, GINT_TO_POINTER(img));
107 assert_int_equal(g_list_length(got), 1);
114 assert_int_equal(g_list_length(got), 1);
120 assert_int_equal(g_list_length(got), 1);
132 assert_true(a > 0 && b > 0);
134 GList *ids = g_list_append(g_list_append(NULL, GINT_TO_POINTER(a)), GINT_TO_POINTER(b));
136 assert_int_equal(g_list_length(paths), 2);
138 gchar *expected_a = g_strconcat(
"/testdb/paths", G_DIR_SEPARATOR_S,
"a.raw", NULL);
139 gchar *expected_b = g_strconcat(
"/testdb/paths", G_DIR_SEPARATOR_S,
"b.raw", NULL);
140 assert_string_equal((
const char *)paths->data, expected_a);
141 assert_string_equal((
const char *)paths->next->data, expected_b);
144 g_list_free_full(paths,
g_free);
155 assert_true(a > 0 && c > a);
171 const int64_t year2100 = 4102444800LL;
182 assert_true(a > 0 && b > 0);
187 assert_int_equal(g_list_length(members), 2);
190 assert_int_equal(first->
imgid, a);
191 assert_string_equal(first->
filename,
"a.raw");
192 assert_int_equal(second->
imgid, b);
193 assert_string_equal(second->
filename,
"b.raw");
203 assert_true(a > 0 && b > 0);
205 GList *ids = g_list_append(g_list_append(NULL, GINT_TO_POINTER(a)), GINT_TO_POINTER(b));
207 assert_non_null(counts);
222 const int version,
const char *image_path,
const int flags,
226 (
void)write_timestamp;
230 int *seen = (
int *)user_data;
241 assert_true(film > 0);
248 assert_int_equal(seen, 2);
258 assert_true(film > 0);
277 _dir = g_dir_make_tmp(
"ansel_test_image_repository_XXXXXX", NULL);
293 GDir *
d = g_dir_open(
_dir, 0, NULL);
296 const char *
name = NULL;
297 while((
name = g_dir_read_name(
d)))
299 gchar *path = g_build_filename(
_dir,
name, NULL);
319 assert_true(film > 0);
323 sqlite3 *other = NULL;
324 assert_int_equal(sqlite3_open(
_library, &other), SQLITE_OK);
325 assert_int_equal(sqlite3_exec(other,
"BEGIN EXCLUSIVE", NULL, NULL, NULL), SQLITE_OK);
334 sqlite3_exec(other,
"ROLLBACK", NULL, NULL, NULL);
335 sqlite3_close(other);
338 assert_int_equal(img.
id,
id);
339 assert_int_equal(img.
width, 4242);
342int main(
int argc,
char *argv[])
344 const struct CMUnitTest tests[] = {
355 const struct CMUnitTest on_disk[] = {
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
void dt_image_init(dt_image_t *img)
dt_database_open_result_t dt_database_open(const dt_database_params_t *params)
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.
gboolean dt_image_repository_set_flags_masked(const int32_t imgid, const int mask, const int value)
Write only mask's bits of imgid's flags, taking them from value.
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().
gboolean dt_image_repository_load(const int32_t imgid, dt_image_t *img)
Fill img from the main.images row for imgid.
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...
void dt_image_repository_foreach_with_path(dt_image_repository_path_row_cb cb, void *user_data)
Walk every image in the library, film roll by film roll, filename within each.
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_FILENAME
@ DT_IMAGE_FIELD_FILM_ROLL
static const dt_iop_drawlayer_params_t * params
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
dt_mipmap_buffer_dsc_flags flags
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Apply one channel's tone curve to each of the three colour channels, or pass the channel through unto...
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 int _file_teardown(void **state)
static void test_load_marks_an_absent_image_invalid(void **state __attribute__((unused)))
static void test_foreach_with_path_stops_when_asked(void **state)
static void test_write_timestamp_is_64bit(void **state)
static void test_set_flags_masked_leaves_other_bits(void **state)
static void test_group_member_rows(void **state)
static int _file_setup(void **state __attribute__((unused)))
static gboolean _count_two_rows(const int32_t imgid, const int64_t write_timestamp, const int version, const char *image_path, const int flags, void *user_data)
static void test_count_distinct_fields(void **state)
static void test_full_paths(void **state)
static void test_load_failure_leaves_the_image_untouched(void **state __attribute__((unused)))
static void test_id_range(void **state)
Shared fixture for the src/database repository tests.
static int testdb_setup(void **state)
static int32_t testdb_make_film(const char *folder)
static int testdb_teardown(void **state)
static int32_t testdb_make_image(const int32_t film_id, const char *filename)