Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_conf_save.c File Reference
#include "common/conf.h"
#include "darktable.h"
#include "system/macros.h"
#include <glib.h>
#include <glib/gstdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#include <stdint.h>
#include <cmocka.h>
#include "win/main_wrapper.h"
+ Include dependency graph for test_conf_save.c:

Go to the source code of this file.

Macros

#define TEST_KEY   "plugins/test/conf_save"
 

Functions

static int _count_entries (const char *dir)
 
static int _setup (void **state __attribute__((unused)))
 
static int _teardown (void **state __attribute__((unused)))
 
static void _flush_writes_what_was_set (void **state __attribute__((unused)))
 
static void _flush_replaces_the_file_rather_than_rewriting_it (void **state __attribute__((unused)))
 
static void _a_failed_flush_returns_1_and_writes_nothing (void **state __attribute__((unused)))
 
int main (int argc, char *argv[])
 

Variables

static char * _dir = NULL
 
static char * _rcfile = NULL
 

Macro Definition Documentation

◆ TEST_KEY

#define TEST_KEY   "plugins/test/conf_save"

What dt_conf_flush() leaves on disk.

The settings file is replaced, not rewritten in place: a process that dies during a save must leave the previous file whole. The observable, without killing anything, is a handle opened on the old file before the save: a replacement leaves it reading the old content, a rewrite in place ("wb") truncates it under the reader.

The tests share a directory of their own, so that what is left beside the settings file – the temporary file of the replacement – can be counted.

Checked against the defect: with the save put back to g_fopen(filename, "wb"), _flush_replaces_the_file_rather_than_rewriting_it() fails on old_intact, the old handle reading the rewritten file. The other two pass either way: they pin what is written and what a failure returns, not how the file is replaced. A key with no confgen declaration, so nothing clamps or sanitises what we store.

Definition at line 57 of file test_conf_save.c.

Function Documentation

◆ _a_failed_flush_returns_1_and_writes_nothing()

static void _a_failed_flush_returns_1_and_writes_nothing ( void **state   __attribute__(unused))
static

A flush that cannot write returns 1 and leaves nothing behind. The settings file is pointed below a regular file, which no platform and no user, root included, can create a file in.

Definition at line 165 of file test_conf_save.c.

References _count_entries(), _dir, darktable_t::conf, darktable, dt_conf_flush(), dt_conf_set_string(), entries, dt_conf_t::filename, and TEST_KEY.

Referenced by main().

◆ _count_entries()

static int _count_entries ( const char *  dir)
static

Definition at line 62 of file test_conf_save.c.

References d.

Referenced by _a_failed_flush_returns_1_and_writes_nothing(), and _flush_writes_what_was_set().

◆ _flush_replaces_the_file_rather_than_rewriting_it()

static void _flush_replaces_the_file_rather_than_rewriting_it ( void **state   __attribute__(unused))
static

A handle opened on the old file still reads the old content after the flush: the file was replaced. A rewrite in place would have truncated it under the reader.

Definition at line 130 of file test_conf_save.c.

References _rcfile, dt_conf_flush(), dt_conf_set_string(), IS_NULL_PTR, n, TEST_KEY, and TRUE.

Referenced by main().

◆ _flush_writes_what_was_set()

static void _flush_writes_what_was_set ( void **state   __attribute__(unused))
static

A value set in memory is in the file once the flush returns, and the temporary file the replacement went through is gone.

Definition at line 114 of file test_conf_save.c.

References _count_entries(), _dir, _rcfile, dt_conf_flush(), dt_conf_set_string(), IS_NULL_PTR, and TEST_KEY.

Referenced by main().

◆ _setup()

static int _setup ( void **state   __attribute__(unused))
static

Definition at line 72 of file test_conf_save.c.

References _dir, _rcfile, darktable_t::conf, darktable, dt_conf_init(), and IS_NULL_PTR.

Referenced by main().

◆ _teardown()

static int _teardown ( void **state   __attribute__(unused))
static

Definition at line 84 of file test_conf_save.c.

References _dir, _rcfile, darktable_t::conf, d, darktable, dt_conf_cleanup(), IS_NULL_PTR, and name.

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)
Todo:
: test if file with replaced ext exists
Todo:
: add a callback to set the bpp without going through the config
Todo:
: have a parameter in command line to get the export presets

Definition at line 193 of file test_conf_save.c.

References _a_failed_flush_returns_1_and_writes_nothing(), _flush_replaces_the_file_rather_than_rewriting_it(), _flush_writes_what_was_set(), _setup(), and _teardown().

Variable Documentation

◆ _dir

char* _dir = NULL
static

◆ _rcfile

char* _rcfile = NULL
static