Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_import_jobs.c
Go to the documentation of this file.
1/*
2 This file is part of Ansel,
3 Copyright (C) 2026 Paolo SANTUCCI.
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
11#include "common/utility.h"
12#include "common/variables.h"
13#include "common/conf.h"
14#include "common/image.h"
15#include "control/control.h"
17#include "darktable.h"
19#include "system/macros.h"
20#include "system/mem_alloc.h"
21
22#include <setjmp.h>
23#include <stdarg.h>
24#include <stddef.h>
25#include <stdint.h>
26#include <stdlib.h>
27#include <fcntl.h>
28#include <cmocka.h>
29#include <glib/gstdio.h>
30
31#ifdef _WIN32
32#include <io.h>
33#include "win/main_wrapper.h"
34#define test_dup _dup
35// _dup2() answers 0 on success where POSIX dup2() answers the target descriptor
36#define test_dup2(fd, fd2) (_dup2((fd), (fd2)) == 0 ? (fd2) : -1)
37#define test_close _close
38#else
39#include <unistd.h>
40#define test_dup dup
41#define test_dup2 dup2
42#define test_close close
43#endif
44
45extern int _import_copy_file(const char *filename, const char *destination, dt_control_import_t *data,
46 gchar *img_path_to_db, size_t pathname_len, GList **discarded);
47
48typedef struct extension_case_t
49{
50 const char *path;
51 const char *extension;
52 const char *variables;
53 const char *replacement;
55
57 { "capture.raw", "raw", "capture|capture|raw", "capture.jpg" },
58 { ".profile.jpg", "jpg", ".profile|.profile|jpg", ".profile.jpg" },
59 { "/a.b/capture", NULL, "capture|capture|", NULL },
60 { "C:\\a.b\\capture", NULL, "capture|capture|", NULL },
61 { ".profile", NULL, ".profile|.profile|", NULL },
62 { "capture.", NULL, "capture.|capture.|", NULL },
63 { "capture", NULL, "capture|capture|", NULL },
64 { "", NULL, "||", NULL },
65 { "/", NULL, "||", NULL },
66 { "\\", NULL, "||", NULL },
67};
68
69static char *_rcfile = NULL;
70static char *_integration_config = NULL;
71static char *_integration_cache = NULL;
72static char *_integration_tmp = NULL;
73static char *_integration_datadir = NULL;
74
83
84static void _import_completed(const char *source, gboolean success, gpointer user_data)
85{
86 import_completion_t *completion = user_data;
87 g_hash_table_insert(completion->sources, g_strdup(source), GINT_TO_POINTER(success));
88 completion->completed++;
89 completion->succeeded += success;
90}
91
92static void _import_job_disposed(gpointer user_data)
93{
94 import_completion_t *completion = user_data;
95 completion->job_disposed = TRUE;
96}
97
98static void _completion_init(import_completion_t *completion, const int expected)
99{
100 completion->expected = expected;
101 completion->sources = g_hash_table_new_full(g_str_hash, g_str_equal, dt_free_gpointer, NULL);
102}
103
105{
106 g_hash_table_destroy(completion->sources);
107}
108
109static void _remove_tree(const char *path)
110{
111 GDir *directory = g_dir_open(path, 0, NULL);
113 {
114 g_remove(path);
115 return;
116 }
117
118 const char *name = NULL;
119 while((name = g_dir_read_name(directory)))
120 {
121 char *child = g_build_filename(path, name, NULL);
122 _remove_tree(child);
123 dt_free(child);
124 }
125 g_dir_close(directory);
126 g_rmdir(path);
127}
128
129static char *_make_jpeg(const char *directory, const char *name, const uint8_t value)
130{
131 char *path = g_build_filename(directory, name, NULL);
132 const uint8_t pixels[] = { value, value, value, 255, value, value, value, 255,
133 value, value, value, 255, value, value, value, 255 };
134 assert_int_equal(dt_imageio_jpeg_write(path, pixels, 2, 2, 90, NULL, 0), 0);
135 return path;
136}
137
138static void _assert_file_bytes(const char *path, const gchar *expected, const gsize expected_size)
139{
140 gchar *actual = NULL;
141 gsize actual_size = 0;
142 assert_true(g_file_get_contents(path, &actual, &actual_size, NULL));
143 assert_int_equal(actual_size, expected_size);
144 assert_int_equal(memcmp(actual, expected, expected_size), 0);
145 dt_free(actual);
146}
147
148static void _assert_different_bytes(const gchar *first, const gsize first_size, const gchar *second,
149 const gsize second_size)
150{
151 assert_true(first_size != second_size || memcmp(first, second, first_size) != 0);
152}
153
154static void _assert_import(import_completion_t *completion, const int expected_successes)
155{
156 assert_int_equal(completion->completed, completion->expected);
157 assert_int_equal(completion->succeeded, expected_successes);
158 assert_int_equal(g_hash_table_size(completion->sources), completion->expected);
159 assert_true(completion->job_disposed);
160}
161
162static dt_control_import_t _copy_import(GList *sources, const int elements, const char *destination,
163 const char *pattern, const dt_import_onconflict_t policy,
164 import_completion_t *completion)
165{
166 dt_control_import_t data = { .imgs = sources, .elements = elements };
167 data.datetime = g_date_time_new_now_local();
168 data.copy = TRUE;
169 data.on_conflict = policy;
170 data.base_folder = g_strdup(destination);
171 data.target_subfolder_pattern = g_strdup("");
172 data.target_file_pattern = g_strdup(pattern);
173 data.file_imported = _import_completed;
174 data.callback_data = completion;
175 data.callback_data_free = _import_job_disposed;
176 return data;
177}
178
180{
181 char *root = g_dir_make_tmp("ansel-import-siblings-XXXXXX", NULL);
182 char *source = g_build_filename(root, "source", NULL);
183 char *destination = g_build_filename(root, "destination", NULL);
184 assert_int_equal(g_mkdir(source, 0700), 0);
185 char *jpg = _make_jpeg(source, "capture.jpg", 20);
186 char *jpeg = _make_jpeg(source, "capture.jpeg", 21);
187 gchar *jpg_bytes = NULL;
188 gchar *jpeg_bytes = NULL;
189 gsize jpg_size = 0;
190 gsize jpeg_size = 0;
191 assert_true(g_file_get_contents(jpg, &jpg_bytes, &jpg_size, NULL));
192 assert_true(g_file_get_contents(jpeg, &jpeg_bytes, &jpeg_size, NULL));
193 _assert_different_bytes(jpg_bytes, jpg_size, jpeg_bytes, jpeg_size);
194 dt_free(jpeg_bytes);
195 dt_free(jpg_bytes);
196
197 import_completion_t completion = { 0 };
198 _completion_init(&completion, 2);
199 GList *sources = g_list_append(g_list_append(NULL, jpg), jpeg);
200 assert_int_equal(dt_control_import(_copy_import(sources, 2, destination,
201 "$(FILE.NAME)_$(FILE.EXTENSION)_$(SEQUENCE).jpg",
202 DT_IMPORT_ONCONFLICT_SKIP, &completion)), 0);
203 _assert_import(&completion, 2);
204 char *first = g_build_filename(destination, "capture_jpg_0001.jpg", NULL);
205 char *second = g_build_filename(destination, "capture_jpeg_0001.jpg", NULL);
206 assert_true(g_file_test(first, G_FILE_TEST_IS_REGULAR));
207 assert_true(g_file_test(second, G_FILE_TEST_IS_REGULAR));
208 assert_true(dt_image_get_id_full_path(first) > UNKNOWN_IMAGE);
209 assert_true(dt_image_get_id_full_path(second) > UNKNOWN_IMAGE);
210 dt_free(first);
211 dt_free(second);
212 _completion_cleanup(&completion);
213 _remove_tree(root);
214 dt_free(destination);
215 dt_free(source);
216 dt_free(root);
217}
218
220{
221 char *root = g_dir_make_tmp("ansel-import-in-place-XXXXXX", NULL);
222 assert_non_null(root);
223 char *source = _make_jpeg(root, "capture.jpg", 25);
224 char *source_path = g_strdup(source);
225 char *unused_destination = g_build_filename(root, "unused", NULL);
226 import_completion_t completion = { 0 };
227 _completion_init(&completion, 1);
228 dt_control_import_t data = _copy_import(g_list_append(NULL, source), 1, unused_destination,
229 "fixed.jpg", DT_IMPORT_ONCONFLICT_SKIP, &completion);
230 data.copy = FALSE;
231 data.delete_source = TRUE;
232 assert_int_equal(dt_control_import(data), 0);
233 _assert_import(&completion, 1);
234 assert_true(g_file_test(source_path, G_FILE_TEST_IS_REGULAR));
235 assert_true(dt_image_get_id_full_path(source_path) > UNKNOWN_IMAGE);
236 assert_false(g_file_test(unused_destination, G_FILE_TEST_EXISTS));
237 _completion_cleanup(&completion);
238 _remove_tree(root);
239 dt_free(unused_destination);
240 dt_free(source_path);
241 dt_free(root);
242}
243
245{
246 char *root = g_dir_make_tmp("ansel-import-delete-XXXXXX", NULL);
247 assert_non_null(root);
248 char *destination = g_build_filename(root, "destination", NULL);
249 char *source = _make_jpeg(root, "first.jpg", 35);
250 char *source_path = g_strdup(source);
251 gchar *bytes = NULL;
252 gsize size = 0;
253 assert_true(g_file_get_contents(source, &bytes, &size, NULL));
254 import_completion_t completion = { 0 };
255 _completion_init(&completion, 1);
256 dt_control_import_t data = _copy_import(g_list_append(NULL, source), 1, destination,
257 "fixed.jpg", DT_IMPORT_ONCONFLICT_SKIP, &completion);
258 data.delete_source = TRUE;
259 assert_int_equal(dt_control_import(data), 0);
260 _assert_import(&completion, 1);
261 assert_false(g_file_test(source_path, G_FILE_TEST_EXISTS));
262 char *copied = g_build_filename(destination, "fixed.jpg", NULL);
263 _assert_file_bytes(copied, bytes, size);
264 _completion_cleanup(&completion);
265 dt_free(source_path);
266
267 source = _make_jpeg(root, "second.jpg", 45);
268 source_path = g_strdup(source);
269 completion = (import_completion_t){ 0 };
270 _completion_init(&completion, 1);
271 dt_control_import_t skipped = _copy_import(g_list_append(NULL, source), 1, destination,
272 "fixed.jpg", DT_IMPORT_ONCONFLICT_SKIP, &completion);
273 skipped.delete_source = TRUE;
274 assert_int_equal(dt_control_import(skipped), 0);
275 _assert_import(&completion, 1);
276 assert_true(g_file_test(source_path, G_FILE_TEST_IS_REGULAR));
277 _assert_file_bytes(copied, bytes, size);
278 _completion_cleanup(&completion);
279 dt_free(source_path);
280 dt_free(copied);
281 dt_free(bytes);
282 _remove_tree(root);
283 dt_free(destination);
284 dt_free(root);
285}
286
287static void _test_stream_comparison_boundaries(void **state G_GNUC_UNUSED)
288{
289 char *directory = g_dir_make_tmp("ansel-stream-compare-XXXXXX", NULL);
290 assert_non_null(directory);
291 char *first_path = g_build_filename(directory, "first", NULL);
292 char *second_path = g_build_filename(directory, "second", NULL);
293 const size_t sizes[] = { 0, 1, 65535, 65536, 65537, 131073 };
294 unsigned char *bytes = g_malloc0(sizes[G_N_ELEMENTS(sizes) - 1]);
295 gboolean streams_opened = TRUE;
296 size_t i = 0;
297 while(i < G_N_ELEMENTS(sizes) && streams_opened)
298 {
299 assert_true(g_file_set_contents(first_path, (const char *)bytes, sizes[i], NULL));
300 assert_true(g_file_set_contents(second_path, (const char *)bytes, sizes[i], NULL));
301 FILE *first = g_fopen(first_path, "rb");
302 FILE *second = g_fopen(second_path, "r+b");
303 streams_opened = !IS_NULL_PTR(first) && !IS_NULL_PTR(second);
304 if(!streams_opened)
305 {
306 if(!IS_NULL_PTR(first)) fclose(first);
307 if(!IS_NULL_PTR(second)) fclose(second);
308 goto cleanup;
309 }
310 const int equal = dt_util_streams_equal(first, second);
311 int mismatch = 0;
312 if(sizes[i] > 0)
313 {
314 assert_int_equal(fseek(second, -1, SEEK_END), 0);
315 assert_int_equal(fputc(1, second), 1);
316 rewind(first);
317 rewind(second);
318 mismatch = dt_util_streams_equal(first, second);
319 assert_int_equal(fseek(second, -1, SEEK_END), 0);
320 assert_int_equal(fputc(0, second), 0);
321 }
322 assert_int_equal(fseek(second, 0, SEEK_END), 0);
323 assert_int_equal(fputc(2, second), 2);
324 rewind(first);
325 rewind(second);
326 const int longer = dt_util_streams_equal(first, second);
327 fclose(second);
328 second = g_fopen(second_path, "wb");
329 streams_opened = !IS_NULL_PTR(second);
330 int read_error = 0;
331 if(streams_opened)
332 {
333 rewind(first);
334 read_error = dt_util_streams_equal(first, second);
335 fclose(second);
336 }
337 fclose(first);
338 assert_int_equal(equal, 1);
339 assert_int_equal(mismatch, 0);
340 assert_int_equal(longer, 0);
341 if(streams_opened) assert_int_equal(read_error, -1);
342 i++;
343 }
344cleanup:
345 dt_free(bytes)
346 g_remove(first_path);
347 g_remove(second_path);
348 g_rmdir(directory);
349 dt_free(first_path);
350 dt_free(second_path);
352 assert_true(streams_opened);
353}
354
356{
357 char *root = g_dir_make_tmp("ansel-import-fallback-XXXXXX", NULL);
358 char *source = g_build_filename(root, "source", NULL);
359 char *destination = g_build_filename(root, "destination", NULL);
360 assert_int_equal(g_mkdir(source, 0700), 0);
361 char *jpg = _make_jpeg(source, "capture.jpg", 30);
362 char *jpeg = _make_jpeg(source, "capture.jpeg", 31);
363 gchar *first_bytes = NULL;
364 gchar *fallback_bytes = NULL;
365 gsize first_size = 0;
366 gsize fallback_size = 0;
367 assert_true(g_file_get_contents(jpg, &first_bytes, &first_size, NULL));
368 assert_true(g_file_get_contents(jpeg, &fallback_bytes, &fallback_size, NULL));
369 _assert_different_bytes(first_bytes, first_size, fallback_bytes, fallback_size);
370
371 import_completion_t completion = { 0 };
372 _completion_init(&completion, 2);
373 GList *sources = g_list_append(g_list_append(NULL, jpg), jpeg);
374 assert_int_equal(dt_control_import(_copy_import(sources, 2, destination, "$(FILE.NAME)_$(SEQUENCE).jpg",
375 DT_IMPORT_ONCONFLICT_SKIP, &completion)), 0);
376 _assert_import(&completion, 2);
377 char *first = g_build_filename(destination, "capture_0001.jpg", NULL);
378 char *fallback = g_build_filename(destination, "capture_0002.jpg", NULL);
379 assert_true(g_file_test(first, G_FILE_TEST_IS_REGULAR));
380 assert_true(g_file_test(fallback, G_FILE_TEST_IS_REGULAR));
381 assert_true(dt_image_get_id_full_path(first) > UNKNOWN_IMAGE);
382 assert_true(dt_image_get_id_full_path(fallback) > UNKNOWN_IMAGE);
383 _assert_file_bytes(first, first_bytes, first_size);
384 _assert_file_bytes(fallback, fallback_bytes, fallback_size);
385 dt_free(fallback_bytes);
386 dt_free(first_bytes);
387 dt_free(first);
388 dt_free(fallback);
389 _completion_cleanup(&completion);
390 _remove_tree(root);
391 dt_free(destination);
392 dt_free(source);
393 dt_free(root);
394}
395
397{
400 for(size_t policy = 0; policy < G_N_ELEMENTS(policies); policy++)
401 {
402 char *root = g_dir_make_tmp("ansel-import-fixed-XXXXXX", NULL);
403 char *source = g_build_filename(root, "source", NULL);
404 char *destination = g_build_filename(root, "destination", NULL);
405 assert_int_equal(g_mkdir(source, 0700), 0);
406 char *jpg = _make_jpeg(source, "capture.jpg", 40);
407 char *jpeg = _make_jpeg(source, "capture.jpeg", 41);
408 gchar *first_bytes = NULL;
409 gchar *second_bytes = NULL;
410 gsize first_size = 0;
411 gsize second_size = 0;
412 assert_true(g_file_get_contents(jpg, &first_bytes, &first_size, NULL));
413 assert_true(g_file_get_contents(jpeg, &second_bytes, &second_size, NULL));
414 _assert_different_bytes(first_bytes, first_size, second_bytes, second_size);
415 import_completion_t completion = { 0 };
416 _completion_init(&completion, 2);
417 GList *sources = g_list_append(g_list_append(NULL, jpg), jpeg);
418 assert_int_equal(dt_control_import(_copy_import(sources, 2, destination, "fixed.jpg", policies[policy],
419 &completion)), 0);
420 _assert_import(&completion, 2);
421 char *fixed = g_build_filename(destination, "fixed.jpg", NULL);
422 char *unique = g_build_filename(destination, "fixed_01.jpg", NULL);
423 assert_true(g_file_test(fixed, G_FILE_TEST_IS_REGULAR));
424 assert_true(dt_image_get_id_full_path(fixed) > UNKNOWN_IMAGE);
425 _assert_file_bytes(fixed, policies[policy] == DT_IMPORT_ONCONFLICT_OVERWRITE ? second_bytes : first_bytes,
426 policies[policy] == DT_IMPORT_ONCONFLICT_OVERWRITE ? second_size : first_size);
427 assert_int_equal(g_file_test(unique, G_FILE_TEST_IS_REGULAR), policies[policy] == DT_IMPORT_ONCONFLICT_UNIQUE);
428 if(policies[policy] == DT_IMPORT_ONCONFLICT_UNIQUE)
429 {
430 assert_true(dt_image_get_id_full_path(unique) > UNKNOWN_IMAGE);
431 _assert_file_bytes(unique, second_bytes, second_size);
432 }
433 dt_free(second_bytes);
434 dt_free(first_bytes);
435 dt_free(unique);
436 dt_free(fixed);
437 _completion_cleanup(&completion);
438 _remove_tree(root);
439 dt_free(destination);
440 dt_free(source);
441 dt_free(root);
442 }
443}
444
446{
449 for(size_t policy = 0; policy < G_N_ELEMENTS(policies); policy++)
450 {
451 char *root = g_dir_make_tmp("ansel-import-unrelated-XXXXXX", NULL);
452 char *source = g_build_filename(root, "source", NULL);
453 char *destination = g_build_filename(root, "destination", NULL);
454 assert_int_equal(g_mkdir(source, 0700), 0);
455 char *first_source = _make_jpeg(source, "first.jpg", 50);
456 char *second_source = _make_jpeg(source, "second.jpg", 60);
457 gchar *first_bytes = NULL;
458 gchar *second_bytes = NULL;
459 gsize first_size = 0;
460 gsize second_size = 0;
461 assert_true(g_file_get_contents(first_source, &first_bytes, &first_size, NULL));
462 assert_true(g_file_get_contents(second_source, &second_bytes, &second_size, NULL));
463 _assert_different_bytes(first_bytes, first_size, second_bytes, second_size);
464 import_completion_t completion = { 0 };
465 _completion_init(&completion, 2);
466 GList *sources = g_list_append(g_list_append(NULL, first_source), second_source);
467 assert_int_equal(dt_control_import(_copy_import(sources, 2, destination, "fixed.jpg", policies[policy],
468 &completion)), 0);
469 _assert_import(&completion, 2);
470 char *fixed = g_build_filename(destination, "fixed.jpg", NULL);
471 char *fallback = g_build_filename(destination, "fixed_2.jpg", NULL);
472 char *unique = g_build_filename(destination, "fixed_01.jpg", NULL);
473 assert_true(g_file_test(fixed, G_FILE_TEST_IS_REGULAR));
474 assert_false(g_file_test(fallback, G_FILE_TEST_EXISTS));
475 _assert_file_bytes(fixed, policies[policy] == DT_IMPORT_ONCONFLICT_OVERWRITE ? second_bytes : first_bytes,
476 policies[policy] == DT_IMPORT_ONCONFLICT_OVERWRITE ? second_size : first_size);
477 if(policies[policy] == DT_IMPORT_ONCONFLICT_UNIQUE)
478 {
479 assert_true(g_file_test(unique, G_FILE_TEST_IS_REGULAR));
480 _assert_file_bytes(unique, second_bytes, second_size);
481 }
482 dt_free(second_bytes);
483 dt_free(first_bytes);
484 dt_free(unique);
485 dt_free(fallback);
486 dt_free(fixed);
487 _completion_cleanup(&completion);
488 _remove_tree(root);
489 dt_free(destination);
490 dt_free(source);
491 dt_free(root);
492 }
493}
494
496{
497 char *root = g_dir_make_tmp("ansel-import-failures-XXXXXX", NULL);
498 char *source = g_build_filename(root, "source", NULL);
499 char *destination = g_build_filename(root, "destination", NULL);
500 assert_int_equal(g_mkdir(source, 0700), 0);
501 char *missing = g_build_filename(source, "missing.jpg", NULL);
502 char *invalid = g_build_filename(source, "invalid.dt", NULL);
503 char *valid = _make_jpeg(source, "valid.jpg", 70);
504 char *missing_key = g_strdup(missing);
505 char *invalid_key = g_strdup(invalid);
506 char *valid_key = g_strdup(valid);
507 assert_true(g_file_set_contents(invalid, "not a jpeg", -1, NULL));
508 import_completion_t completion = { 0 };
509 _completion_init(&completion, 3);
510 GList *sources = g_list_append(g_list_append(g_list_append(NULL, missing), invalid), valid);
511 assert_int_equal(dt_control_import(_copy_import(sources, 3, destination, "$(FILE.NAME)_$(SEQUENCE).$(FILE.EXTENSION)",
512 DT_IMPORT_ONCONFLICT_SKIP, &completion)), 0);
513 _assert_import(&completion, 1);
514 assert_false(GPOINTER_TO_INT(g_hash_table_lookup(completion.sources, missing_key)));
515 assert_false(GPOINTER_TO_INT(g_hash_table_lookup(completion.sources, invalid_key)));
516 assert_true(GPOINTER_TO_INT(g_hash_table_lookup(completion.sources, valid_key)));
517 char *missing_destination = g_build_filename(destination, "missing_0001.jpg", NULL);
518 char *invalid_destination = g_build_filename(destination, "invalid_0002.dt", NULL);
519 char *valid_destination = g_build_filename(destination, "valid_0003.jpg", NULL);
520 assert_false(g_file_test(missing_destination, G_FILE_TEST_EXISTS));
521 assert_true(g_file_test(invalid_destination, G_FILE_TEST_IS_REGULAR));
522 assert_true(g_file_test(valid_destination, G_FILE_TEST_IS_REGULAR));
523 assert_int_equal(dt_image_get_id_full_path(invalid_destination), UNKNOWN_IMAGE);
524 assert_true(dt_image_get_id_full_path(valid_destination) > UNKNOWN_IMAGE);
525 dt_free(missing_destination);
526 dt_free(invalid_destination);
527 dt_free(valid_destination);
528 dt_free(valid_key);
529 dt_free(invalid_key);
530 dt_free(missing_key);
531 _completion_cleanup(&completion);
532 _remove_tree(root);
533 dt_free(destination);
534 dt_free(source);
535 dt_free(root);
536}
537
539{
540 char *root = g_dir_make_tmp("ansel-import-copy-reservation-XXXXXX", NULL);
541 char *source = g_build_filename(root, "source", NULL);
542 char *destination = g_build_filename(root, "destination", NULL);
543 assert_int_equal(g_mkdir(source, 0700), 0);
544 char *missing = g_build_filename(source, "capture.jpg", NULL);
545 char *sibling = _make_jpeg(source, "capture.jpeg", 80);
546 char *missing_key = g_strdup(missing);
547 char *sibling_key = g_strdup(sibling);
548 import_completion_t completion = { 0 };
549 _completion_init(&completion, 2);
550 GList *sources = g_list_append(g_list_append(NULL, missing), sibling);
551 assert_int_equal(dt_control_import(_copy_import(sources, 2, destination, "$(FILE.NAME)_$(SEQUENCE).jpg",
552 DT_IMPORT_ONCONFLICT_SKIP, &completion)), 0);
553 _assert_import(&completion, 1);
554 assert_false(GPOINTER_TO_INT(g_hash_table_lookup(completion.sources, missing_key)));
555 assert_true(GPOINTER_TO_INT(g_hash_table_lookup(completion.sources, sibling_key)));
556 char *failed = g_build_filename(destination, "capture_0001.jpg", NULL);
557 char *fallback = g_build_filename(destination, "capture_0002.jpg", NULL);
558 assert_false(g_file_test(failed, G_FILE_TEST_EXISTS));
559 assert_true(g_file_test(fallback, G_FILE_TEST_IS_REGULAR));
560 assert_true(dt_image_get_id_full_path(fallback) > UNKNOWN_IMAGE);
561 dt_free(fallback);
562 dt_free(failed);
563 dt_free(sibling_key);
564 dt_free(missing_key);
565 _completion_cleanup(&completion);
566 _remove_tree(root);
567 dt_free(destination);
568 dt_free(source);
569 dt_free(root);
570}
571
573{
574 char *root = g_dir_make_tmp("ansel-import-db-reservation-XXXXXX", NULL);
575 char *source = g_build_filename(root, "source", NULL);
576 char *destination = g_build_filename(root, "destination", NULL);
577 assert_int_equal(g_mkdir(source, 0700), 0);
578 char *first = _make_jpeg(source, "capture.jpg", 90);
579 char *sibling = _make_jpeg(source, "capture.jpeg", 91);
580 gchar *first_bytes = NULL;
581 gchar *sibling_bytes = NULL;
582 gsize first_size = 0;
583 gsize sibling_size = 0;
584 assert_true(g_file_get_contents(first, &first_bytes, &first_size, NULL));
585 assert_true(g_file_get_contents(sibling, &sibling_bytes, &sibling_size, NULL));
586 _assert_different_bytes(first_bytes, first_size, sibling_bytes, sibling_size);
587 dt_free(sibling_bytes);
588 dt_free(first_bytes);
589 char *first_key = g_strdup(first);
590 char *sibling_key = g_strdup(sibling);
591 import_completion_t completion = { 0 };
592 _completion_init(&completion, 2);
593 GList *sources = g_list_append(g_list_append(NULL, first), sibling);
594 assert_int_equal(dt_control_import(_copy_import(sources, 2, destination, "$(FILE.NAME)_$(SEQUENCE).dt",
595 DT_IMPORT_ONCONFLICT_SKIP, &completion)), 0);
596 _assert_import(&completion, 0);
597 assert_false(GPOINTER_TO_INT(g_hash_table_lookup(completion.sources, first_key)));
598 assert_false(GPOINTER_TO_INT(g_hash_table_lookup(completion.sources, sibling_key)));
599 char *first_destination = g_build_filename(destination, "capture_0001.dt", NULL);
600 char *fallback = g_build_filename(destination, "capture_0002.dt", NULL);
601 assert_true(g_file_test(first_destination, G_FILE_TEST_IS_REGULAR));
602 assert_true(g_file_test(fallback, G_FILE_TEST_IS_REGULAR));
603 assert_int_equal(dt_image_get_id_full_path(first_destination), UNKNOWN_IMAGE);
604 assert_int_equal(dt_image_get_id_full_path(fallback), UNKNOWN_IMAGE);
605 dt_free(fallback);
606 dt_free(first_destination);
607 dt_free(sibling_key);
608 dt_free(first_key);
609 _completion_cleanup(&completion);
610 _remove_tree(root);
611 dt_free(destination);
612 dt_free(source);
613 dt_free(root);
614}
615
617{
620 for(size_t policy = 0; policy < G_N_ELEMENTS(policies); policy++)
621 {
622 char *root = g_dir_make_tmp("ansel-import-reserved-fallback-XXXXXX", NULL);
623 char *source = g_build_filename(root, "source", NULL);
624 char *destination = g_build_filename(root, "destination", NULL);
625 assert_int_equal(g_mkdir(source, 0700), 0);
626 char *capture = _make_jpeg(source, "capture.jpg", 100);
627 char *fallback_owner = _make_jpeg(source, "capture1.jpg", 101);
628 char *capture_key = g_strdup(capture);
629 char *owner_key = g_strdup(fallback_owner);
630 gchar *capture_bytes = NULL;
631 gchar *owner_bytes = NULL;
632 gchar *sibling_bytes = NULL;
633 gsize capture_size = 0;
634 gsize owner_size = 0;
635 gsize sibling_size = 0;
636 assert_true(g_file_get_contents(capture, &capture_bytes, &capture_size, NULL));
637 assert_true(g_file_get_contents(fallback_owner, &owner_bytes, &owner_size, NULL));
638 GList *sources = g_list_append(g_list_append(NULL, capture), fallback_owner);
639 for(int sequence = 3; sequence < 12; sequence++)
640 {
641 char *name = g_strdup_printf("other%d.jpg", sequence);
642 sources = g_list_append(sources, _make_jpeg(source, name, (uint8_t)(100 + sequence)));
643 dt_free(name);
644 }
645 char *sibling = _make_jpeg(source, "capture.jpeg", 120);
646 char *sibling_key = g_strdup(sibling);
647 assert_true(g_file_get_contents(sibling, &sibling_bytes, &sibling_size, NULL));
648 _assert_different_bytes(capture_bytes, capture_size, owner_bytes, owner_size);
649 _assert_different_bytes(owner_bytes, owner_size, sibling_bytes, sibling_size);
650 sources = g_list_append(sources, sibling);
651 import_completion_t completion = { 0 };
652 _completion_init(&completion, 12);
653 assert_int_equal(dt_control_import(_copy_import(sources, 12, destination, "$(FILE.NAME)$(SEQUENCE1).jpg",
654 policies[policy], &completion)), 0);
655 _assert_import(&completion, 12);
656 assert_true(GPOINTER_TO_INT(g_hash_table_lookup(completion.sources, capture_key)));
657 assert_true(GPOINTER_TO_INT(g_hash_table_lookup(completion.sources, owner_key)));
658 assert_true(GPOINTER_TO_INT(g_hash_table_lookup(completion.sources, sibling_key)));
659 char *first_destination = g_build_filename(destination, "capture1.jpg", NULL);
660 char *reserved_fallback = g_build_filename(destination, "capture12.jpg", NULL);
661 char *third_retry = g_build_filename(destination, "capture13.jpg", NULL);
662 char *unique = g_build_filename(destination, "capture12_01.jpg", NULL);
663 assert_true(g_file_test(first_destination, G_FILE_TEST_IS_REGULAR));
664 assert_true(g_file_test(reserved_fallback, G_FILE_TEST_IS_REGULAR));
665 assert_false(g_file_test(third_retry, G_FILE_TEST_EXISTS));
666 _assert_file_bytes(first_destination, capture_bytes, capture_size);
667 _assert_file_bytes(reserved_fallback, policies[policy] == DT_IMPORT_ONCONFLICT_OVERWRITE ? sibling_bytes : owner_bytes,
668 policies[policy] == DT_IMPORT_ONCONFLICT_OVERWRITE ? sibling_size : owner_size);
669 assert_int_equal(g_file_test(unique, G_FILE_TEST_IS_REGULAR), policies[policy] == DT_IMPORT_ONCONFLICT_UNIQUE);
670 if(policies[policy] == DT_IMPORT_ONCONFLICT_UNIQUE)
671 _assert_file_bytes(unique, sibling_bytes, sibling_size);
672 dt_free(unique);
673 dt_free(third_retry);
674 dt_free(reserved_fallback);
675 dt_free(first_destination);
676 dt_free(sibling_key);
677 dt_free(sibling_bytes);
678 dt_free(owner_bytes);
679 dt_free(capture_bytes);
680 dt_free(owner_key);
681 dt_free(capture_key);
682 _completion_cleanup(&completion);
683 _remove_tree(root);
684 dt_free(destination);
685 dt_free(source);
686 dt_free(root);
687 }
688}
689
690static char *_prepare_test_datadir(const char *tmp_dir)
691{
692 char *datadir = g_build_filename(tmp_dir, "data", NULL);
693 char *rawspeed_dir = g_build_filename(datadir, "rawspeed", NULL);
694 char *rawspeed_xml = g_build_filename(rawspeed_dir, "cameras.xml", NULL);
695 char *source_xml = g_build_filename(ANSEL_TEST_SOURCE_DIR, "src", "external", "rawspeed", "data", "cameras.xml", NULL);
696 assert_int_equal(g_mkdir(datadir, 0700), 0);
697 assert_int_equal(g_mkdir(rawspeed_dir, 0700), 0);
698 GFile *source_file = g_file_new_for_path(source_xml);
699 GFile *destination_file = g_file_new_for_path(rawspeed_xml);
700 assert_true(g_file_copy(source_file, destination_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL));
701 g_object_unref(destination_file);
702 g_object_unref(source_file);
703 dt_free(source_xml);
704 dt_free(rawspeed_xml);
705 dt_free(rawspeed_dir);
706 return datadir;
707}
708
709static int _setup(void **state G_GNUC_UNUSED)
710{
711 _rcfile = g_build_filename(g_get_tmp_dir(), "ansel-test-import-jobs.rc", NULL);
712 g_remove(_rcfile);
713 darktable.conf = calloc(1, sizeof(dt_conf_t));
714 dt_conf_init(darktable.conf, _rcfile, NULL);
715 return 0;
716}
717
718static int _teardown(void **state G_GNUC_UNUSED)
719{
721 free(darktable.conf);
722 darktable.conf = NULL;
723 g_remove(_rcfile);
725 _rcfile = NULL;
726 return 0;
727}
728
729static void _test_extension_contract(void **state G_GNUC_UNUSED)
730{
733
734 for(size_t i = 0; i < G_N_ELEMENTS(_extension_cases); i++)
735 {
736 const extension_case_t *test_case = &_extension_cases[i];
737 char *path = g_strdup(test_case->path);
738 const char *extension = dt_util_path_get_extension(path);
739
740 if(test_case->extension)
741 assert_ptr_equal(extension, path + strlen(path) - strlen(test_case->extension));
742 else
743 assert_null(extension);
744 assert_string_equal(path, test_case->path);
745
746 params->filename = path;
747 char source[] = "$(FILE.NAME)|$(IMAGE.BASENAME)|$(FILE.EXTENSION)";
748 char *variables = dt_variables_expand(params, source, FALSE);
749 assert_string_equal(variables, test_case->variables);
750 assert_string_equal(path, test_case->path);
751 dt_free(variables);
752
753 if(test_case->replacement)
754 {
755 char *replacement = dt_copy_filename_extension(path, "capture.jpg");
756 assert_string_equal(replacement, test_case->replacement);
757 assert_true(dt_has_same_path_basename(path, replacement));
758 assert_string_equal(path, test_case->path);
759 dt_free(replacement);
760 }
761 else
762 {
763 assert_null(dt_copy_filename_extension(path, "capture.jpg"));
764 assert_false(dt_has_same_path_basename(path, "capture.jpg"));
765 }
766
767 dt_free(path);
768 }
769
771}
772
773static void _test_extension_utility_rejections(void **state G_GNUC_UNUSED)
774{
775 assert_false(dt_has_same_path_basename("capture.raw", "other.jpg"));
776 assert_false(dt_has_same_path_basename("/a.b/capture.raw", "/a/capture.jpg"));
777 assert_false(dt_has_same_path_basename(NULL, "capture.jpg"));
778 assert_false(dt_has_same_path_basename("capture.raw", NULL));
779
780 assert_null(dt_copy_filename_extension(NULL, "capture.jpg"));
781 assert_null(dt_copy_filename_extension("capture.raw", NULL));
782 assert_null(dt_copy_filename_extension("capture.raw", ".profile"));
783 assert_null(dt_copy_filename_extension("capture.raw", "capture."));
784}
785
787{
789 dt_image_t image;
790 char *directory = g_dir_make_tmp("ansel-test-pattern-expansion-XXXXXX", NULL);
791 assert_non_null(directory);
792 data.base_folder = directory;
793 data.datetime = g_date_time_new_now_local();
794 dt_image_init(&image);
795
796 assert_null(dt_build_filename_from_pattern("source.raw", 1, &image, &data));
797 assert_null(data.target_dir);
798
799 data.target_file_pattern = "target.raw";
800 data.target_subfolder_pattern = "";
801 data.base_folder = NULL;
802 assert_null(dt_build_filename_from_pattern("source.raw", 1, &image, &data));
803 assert_null(data.target_dir);
804
805 g_date_time_unref(data.datetime);
808}
809
810static void _test_image_import_extension_boundaries(void **state G_GNUC_UNUSED)
811{
812 char *directory = g_dir_make_tmp("ansel-test-image-import-XXXXXX", NULL);
813 assert_non_null(directory);
814 char *dotted_directory = g_build_filename(directory, "a.b", NULL);
815 assert_int_equal(g_mkdir(dotted_directory, 0700), 0);
816
817 char *extensionless = g_build_filename(dotted_directory, "capture", NULL);
818 char *dotfile = g_build_filename(directory, ".profile", NULL);
819 char *trailing_dot = g_build_filename(directory, "capture.", NULL);
820 assert_true(g_file_set_contents(extensionless, "x", 1, NULL));
821 assert_true(g_file_set_contents(dotfile, "x", 1, NULL));
822 assert_true(g_file_set_contents(trailing_dot, "x", 1, NULL));
823
824 assert_int_equal(dt_image_import(0, extensionless, FALSE), 0);
825 assert_int_equal(dt_image_import(0, dotfile, FALSE), 0);
826 assert_int_equal(dt_image_import(0, trailing_dot, FALSE), 0);
827
828 assert_true(dt_image_flags_from_extension(".cr2") & DT_IMAGE_RAW);
829 assert_true(dt_image_flags_from_extension(".jpg") & DT_IMAGE_LDR);
830
831 g_remove(extensionless);
832 g_remove(dotfile);
833 g_remove(trailing_dot);
834 g_rmdir(dotted_directory);
835 g_rmdir(directory);
836 dt_free(extensionless);
837 dt_free(dotfile);
838 dt_free(trailing_dot);
839 dt_free(dotted_directory);
841}
842
850
852 { "blocker", "Unable to create the target folder", "Not allowed to write", TRUE },
853 { "read-only", "Not allowed to write", "Unable to create the target folder", FALSE },
854};
855
875
878{
880 int result = 0;
881 if(fixture->stdout_fd >= 0) test_close(fixture->stdout_fd);
882 if(fixture->stderr_fd >= 0) test_close(fixture->stderr_fd);
883 if(fixture->diagnostic_fd >= 0) test_close(fixture->diagnostic_fd);
884 g_list_free_full(fixture->discarded, dt_free_gpointer);
885 dt_free(fixture->output);
886 dt_free(fixture->destination);
887 if(!IS_NULL_PTR(fixture->diagnostics)) g_remove(fixture->diagnostics);
888 dt_free(fixture->diagnostics);
889 dt_free(fixture->data.target_dir);
891 darktable.control = fixture->saved_control;
892 if(fixture->target_created)
893 {
894 if(fixture->test_case->target_is_file)
895 result = g_remove(fixture->target);
896 else
897 {
898 result = g_chmod(fixture->target, 0700);
899 if(g_rmdir(fixture->target) != 0) result = -1;
900 }
901 }
902 if(!IS_NULL_PTR(fixture->directory) && g_rmdir(fixture->directory) != 0) result = -1;
903 dt_free(fixture->target);
904 dt_free(fixture->directory);
905 return result;
906}
907
910{
912 const directory_failure_case_t *test_case = fixture->test_case;
913 fixture->stdout_fd = -1;
914 fixture->stderr_fd = -1;
915 fixture->diagnostic_fd = -1;
916 fixture->saved_control = darktable.control;
917 fixture->directory = g_dir_make_tmp("ansel-test-import-copy-XXXXXX", NULL);
918 if(IS_NULL_PTR(fixture->directory)) goto failed;
919 fixture->target = g_build_filename(fixture->directory, test_case->target_name, NULL);
920 if(test_case->target_is_file)
921 fixture->target_created = g_file_set_contents(fixture->target, "x", 1, NULL);
922 else
923 fixture->target_created = g_mkdir(fixture->target, 0700) == 0;
924 if(!fixture->target_created) goto failed;
925 if(!test_case->target_is_file)
926 {
927 if(g_chmod(fixture->target, 0500) != 0) goto failed;
929 }
930 if(dt_pthread_mutex_init(&fixture->control.log_mutex, NULL) != 0) goto failed;
931 fixture->mutex_initialized = TRUE;
932 darktable.control = &fixture->control;
933 fixture->data.target_dir = test_case->target_is_file
934 ? g_build_filename(fixture->target, "missing", NULL) : g_strdup(fixture->target);
935 fixture->destination = g_build_filename(fixture->data.target_dir, "target.raw", NULL);
936 fixture->diagnostics = g_build_filename(fixture->directory, "diagnostics", NULL);
937 fixture->diagnostic_fd = g_open(fixture->diagnostics, O_CREAT | O_EXCL | O_RDWR, 0600);
938 if(fixture->diagnostic_fd < 0) goto failed;
939 fixture->stdout_fd = test_dup(fileno(stdout));
940 if(fixture->stdout_fd < 0) goto failed;
941 fixture->stderr_fd = test_dup(fileno(stderr));
942 if(fixture->stderr_fd < 0) goto failed;
943 return 0;
944
945failed:
947 return -1;
948}
949
951{
953 const directory_failure_case_t *test_case = fixture->test_case;
954 if(fixture->writable_after_chmod) skip();
955 gchar image_path[DT_PATH_MAX] = { 0 };
956 int import_result = 0;
957 int stderr_redirect_result = -1;
958 fflush(stdout);
959 fflush(stderr);
960 const int stdout_redirect_result = test_dup2(fixture->diagnostic_fd, fileno(stdout));
961 if(stdout_redirect_result != fileno(stdout)) goto restore;
962 stderr_redirect_result = test_dup2(fixture->diagnostic_fd, fileno(stderr));
963 if(stderr_redirect_result != fileno(stderr)) goto restore;
964 import_result = _import_copy_file("source.raw", fixture->destination, &fixture->data,
965 image_path, sizeof(image_path), &fixture->discarded);
966
967restore:
968 fflush(stdout);
969 fflush(stderr);
970 const int stdout_restore_result = test_dup2(fixture->stdout_fd, fileno(stdout));
971 const int stderr_restore_result = test_dup2(fixture->stderr_fd, fileno(stderr));
972 assert_int_equal(stdout_restore_result, fileno(stdout));
973 assert_int_equal(stderr_restore_result, fileno(stderr));
974 assert_int_equal(stdout_redirect_result, fileno(stdout));
975 assert_int_equal(stderr_redirect_result, fileno(stderr));
976 assert_int_equal(import_result, -1);
977 assert_true(g_file_get_contents(fixture->diagnostics, &fixture->output, NULL, NULL));
978 assert_non_null(strstr(fixture->output, test_case->expected_diagnostic));
979 assert_null(strstr(fixture->output, test_case->unexpected_diagnostic));
980 assert_null(strstr(fixture->output, "Unable to copy the file"));
981 assert_string_equal(image_path, "");
982 assert_null(fixture->discarded);
983 if(test_case->target_is_file)
984 {
985 assert_int_equal(fixture->control.log_pos, 1);
986 assert_non_null(strstr(fixture->control.log_message[0], "Impossible to create directory"));
987 }
988}
989
990int main(int argc, char *argv[])
991{
992 directory_failure_fixture_t directory_fixtures[] = {
993 { .test_case = &_directory_failure_cases[0] },
994 { .test_case = &_directory_failure_cases[1] },
995 };
996 const struct CMUnitTest tests[] = {
997 cmocka_unit_test(_test_extension_contract),
998 cmocka_unit_test(_test_extension_utility_rejections),
1001 cmocka_unit_test(_test_stream_comparison_boundaries),
1002 cmocka_unit_test_prestate_setup_teardown(_test_copy_directory_failure_reports_only_its_cause,
1003 _directory_failure_setup, _directory_failure_teardown, &directory_fixtures[0]),
1004 cmocka_unit_test_prestate_setup_teardown(_test_copy_directory_failure_reports_only_its_cause,
1005 _directory_failure_setup, _directory_failure_teardown, &directory_fixtures[1]),
1006 };
1007 const int unit_result = cmocka_run_group_tests(tests, _setup, _teardown);
1008 if(unit_result) return unit_result;
1009
1010 _integration_config = g_strdup_printf("%s/ansel-test-import-config-XXXXXX", g_get_tmp_dir());
1011 _integration_cache = g_strdup_printf("%s/ansel-test-import-cache-XXXXXX", g_get_tmp_dir());
1012 _integration_tmp = g_strdup_printf("%s/ansel-test-import-tmp-XXXXXX", g_get_tmp_dir());
1013 assert_non_null(g_mkdtemp(_integration_config));
1014 assert_non_null(g_mkdtemp(_integration_cache));
1015 assert_non_null(g_mkdtemp(_integration_tmp));
1017 char *noiseprofiles = g_build_filename(ANSEL_TEST_SOURCE_DIR, "data", "noiseprofiles.json", NULL);
1018 char *init_argv[] = { "ansel-test-import-jobs", "--library", ":memory:", "--datadir", _integration_datadir,
1019 "--noiseprofiles", noiseprofiles, "--moduledir", ANSEL_TEST_BINARY_DIR "/src",
1020 "--configdir", _integration_config, "--cachedir", _integration_cache, "--tmpdir", _integration_tmp,
1021 "--disable-opencl", "--conf", "write_sidecar_files=FALSE", "-t", "1", NULL };
1022 assert_int_equal(dt_init(G_N_ELEMENTS(init_argv) - 1, init_argv, FALSE, FALSE), 0);
1023 dt_pthread_mutex_init(&darktable.control->progress_system.mutex, NULL);
1024 dt_free(noiseprofiles);
1025
1026 const struct CMUnitTest integration_tests[] = {
1037 };
1038 const int integration_result = cmocka_run_group_tests(integration_tests, NULL, NULL);
1039 dt_pthread_mutex_destroy(&darktable.control->progress_system.mutex);
1040 dt_cleanup();
1048 return integration_result;
1049}
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
const char * extension(dt_imageio_module_data_t *data)
Definition avif.c:651
void cleanup(dt_imageio_module_format_t *self)
Definition avif.c:170
void dt_conf_cleanup(dt_conf_t *cf)
Free everything cf owns. No dt_conf_*() call is valid afterwards.
void dt_conf_init(dt_conf_t *cf, const char *filename, GSList *override_entries)
Populate cf from filename and from the generated defaults.
int32_t dt_image_import(const int32_t film_id, const char *filename, gboolean raise_signals)
dt_image_flags_t dt_image_flags_from_extension(const char *extension)
void dt_image_init(dt_image_t *img)
int32_t dt_image_get_id_full_path(const gchar *filename)
void dt_cleanup()
Definition darktable.c:1867
darktable_t darktable
Definition darktable.c:213
int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load_data)
Definition darktable.c:888
dev roi_request value
gchar * directory
documentation root given after –doc, or NULL
static int dt_pthread_mutex_init(dt_pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr)
Initialise a mutex. With mutexattr NULL – which is how 54 of the 56 call sites in this tree spell it ...
Definition dtpthread.h:104
static int dt_pthread_mutex_destroy(dt_pthread_mutex_t *mutex)
Definition dtpthread.h:132
GList * missing
Definition geometry.c:82
void * data
Definition geometry.h:111
#define UNKNOWN_IMAGE
Definition image.h:78
@ DT_IMAGE_RAW
Definition image.h:133
@ DT_IMAGE_LDR
Definition image.h:131
int dt_imageio_jpeg_write(const char *filename, const uint8_t *in, const int width, const int height, const int quality, const void *exif, int exif_len)
gchar * dt_build_filename_from_pattern(const char *const filename, const int index, dt_image_t *img, dt_control_import_t *data)
Build a full path for a given image file, given a pattern.
Definition import_jobs.c:81
int dt_control_import(dt_control_import_t data)
Process a list of images to import with or without copying the files on an arbitrary hard-drive.
dt_import_onconflict_t
Behaviour when a copy-on-import destination path already exists.
Definition import_jobs.h:36
@ DT_IMPORT_ONCONFLICT_UNIQUE
Definition import_jobs.h:39
@ DT_IMPORT_ONCONFLICT_SKIP
Definition import_jobs.h:37
@ DT_IMPORT_ONCONFLICT_OVERWRITE
Definition import_jobs.h:38
TIFF sidecar I/O API for drawlayer layers.
static const dt_iop_drawlayer_params_t * params
Definition layers.h:80
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition macros.h:96
static void dt_free_gpointer(gpointer ptr)
g_free() one pointer, with the signature GDestroyNotify wants.
Definition mem_alloc.h:184
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
size_t size
Definition mipmap_cache.c:3
#define DT_PATH_MAX
Buffer size for a filesystem path anywhere in Ansel.
Definition paths.h:57
const char * name
Definition pdf.h:90
int main()
Definition prova.c:47
char * dt_variables_expand(dt_variables_params_t *params, gchar *source, gboolean iterate)
void dt_variables_params_destroy(dt_variables_params_t *params)
void dt_variables_params_init(dt_variables_params_t **params)
const float uint32_t state[4]
const directory_failure_case_t * test_case
The whole configuration state. One instance lives at darktable.conf.
dt_pthread_mutex_t log_mutex
Definition control.h:232
char log_message[10][1000]
Definition control.h:229
const char * variables
const char * replacement
const char * extension
static int _teardown(void **state __attribute__((unused)))
static int _setup(void **state __attribute__((unused)))
static char * _rcfile
static void _assert_file_bytes(const char *path, const gchar *expected, const gsize expected_size)
static void _test_copy_directory_failure_reports_only_its_cause(void **state)
static char * _integration_datadir
static void _test_pattern_expansion_rejects_missing_patterns(void **state G_GNUC_UNUSED)
static void _assert_different_bytes(const gchar *first, const gsize first_size, const gchar *second, const gsize second_size)
static dt_control_import_t _copy_import(GList *sources, const int elements, const char *destination, const char *pattern, const dt_import_onconflict_t policy, import_completion_t *completion)
static void _test_extension_contract(void **state G_GNUC_UNUSED)
static void _test_public_copy_failure_reservation_forces_sibling_fallback(void **state G_GNUC_UNUSED)
static void _test_stream_comparison_boundaries(void **state G_GNUC_UNUSED)
static void _import_job_disposed(gpointer user_data)
#define test_dup
static char * _integration_cache
static void _test_public_siblings_keep_sequence_for_distinct_destinations(void **state G_GNUC_UNUSED)
static void _test_image_import_extension_boundaries(void **state G_GNUC_UNUSED)
static char * _make_jpeg(const char *directory, const char *name, const uint8_t value)
static void _test_public_reserved_fallback_reaches_policy_without_third_expansion(void **state G_GNUC_UNUSED)
static void _test_public_fixed_destination_follows_all_policies(void **state G_GNUC_UNUSED)
static void _test_extension_utility_rejections(void **state G_GNUC_UNUSED)
static void _import_completed(const char *source, gboolean success, gpointer user_data)
static char * _prepare_test_datadir(const char *tmp_dir)
static void _test_public_unrelated_collision_has_no_sibling_fallback(void **state G_GNUC_UNUSED)
static int _setup(void **state G_GNUC_UNUSED)
static int _teardown(void **state G_GNUC_UNUSED)
#define test_close
static const extension_case_t _extension_cases[]
static void _assert_import(import_completion_t *completion, const int expected_successes)
static void _test_public_sibling_collision_reexpands_once(void **state G_GNUC_UNUSED)
static void _completion_cleanup(import_completion_t *completion)
static void _completion_init(import_completion_t *completion, const int expected)
static int _directory_failure_setup(void **state)
Prepare both diagnostic cases without redirecting process-wide output.
static char * _integration_config
static int _directory_failure_teardown(void **state)
Release fixture resources after setup failure, assertion failure, or skip.
int _import_copy_file(const char *filename, const char *destination, dt_control_import_t *data, gchar *img_path_to_db, size_t pathname_len, GList **discarded)
copy a file to a destination path after checking if everything is allright.
static void _test_public_delete_source_requires_successful_copy(void **state G_GNUC_UNUSED)
static void _remove_tree(const char *path)
static void _test_public_in_place_import_preserves_source(void **state G_GNUC_UNUSED)
static char * _integration_tmp
static void _test_public_failures_consume_sequences_and_complete_once(void **state G_GNUC_UNUSED)
static void _test_public_database_failure_reservation_forces_sibling_fallback(void **state G_GNUC_UNUSED)
#define test_dup2(fd, fd2)
static const directory_failure_case_t _directory_failure_cases[]
#define ANSEL_TEST_SOURCE_DIR
#define ANSEL_TEST_BINARY_DIR
gboolean dt_has_same_path_basename(const char *filename1, const char *filename2)
Test whether two paths are byte-identical before their normal extensions.
Definition utility.c:1049
int dt_util_streams_equal(FILE *first, FILE *second)
Compare the remaining bytes of two borrowed binary streams.
Definition utility.c:94
gboolean dt_util_test_writable_dir(const char *path)
Definition utility.c:371
const char * dt_util_path_get_extension(const char *path)
Locate a normal filename extension in a path basename.
Definition utility.c:1033
char * dt_copy_filename_extension(const char *filename1, const char *filename2)
Replace filename1's normal extension with filename2's normal extension.
Definition utility.c:1062