1.1 --- a/gmyth/tests/gmyth_test_file_download.c Tue May 08 16:05:47 2007 +0100
1.2 +++ b/gmyth/tests/gmyth_test_file_download.c Thu Jun 14 18:19:52 2007 +0100
1.3 @@ -12,101 +12,107 @@
1.4 #define URI_FILE_TRANSFER_DEFAULT "myth://192.168.3.165:6543/"
1.5
1.6 static gboolean
1.7 -test_file_download_setup( gchar *uri ) {
1.8 - GMythFile *file = NULL;
1.9 - GMythFileReadResult result;
1.10 - gint64 num_bytes;
1.11 - GByteArray *file_buffer = g_byte_array_new ();
1.12 - gboolean ret = TRUE;
1.13 - gboolean is_local = FALSE;
1.14 +test_file_download_setup(gchar * uri)
1.15 +{
1.16 + GMythFile *file = NULL;
1.17 + GMythFileReadResult result;
1.18 + gint64 num_bytes;
1.19 + GByteArray *file_buffer = g_byte_array_new();
1.20 + gboolean ret = TRUE;
1.21 + gboolean is_local = FALSE;
1.22
1.23 - if ( NULL == uri)
1.24 - uri = g_strdup( URI_FILE_TRANSFER_DEFAULT );
1.25 + if (NULL == uri)
1.26 + uri = g_strdup(URI_FILE_TRANSFER_DEFAULT);
1.27
1.28 - GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri);
1.29 + GMythURI *gmyth_uri = gmyth_uri_new_with_value(uri);
1.30
1.31 - GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri(uri);
1.32 + GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri(uri);
1.33
1.34 - /* Check if the file is local to this specific client renderer, and tries to open
1.35 - * a local connection
1.36 - */
1.37 - if ( gmyth_uri_is_local_file(gmyth_uri)) {
1.38 - g_debug( "Opening local file connection to download...");
1.39 - file = GMYTH_FILE(gmyth_file_local_new(backend_info));
1.40 - ret = gmyth_file_local_open( GMYTH_FILE_LOCAL( file ) );
1.41 - } else {
1.42 - g_debug( "Opening remote file connection to download...");
1.43 - file = GMYTH_FILE(gmyth_file_transfer_new(backend_info));
1.44 - ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(file), uri);
1.45 - }
1.46 + /* Check if the file is local to this specific client renderer, and tries to open
1.47 + * a local connection
1.48 + */
1.49 + if (gmyth_uri_is_local_file(gmyth_uri))
1.50 + {
1.51 + g_debug("Opening local file connection to download...");
1.52 + file = GMYTH_FILE(gmyth_file_local_new(backend_info));
1.53 + ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(file));
1.54 + }
1.55 + else
1.56 + {
1.57 + g_debug("Opening remote file connection to download...");
1.58 + file = GMYTH_FILE(gmyth_file_transfer_new(backend_info));
1.59 + ret = gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(file), uri);
1.60 + }
1.61
1.62 - if (NULL == file) {
1.63 - g_debug("FileTransfer is NULL");
1.64 - ret = FALSE;
1.65 - goto init_failed;
1.66 - }
1.67 -
1.68 - g_debug( "uri = %s", uri);
1.69 + if (NULL == file)
1.70 + {
1.71 + g_debug("FileTransfer is NULL");
1.72 + ret = FALSE;
1.73 + goto init_failed;
1.74 + }
1.75
1.76 - if (ret == FALSE) {
1.77 - g_debug("MythTV FileTransfer request failed when setting up socket connection!");
1.78 - goto init_failed;
1.79 - }
1.80 + g_debug("uri = %s", uri);
1.81
1.82 - g_debug( "MythTV FileTransfer filesize = %lld",
1.83 - num_bytes = gmyth_file_get_filesize( file ) );
1.84 -
1.85 - is_local = gmyth_uri_is_local_file(gmyth_uri);
1.86 -
1.87 - do
1.88 - {
1.89 + if (ret == FALSE)
1.90 + {
1.91 + g_debug
1.92 + ("MythTV FileTransfer request failed when setting up socket connection!");
1.93 + goto init_failed;
1.94 + }
1.95
1.96 - if ( is_local )
1.97 - result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(file),
1.98 - file_buffer,
1.99 - num_bytes, FALSE );
1.100 - else
1.101 - result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(file),
1.102 - file_buffer,
1.103 - num_bytes, FALSE );
1.104 + g_debug("MythTV FileTransfer filesize = %lld",
1.105 + num_bytes = gmyth_file_get_filesize(file));
1.106
1.107 - } while ( result == GMYTH_FILE_READ_OK );
1.108 + is_local = gmyth_uri_is_local_file(gmyth_uri);
1.109
1.110 -init_failed:
1.111 + do
1.112 + {
1.113
1.114 - if ( file != NULL)
1.115 - g_object_unref(file);
1.116 + if (is_local)
1.117 + result = gmyth_file_local_read(GMYTH_FILE_LOCAL(file),
1.118 + file_buffer, num_bytes, FALSE);
1.119 + else
1.120 + result = gmyth_file_transfer_read(GMYTH_FILE_TRANSFER(file),
1.121 + file_buffer, num_bytes, FALSE);
1.122
1.123 - if ( gmyth_uri != NULL)
1.124 - g_object_unref( gmyth_uri);
1.125 + }
1.126 + while (result == GMYTH_FILE_READ_OK);
1.127
1.128 - if ( backend_info != NULL)
1.129 - g_object_unref( backend_info);
1.130 +init_failed:
1.131
1.132 - return ret;
1.133 + if (file != NULL)
1.134 + g_object_unref(file);
1.135 +
1.136 + if (gmyth_uri != NULL)
1.137 + g_object_unref(gmyth_uri);
1.138 +
1.139 + if (backend_info != NULL)
1.140 + g_object_unref(backend_info);
1.141 +
1.142 + return ret;
1.143
1.144 }
1.145
1.146 gint
1.147 -main(gint args, const gchar **argv) {
1.148 - gboolean ret = FALSE;
1.149 +main(gint args, const gchar ** argv)
1.150 +{
1.151 + gboolean ret = FALSE;
1.152
1.153 - g_type_init();
1.154 + g_type_init();
1.155
1.156 - g_thread_init(NULL);
1.157 + g_thread_init(NULL);
1.158
1.159 - fprintf(stdout, SYNC_STRING);
1.160 - fflush(NULL);
1.161 - getchar();
1.162 + fprintf(stdout, SYNC_STRING);
1.163 + fflush(NULL);
1.164 + getchar();
1.165
1.166 - if ( args > 1)
1.167 - ret = test_file_download_setup( argv[1]);
1.168 + if (args > 1)
1.169 + ret = test_file_download_setup(argv[1]);
1.170
1.171 - if ( !ret)
1.172 - g_debug("Error when running LiveTV setup test script!");
1.173 - else
1.174 - g_debug("LiveTV setup test script finished with success.");
1.175 + if (!ret)
1.176 + g_debug("Error when running LiveTV setup test script!");
1.177 + else
1.178 + g_debug("LiveTV setup test script finished with success.");
1.179
1.180 - return (0);
1.181 + return (0);
1.182 }
1.183 -