[libgdata/online-tests: 1/2] [tests] Add support for a --no-internet option to the tests



commit 5d8cd9f70710231b0360e8806caa2e991563a80d
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Sat Aug 7 17:02:21 2010 +0100

    [tests] Add support for a --no-internet option to the tests
    
    This should allow automated testing to run more than just the general tests.

 gdata/tests/calendar.c  |    2 +-
 gdata/tests/common.c    |   52 +++++++++++++++++++++++++++++++++++++++++++++-
 gdata/tests/common.h    |    4 ++-
 gdata/tests/contacts.c  |    2 +-
 gdata/tests/documents.c |    2 +-
 gdata/tests/general.c   |    2 +-
 gdata/tests/picasaweb.c |    2 +-
 gdata/tests/youtube.c   |    2 +-
 8 files changed, 59 insertions(+), 9 deletions(-)
---
diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c
index 1575418..aed81ca 100644
--- a/gdata/tests/calendar.c
+++ b/gdata/tests/calendar.c
@@ -736,7 +736,7 @@ main (int argc, char *argv[])
 	gint retval;
 	GDataService *service;
 
-	gdata_test_init (&argc, &argv);
+	gdata_test_init (argc, argv);
 
 	service = GDATA_SERVICE (gdata_calendar_service_new (CLIENT_ID));
 	gdata_service_authenticate (service, USERNAME, PASSWORD, NULL, NULL);
diff --git a/gdata/tests/common.c b/gdata/tests/common.c
index e1185f5..1de14f4 100644
--- a/gdata/tests/common.c
+++ b/gdata/tests/common.c
@@ -20,21 +20,69 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <stdio.h>
+#include <string.h>
 
 #include "common.h"
 
+/* %TRUE if there's no Internet connection, so we should only run local tests */
+static gboolean no_internet = FALSE;
+
 void
-gdata_test_init (int *argc, char ***argv)
+gdata_test_init (int argc, char **argv)
 {
+	gint i;
+
 	g_type_init ();
 	g_thread_init (NULL);
-	g_test_init (argc, argv, NULL);
+
+	/* Parse the --no-internet option */
+	for (i = 1; i < argc; i++) {
+		if (strcmp ("--no-internet", argv[i]) == 0 || strcmp ("-n", argv[i]) == 0) {
+			no_internet = TRUE;
+			argv[i] = (char*) "";
+		} else if (strcmp ("-?", argv[i]) == 0 || strcmp ("--help", argv[i]) == 0 || strcmp ("-h" , argv[i]) == 0) {
+			/* We have to override --help in order to document --no-internet */
+			printf ("Usage:\n"
+			          "  %s [OPTION...]\n\n"
+			          "Help Options:\n"
+			          "  -?, --help                     Show help options\n"
+			          "Test Options:\n"
+			          "  -l                             List test cases available in a test executable\n"
+			          "  -seed=RANDOMSEED               Provide a random seed to reproduce test\n"
+			          "                                 runs using random numbers\n"
+			          "  --verbose                      Run tests verbosely\n"
+			          "  -q, --quiet                    Run tests quietly\n"
+			          "  -p TESTPATH                    Execute all tests matching TESTPATH\n"
+			          "  -m {perf|slow|thorough|quick}  Execute tests according modes\n"
+			          "  --debug-log                    Debug test logging output\n"
+			          "  -n, --no-internet              Only execute tests which don't require Internet connectivity\n",
+			          argv[0]);
+			exit (0);
+		}
+	}
+
+	g_test_init (&argc, &argv, NULL);
 	g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=";);
 
 	/* Enable full debugging */
 	g_setenv ("LIBGDATA_DEBUG", "3", FALSE);
 }
 
