[discident-glib] tests: Split out GTIN handling



commit f11a52a86a971123d70a503a34bf2994b02862c6
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Oct 8 20:53:42 2012 +0200

    tests: Split out GTIN handling

 discident-glib/test-diglib.c |   79 ++++++++++++++++++++++--------------------
 1 files changed, 41 insertions(+), 38 deletions(-)
---
diff --git a/discident-glib/test-diglib.c b/discident-glib/test-diglib.c
index e1a9983..4f2227b 100644
--- a/discident-glib/test-diglib.c
+++ b/discident-glib/test-diglib.c
@@ -152,6 +152,46 @@ discident_gtin_print (GObject *source_object,
 
 static char **uris = NULL;
 
+static void
+handle_gtin_uri (const char *uri)
+{
+	GFile *file;
+	char *gtin;
+	GError *error = NULL;
+
+	file = g_file_new_for_path (uri);
+	if (file == NULL) {
+		g_message ("Could not convert %s", uri);
+		return;
+	}
+	g_object_set_data (G_OBJECT (file), "wants-file-list", GINT_TO_POINTER (option_file_list));
+	if (!option_async) {
+		char *title;
+		gtin = discident_get_gtin_file (file, &error);
+		g_object_unref (file);
+		if (gtin == NULL) {
+			g_message ("Could not get disc ID: %s", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_print ("URI: %s\n", uri);
+
+		g_print ("Disc GTIN: %s\n", gtin);
+		g_print ("Query URI: "QUERY_GTIN"\n", gtin);
+
+		title = discident_get_title_for_gtin (gtin, NULL);
+		g_free (gtin);
+		g_print ("Title: %s\n", title);
+		g_free (title);
+	} else {
+		num_queries++;
+		discident_get_gtin_file_async (file, NULL, discident_gtin_print, NULL);
+		num_queries++;
+		discident_get_title_file_async (file, NULL, discident_title_print, NULL);
+		g_object_unref (file);
+	}
+}
+
 int main (int argc, char **argv)
 {
 	GError *error = NULL;
@@ -188,44 +228,7 @@ int main (int argc, char **argv)
 	}
 
 	for (i = 0; uris[i] != NULL; i++) {
-		GFile *file;
-		char *gtin;
-		GError *error = NULL;
-
-		file= g_file_new_for_path (uris[i]);
-		if (file == NULL) {
-			g_message ("Could not convert %s", uris[i]);
-			continue;
-		}
-		g_object_set_data (G_OBJECT (file), "wants-file-list", GINT_TO_POINTER (option_file_list));
-		if (!option_async) {
-			char *uri, *title;
-			gtin = discident_get_gtin_file (file, &error);
-			if (gtin == NULL) {
-				g_object_unref (file);
-				g_message ("Could not get disc ID: %s", error->message);
-				g_error_free (error);
-				continue;
-			}
-			uri = g_file_get_uri (file);
-			g_object_unref (file);
-			g_print ("URI: %s\n", uri);
-			g_free (uri);
-
-			g_print ("Disc GTIN: %s\n", gtin);
-			g_print ("Query URI: "QUERY_GTIN"\n", gtin);
-
-			title = discident_get_title_for_gtin (gtin, NULL);
-			g_free (gtin);
-			g_print ("Title: %s\n", title);
-			g_free (title);
-		} else {
-			num_queries++;
-			discident_get_gtin_file_async (file, NULL, discident_gtin_print, NULL);
-			num_queries++;
-			discident_get_title_file_async (file, NULL, discident_title_print, NULL);
-			g_object_unref (file);
-		}
+		handle_gtin_uri (uris[i]);
 	}
 
 	if (option_async) {



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