[libgdata] tests: Use g_test_build_filename() to load test data files
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] tests: Use g_test_build_filename() to load test data files
- Date: Tue, 5 May 2015 23:50:10 +0000 (UTC)
commit 10f67845a07c75bf92f1128d949edae75d645ec7
Author: Philip Withnall <philip tecnocode co uk>
Date: Wed May 6 00:21:17 2015 +0100
tests: Use g_test_build_filename() to load test data files
Rather than TEST_FILE_DIR, which is completely non-relocatable and a bit
of a hack.
This is one step towards supporting installed-tests.
https://wiki.gnome.org/Initiatives/GnomeGoals/InstalledTests
gdata/tests/Makefile.am | 1 -
gdata/tests/calendar.c | 5 ++-
gdata/tests/client-login-authorizer.c | 5 ++-
gdata/tests/common.c | 10 +++++-
gdata/tests/contacts.c | 20 +++++++++--
gdata/tests/documents.c | 24 +++++++++----
gdata/tests/freebase.c | 5 ++-
gdata/tests/oauth1-authorizer.c | 5 ++-
gdata/tests/oauth2-authorizer.c | 5 ++-
gdata/tests/picasaweb.c | 15 ++++++--
gdata/tests/tasks.c | 5 ++-
gdata/tests/youtube.c | 10 ++++-
gtester.mk | 60 ---------------------------------
13 files changed, 86 insertions(+), 84 deletions(-)
---
diff --git a/gdata/tests/Makefile.am b/gdata/tests/Makefile.am
index c42c85a..87b9b66 100644
--- a/gdata/tests/Makefile.am
+++ b/gdata/tests/Makefile.am
@@ -20,7 +20,6 @@ libgdata_test_la_LIBADD = \
AM_CPPFLAGS = \
-I$(top_srcdir)/ \
-I$(top_srcdir)/gdata \
- -DTEST_FILE_DIR="\"$(top_srcdir)/gdata/tests/\"" \
-DG_LOG_DOMAIN=\"libgdata\" \
$(DISABLE_DEPRECATED) \
$(NULL)
diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c
index 9a30eac..115bb58 100644
--- a/gdata/tests/calendar.c
+++ b/gdata/tests/calendar.c
@@ -1601,12 +1601,15 @@ main (int argc, char *argv[])
GDataAuthorizer *authorizer = NULL;
GDataService *service = NULL;
GFile *trace_directory;
+ gchar *path = NULL;
gdata_test_init (argc, argv);
mock_server = gdata_test_get_mock_server ();
g_signal_connect (G_OBJECT (mock_server), "notify::resolver", (GCallback)
mock_server_notify_resolver_cb, NULL);
- trace_directory = g_file_new_for_path (TEST_FILE_DIR "traces/calendar");
+ path = g_test_build_filename (G_TEST_DIST, "traces/calendar", NULL);
+ trace_directory = g_file_new_for_path (path);
+ g_free (path);
uhm_server_set_trace_directory (mock_server, trace_directory);
g_object_unref (trace_directory);
#if 0
diff --git a/gdata/tests/client-login-authorizer.c b/gdata/tests/client-login-authorizer.c
index 515df21..1f40dfa 100644
--- a/gdata/tests/client-login-authorizer.c
+++ b/gdata/tests/client-login-authorizer.c
@@ -734,12 +734,15 @@ int
main (int argc, char *argv[])
{
GFile *trace_directory;
+ gchar *path = NULL;
gdata_test_init (argc, argv);
mock_server = gdata_test_get_mock_server ();
g_signal_connect (G_OBJECT (mock_server), "notify::resolver", (GCallback)
mock_server_notify_resolver_cb, NULL);
- trace_directory = g_file_new_for_path (TEST_FILE_DIR "traces/client-login-authorizer");
+ path = g_test_build_filename (G_TEST_DIST, "traces/client-login-authorizer", NULL);
+ trace_directory = g_file_new_for_path (path);
+ g_free (path);
uhm_server_set_trace_directory (mock_server, trace_directory);
g_object_unref (trace_directory);
diff --git a/gdata/tests/common.c b/gdata/tests/common.c
index 720b779..c90a74c 100644
--- a/gdata/tests/common.c
+++ b/gdata/tests/common.c
@@ -50,6 +50,7 @@ gdata_test_init (int argc, char **argv)
{
GTlsCertificate *cert;
GError *child_error = NULL;
+ gchar *cert_path = NULL, *key_path = NULL;
gint i;
setlocale (LC_ALL, "");
@@ -130,8 +131,15 @@ gdata_test_init (int argc, char **argv)
uhm_server_set_enable_online (mock_server, write_traces || compare_traces);
/* Build the certificate. */
- cert = g_tls_certificate_new_from_files (TEST_FILE_DIR "cert.pem", TEST_FILE_DIR "key.pem",
&child_error);
+ cert_path = g_test_build_filename (G_TEST_DIST, "cert.pem", NULL);
+ key_path = g_test_build_filename (G_TEST_DIST, "key.pem", NULL);
+
+ cert = g_tls_certificate_new_from_files (cert_path, key_path, &child_error);
g_assert_no_error (child_error);
+
+ g_free (key_path);
+ g_free (cert_path);
+
/* Set it as the property. */
uhm_server_set_tls_certificate (mock_server, cert);
g_object_unref (cert);
diff --git a/gdata/tests/contacts.c b/gdata/tests/contacts.c
index b0a740b..2f8ae8e 100644
--- a/gdata/tests/contacts.c
+++ b/gdata/tests/contacts.c
@@ -1979,12 +1979,15 @@ test_photo_add (TempContactData *data, gconstpointer service)
guint8 *photo_data;
gsize length;
gboolean retval;
+ gchar *path = NULL;
GError *error = NULL;
gdata_test_mock_server_start_trace (mock_server, "photo-add");
/* Get the photo */
- g_assert (g_file_get_contents (TEST_FILE_DIR "photo.jpg", (gchar**) &photo_data, &length, NULL) ==
TRUE);
+ path = g_test_build_filename (G_TEST_DIST, "photo.jpg", NULL);
+ g_assert (g_file_get_contents (path, (gchar**) &photo_data, &length, NULL) == TRUE);
+ g_free (path);
/* Add it to the contact */
retval = gdata_contacts_contact_set_photo (data->contact, GDATA_CONTACTS_SERVICE (service),
photo_data, length, "image/jpeg", NULL, &error);
@@ -2001,9 +2004,12 @@ GDATA_ASYNC_TEST_FUNCTIONS (photo_add, TempContactData,
G_STMT_START {
guint8 *photo_data;
gsize length;
+ gchar *path = NULL;
/* Get the photo */
- g_assert (g_file_get_contents (TEST_FILE_DIR "photo.jpg", (gchar**) &photo_data, &length, NULL) ==
TRUE);
+ path = g_test_build_filename (G_TEST_DIST, "photo.jpg", NULL);
+ g_assert (g_file_get_contents (path, (gchar**) &photo_data, &length, NULL) == TRUE);
+ g_free (path);
/* Add it to the contact asynchronously */
gdata_contacts_contact_set_photo_async (data->contact, GDATA_CONTACTS_SERVICE (service), photo_data,
length, "image/jpeg", cancellable,
@@ -2039,11 +2045,14 @@ add_photo_to_contact (GDataContactsService *service, GDataContactsContact **cont
guint8 *photo_data;
gsize length;
GDataEntry *updated_contact;
+ gchar *path = NULL;
/* Get the photo and add it to the contact */
- g_assert (g_file_get_contents (TEST_FILE_DIR "photo.jpg", (gchar**) &photo_data, &length, NULL) ==
TRUE);
+ path = g_test_build_filename (G_TEST_DIST, "photo.jpg", NULL);
+ g_assert (g_file_get_contents (path, (gchar**) &photo_data, &length, NULL) == TRUE);
g_assert (gdata_contacts_contact_set_photo (*contact, service, photo_data, length, "image/jpeg",
NULL, NULL) == TRUE);
+ g_free (path);
g_free (photo_data);
/* HACK: It fairly consistently seems to take the Google servers about 4 seconds to process uploaded
photos. Before this
@@ -2595,13 +2604,16 @@ main (int argc, char *argv[])
GDataAuthorizer *authorizer = NULL; /* owned */
GDataService *service = NULL; /* owned */
GFile *trace_directory = NULL; /* owned */
+ gchar *path = NULL; /* owned */
gdata_test_init (argc, argv);
mock_server = gdata_test_get_mock_server ();
g_signal_connect (G_OBJECT (mock_server), "notify::resolver",
(GCallback) mock_server_notify_resolver_cb, NULL);
- trace_directory = g_file_new_for_path (TEST_FILE_DIR "traces/contacts");
+ path = g_test_build_filename (G_TEST_DIST, "traces/contacts", NULL);
+ trace_directory = g_file_new_for_path (path);
+ g_free (path);
uhm_server_set_trace_directory (mock_server, trace_directory);
g_object_unref (trace_directory);
diff --git a/gdata/tests/documents.c b/gdata/tests/documents.c
index e971b28..f75b72c 100644
--- a/gdata/tests/documents.c
+++ b/gdata/tests/documents.c
@@ -300,7 +300,7 @@ set_up_temp_document_spreadsheet (TempDocumentData *data, gconstpointer service)
document = gdata_documents_spreadsheet_new (NULL);
gdata_entry_set_title (GDATA_ENTRY (document), "Temporary Document (Spreadsheet)");
- document_file_path = g_strconcat (TEST_FILE_DIR, "test.ods", NULL);
+ document_file_path = g_test_build_filename (G_TEST_DIST, "test.ods", NULL);
document_file = g_file_new_for_path (document_file_path);
g_free (document_file_path);
@@ -445,7 +445,7 @@ set_up_temp_documents (TempDocumentsData *data, gconstpointer service)
g_assert (GDATA_IS_DOCUMENTS_TEXT (data->text_document));
g_object_unref (document);
- document_file_path = g_strconcat (TEST_FILE_DIR, "test.odt", NULL);
+ document_file_path = g_test_build_filename (G_TEST_DIST, "test.odt", NULL);
document_file = g_file_new_for_path (document_file_path);
g_free (document_file_path);
@@ -768,7 +768,7 @@ test_upload (UploadDocumentData *data, gconstpointer _test_params)
break;
case UPLOAD_CONTENT_ONLY:
case UPLOAD_CONTENT_AND_METADATA: {
- gchar *document_file_path = g_strconcat (TEST_FILE_DIR, document_filename, NULL);
+ gchar *document_file_path = g_test_build_filename (G_TEST_DIST, document_filename,
NULL);
document_file = g_file_new_for_path (document_file_path);
g_free (document_file_path);
@@ -976,7 +976,7 @@ set_up_update_document (UpdateDocumentData *data, gconstpointer _test_params)
gdata_entry_set_title (GDATA_ENTRY (document), title);
g_free (title);
- document_file_path = g_strconcat (TEST_FILE_DIR, "test.odt", NULL);
+ document_file_path = g_test_build_filename (G_TEST_DIST, "test.odt", NULL);
document_file = g_file_new_for_path (document_file_path);
g_free (document_file_path);
@@ -1064,9 +1064,12 @@ test_update (UpdateDocumentData *data, gconstpointer _test_params)
GFileInputStream *file_stream;
GFile *updated_document_file;
GFileInfo *file_info;
+ gchar *path = NULL;
/* Prepare the updated file */
- updated_document_file = g_file_new_for_path (TEST_FILE_DIR "test_updated.odt");
+ path = g_test_build_filename (G_TEST_DIST, "test_updated.odt", NULL);
+ updated_document_file = g_file_new_for_path (path);
+ g_free (path);
file_info = g_file_query_info (updated_document_file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
","
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE,
@@ -1200,6 +1203,7 @@ set_up_folders (FoldersData *data, GDataDocumentsService *service, gboolean init
GFile *document_file;
GFileInfo *file_info;
gchar *upload_uri;
+ gchar *path = NULL;
GError *error = NULL;
/* Create a new folder for the tests */
@@ -1219,7 +1223,10 @@ set_up_folders (FoldersData *data, GDataDocumentsService *service, gboolean init
g_object_unref (folder);
/* Create a new file for the tests */
- document_file = g_file_new_for_path (TEST_FILE_DIR "test.odt");
+ path = g_test_build_filename (G_TEST_DIST, "test.odt", NULL);
+ document_file = g_file_new_for_path (path);
+ g_free (path);
+
document = GDATA_DOCUMENTS_DOCUMENT (gdata_documents_text_new (NULL));
gdata_entry_set_title (GDATA_ENTRY (document), "add_file_folder_move_text");
@@ -2050,12 +2057,15 @@ main (int argc, char *argv[])
GDataAuthorizer *authorizer = NULL;
GDataService *service = NULL;
GFile *trace_directory;
+ gchar *path = NULL;
gdata_test_init (argc, argv);
mock_server = gdata_test_get_mock_server ();
g_signal_connect (G_OBJECT (mock_server), "notify::resolver", (GCallback)
mock_server_notify_resolver_cb, NULL);
- trace_directory = g_file_new_for_path (TEST_FILE_DIR "traces/documents");
+ path = g_test_build_filename (G_TEST_DIST, "traces/documents", NULL);
+ trace_directory = g_file_new_for_path (path);
+ g_free (path);
uhm_server_set_trace_directory (mock_server, trace_directory);
g_object_unref (trace_directory);
diff --git a/gdata/tests/freebase.c b/gdata/tests/freebase.c
index ab2a1b9..d5065f8 100644
--- a/gdata/tests/freebase.c
+++ b/gdata/tests/freebase.c
@@ -396,13 +396,16 @@ main (int argc, char *argv[])
{
GFile *trace_directory;
gint retval;
+ gchar *path = NULL;
gdata_test_init (argc, argv);
mock_server = gdata_test_get_mock_server ();
g_signal_connect (G_OBJECT (mock_server), "notify::resolver",
(GCallback) mock_server_notify_resolver_cb, NULL);
- trace_directory = g_file_new_for_path (TEST_FILE_DIR "traces/freebase");
+ path = g_test_build_filename (G_TEST_DIST, "traces/freebase", NULL);
+ trace_directory = g_file_new_for_path (path);
+ g_free (path);
uhm_server_set_trace_directory (mock_server, trace_directory);
g_object_unref (trace_directory);
diff --git a/gdata/tests/oauth1-authorizer.c b/gdata/tests/oauth1-authorizer.c
index 46e723b..9f776da 100644
--- a/gdata/tests/oauth1-authorizer.c
+++ b/gdata/tests/oauth1-authorizer.c
@@ -1008,12 +1008,15 @@ int
main (int argc, char *argv[])
{
GFile *trace_directory;
+ gchar *path = NULL;
gdata_test_init (argc, argv);
mock_server = gdata_test_get_mock_server ();
g_signal_connect (G_OBJECT (mock_server), "notify::resolver", (GCallback)
mock_server_notify_resolver_cb, NULL);
- trace_directory = g_file_new_for_path (TEST_FILE_DIR "traces/oauth1-authorizer");
+ path = g_test_build_filename (G_TEST_DIST, "traces/oauth1-authorizer", NULL);
+ trace_directory = g_file_new_for_path (path);
+ g_free (path);
uhm_server_set_trace_directory (mock_server, trace_directory);
g_object_unref (trace_directory);
diff --git a/gdata/tests/oauth2-authorizer.c b/gdata/tests/oauth2-authorizer.c
index d1e8bcf..5eb2364 100644
--- a/gdata/tests/oauth2-authorizer.c
+++ b/gdata/tests/oauth2-authorizer.c
@@ -929,13 +929,16 @@ int
main (int argc, char *argv[])
{
GFile *trace_directory;
+ gchar *path = NULL;
gdata_test_init (argc, argv);
mock_server = gdata_test_get_mock_server ();
g_signal_connect (G_OBJECT (mock_server), "notify::resolver",
(GCallback) mock_server_notify_resolver_cb, NULL);
- trace_directory = g_file_new_for_path (TEST_FILE_DIR "traces/oauth2-authorizer");
+ path = g_test_build_filename (G_TEST_DIST, "traces/oauth2-authorizer", NULL);
+ trace_directory = g_file_new_for_path (path);
+ g_free (path);
uhm_server_set_trace_directory (mock_server, trace_directory);
g_object_unref (trace_directory);
diff --git a/gdata/tests/picasaweb.c b/gdata/tests/picasaweb.c
index 3f6fd97..24d0401 100644
--- a/gdata/tests/picasaweb.c
+++ b/gdata/tests/picasaweb.c
@@ -429,12 +429,15 @@ upload_file (GDataPicasaWebService *service, const gchar *title, GDataPicasaWebA
GFileInfo *file_info;
GFileInputStream *input_stream;
GDataUploadStream *upload_stream;
+ gchar *path = NULL;
file = gdata_picasaweb_file_new (NULL);
gdata_entry_set_title (GDATA_ENTRY (file), title);
/* File is public domain: http://en.wikipedia.org/wiki/File:German_garden_gnome_cropped.jpg */
- photo_file = g_file_new_for_path (TEST_FILE_DIR "photo.jpg");
+ path = g_test_build_filename (G_TEST_DIST, "photo.jpg", NULL);
+ photo_file = g_file_new_for_path (path);
+ g_free (path);
/* Get the file's info */
file_info = g_file_query_info (photo_file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
@@ -1598,6 +1601,7 @@ set_up_upload (UploadData *data, gconstpointer service)
{
GFileInfo *file_info;
const gchar * const tags[] = { "foo", "bar", ",,baz,baz", NULL };
+ gchar *path = NULL;
GError *error = NULL;
gdata_test_mock_server_start_trace (mock_server, "setup-upload");
@@ -1612,7 +1616,9 @@ set_up_upload (UploadData *data, gconstpointer service)
gdata_picasaweb_file_set_coordinates (data->photo, 17.127, -110.35);
/* File is public domain: http://en.wikipedia.org/wiki/File:German_garden_gnome_cropped.jpg */
- data->photo_file = g_file_new_for_path (TEST_FILE_DIR "photo.jpg");
+ path = g_test_build_filename (G_TEST_DIST, "photo.jpg", NULL);
+ data->photo_file = g_file_new_for_path (path);
+ g_free (path);
/* Get the file's info */
file_info = g_file_query_info (data->photo_file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
@@ -2091,12 +2097,15 @@ main (int argc, char *argv[])
GDataAuthorizer *authorizer = NULL;
GDataService *service = NULL;
GFile *trace_directory;
+ gchar *path = NULL;
gdata_test_init (argc, argv);
mock_server = gdata_test_get_mock_server ();
g_signal_connect (G_OBJECT (mock_server), "notify::resolver", (GCallback)
mock_server_notify_resolver_cb, NULL);
- trace_directory = g_file_new_for_path (TEST_FILE_DIR "traces/picasaweb");
+ path = g_test_build_filename (G_TEST_DIST, "traces/picasaweb", NULL);
+ trace_directory = g_file_new_for_path (path);
+ g_free (path);
uhm_server_set_trace_directory (mock_server, trace_directory);
g_object_unref (trace_directory);
diff --git a/gdata/tests/tasks.c b/gdata/tests/tasks.c
index 7bf3174..4f0f895 100644
--- a/gdata/tests/tasks.c
+++ b/gdata/tests/tasks.c
@@ -1354,13 +1354,16 @@ main (int argc, char *argv[])
GDataService *service = NULL; /* owned */
GDataService *unauthorised_service = NULL; /* owned */
GFile *trace_directory = NULL; /* owned */
+ gchar *path = NULL;
gdata_test_init (argc, argv);
mock_server = gdata_test_get_mock_server ();
g_signal_connect (G_OBJECT (mock_server), "notify::resolver",
(GCallback) mock_server_notify_resolver_cb, NULL);
- trace_directory = g_file_new_for_path (TEST_FILE_DIR "traces/tasks");
+ path = g_test_build_filename (G_TEST_DIST, "traces/tasks", NULL);
+ trace_directory = g_file_new_for_path (path);
+ g_free (path);
uhm_server_set_trace_directory (mock_server, trace_directory);
g_object_unref (trace_directory);
diff --git a/gdata/tests/youtube.c b/gdata/tests/youtube.c
index 5e5b2ae..4433093 100644
--- a/gdata/tests/youtube.c
+++ b/gdata/tests/youtube.c
@@ -710,6 +710,7 @@ set_up_upload (UploadData *data, gconstpointer service)
GDataMediaCategory *category;
GFileInfo *file_info;
const gchar * const tags[] = { "toast", "wedding", NULL };
+ gchar *path = NULL;
GError *error = NULL;
data->service = g_object_ref ((gpointer) service);
@@ -726,7 +727,9 @@ set_up_upload (UploadData *data, gconstpointer service)
/* Get a file to upload */
/* TODO: fix the path */
- data->video_file = g_file_new_for_path (TEST_FILE_DIR "sample.ogg");
+ path = g_test_build_filename (G_TEST_DIST, "sample.ogg", NULL);
+ data->video_file = g_file_new_for_path (path);
+ g_free (path);
/* Get the file's info */
file_info = g_file_query_info (data->video_file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
@@ -2698,13 +2701,16 @@ main (int argc, char *argv[])
GDataAuthorizer *authorizer = NULL; /* owned */
GDataService *service = NULL; /* owned */
GFile *trace_directory = NULL; /* owned */
+ gchar *path = NULL;
gdata_test_init (argc, argv);
mock_server = gdata_test_get_mock_server ();
g_signal_connect (G_OBJECT (mock_server), "notify::resolver",
(GCallback) mock_server_notify_resolver_cb, NULL);
- trace_directory = g_file_new_for_path (TEST_FILE_DIR "traces/youtube");
+ path = g_test_build_filename (G_TEST_DIST, "traces/youtube", NULL);
+ trace_directory = g_file_new_for_path (path);
+ g_free (path);
uhm_server_set_trace_directory (mock_server, trace_directory);
g_object_unref (trace_directory);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]