[svn r571] Added test to the LiveTV module. trunk
authorrosfran
Wed Apr 18 16:21:38 2007 +0100 (2007-04-18)
branchtrunk
changeset 56625f194cfa60b
parent 565 ed34b1dab103
child 567 0200f97ac289
[svn r571] Added test to the LiveTV module.
gmyth/tests/Makefile.am
gmyth/tests/gmyth_test_livetv.c
     1.1 --- a/gmyth/tests/Makefile.am	Wed Apr 18 15:59:10 2007 +0100
     1.2 +++ b/gmyth/tests/Makefile.am	Wed Apr 18 16:21:38 2007 +0100
     1.3 @@ -22,6 +22,7 @@
     1.4  	gmyth_test_recordings \
     1.5  	gmyth_test_transcode \
     1.6  	gmyth_test_vlc \
     1.7 +	gmyth_test_livetv \
     1.8  	gmyth_test_http
     1.9  
    1.10  TESTS = \
    1.11 @@ -32,6 +33,7 @@
    1.12  	gmyth_test_recordings \
    1.13  	gmyth_test_transcode \
    1.14  	gmyth_test_vlc \
    1.15 +	gmyth_test_livetv \
    1.16  	gmyth_test_http
    1.17  
    1.18  #TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) @GLIB_LIBS@ @GOBJECT_LIBS@ @LIBCURL_LIBS@
    1.19 @@ -60,3 +62,6 @@
    1.20  gmyth_test_transcode_SOURCES = \
    1.21  	gmyth_test_transcode.c
    1.22  
    1.23 +gmyth_test_livetv_SOURCES = \
    1.24 +	gmyth_test_livetv.c
    1.25 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gmyth/tests/gmyth_test_livetv.c	Wed Apr 18 16:21:38 2007 +0100
     2.3 @@ -0,0 +1,138 @@
     2.4 +#include <glib-object.h>
     2.5 +
     2.6 +#include "gmyth_uri.h"
     2.7 +#include "gmyth_backendinfo.h"
     2.8 +#include "gmyth_livetv.h"
     2.9 +#include "gmyth_file.h"
    2.10 +#include "gmyth_file_transfer.h"
    2.11 +#include "gmyth_file_local.h"
    2.12 +#include "gmyth_common.h"
    2.13 +
    2.14 +static gboolean
    2.15 +test_livetv_setup ()
    2.16 +{
    2.17 +  GMythLiveTV *livetv = NULL;
    2.18 +  GMythFile *file = NULL;
    2.19 +  gchar *channel_name = NULL;
    2.20 +  gboolean ret = TRUE;
    2.21 +  gboolean live_tv = FALSE;
    2.22 +  
    2.23 +  gchar *uri = "myth://192.168.3.165:6543/livetv?channel=9";
    2.24 +  
    2.25 +  GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri );
    2.26 +
    2.27 +  GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri (uri);
    2.28 +  live_tv = gmyth_uri_is_livetv( gmyth_uri );
    2.29 +  if ( live_tv ) {
    2.30 +   livetv = gmyth_livetv_new (backend_info);
    2.31 +    
    2.32 +    gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
    2.33 +    if ( ch != NULL )
    2.34 +        channel_name = ch;
    2.35 +        
    2.36 +    if (channel_name != NULL) {
    2.37 +      if (gmyth_livetv_channel_name_setup (livetv, channel_name) == FALSE) {
    2.38 +        g_debug("LiveTV setup felt down on error.");
    2.39 +        ret = FALSE;
    2.40 +        goto init_failed;
    2.41 +      }
    2.42 +    } else {
    2.43 +      if (gmyth_livetv_setup (livetv) == FALSE) {
    2.44 +        g_debug("LiveTV setup felt down on error");
    2.45 +        ret = FALSE;
    2.46 +        goto init_failed;
    2.47 +      }
    2.48 +    }
    2.49 +
    2.50 +    file = GMYTH_FILE( gmyth_livetv_create_file_transfer (livetv) );
    2.51 +
    2.52 +    if (NULL == file) {
    2.53 +      g_debug("[LiveTV] FileTransfer equals to NULL");
    2.54 +      ret = FALSE;
    2.55 +      goto init_failed;
    2.56 +    }
    2.57 +    
    2.58 +    /* Check if the file is local to this specific client renderer */
    2.59 +    if ( gmyth_uri_is_local_file(gmyth_uri) )
    2.60 +        ret = gmyth_file_local_open( GMYTH_FILE_LOCAL(file) );
    2.61 +    else
    2.62 +        ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(file), livetv->uri != NULL ? 
    2.63 +            gmyth_uri_get_path(livetv->uri) : 
    2.64 +            livetv->proginfo->pathname->str );
    2.65 +
    2.66 +    if ( !ret )
    2.67 +    {
    2.68 +        g_debug("Error: couldn't open the FileTransfer from LiveTV source!" );
    2.69 +        goto init_failed;
    2.70 +    }
    2.71 +  } else {
    2.72 +    
    2.73 +    /* Check if the file is local to this specific client renderer, and tries to open
    2.74 +     * a local connection
    2.75 +     */
    2.76 +    if ( gmyth_uri_is_local_file(gmyth_uri) )
    2.77 +    {
    2.78 +        g_debug ( "Opening local file connection to download..." );
    2.79 +        file = GMYTH_FILE(gmyth_file_local_new(backend_info));
    2.80 +        ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( file ) );      
    2.81 +    } else {
    2.82 +        g_debug ( "Opening remote file connection to download..." );
    2.83 +        file = GMYTH_FILE(gmyth_file_transfer_new(backend_info));
    2.84 +        ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(file), uri );
    2.85 +    }
    2.86 +
    2.87 +  } /* if (else) - recorded FileTransfer */
    2.88 +
    2.89 +  if (NULL == file) {
    2.90 +    g_debug("FileTransfer is NULL");
    2.91 +    ret = FALSE;
    2.92 +    goto init_failed;
    2.93 +  }
    2.94 +  g_debug( "uri = %s", uri);
    2.95 +
    2.96 +  if (ret == FALSE) {
    2.97 +      g_debug("MythTV FileTransfer request failed when setting up socket connection!");
    2.98 +      goto init_failed;
    2.99 +  }
   2.100 +
   2.101 +  g_debug( "MythTV FileTransfer filesize = %lld",
   2.102 +      gmyth_file_get_filesize( file ));
   2.103 +
   2.104 +init_failed:
   2.105 +    if ( livetv != NULL )
   2.106 +        g_object_unref(livetv);
   2.107 +  
   2.108 +    if ( file != NULL )
   2.109 +        g_object_unref(file);
   2.110 +    
   2.111 +//    if ( uri != NULL )
   2.112 +//        g_free( uri );
   2.113 +  
   2.114 +    if ( gmyth_uri != NULL )
   2.115 +        g_object_unref( gmyth_uri );
   2.116 +
   2.117 +//    if ( backend_info != NULL )
   2.118 +//       g_object_unref( backend_info );
   2.119 +
   2.120 +    return ret;
   2.121 +    
   2.122 +}
   2.123 +
   2.124 +gint
   2.125 +main (gint args, const gchar **argv)
   2.126 +{
   2.127 +    g_type_init ();
   2.128 +    
   2.129 +    g_thread_init (NULL);
   2.130 +
   2.131 +    gboolean ret = test_livetv_setup ();
   2.132 +    
   2.133 +    if ( !ret )
   2.134 +        g_debug ("Error when running LiveTV setup test script!");
   2.135 +    else
   2.136 +        g_debug ("LiveTV setup test script finished with success.");
   2.137 +}
   2.138 +
   2.139 +
   2.140 +
   2.141 +