Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
styles.c File Reference
#include "common/darktable.h"
#include "common/database.h"
#include "common/film.h"
#include "common/history_actions.h"
#include "common/history_merge.h"
#include "common/image.h"
#include "common/styles.h"
#include <assert.h>
#include <gio/gio.h>
#include <glib/gstdio.h>
#include <sqlite3.h>
#include <stdio.h>
#include <stdlib.h>
+ Include dependency graph for tests/styles.c:

Go to the source code of this file.

Data Structures

struct  dt_style_scenario_result_t
 One-line scenario result printed after every style has run. More...
 

Macros

#define ANSEL_TEST_SOURCE_DIR   "."
 
#define ANSEL_TEST_BINARY_DIR   "."
 

Typedefs

typedef struct dt_style_scenario_result_t dt_style_scenario_result_t
 One-line scenario result printed after every style has run.
 

Functions

static int test_fail (const char *scenario, const char *message, char **failure_reason)
 
static gboolean is_style_file (const char *filename)
 
static char * scenario_name_from_style_file (const char *filename)
 
static int sql_int_for_bound_images (const char *query, const int32_t imgid_a, const int32_t imgid_b)
 
static int max_style_id (void)
 
static char * imported_style_name (const int before_import_style_id)
 
static int32_t create_test_image (const char *source_image_path)
 
static int load_xmp_on_image (const char *scenario, const int32_t imgid, const char *xmp_path, char **failure_reason)
 
static int load_start_history (const char *scenario, const int32_t imgid, const char *start_xmp_path, const char *start_xmp_name, char **failure_reason)
 
static void print_module_order_summary (const char *label, const int32_t imgid)
 
static int compare_pipe_order (const char *scenario, const int32_t actual_imgid, const int32_t expected_imgid, char **failure_reason)
 
static void print_enabled_state_summary (const char *label, const int32_t imgid)
 
static int compare_enabled_state (const char *scenario, const int32_t actual_imgid, const int32_t expected_imgid, char **failure_reason)
 
static int apply_style_to_image (const char *scenario, const char *style_name, const int32_t imgid, char **failure_reason)
 
static int run_style_scenario (const char *scenario_dir, const char *source_image_path, const char *style_file, char **failure_reason)
 
static int run_style_scenarios (const char *scenario_dir, const char *source_image_path)
 
static char * prepare_test_datadir (const char *tmp_dir)
 
int main (int argc, char *argv[])
 

Variables

static char * test_image_dir = NULL
 Run style-application scenarios from tests/styles.
 

Macro Definition Documentation

◆ ANSEL_TEST_BINARY_DIR

#define ANSEL_TEST_BINARY_DIR   "."

Definition at line 43 of file tests/styles.c.

◆ ANSEL_TEST_SOURCE_DIR

#define ANSEL_TEST_SOURCE_DIR   "."

Definition at line 39 of file tests/styles.c.

Typedef Documentation

◆ dt_style_scenario_result_t

One-line scenario result printed after every style has run.

The full diagnostics are emitted where the failure is detected. This summary keeps only the first failure reason so the final output stays readable when several fixtures are executed in a single run.

Function Documentation

◆ apply_style_to_image()

static int apply_style_to_image ( const char *  scenario,
const char *  style_name,
const int32_t  imgid,
char **  failure_reason 
)
static

◆ compare_enabled_state()

static int compare_enabled_state ( const char *  scenario,
const int32_t  actual_imgid,
const int32_t  expected_imgid,
char **  failure_reason 
)
static

◆ compare_pipe_order()

static int compare_pipe_order ( const char *  scenario,
const int32_t  actual_imgid,
const int32_t  expected_imgid,
char **  failure_reason 
)
static

Definition at line 219 of file tests/styles.c.

References print_module_order_summary(), sql_int_for_bound_images(), and test_fail().

Referenced by run_style_scenario().

◆ create_test_image()

static int32_t create_test_image ( const char *  source_image_path)
static

◆ imported_style_name()

