gmyth/tests/gmyth_test_epg.c
branchtrunk
changeset 750 312d6bc514f3
parent 618 88001a25ab5a
child 754 cb885ee44618
     1.1 --- a/gmyth/tests/gmyth_test_epg.c	Wed May 02 16:11:14 2007 +0100
     1.2 +++ b/gmyth/tests/gmyth_test_epg.c	Thu Jun 14 18:19:52 2007 +0100
     1.3 @@ -5,119 +5,133 @@
     1.4  #include "common.h"
     1.5  
     1.6  static gboolean
     1.7 -test_epg_connection (GMythBackendInfo *backend_info)
     1.8 +test_epg_connection(GMythBackendInfo * backend_info)
     1.9  {
    1.10 -    GMythEPG *epg = gmyth_epg_new ();
    1.11 -    gboolean res = FALSE;
    1.12 +  GMythEPG *epg = gmyth_epg_new();
    1.13 +  gboolean res = FALSE;
    1.14  
    1.15 -    res = gmyth_epg_connect (epg, backend_info);
    1.16 +  res = gmyth_epg_connect(epg, backend_info);
    1.17  
    1.18 -    gmyth_epg_disconnect (epg);
    1.19 -    if ( epg != NULL )
    1.20 -    	g_object_unref (epg);
    1.21 +  gmyth_epg_disconnect(epg);
    1.22 +  if (epg != NULL)
    1.23 +	g_object_unref(epg);
    1.24  
    1.25 -    return res; 
    1.26 +  return res;
    1.27  }
    1.28  
    1.29  
    1.30  static gboolean
    1.31 -test_epg_get_channels (GMythBackendInfo *backend_info)
    1.32 +test_epg_get_channels(GMythBackendInfo * backend_info)
    1.33  {
    1.34 -    GMythEPG *epg = gmyth_epg_new ();
    1.35 -    GList *clist;
    1.36 -    gint i, length;
    1.37 +  GMythEPG *epg = gmyth_epg_new();
    1.38 +  GList *clist;
    1.39 +  gint i, length;
    1.40  
    1.41 -    if (!gmyth_epg_connect (epg, backend_info)) {
    1.42 -        return FALSE;
    1.43 -    }
    1.44 +  if (!gmyth_epg_connect(epg, backend_info))
    1.45 +	{
    1.46 +	  return FALSE;
    1.47 +	}
    1.48  
    1.49 -    length = gmyth_epg_get_channel_list (epg, &clist);
    1.50 -    g_debug ("==== %d channels found in the EPG ====\n", length);
    1.51 -    for (i=0; i<length; i++) {
    1.52 -        GMythChannelInfo *channel_info = (GMythChannelInfo*) g_list_nth_data (clist, i);
    1.53 +  length = gmyth_epg_get_channel_list(epg, &clist);
    1.54 +  g_debug("==== %d channels found in the EPG ====\n", length);
    1.55 +  for (i = 0; i < length; i++)
    1.56 +	{
    1.57 +	  GMythChannelInfo *channel_info =
    1.58 +		(GMythChannelInfo *) g_list_nth_data(clist, i);
    1.59  
    1.60 -        gmyth_channel_info_print(channel_info);
    1.61 -    }
    1.62 +	  gmyth_channel_info_print(channel_info);
    1.63 +	}
    1.64  
    1.65 -    g_list_free (clist);
    1.66 -    gmyth_epg_disconnect (epg);
    1.67 -    if ( epg != NULL )
    1.68 -    	g_object_unref (epg);
    1.69 +  g_list_free(clist);
    1.70 +  gmyth_epg_disconnect(epg);
    1.71 +  if (epg != NULL)
    1.72 +	g_object_unref(epg);
    1.73  }
    1.74  
    1.75  static gboolean
    1.76 -test_epg_get_channel_icon (GMythBackendInfo *backend_info)
    1.77 +test_epg_get_channel_icon(GMythBackendInfo * backend_info)
    1.78  {
    1.79 -    GMythEPG *epg = gmyth_epg_new ();
    1.80 -    GList *clist;
    1.81 -    gint i, length;
    1.82 +  GMythEPG *epg = gmyth_epg_new();
    1.83 +  GList *clist;
    1.84 +  gint i, length;
    1.85  
    1.86 -    if (!gmyth_epg_connect (epg, backend_info)) {
    1.87 -        return FALSE;
    1.88 -    }
    1.89 +  if (!gmyth_epg_connect(epg, backend_info))
    1.90 +	{
    1.91 +	  return FALSE;
    1.92 +	}
    1.93  
    1.94 -    length = gmyth_epg_get_channel_list (epg, &clist);
    1.95 -    g_debug ("==== %d channels found in the EPG ====\n", length);
    1.96 -    for (i=0; i<length; i++) {
    1.97 -        GMythChannelInfo *channel_info = (GMythChannelInfo*) g_list_nth_data (clist, i);
    1.98 -        
    1.99 -        if (gmyth_epg_channel_has_icon (epg, channel_info)) {
   1.100 -            gchar *icon_name = g_strdup_printf ("%s.jpg", channel_info->channel_name->str);
   1.101 -            guint8 *icon_data = NULL;
   1.102 -            guint icon_length;
   1.103 +  length = gmyth_epg_get_channel_list(epg, &clist);
   1.104 +  g_debug("==== %d channels found in the EPG ====\n", length);
   1.105 +  for (i = 0; i < length; i++)
   1.106 +	{
   1.107 +	  GMythChannelInfo *channel_info =
   1.108 +		(GMythChannelInfo *) g_list_nth_data(clist, i);
   1.109  
   1.110 -            g_debug ("Channel %s has icon %s\n", channel_info->channel_name->str, channel_info->channel_icon->str);
   1.111 +	  if (gmyth_epg_channel_has_icon(epg, channel_info))
   1.112 +		{
   1.113 +		  gchar *icon_name =
   1.114 +			g_strdup_printf("%s.jpg", channel_info->channel_name->str);
   1.115 +		  guint8 *icon_data = NULL;
   1.116 +		  guint icon_length;
   1.117  
   1.118 -            if (gmyth_epg_channel_get_icon (epg, channel_info, &icon_data, &icon_length)) {
   1.119 -                FILE *outfile = fopen (icon_name, "w+");
   1.120 -                if (fwrite (icon_data, icon_length, 1, outfile) == icon_length)
   1.121 -                    g_debug ("\tIcon saved as %s", icon_name);
   1.122 -                else
   1.123 -                    g_debug ("\tError while downloading the file or writing it");
   1.124 +		  g_debug("Channel %s has icon %s\n", channel_info->channel_name->str,
   1.125 +				  channel_info->channel_icon->str);
   1.126  
   1.127 -                g_free (icon_data);
   1.128 -            }
   1.129 -            g_free (icon_name);
   1.130 -            
   1.131 -        } else {
   1.132 -            g_debug ("Channel %s does not have icon\n", channel_info->channel_name->str);
   1.133 -        }
   1.134 -        gmyth_channel_info_print(channel_info);
   1.135 -    }
   1.136 +		  if (gmyth_epg_channel_get_icon
   1.137 +			  (epg, channel_info, &icon_data, &icon_length))
   1.138 +			{
   1.139 +			  FILE *outfile = fopen(icon_name, "w+");
   1.140 +			  if (fwrite(icon_data, icon_length, 1, outfile) == icon_length)
   1.141 +				g_debug("\tIcon saved as %s", icon_name);
   1.142 +			  else
   1.143 +				g_debug("\tError while downloading the file or writing it");
   1.144  
   1.145 -    g_list_free (clist);
   1.146 -    gmyth_epg_disconnect (epg);
   1.147 -    g_object_unref (epg);
   1.148 +			  g_free(icon_data);
   1.149 +			}
   1.150 +		  g_free(icon_name);
   1.151  
   1.152 -    return TRUE;
   1.153 +		}
   1.154 +	  else
   1.155 +		{
   1.156 +		  g_debug("Channel %s does not have icon\n",
   1.157 +				  channel_info->channel_name->str);
   1.158 +		}
   1.159 +	  gmyth_channel_info_print(channel_info);
   1.160 +	}
   1.161 +
   1.162 +  g_list_free(clist);
   1.163 +  gmyth_epg_disconnect(epg);
   1.164 +  g_object_unref(epg);
   1.165 +
   1.166 +  return TRUE;
   1.167  }
   1.168  
   1.169  int
   1.170 -main (int args, const char **argv)
   1.171 +main(int args, const char **argv)
   1.172  {
   1.173  
   1.174 -    GMythBackendInfo *backend_info;
   1.175 -    g_type_init ();
   1.176 -    g_thread_init (NULL);
   1.177 +  GMythBackendInfo *backend_info;
   1.178 +  g_type_init();
   1.179 +  g_thread_init(NULL);
   1.180  
   1.181 -    if (args < 2) {
   1.182 -        g_debug ("Type %s myth://hostname:port/?mythconverg\n", argv[0]);
   1.183 -        return -1;
   1.184 -    }
   1.185 +  if (args < 2)
   1.186 +	{
   1.187 +	  g_debug("Type %s myth://hostname:port/?mythconverg\n", argv[0]);
   1.188 +	  return -1;
   1.189 +	}
   1.190  
   1.191 -    backend_info = gmyth_backend_info_new_with_uri (argv[1]);
   1.192 +  backend_info = gmyth_backend_info_new_with_uri(argv[1]);
   1.193  
   1.194 -    fprintf(stdout, SYNC_STRING);
   1.195 -    fflush(NULL);
   1.196 -    getchar();
   1.197 +  fprintf(stdout, SYNC_STRING);
   1.198 +  fflush(NULL);
   1.199 +  getchar();
   1.200  
   1.201 -    test_epg_connection (backend_info);
   1.202 -    test_epg_get_channels (backend_info);
   1.203 -    test_epg_get_channel_icon (backend_info);
   1.204 +  test_epg_connection(backend_info);
   1.205 +  test_epg_get_channels(backend_info);
   1.206 +  test_epg_get_channel_icon(backend_info);
   1.207  
   1.208 -    if ( backend_info != NULL )
   1.209 -    	g_object_unref( backend_info );
   1.210 +  if (backend_info != NULL)
   1.211 +	g_object_unref(backend_info);
   1.212  
   1.213 -    return(0);
   1.214 +  return (0);
   1.215  }
   1.216 -