Skip to content

Commit 4c81bc3

Browse files
committed
[WIN32]Fix path problems prevneting test-backend-dbi from working.
1 parent 5466435 commit 4c81bc3

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

libgnucash/backend/dbi/test/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,24 @@ if (WITH_SQL)
3939
gnc_add_test(test-backend-dbi "${test_dbi_backend_SOURCES}"
4040
BACKEND_DBI_TEST_INCLUDE_DIRS BACKEND_DBI_TEST_LIBS
4141
)
42+
if (DEFINED ENV{TMPDIR})
43+
set(temp_dir "$ENV{TMPDIR}")
44+
elseif (DEFINED ENV{TMP})
45+
set(temp_dir "$ENV{TMP}")
46+
elseif (DEFINED ENV{TEMP})
47+
set(temp_dir "$ENV{TEMP}")
48+
else()
49+
set(temp_dir "${CMAKE_TOP_BUILD_DIR}/tmp")
50+
file(MAKE_DIRECTORY ${temp_dir})
51+
endif()
52+
53+
if (MINGW64)
54+
string(REGEX REPLACE "\\\\" "/" temp_dir ${temp_dir})
55+
endif()
4256

4357
target_compile_definitions(test-backend-dbi PRIVATE
4458
DBI_TEST_XML_FILENAME=\"${CMAKE_CURRENT_SOURCE_DIR}/test-dbi.xml\"
59+
TEMPDIR=\"${temp_dir}\"
4560
G_LOG_DOMAIN=\"gnc.backend.dbi\"
4661
)
4762
endif()

libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ typedef struct
8383
GSList* hdlrs;
8484
} Fixture;
8585

86+
87+
static char*
88+
normalize_path(char* path)
89+
{
90+
g_return_val_if_fail(path, nullptr);
91+
auto rv = gnc_uri_normalize_uri (path, FALSE);
92+
g_free (path);
93+
return rv;
94+
}
95+
96+
8697
static void
8798
setup (Fixture* fixture, gconstpointer pData)
8899
{
@@ -94,14 +105,17 @@ setup (Fixture* fixture, gconstpointer pData)
94105
* prevents creating the lock file. Force the session to get
95106
* around that.
96107
*/
97-
qof_session_begin (fixture->session, DBI_TEST_XML_FILENAME,
108+
qof_session_begin (fixture->session,
109+
normalize_path (g_strdup (DBI_TEST_XML_FILENAME)),
98110
SESSION_BREAK_LOCK);
99111
g_assert_cmpint (qof_session_get_error (fixture->session), == ,
100112
ERR_BACKEND_NO_ERR);
101113
qof_session_load (fixture->session, NULL);
102114

103115
if (g_strcmp0 (url, "sqlite3") == 0)
104-
fixture->filename = g_strdup_printf ("/tmp/test-sqlite-%d", getpid ());
116+
fixture->filename =
117+
normalize_path (g_strdup_printf (TEMPDIR "/test-sqlite-%d",
118+
getpid ()));
105119
else
106120
fixture->filename = NULL;
107121
}
@@ -158,7 +172,9 @@ setup_memory (Fixture* fixture, gconstpointer pData)
158172

159173
fixture->session = session;
160174
if (g_strcmp0 (url, "sqlite3") == 0)
161-
fixture->filename = g_strdup_printf ("/tmp/test-sqlite-%d", getpid ());
175+
fixture->filename =
176+
normalize_path (g_strdup_printf (TEMPDIR "/test-sqlite-%d",
177+
getpid ()));
162178
else
163179
fixture->filename = NULL;
164180
}
@@ -237,7 +253,9 @@ setup_business (Fixture* fixture, gconstpointer pData)
237253

238254
fixture->session = session;
239255
if (g_strcmp0 (url, "sqlite3") == 0)
240-
fixture->filename = g_strdup_printf ("/tmp/test-sqlite-%d", getpid ());
256+
fixture->filename =
257+
normalize_path (g_strdup_printf (TEMPDIR "/test-sqlite-%d",
258+
getpid ()));
241259
else
242260
fixture->filename = NULL;
243261
}

0 commit comments

Comments
 (0)