[libsoup/wip/smcv/save-server-root-2-74: 1/3] tests: add soup_test_build_filename_abs()
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/wip/smcv/save-server-root-2-74: 1/3] tests: add soup_test_build_filename_abs()
- Date: Mon, 27 Dec 2021 18:17:02 +0000 (UTC)
commit e9c34927c7e444bc1e272d7c98583758068997e4
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Wed Apr 28 13:54:52 2021 +0200
tests: add soup_test_build_filename_abs()
And use it when an absolute patch is required.
(cherry picked from commit 235160bc0cfb75c98bb3cfde53e166dcb001aa58)
tests/session-test.c | 7 ++++---
tests/test-utils.c | 45 +++++++++++++++++++++++++++++++++++++--------
tests/test-utils.h | 4 ++++
3 files changed, 45 insertions(+), 11 deletions(-)
---
diff --git a/tests/session-test.c b/tests/session-test.c
index eb8cbc13..baca05fa 100644
--- a/tests/session-test.c
+++ b/tests/session-test.c
@@ -340,11 +340,12 @@ do_property_tests (void)
*/
if (tls_available) {
GError *error = NULL;
+ char *db_path;
- tlsdb = g_tls_file_database_new (g_test_get_filename (G_TEST_DIST,
- "test-cert.pem",
- NULL), &error);
+ db_path = soup_test_build_filename_abs (G_TEST_DIST, "test-cert.pem", NULL);
+ tlsdb = g_tls_file_database_new (db_path, &error);
g_assert_no_error (error);
+ g_free (db_path);
session = g_object_new (SOUP_TYPE_SESSION,
SOUP_SESSION_TLS_DATABASE, tlsdb,
diff --git a/tests/test-utils.c b/tests/test-utils.c
index a83db261..923394d0 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -157,14 +157,7 @@ apache_cmd (const char *cmd)
int status;
gboolean ok;
- server_root = g_test_build_filename (G_TEST_BUILT, "", NULL);
- if (!g_path_is_absolute (server_root)) {
- char *abs_server_root;
-
- abs_server_root = g_canonicalize_filename (server_root, NULL);
- g_free (server_root);
- server_root = abs_server_root;
- }
+ server_root = soup_test_build_filename_abs (G_TEST_BUILT, "", NULL);
cwd = g_get_current_dir ();
#ifdef HAVE_APACHE_2_4
@@ -821,6 +814,42 @@ soup_test_get_index (void)
return index_buffer;
}
+char *
+soup_test_build_filename_abs (GTestFileType file_type,
+ const gchar *first_path,
+ ...)
+{
+ const gchar *pathv[16];
+ gsize num_path_segments;
+ char *path;
+ char *path_abs;
+ va_list ap;
+
+ va_start (ap, first_path);
+
+ pathv[0] = g_test_get_dir (file_type);
+ pathv[1] = first_path;
+
+ for (num_path_segments = 2; num_path_segments < G_N_ELEMENTS (pathv); num_path_segments++) {
+ pathv[num_path_segments] = va_arg (ap, const char *);
+ if (pathv[num_path_segments] == NULL)
+ break;
+ }
+
+ va_end (ap);
+
+ g_assert_cmpint (num_path_segments, <, G_N_ELEMENTS (pathv));
+
+ path = g_build_filenamev ((gchar **) pathv);
+ if (g_path_is_absolute (path))
+ return path;
+
+ path_abs = g_canonicalize_filename (path, NULL);
+ g_free (path);
+
+ return path_abs;
+}
+
#ifndef G_HAVE_ISO_VARARGS
void
soup_test_assert (gboolean expr, const char *fmt, ...)
diff --git a/tests/test-utils.h b/tests/test-utils.h
index 7beb2b28..4477edca 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -93,6 +93,10 @@ SoupBuffer *soup_test_load_resource (const char *name,
SoupBuffer *soup_test_get_index (void);
+char *soup_test_build_filename_abs (GTestFileType file_type,
+ const gchar *first_path,
+ ...);
+
#ifdef G_HAVE_ISO_VARARGS
#define soup_test_assert(expr, ...) \
G_STMT_START { \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]