a2964ab053a95db121ea678316e9345e33dc422b
[maevies] / test / mvs-minfo-provider-test.c
1 /*
2  * mvs-minfo-provider-test.c
3  *
4  * This file is part of maevies
5  * Copyright (C) 2010 Simón Pena <spenap@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  */
18
19 #include <stdio.h>
20 #include <glib.h>
21
22 #include "mvs-minfo-provider.h"
23 #include "mvs-tmdb-movie.h"
24
25 static GMainLoop *loop = NULL;
26 static gchar *query = "Zombieland";
27
28 static GOptionEntry entries[] = {
29         { "query", 'q', 0, G_OPTION_ARG_STRING, &query, "query", "query term" },
30         { NULL }
31 };
32
33 static void
34 response_received_callback (MvsMInfoProvider *minfo_provider, GList *list,
35                             gpointer user_data)
36 {
37         GList *tmp = NULL;
38
39         for (tmp = list; tmp; tmp = tmp->next) {
40
41                 g_return_if_fail (MVS_IS_TMDB_MOVIE (tmp->data));
42
43                 MvsTmdbMovie *movie_info = MVS_TMDB_MOVIE (tmp->data);
44
45                 mvs_tmdb_movie_print (movie_info);
46                 g_print ("\n");
47
48                 g_object_unref (movie_info);
49         }
50
51         g_list_free (list);
52         g_main_loop_quit (loop);
53 }
54
55 int
56 main (int argc, char **argv)
57 {
58         MvsMInfoProvider *minfo_provider = NULL;
59         MvsTmdbMovie *movie_info = NULL;
60         GOptionContext *context = NULL;
61         GOptionGroup *gst_option_group = NULL;
62         GError *error = NULL;
63
64         g_type_init ();
65
66         g_thread_init (NULL);
67
68         context = g_option_context_new (" - Tests data provider behavior");
69         g_option_context_add_main_entries (context, entries, NULL);
70         if (!g_option_context_parse (context, &argc, &argv, &error)) {
71                 g_critical ("option parsing failed: %s", error->message);
72                 return -1;
73         }
74
75
76         minfo_provider = mvs_minfo_provider_new ();
77         g_signal_connect (minfo_provider, "response-received",
78                           G_CALLBACK (response_received_callback), NULL);
79
80         movie_info = mvs_tmdb_movie_new ();
81         loop = g_main_loop_new (NULL, FALSE);
82
83         mvs_minfo_provider_query (minfo_provider, query);
84
85         g_main_loop_run (loop);
86
87         g_object_unref (minfo_provider);
88         g_object_unref (movie_info);
89         g_main_loop_unref (loop);
90
91         return 0;
92 }