[libsoup/carlosgc/client-side-certs2: 6/10] tests: add soup_test_build_filename_abs()
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/carlosgc/client-side-certs2: 6/10] tests: add soup_test_build_filename_abs()
- Date: Fri, 30 Apr 2021 09:52:05 +0000 (UTC)
commit 07f2302e025f736d5c54b9ed3073967d7972651e
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.
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 4357a47b..9a4974e0 100644
--- a/tests/session-test.c
+++ b/tests/session-test.c
@@ -294,11 +294,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,
"tls-database", tlsdb,
diff --git a/tests/test-utils.c b/tests/test-utils.c
index d8b9c68d..40db0308 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -168,14 +168,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
@@ -877,6 +870,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 1b4cfa75..7b6de74e 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -99,6 +99,10 @@ GBytes *soup_test_load_resource (const char *name,
GBytes *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, ...) \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]