branches/gmyth-0.1b/tests/gmyth_test_recorder.c
author rosfran
Tue Feb 13 23:17:35 2007 +0000 (2007-02-13)
branchtrunk
changeset 358 06009f72d657
permissions -rw-r--r--
[svn r360] Removed a lot of GStaticMutex references.
     1 #include <glib-object.h>
     2 
     3 #include "gmyth_backendinfo.h"
     4 #include "gmyth_remote_util.h"
     5 #include "gmyth_query.h"
     6 #include "gmyth_epg.h"
     7 #include "gmyth_common.h"
     8 
     9 
    10 static gboolean
    11 test_recorder_availability (GMythBackendInfo *backend_info)
    12 {
    13     GMythRecorder* recorder;
    14     GMythSocket *socket = gmyth_socket_new ();
    15 
    16     if (gmyth_socket_connect_to_backend (socket, 
    17 	    gmyth_backend_info_get_hostname (backend_info),
    18 	    gmyth_backend_info_get_port (backend_info), TRUE) == FALSE) {
    19 	g_debug ("Test recorder failed: Connection failed");
    20 	return FALSE;
    21     }
    22 
    23     recorder = remote_request_next_free_recorder (socket, -1);
    24     gmyth_socket_close_connection (socket);
    25     if (recorder == NULL) {
    26 	g_debug ("Recorder not available\n");
    27 	return FALSE;
    28     }
    29     
    30     g_debug ("Recorder found (num): %d", recorder->recorder_num);
    31     
    32     return TRUE;
    33 }
    34 
    35 static gboolean
    36 test_recorder_setup (GMythBackendInfo *backend_info)
    37 {
    38     GMythQuery *query = gmyth_query_new ();
    39 
    40     if (gmyth_query_connect_with_timeout (query, backend_info, 3) == TRUE) {
    41 	g_debug ("Mysql connection success");
    42 	return TRUE;
    43     } else {
    44 	g_debug ("Mysql connection failed");
    45 	return FALSE;
    46     }
    47        
    48 }
    49 
    50 static gboolean
    51 test_recorder_check_channels (GMythBackendInfo *backend_info)
    52 {
    53     GMythRecorder* recorder;
    54     GMythSocket *socket = gmyth_socket_new ();
    55     GMythEPG *epg = gmyth_epg_new ();
    56     GList *clist;
    57     gint i, length;
    58 
    59     // Gets the free recorder
    60     if (gmyth_socket_connect_to_backend (socket, 
    61 	    gmyth_backend_info_get_hostname (backend_info),
    62 	    gmyth_backend_info_get_port (backend_info), TRUE) == FALSE) {
    63 	g_debug ("Test recorder failed: Connection failed");
    64 	return FALSE;
    65     }
    66 
    67     recorder = remote_request_next_free_recorder (socket, -1);
    68     gmyth_socket_close_connection (socket);
    69     if (recorder == NULL) {
    70 	g_debug ("[%s] Recorder not available", __FUNCTION__);
    71 	return FALSE;
    72     }
    73 
    74     // Connects the recorder socket
    75     gmyth_recorder_setup (recorder);
    76 
    77     // Gets the list of channels
    78     if (!gmyth_epg_connect (epg, backend_info)) {
    79         g_debug ("%s: Not connected\n", __FUNCTION__);
    80         return FALSE;
    81     }
    82 
    83     length = gmyth_epg_get_channel_list (epg, &clist);
    84     gmyth_epg_disconnect (epg);
    85     g_object_unref (epg);
    86 
    87     g_print ("==== Verifying the %d channels found in the EPG ====\n", length);
    88     for (i=0; i<length; i++) {
    89         GMythChannelInfo *channel_info = (GMythChannelInfo*) g_list_nth_data (clist, i);
    90 	gboolean res;
    91 
    92 	// Checks the channels
    93         res = gmyth_recorder_check_channel (recorder, channel_info->channel_ID);
    94 	g_debug ("Channel %d %s", channel_info->channel_ID, res ? "Found" : "Not found");
    95     }
    96 
    97     g_list_free (clist);
    98 
    99 }
   100 
   101 
   102 int
   103 main (int args, const char **argv)
   104 {
   105     const char* uri = argv[1];
   106 
   107     GMythBackendInfo *backend_info;
   108     g_type_init ();
   109     g_thread_init (NULL);
   110 
   111     backend_info = gmyth_backend_info_new_with_uri (argv[1]);
   112 
   113     printf ("******** Testing recorder availability ***********\n");
   114     test_recorder_availability (backend_info);
   115 
   116     printf ("******** Testing recorder check channels function ***********\n");
   117     test_recorder_check_channels (backend_info);
   118 }
   119 
   120 
   121 
   122 
   123