static char * imported_style_name ( const int  before_import_style_id)
static

Definition at line 119 of file tests/styles.c.

References darktable, darktable_t::db, dt_database_get(), and name.

Referenced by run_style_scenario().

◆ is_style_file()

static gboolean is_style_file ( const char *  filename)
static

Definition at line 84 of file tests/styles.c.

References extension(), and IS_NULL_PTR.

Referenced by run_style_scenarios().

◆ load_start_history()

static int load_start_history ( const char *  scenario,
const int32_t  imgid,
const char *  start_xmp_path,
const char *  start_xmp_name,
char **  failure_reason 
)
static

Definition at line 187 of file tests/styles.c.

References load_xmp_on_image().

Referenced by run_style_scenario().

◆ load_xmp_on_image()

static int load_xmp_on_image ( const char *  scenario,
const int32_t  imgid,
const char *  xmp_path,
char **  failure_reason 
)
static

Definition at line 176 of file tests/styles.c.

References dt_history_load_and_apply(), test_fail(), and TRUE.

Referenced by load_start_history(), and run_style_scenario().

◆ 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 476 of file tests/styles.c.

References ANSEL_TEST_BINARY_DIR, ANSEL_TEST_SOURCE_DIR, dt_cleanup(), dt_free, dt_init(), FALSE, IS_NULL_PTR, prepare_test_datadir(), run_style_scenarios(), and test_image_dir.

◆ max_style_id()

static int max_style_id ( void  )
static

Definition at line 109 of file tests/styles.c.

References darktable, darktable_t::db, dt_database_get(), and value.

Referenced by run_style_scenario().

◆ prepare_test_datadir()

static char * prepare_test_datadir ( const char *  tmp_dir)
static

Definition at line 444 of file tests/styles.c.

References ANSEL_TEST_SOURCE_DIR, dt_free, and error().

Referenced by main().

◆ print_enabled_state_summary()

static void print_enabled_state_summary ( const char *  label,
const int32_t  imgid 
)
static

Definition at line 243 of file tests/styles.c.

References darktable, darktable_t::db, and dt_database_get().

Referenced by compare_enabled_state().

◆ print_module_order_summary()

static void print_module_order_summary ( const char *  label,
const int32_t  imgid 
)
static

Definition at line 197 of file tests/styles.c.

References darktable, darktable_t::db, and dt_database_get().

Referenced by compare_pipe_order().

◆ run_style_scenario()

static int run_style_scenario ( const char *  scenario_dir,
const char *  source_image_path,
const char *  style_file,
char **  failure_reason 
)
static

◆ run_style_scenarios()

static int run_style_scenarios ( const char *  scenario_dir,
const char *  source_image_path 
)
static

◆ scenario_name_from_style_file()

static char * scenario_name_from_style_file ( const char *  filename)
static

Definition at line 90 of file tests/styles.c.

References extension(), and IS_NULL_PTR.

Referenced by run_style_scenario().

◆ sql_int_for_bound_images()

static int sql_int_for_bound_images ( const char *  query,
const int32_t  imgid_a,
const int32_t  imgid_b 
)
static

Definition at line 98 of file tests/styles.c.

References darktable, darktable_t::db, dt_database_get(), and value.

Referenced by compare_enabled_state(), and compare_pipe_order().

◆ test_fail()

static int test_fail ( const char *  scenario,
const char *  message,
char **  failure_reason 
)
static

Variable Documentation

◆ test_image_dir

char* test_image_dir = NULL
static

Run style-application scenarios from tests/styles.

Each *.dtstyle file defines one scenario. The basename of the style file is used to find start_<style>.xmp and end_<style>.xmp. The start sidecar is optional: if it is missing, the runner keeps the raw import history. The end sidecar is required and provides the expected history after applying the style.

The comparison is intentionally limited to the resulting pipe order and final enabled states. The history stack can legitimately differ after a merge, so the enabled-state check only looks at the last active history item for each module instance.

Definition at line 60 of file tests/styles.c.

Referenced by create_test_image(), and main().