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

Go to the source code of this file.

Macros

#define XDG_KEY   "XDG_CACHE_HOME"
 
#define FAKE_ABSOLUTE_DIR   G_DIR_SEPARATOR_S "nonexistent-ansel-test" G_DIR_SEPARATOR_S "xdg-cache-home"
 

Functions

static int _setup (void **state G_GNUC_UNUSED)
 
static int _teardown (void **state G_GNUC_UNUSED)
 
static void _xdg_cache_home_wins (void **state G_GNUC_UNUSED)
 
static void _an_empty_xdg_is_ignored (void **state G_GNUC_UNUSED)
 
static void _a_relative_xdg_is_ignored (void **state G_GNUC_UNUSED)
 
static void _the_default_is_not_a_shell_managed_temporary_folder (void **state G_GNUC_UNUSED)
 
static void _every_call_answers_the_same (void **state G_GNUC_UNUSED)
 
int main (int argc, char *argv[])
 

Variables

static gchar * _saved_xdg = NULL
 
static gboolean _had_xdg = FALSE
 

Macro Definition Documentation

◆ FAKE_ABSOLUTE_DIR

#define FAKE_ABSOLUTE_DIR   G_DIR_SEPARATOR_S "nonexistent-ansel-test" G_DIR_SEPARATOR_S "xdg-cache-home"

Definition at line 62 of file test_loc_cache_dir.c.

◆ XDG_KEY

#define XDG_KEY   "XDG_CACHE_HOME"

Where the default user cache directory is, per platform.

dt_loc_default_user_cache_dir() is the one definition of that path: dt_loc_init_user_cache_dir() takes its default from it, and the two callers that run BEFORE dt_loc_init() – main()'s Windows log redirection and the usage text naming that log – resolve it through the same function so they cannot name different directories.

The regression these tests exist for is Windows-specific and invisible on this machine: GLib's g_get_user_cache_dir() returns FOLDERID_InternetCache there – the shell folder still labelled "Temporary Internet Files" – which Storage Sense empties, whenever it runs, of every file not written in the last week or so, and which Explorer does not show. A thumbnail cache written there is deleted behind the user's back and a log file written there is unfindable (#1473). The last test below is the guard, and it asserts on the base directory rather than on the string, so it says something true on every platform and fails on the one that regresses.

The XDG tests are the part that runs meaningfully here: XDG_CACHE_HOME must win on every platform, because a caller who sets it means it, and GLib honours it on Windows too.

Definition at line 56 of file test_loc_cache_dir.c.

Function Documentation

◆ _a_relative_xdg_is_ignored()

static void _a_relative_xdg_is_ignored ( void **state  G_GNUC_UNUSED)
static

Definition at line 118 of file test_loc_cache_dir.c.

References dt_free, dt_loc_default_user_cache_dir(), TRUE, and XDG_KEY.

Referenced by main().

◆ _an_empty_xdg_is_ignored()

static void _an_empty_xdg_is_ignored ( void **state  G_GNUC_UNUSED)
static

Definition at line 103 of file test_loc_cache_dir.c.

References dt_free, dt_loc_default_user_cache_dir(), TRUE, and XDG_KEY.

Referenced by main().

◆ _every_call_answers_the_same()

static void _every_call_answers_the_same ( void **state  G_GNUC_UNUSED)
static

Definition at line 166 of file test_loc_cache_dir.c.

References dt_free, dt_loc_default_user_cache_dir(), and XDG_KEY.

Referenced by main().

◆ _setup()

static int _setup ( void **state  G_GNUC_UNUSED)
static

Definition at line 69 of file test_loc_cache_dir.c.

References _had_xdg, _saved_xdg, IS_NULL_PTR, and XDG_KEY.

Referenced by main().

◆ _teardown()

static int _teardown ( void **state  G_GNUC_UNUSED)
static

Definition at line 77 of file test_loc_cache_dir.c.

References _had_xdg, _saved_xdg, dt_free, FALSE, TRUE, and XDG_KEY.

Referenced by main().

◆ _the_default_is_not_a_shell_managed_temporary_folder()

static void _the_default_is_not_a_shell_managed_temporary_folder ( void **state  G_GNUC_UNUSED)
static

Definition at line 133 of file test_loc_cache_dir.c.

References dt_free, dt_loc_default_user_cache_dir(), IS_NULL_PTR, and XDG_KEY.

Referenced by main().

◆ _xdg_cache_home_wins()

static void _xdg_cache_home_wins ( void **state  G_GNUC_UNUSED)
static

Definition at line 89 of file test_loc_cache_dir.c.

References dt_free, dt_loc_default_user_cache_dir(), FAKE_ABSOLUTE_DIR, TRUE, and XDG_KEY.

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 184 of file test_loc_cache_dir.c.

References _a_relative_xdg_is_ignored(), _an_empty_xdg_is_ignored(), _every_call_answers_the_same(), _setup(), _teardown(), _the_default_is_not_a_shell_managed_temporary_folder(), and _xdg_cache_home_wins().

Variable Documentation

◆ _had_xdg

gboolean _had_xdg = FALSE
static

Definition at line 67 of file test_loc_cache_dir.c.

Referenced by _setup(), and _teardown().

◆ _saved_xdg

gchar* _saved_xdg = NULL
static

Definition at line 66 of file test_loc_cache_dir.c.

Referenced by _setup(), and _teardown().