+/*
+ * gdata_test_internet:
+ *
+ * Returns whether tests which require Internet access should be run.
+ *
+ * Return value: %TRUE if Internet-requiring tests should be run, %FALSE otherwise
+ *
+ * Since: 0.7.0
+ */
+gboolean
+gdata_test_internet (void)
+{
+	return (no_internet == FALSE) ? TRUE : FALSE;
+}
+
 typedef struct {
 	guint op_id;
 	GDataBatchOperationType operation_type;
diff --git a/gdata/tests/common.h b/gdata/tests/common.h
index 325d979..4c9492d 100644
--- a/gdata/tests/common.h
+++ b/gdata/tests/common.h
@@ -30,7 +30,9 @@ G_BEGIN_DECLS
 #define DOCUMENTS_USERNAME "libgdata documents gmail com"
 #define PASSWORD "gdata-libgdata"
 
-void gdata_test_init (int *argc, char ***argv);
+void gdata_test_init (int argc, char **argv);
+
+gboolean gdata_test_internet (void);
 
 guint gdata_test_batch_operation_query (GDataBatchOperation *operation, const gchar *id, GType entry_type,
                                         GDataEntry *entry, GDataEntry **returned_entry, GError **error);
diff --git a/gdata/tests/contacts.c b/gdata/tests/contacts.c
index c788f58..2d79bf8 100644
--- a/gdata/tests/contacts.c
+++ b/gdata/tests/contacts.c
@@ -1485,7 +1485,7 @@ main (int argc, char *argv[])
 	GDataService *service;
 	gint retval;
 
-	gdata_test_init (&argc, &argv);
+	gdata_test_init (argc, argv);
 
 	service = GDATA_SERVICE (gdata_contacts_service_new (CLIENT_ID));
 	gdata_service_authenticate (service, USERNAME, PASSWORD, NULL, NULL);
diff --git a/gdata/tests/documents.c b/gdata/tests/documents.c
index 0f50ee7..454ab85 100644
--- a/gdata/tests/documents.c
+++ b/gdata/tests/documents.c
@@ -586,7 +586,7 @@ main (int argc, char *argv[])
 	GDataService *service;
 	gint retval;
 
-	gdata_test_init (&argc, &argv);
+	gdata_test_init (argc, argv);
 
 	service = GDATA_SERVICE (gdata_documents_service_new (CLIENT_ID));
 	gdata_service_authenticate (service, DOCUMENTS_USERNAME, PASSWORD, NULL, NULL);
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index 8e27f42..93eb792 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -3005,7 +3005,7 @@ test_gcontact_website_error_handling (void)
 int
 main (int argc, char *argv[])
 {
-	gdata_test_init (&argc, &argv);
+	gdata_test_init (argc, argv);
 
 	g_test_add_func ("/service/network_error", test_service_network_error);
 	g_test_add_func ("/service/locale", test_service_locale);
diff --git a/gdata/tests/picasaweb.c b/gdata/tests/picasaweb.c
index aa07f07..58b0dea 100644
--- a/gdata/tests/picasaweb.c
+++ b/gdata/tests/picasaweb.c
@@ -1361,7 +1361,7 @@ main (int argc, char *argv[])
 	GDataService *service;
 	gint retval;
 
-	gdata_test_init (&argc, &argv);
+	gdata_test_init (argc, argv);
 
 	service = GDATA_SERVICE (gdata_picasaweb_service_new (CLIENT_ID));
 	gdata_service_authenticate (service, PW_USERNAME, PASSWORD, NULL, NULL);
diff --git a/gdata/tests/youtube.c b/gdata/tests/youtube.c
index 36d5370..32b8cf6 100644
--- a/gdata/tests/youtube.c
+++ b/gdata/tests/youtube.c
@@ -1082,7 +1082,7 @@ main (int argc, char *argv[])
 	gint retval;
 	GDataService *service;
 
-	gdata_test_init (&argc, &argv);
+	gdata_test_init (argc, argv);
 
 	service = GDATA_SERVICE (gdata_youtube_service_new (DEVELOPER_KEY, CLIENT_ID));
 	gdata_service_authenticate (service, USERNAME, PASSWORD, NULL, NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]