[svn r600] Added clean-up code to the GMyth test cases. trunk
authorrosfran
Wed Apr 25 15:50:41 2007 +0100 (2007-04-25)
branchtrunk
changeset 594f36075170a4e
parent 593 95263ab433f1
child 595 5c5cff842d57
[svn r600] Added clean-up code to the GMyth test cases.
gmyth/tests/gmyth_test_connection.c
gmyth/tests/gmyth_test_epg.c
gmyth/tests/gmyth_test_http.c
gmyth/tests/gmyth_test_livetv.c
gmyth/tests/gmyth_test_recorder.c
gmyth/tests/gmyth_test_recordings.c
gmyth/tests/test_connection.py
gmyth/tests/test_livetv.py
gmyth/tests/testing_tools.py
     1.1 --- a/gmyth/tests/gmyth_test_connection.c	Wed Apr 25 01:07:56 2007 +0100
     1.2 +++ b/gmyth/tests/gmyth_test_connection.c	Wed Apr 25 15:50:41 2007 +0100
     1.3 @@ -17,7 +17,8 @@
     1.4      if (gmyth_socket_connect_with_timeout (socket, 
     1.5  	    gmyth_backend_info_get_hostname (backend_info),
     1.6  	    gmyth_backend_info_get_port (backend_info), 4) == TRUE) {
     1.7 -	g_debug ("Socket connection success");
     1.8 +        g_object_unref( socket );
     1.9 +        g_debug ("Socket connection success");
    1.10  	return TRUE;
    1.11      } else {
    1.12  	g_debug ("Connection failed");
    1.13 @@ -32,7 +33,9 @@
    1.14      if (gmyth_socket_connect_to_backend (socket,
    1.15  	    gmyth_backend_info_get_hostname (backend_info),
    1.16  	    gmyth_backend_info_get_port (backend_info), TRUE) == TRUE) {
    1.17 -
    1.18 +        
    1.19 +    
    1.20 +    g_object_unref( socket );
    1.21  		    
    1.22  	g_debug ("Backend socket connection success");
    1.23  	return TRUE;
    1.24 @@ -48,6 +51,7 @@
    1.25      GMythQuery *query = gmyth_query_new ();
    1.26  
    1.27      if (gmyth_query_connect_with_timeout (query, backend_info, 3) == TRUE) {
    1.28 +        g_object_unref( query );
    1.29  	g_debug ("Mysql connection success");
    1.30  	return TRUE;
    1.31      } else {
    1.32 @@ -61,8 +65,6 @@
    1.33  int
    1.34  main (int args, const char **argv)
    1.35  {
    1.36 -    const char* uri = argv[1];
    1.37 -
    1.38      GMythBackendInfo *backend_info;
    1.39      g_type_init ();
    1.40      g_thread_init (NULL);
    1.41 @@ -76,6 +78,9 @@
    1.42      fprintf(stdout, SYNC_STRING);
    1.43      fflush(NULL);
    1.44      getchar();
    1.45 +    
    1.46 +    if ( backend_info != NULL )
    1.47 +        g_object_unref( backend_info );
    1.48  
    1.49      return (0);
    1.50  
     2.1 --- a/gmyth/tests/gmyth_test_epg.c	Wed Apr 25 01:07:56 2007 +0100
     2.2 +++ b/gmyth/tests/gmyth_test_epg.c	Wed Apr 25 15:50:41 2007 +0100
     2.3 @@ -13,7 +13,8 @@
     2.4      res = gmyth_epg_connect (epg, backend_info);
     2.5  
     2.6      gmyth_epg_disconnect (epg);
     2.7 -    g_object_unref (epg);
     2.8 +    if ( epg != NULL )
     2.9 +    	g_object_unref (epg);
    2.10  
    2.11      return res; 
    2.12  }
    2.13 @@ -31,7 +32,7 @@
    2.14      }
    2.15  
    2.16      length = gmyth_epg_get_channel_list (epg, &clist);
    2.17 -    g_print ("==== %d channels found in the EPG ====\n", length);
    2.18 +    g_debug ("==== %d channels found in the EPG ====\n", length);
    2.19      for (i=0; i<length; i++) {
    2.20          GMythChannelInfo *channel_info = (GMythChannelInfo*) g_list_nth_data (clist, i);
    2.21  
    2.22 @@ -40,7 +41,8 @@
    2.23  
    2.24      g_list_free (clist);
    2.25      gmyth_epg_disconnect (epg);
    2.26 -    g_object_unref (epg);
    2.27 +    if ( epg != NULL )
    2.28 +    	g_object_unref (epg);
    2.29  }
    2.30  
    2.31  static gboolean
    2.32 @@ -55,7 +57,7 @@
    2.33      }
    2.34  
    2.35      length = gmyth_epg_get_channel_list (epg, &clist);
    2.36 -    g_print ("==== %d channels found in the EPG ====\n", length);
    2.37 +    g_debug ("==== %d channels found in the EPG ====\n", length);
    2.38      for (i=0; i<length; i++) {
    2.39          GMythChannelInfo *channel_info = (GMythChannelInfo*) g_list_nth_data (clist, i);
    2.40          
    2.41 @@ -64,21 +66,21 @@
    2.42              guint8 *icon_data = NULL;
    2.43              guint icon_length;
    2.44  
    2.45 -            g_print ("Channel %s has icon %s\n", channel_info->channel_name->str, channel_info->channel_icon->str);
    2.46 +            g_debug ("Channel %s has icon %s\n", channel_info->channel_name->str, channel_info->channel_icon->str);
    2.47  
    2.48              if (gmyth_epg_channel_get_icon (epg, channel_info, &icon_data, &icon_length)) {
    2.49                  FILE *outfile = fopen (icon_name, "w+");
    2.50                  if (fwrite (icon_data, icon_length, 1, outfile) == icon_length)
    2.51 -                    g_print ("\tIcon saved as %s", icon_name);
    2.52 +                    g_debug ("\tIcon saved as %s", icon_name);
    2.53                  else
    2.54 -                    g_print ("\tError while downloading the file or writing it");
    2.55 +                    g_debug ("\tError while downloading the file or writing it");
    2.56  
    2.57                  g_free (icon_data);
    2.58              }
    2.59              g_free (icon_name);
    2.60              
    2.61          } else {
    2.62 -            g_print ("Channel %s does not have icon\n", channel_info->channel_name->str);
    2.63 +            g_debug ("Channel %s does not have icon\n", channel_info->channel_name->str);
    2.64          }
    2.65          gmyth_channel_info_print(channel_info);
    2.66      }
    2.67 @@ -93,14 +95,13 @@
    2.68  int
    2.69  main (int args, const char **argv)
    2.70  {
    2.71 -    const char* uri = argv[1];
    2.72  
    2.73      GMythBackendInfo *backend_info;
    2.74      g_type_init ();
    2.75      g_thread_init (NULL);
    2.76  
    2.77      if (args < 2) {
    2.78 -        g_printf ("Type %s myth://hostname:port/?mythconverg\n", argv[0]);
    2.79 +        g_debug ("Type %s myth://hostname:port/?mythconverg\n", argv[0]);
    2.80          return -1;
    2.81      }
    2.82  
    2.83 @@ -114,6 +115,9 @@
    2.84      test_epg_get_channels (backend_info);
    2.85      test_epg_get_channel_icon (backend_info);
    2.86  
    2.87 +    if ( backend_info != NULL )
    2.88 +    	g_object_unref( backend_info );
    2.89 +
    2.90      return(0);
    2.91  }
    2.92  
     3.1 --- a/gmyth/tests/gmyth_test_http.c	Wed Apr 25 01:07:56 2007 +0100
     3.2 +++ b/gmyth/tests/gmyth_test_http.c	Wed Apr 25 15:50:41 2007 +0100
     3.3 @@ -19,44 +19,51 @@
     3.4      
     3.5      GTimeVal* start = gmyth_util_string_to_time_val("2007-03-19T17:00:00");
     3.6      //GTimeVal* end = gmyth_util_string_to_time_val("2007-03-10T00:00:00");
     3.7 +    fprintf(stdout, SYNC_STRING);
     3.8 +    fflush(NULL);
     3.9 +    getchar();
    3.10  
    3.11      //GMythEpg epg;
    3.12 -    //epg  = gmyth_http_retrieve_epg(backend_info, start, end, 1000, 10000, "1");
    3.13 +    /*
    3.14 +    epg  = gmyth_http_retrieve_epg(backend_info, start, end, 1000, 10000, "1");
    3.15  
    3.16 -    //if ( NULL == epg.channelList || g_slist_length( epg.channelList ) <= 0 )
    3.17 -    //	printf( "Channel list is empty!!!" );
    3.18 +    if ( NULL == epg.channelList || g_slist_length( epg.channelList ) <= 0 )
    3.19 +    	printf( "Channel list is empty!!!" );
    3.20   
    3.21 -    //GMythRecorded recorded;
    3.22 -    //recorded = gmyth_http_retrieve_recorded(backend_info);
    3.23 +    GMythRecorded recorded;
    3.24 +    recorded = gmyth_http_retrieve_recorded(backend_info);
    3.25  
    3.26 -    //GMythRecorded_Program* program = recorded.programList->data;
    3.27 +    GMythRecorded_Program* program = recorded.programList->data;
    3.28 +    */
    3.29 +    GMythRecProfile* profile;
    3.30  
    3.31 -    //GSList* profiles = gmyth_http_retrieve_rec_profiles(backend_info, "Transcoders");
    3.32 +    GSList* profiles = gmyth_http_retrieve_rec_profiles(backend_info, "Transcoders");
    3.33  
    3.34 -    //GMythRecProfile* prof = profiles->data;
    3.35 +    profile = profiles->data;
    3.36  
    3.37 -    //gchar* sett = gmyth_http_retrieve_setting(backend_info, "JobQueueTranscodeCommand", "wakko");	
    3.38 +    gchar* sett = gmyth_http_retrieve_setting(backend_info, "JobQueueTranscodeCommand", "wakko");	
    3.39  
    3.40 -    //GMythRecProfile* profile = gmyth_recprofile_new();
    3.41 +    profile = gmyth_recprofile_new();
    3.42  
    3.43 -    //gmyth_recprofile_set_name(profile, "Teste");
    3.44 -    //gmyth_recprofile_set_group(profile, "Transcoders");
    3.45 -    //gmyth_recprofile_set_vcodec(profile, "MPEG-4");
    3.46 -    //gmyth_recprofile_set_acodec(profile, "MP3");
    3.47 - 
    3.48 +    gmyth_recprofile_set_name(profile, "Teste");
    3.49 +    gmyth_recprofile_set_group(profile, "Transcoders");
    3.50 +    gmyth_recprofile_set_vcodec(profile, "MPEG-4");
    3.51 +    gmyth_recprofile_set_acodec(profile, "MP3"); 
    3.52  
    3.53 -    //int teste = gmyth_http_create_rec_profile(backend_info, profile);
    3.54 +    int teste = gmyth_http_create_rec_profile(backend_info, profile);
    3.55  	
    3.56 -    //printf("Hello: %d\n", teste);
    3.57 +    printf("Hello: %d\n", teste);
    3.58  
    3.59 -    //int teste2 = gmyth_http_del_rec_profile(backend_info, 56);
    3.60 +    int teste2 = gmyth_http_del_rec_profile(backend_info, 56);
    3.61  
    3.62      gint ret =  gmyth_http_retrieve_job_status(backend_info, 1000, start);
    3.63      printf("Status: %d\n\n", ret);
    3.64  
    3.65 -    fprintf(stdout, SYNC_STRING);
    3.66 -    fflush(NULL);
    3.67 -    getchar();
    3.68 +    //if ( profile != NULL )
    3.69 +    //	g_object_unref( profile );
    3.70 +
    3.71 +    if ( backend_info != NULL )
    3.72 +    	g_object_unref( backend_info );
    3.73  
    3.74      return(0);
    3.75  }
     4.1 --- a/gmyth/tests/gmyth_test_livetv.c	Wed Apr 25 01:07:56 2007 +0100
     4.2 +++ b/gmyth/tests/gmyth_test_livetv.c	Wed Apr 25 15:50:41 2007 +0100
     4.3 @@ -10,8 +10,10 @@
     4.4  #include "gmyth_file_local.h"
     4.5  #include "gmyth_common.h"
     4.6  
     4.7 +#define URI_DEFAULT	"myth://192.168.3.165:6543/livetv?channel=9"
     4.8 +
     4.9  static gboolean
    4.10 -test_livetv_setup ()
    4.11 +test_livetv_setup ( gchar *uri )
    4.12  {
    4.13    GMythLiveTV *livetv = NULL;
    4.14    GMythFile *file = NULL;
    4.15 @@ -19,14 +21,15 @@
    4.16    gboolean ret = TRUE;
    4.17    gboolean live_tv = FALSE;
    4.18    
    4.19 -  gchar *uri = "myth://192.168.3.165:6543/livetv?channel=9";
    4.20 -  
    4.21 +  if ( NULL == uri )
    4.22 +    uri = g_strdup( URI_DEFAULT );
    4.23 +
    4.24    GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri );
    4.25  
    4.26    GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri (uri);
    4.27    live_tv = gmyth_uri_is_livetv( gmyth_uri );
    4.28    if ( live_tv ) {
    4.29 -   livetv = gmyth_livetv_new (backend_info);
    4.30 +    livetv = gmyth_livetv_new (backend_info);
    4.31      
    4.32      gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
    4.33      if ( ch != NULL )
    4.34 @@ -123,21 +126,26 @@
    4.35  gint
    4.36  main (gint args, const gchar **argv)
    4.37  {
    4.38 +    gboolean ret;
    4.39 +
    4.40      g_type_init ();
    4.41      
    4.42      g_thread_init (NULL);
    4.43  
    4.44 -    gboolean ret = test_livetv_setup ();
    4.45 +    fprintf(stdout, SYNC_STRING);
    4.46 +    fflush(NULL);
    4.47 +    getchar();
    4.48 +    
    4.49 +    if ( args > 1 )
    4.50 +	ret = test_livetv_setup ( argv[1] );
    4.51 +    else
    4.52 +    	ret = test_livetv_setup ( NULL );
    4.53      
    4.54      if ( !ret )
    4.55          g_debug ("Error when running LiveTV setup test script!");
    4.56      else
    4.57          g_debug ("LiveTV setup test script finished with success.");
    4.58  
    4.59 -    fprintf(stdout, SYNC_STRING);
    4.60 -    fflush(NULL);
    4.61 -    getchar();
    4.62 -
    4.63      return(0);
    4.64  }
    4.65  
     5.1 --- a/gmyth/tests/gmyth_test_recorder.c	Wed Apr 25 01:07:56 2007 +0100
     5.2 +++ b/gmyth/tests/gmyth_test_recorder.c	Wed Apr 25 15:50:41 2007 +0100
     5.3 @@ -23,13 +23,20 @@
     5.4  
     5.5      recorder = remote_request_next_free_recorder (socket, -1);
     5.6      gmyth_socket_close_connection (socket);
     5.7 +
     5.8 +    if ( socket != NULL )
     5.9 +    	g_object_unref( socket );
    5.10 +
    5.11      if (recorder == NULL) {
    5.12  	g_debug ("Recorder not available\n");
    5.13  	return FALSE;
    5.14      }
    5.15      
    5.16      g_debug ("Recorder found (num): %d", recorder->recorder_num);
    5.17 -    
    5.18 +
    5.19 +    if ( recorder != NULL )
    5.20 +    	g_object_unref( recorder );
    5.21 +   
    5.22      return TRUE;
    5.23  }
    5.24  
    5.25 @@ -45,7 +52,10 @@
    5.26  	g_debug ("Mysql connection failed");
    5.27  	return FALSE;
    5.28      }
    5.29 -       
    5.30 +
    5.31 +    if ( query != NULL )
    5.32 +    	g_object_unref( query );
    5.33 +
    5.34  }
    5.35  
    5.36  static gboolean
    5.37 @@ -67,6 +77,8 @@
    5.38  
    5.39      recorder = remote_request_next_free_recorder (socket, -1);
    5.40      gmyth_socket_close_connection (socket);
    5.41 +    g_object_unref( socket );
    5.42 +
    5.43      if (recorder == NULL) {
    5.44  	g_debug ("[%s] Recorder not available", __FUNCTION__);
    5.45  	return FALSE;
    5.46 @@ -97,9 +109,11 @@
    5.47  
    5.48      g_list_free (clist);
    5.49  
    5.50 +    if ( recorder != NULL )
    5.51 +    	g_object_unref( recorder );
    5.52 +
    5.53  }
    5.54  
    5.55 -
    5.56  int
    5.57  main (int args, const char **argv)
    5.58  {
    5.59 @@ -119,6 +133,9 @@
    5.60      fprintf(stdout, SYNC_STRING);
    5.61      fflush(NULL);
    5.62      getchar();
    5.63 +    
    5.64 +    if ( backend_info != NULL )
    5.65 +      g_object_unref( backend_info );
    5.66  
    5.67      return(0);
    5.68  
     6.1 --- a/gmyth/tests/gmyth_test_recordings.c	Wed Apr 25 01:07:56 2007 +0100
     6.2 +++ b/gmyth/tests/gmyth_test_recordings.c	Wed Apr 25 15:50:41 2007 +0100
     6.3 @@ -40,6 +40,12 @@
     6.4      }
     6.5  
     6.6      gmyth_scheduler_disconnect (scheduler);
     6.7 +
     6.8 +    if ( scheduler != NULL )
     6.9 +    	g_object_unref( scheduler );
    6.10 +
    6.11 +    if ( list != NULL )
    6.12 +    	g_list_free( list );
    6.13      
    6.14  }
    6.15  
    6.16 @@ -57,6 +63,9 @@
    6.17      fflush(NULL);
    6.18      getchar();
    6.19  
    6.20 +    if ( backend_info != NULL )
    6.21 +    	g_object_unref( backend_info );
    6.22 +
    6.23      return(0);
    6.24  }
    6.25  
     7.1 --- a/gmyth/tests/test_connection.py	Wed Apr 25 01:07:56 2007 +0100
     7.2 +++ b/gmyth/tests/test_connection.py	Wed Apr 25 15:50:41 2007 +0100
     7.3 @@ -6,6 +6,5 @@
     7.4  import sys
     7.5  
     7.6  p = start('gmyth_test_connection', ['myth://192.168.3.165:6543/livetv?channel=1'])
     7.7 -#p = start('gmyth_test_connection', ['livetv'])
     7.8  
     7.9  sys.exit(finish(p))
     8.1 --- a/gmyth/tests/test_livetv.py	Wed Apr 25 01:07:56 2007 +0100
     8.2 +++ b/gmyth/tests/test_livetv.py	Wed Apr 25 15:50:41 2007 +0100
     8.3 @@ -5,6 +5,6 @@
     8.4  from testing_tools import start, finish
     8.5  import sys
     8.6  
     8.7 -p = start('gmyth_test_livetv')
     8.8 +p = start('gmyth_test_livetv', ['myth://192.168.3.165:6543/livetv?channel=1'])
     8.9  
    8.10  sys.exit(finish(p))
     9.1 --- a/gmyth/tests/testing_tools.py	Wed Apr 25 01:07:56 2007 +0100
     9.2 +++ b/gmyth/tests/testing_tools.py	Wed Apr 25 15:50:41 2007 +0100
     9.3 @@ -23,6 +23,7 @@
     9.4      def __init__(self, cmd, ignore):
     9.5          #assert isinstance(cmd, list)
     9.6          self.p = popen2.Popen3(cmd, capturestderr = True)
     9.7 +	#self.p = popen2.Popen3(cmd)
     9.8  	print "Executing command... [ %s ]\n" % cmd
     9.9          self.stdin = self.p.tochild
    9.10          self.stdout = self.p.fromchild