branches/gmyth-0.1b/tests/gmyth_test_recorder.c
branchtrunk
changeset 322 eb6b0b1409b5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/branches/gmyth-0.1b/tests/gmyth_test_recorder.c	Fri Feb 02 22:04:00 2007 +0000
     1.3 @@ -0,0 +1,123 @@
     1.4 +#include <glib-object.h>
     1.5 +
     1.6 +#include "gmyth_backendinfo.h"
     1.7 +#include "gmyth_remote_util.h"
     1.8 +#include "gmyth_query.h"
     1.9 +#include "gmyth_epg.h"
    1.10 +#include "gmyth_common.h"
    1.11 +
    1.12 +
    1.13 +static gboolean
    1.14 +test_recorder_availability (GMythBackendInfo *backend_info)
    1.15 +{
    1.16 +    GMythRecorder* recorder;
    1.17 +    GMythSocket *socket = gmyth_socket_new ();
    1.18 +
    1.19 +    if (gmyth_socket_connect_to_backend (socket, 
    1.20 +	    gmyth_backend_info_get_hostname (backend_info),
    1.21 +	    gmyth_backend_info_get_port (backend_info), TRUE) == FALSE) {
    1.22 +	g_debug ("Test recorder failed: Connection failed");
    1.23 +	return FALSE;
    1.24 +    }
    1.25 +
    1.26 +    recorder = remote_request_next_free_recorder (socket, -1);
    1.27 +    gmyth_socket_close_connection (socket);
    1.28 +    if (recorder == NULL) {
    1.29 +	g_debug ("Recorder not available\n");
    1.30 +	return FALSE;
    1.31 +    }
    1.32 +    
    1.33 +    g_debug ("Recorder found (num): %d", recorder->recorder_num);
    1.34 +    
    1.35 +    return TRUE;
    1.36 +}
    1.37 +
    1.38 +static gboolean
    1.39 +test_recorder_setup (GMythBackendInfo *backend_info)
    1.40 +{
    1.41 +    GMythQuery *query = gmyth_query_new ();
    1.42 +
    1.43 +    if (gmyth_query_connect_with_timeout (query, backend_info, 3) == TRUE) {
    1.44 +	g_debug ("Mysql connection success");
    1.45 +	return TRUE;
    1.46 +    } else {
    1.47 +	g_debug ("Mysql connection failed");
    1.48 +	return FALSE;
    1.49 +    }
    1.50 +       
    1.51 +}
    1.52 +
    1.53 +static gboolean
    1.54 +test_recorder_check_channels (GMythBackendInfo *backend_info)
    1.55 +{
    1.56 +    GMythRecorder* recorder;
    1.57 +    GMythSocket *socket = gmyth_socket_new ();
    1.58 +    GMythEPG *epg = gmyth_epg_new ();
    1.59 +    GList *clist;
    1.60 +    gint i, length;
    1.61 +
    1.62 +    // Gets the free recorder
    1.63 +    if (gmyth_socket_connect_to_backend (socket, 
    1.64 +	    gmyth_backend_info_get_hostname (backend_info),
    1.65 +	    gmyth_backend_info_get_port (backend_info), TRUE) == FALSE) {
    1.66 +	g_debug ("Test recorder failed: Connection failed");
    1.67 +	return FALSE;
    1.68 +    }
    1.69 +
    1.70 +    recorder = remote_request_next_free_recorder (socket, -1);
    1.71 +    gmyth_socket_close_connection (socket);
    1.72 +    if (recorder == NULL) {
    1.73 +	g_debug ("[%s] Recorder not available", __FUNCTION__);
    1.74 +	return FALSE;
    1.75 +    }
    1.76 +
    1.77 +    // Connects the recorder socket
    1.78 +    gmyth_recorder_setup (recorder);
    1.79 +
    1.80 +    // Gets the list of channels
    1.81 +    if (!gmyth_epg_connect (epg, backend_info)) {
    1.82 +        g_debug ("%s: Not connected\n", __FUNCTION__);
    1.83 +        return FALSE;
    1.84 +    }
    1.85 +
    1.86 +    length = gmyth_epg_get_channel_list (epg, &clist);
    1.87 +    gmyth_epg_disconnect (epg);
    1.88 +    g_object_unref (epg);
    1.89 +
    1.90 +    g_print ("==== Verifying the %d channels found in the EPG ====\n", length);
    1.91 +    for (i=0; i<length; i++) {
    1.92 +        GMythChannelInfo *channel_info = (GMythChannelInfo*) g_list_nth_data (clist, i);
    1.93 +	gboolean res;
    1.94 +
    1.95 +	// Checks the channels
    1.96 +        res = gmyth_recorder_check_channel (recorder, channel_info->channel_ID);
    1.97 +	g_debug ("Channel %d %s", channel_info->channel_ID, res ? "Found" : "Not found");
    1.98 +    }
    1.99 +
   1.100 +    g_list_free (clist);
   1.101 +
   1.102 +}
   1.103 +
   1.104 +
   1.105 +int
   1.106 +main (int args, const char **argv)
   1.107 +{
   1.108 +    const char* uri = argv[1];
   1.109 +
   1.110 +    GMythBackendInfo *backend_info;
   1.111 +    g_type_init ();
   1.112 +    g_thread_init (NULL);
   1.113 +
   1.114 +    backend_info = gmyth_backend_info_new_with_uri (argv[1]);
   1.115 +
   1.116 +    printf ("******** Testing recorder availability ***********\n");
   1.117 +    test_recorder_availability (backend_info);
   1.118 +
   1.119 +    printf ("******** Testing recorder check channels function ***********\n");
   1.120 +    test_recorder_check_channels (backend_info);
   1.121 +}
   1.122 +
   1.123 +
   1.124 +
   1.125 +
   1.126 +