Fixed test to support signals carrying service
[maevies] / test / mvs-minfo-provider-test.c
index 968f82b..d4b398d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * mvs-info-provider-test.c
+ * mvs-minfo-provider-test.c
  *
  * This file is part of maevies
  * Copyright (C) 2010 Simón Pena <spenap@gmail.com>
 
 #include "mvs-minfo-provider.h"
 #include "mvs-tmdb-movie.h"
+#include "mvs-watc-movie.h"
 
 static GMainLoop *loop = NULL;
 static gchar *query = "Zombieland";
+static gboolean watc = FALSE;
+static gboolean tmdb = FALSE;
 
 static GOptionEntry entries[] = {
+        { "watc", 'w', 0, G_OPTION_ARG_NONE, &watc, "Query WATC service", NULL },
+        { "tmdb", 't', 0, G_OPTION_ARG_NONE, &tmdb, "Query TMDB service (default)", NULL },
         { "query", 'q', 0, G_OPTION_ARG_STRING, &query, "query", "query term" },
         { NULL }
 };
 
 static void
-response_received_callback (MvsMInfoProvider *minfo_provider, GList *list,
-                            gpointer user_data)
+response_received_cb (MvsMInfoProvider *minfo_provider, guint service,
+                      GList *list, gpointer user_data)
 {
         GList *tmp = NULL;
 
         for (tmp = list; tmp; tmp = tmp->next) {
 
-                g_return_if_fail (MVS_IS_TMDB_MOVIE (tmp->data));
+                if (MVS_IS_TMDB_MOVIE (tmp->data)) {
 
-                MvsTmdbMovie *movie_info = MVS_TMDB_MOVIE (tmp->data);
+                        MvsTmdbMovie *tmdb_movie = MVS_TMDB_MOVIE (tmp->data);
 
-                mvs_tmdb_movie_print (movie_info);
-                g_print ("\n");
+                        mvs_tmdb_movie_print (tmdb_movie);
+                        g_print ("\n");
 
-                g_object_unref (movie_info);
+                        g_object_unref (tmdb_movie);
+                }
+                else if (MVS_IS_WATC_MOVIE (tmp->data)) {
+
+                        MvsWatcMovie *watc_movie = MVS_WATC_MOVIE (tmp->data);
+
+                        mvs_watc_movie_print (watc_movie);
+                        g_print ("\n");
+
+                        g_object_unref (watc_movie);
+                }
         }
 
         g_list_free (list);
@@ -56,37 +71,42 @@ int
 main (int argc, char **argv)
 {
         MvsMInfoProvider *minfo_provider = NULL;
-        MvsTmdbMovie *movie_info = NULL;
         GOptionContext *context = NULL;
-        GOptionGroup *gst_option_group = NULL;
         GError *error = NULL;
+        MvsService service = MVS_SERVICE_TMDB;
 
         g_type_init ();
-
-        g_thread_init (NULL);
+        if (!g_thread_supported ())
+                g_thread_init (NULL);
 
         context = g_option_context_new (" - Tests data provider behavior");
         g_option_context_add_main_entries (context, entries, NULL);
         if (!g_option_context_parse (context, &argc, &argv, &error)) {
                 g_critical ("option parsing failed: %s", error->message);
+                g_error_free (error);
+                g_option_context_free (context);
                 return -1;
         }
 
+        if (watc)
+                service = MVS_SERVICE_WATC;
+        else if (tmdb)
+                service = MVS_SERVICE_TMDB;
 
         minfo_provider = mvs_minfo_provider_new ();
         g_signal_connect (minfo_provider, "response-received",
-                          G_CALLBACK (response_received_callback), NULL);
+                          G_CALLBACK (response_received_cb), NULL);
 
-        movie_info = mvs_tmdb_movie_new ();
         loop = g_main_loop_new (NULL, FALSE);
 
-        mvs_minfo_provider_query (minfo_provider, query);
+        mvs_minfo_provider_query (minfo_provider, service,
+                                  query);
 
         g_main_loop_run (loop);
 
         g_object_unref (minfo_provider);
-        g_object_unref (movie_info);
         g_main_loop_unref (loop);
+        g_option_context_free (context);
 
         return 0;
 }