[svn r643] Added test to file local transfers, livetv common error setups, and program info utility functions.
1.1 --- a/gmyth/tests/Makefile.am Tue May 08 15:32:18 2007 +0100
1.2 +++ b/gmyth/tests/Makefile.am Tue May 08 16:05:47 2007 +0100
1.3 @@ -27,7 +27,8 @@
1.4 gmyth_test_http \
1.5 gmyth_test_filetransfer \
1.6 gmyth_test_filelocal \
1.7 - gmyth_test_file_download
1.8 + gmyth_test_file_download \
1.9 + gmyth_test_program_info
1.10
1.11 TESTS = \
1.12 relink.py \
1.13 @@ -44,6 +45,7 @@
1.14 test_filelocal.py \
1.15 test_file_download.py \
1.16 test_livetv_stress.py \
1.17 + test_program_info.py \
1.18 coverage.py
1.19
1.20 TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir)
1.21 @@ -84,6 +86,9 @@
1.22 gmyth_test_file_download_SOURCES = \
1.23 gmyth_test_file_download.c
1.24
1.25 +gmyth_test_program_info_SOURCES = \
1.26 + gmyth_test_program_info.c
1.27 +
1.28 CLEANFILES = $(BUILT_SOURCES) \
1.29 *.gcda \
1.30 *.gcno \
2.1 --- a/gmyth/tests/coverage.py Tue May 08 15:32:18 2007 +0100
2.2 +++ b/gmyth/tests/coverage.py Tue May 08 16:05:47 2007 +0100
2.3 @@ -13,7 +13,7 @@
2.4 return a.groups()[0]
2.5
2.6 def remove_all_gcov_info(base_dir):
2.7 - os.system('for gfile in `find ' + base_dir + ' -name \"*.gcov\" --print`; do rm -f $gfile; done')
2.8 + os.system('for gfile in `find ' + base_dir + ' -name \"*.gcov\" -print`; do rm -f $gfile; done')
2.9
2.10 def gen_cov_info(build_dir):
2.11 # remove all the useless GCOV information
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/gmyth/tests/gmyth_test_file_download.c Tue May 08 16:05:47 2007 +0100
3.3 @@ -0,0 +1,112 @@
3.4 +#include <glib-object.h>
3.5 +
3.6 +#include "common.h"
3.7 +
3.8 +#include <gmyth/gmyth_uri.h>
3.9 +#include <gmyth/gmyth_backendinfo.h>
3.10 +#include <gmyth/gmyth_file.h>
3.11 +#include <gmyth/gmyth_file_transfer.h>
3.12 +#include <gmyth/gmyth_file_local.h>
3.13 +#include <gmyth/gmyth_common.h>
3.14 +
3.15 +#define URI_FILE_TRANSFER_DEFAULT "myth://192.168.3.165:6543/"
3.16 +
3.17 +static gboolean
3.18 +test_file_download_setup( gchar *uri ) {
3.19 + GMythFile *file = NULL;
3.20 + GMythFileReadResult result;
3.21 + gint64 num_bytes;
3.22 + GByteArray *file_buffer = g_byte_array_new ();
3.23 + gboolean ret = TRUE;
3.24 + gboolean is_local = FALSE;
3.25 +
3.26 + if ( NULL == uri)
3.27 + uri = g_strdup( URI_FILE_TRANSFER_DEFAULT );
3.28 +
3.29 + GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri);
3.30 +
3.31 + GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri(uri);
3.32 +
3.33 + /* Check if the file is local to this specific client renderer, and tries to open
3.34 + * a local connection
3.35 + */
3.36 + if ( gmyth_uri_is_local_file(gmyth_uri)) {
3.37 + g_debug( "Opening local file connection to download...");
3.38 + file = GMYTH_FILE(gmyth_file_local_new(backend_info));
3.39 + ret = gmyth_file_local_open( GMYTH_FILE_LOCAL( file ) );
3.40 + } else {
3.41 + g_debug( "Opening remote file connection to download...");
3.42 + file = GMYTH_FILE(gmyth_file_transfer_new(backend_info));
3.43 + ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(file), uri);
3.44 + }
3.45 +
3.46 + if (NULL == file) {
3.47 + g_debug("FileTransfer is NULL");
3.48 + ret = FALSE;
3.49 + goto init_failed;
3.50 + }
3.51 +
3.52 + g_debug( "uri = %s", uri);
3.53 +
3.54 + if (ret == FALSE) {
3.55 + g_debug("MythTV FileTransfer request failed when setting up socket connection!");
3.56 + goto init_failed;
3.57 + }
3.58 +
3.59 + g_debug( "MythTV FileTransfer filesize = %lld",
3.60 + num_bytes = gmyth_file_get_filesize( file ) );
3.61 +
3.62 + is_local = gmyth_uri_is_local_file(gmyth_uri);
3.63 +
3.64 + do
3.65 + {
3.66 +
3.67 + if ( is_local )
3.68 + result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(file),
3.69 + file_buffer,
3.70 + num_bytes, FALSE );
3.71 + else
3.72 + result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(file),
3.73 + file_buffer,
3.74 + num_bytes, FALSE );
3.75 +
3.76 + } while ( result == GMYTH_FILE_READ_OK );
3.77 +
3.78 +init_failed:
3.79 +
3.80 + if ( file != NULL)
3.81 + g_object_unref(file);
3.82 +
3.83 + if ( gmyth_uri != NULL)
3.84 + g_object_unref( gmyth_uri);
3.85 +
3.86 + if ( backend_info != NULL)
3.87 + g_object_unref( backend_info);
3.88 +
3.89 + return ret;
3.90 +
3.91 +}
3.92 +
3.93 +gint
3.94 +main(gint args, const gchar **argv) {
3.95 + gboolean ret = FALSE;
3.96 +
3.97 + g_type_init();
3.98 +
3.99 + g_thread_init(NULL);
3.100 +
3.101 + fprintf(stdout, SYNC_STRING);
3.102 + fflush(NULL);
3.103 + getchar();
3.104 +
3.105 + if ( args > 1)
3.106 + ret = test_file_download_setup( argv[1]);
3.107 +
3.108 + if ( !ret)
3.109 + g_debug("Error when running LiveTV setup test script!");
3.110 + else
3.111 + g_debug("LiveTV setup test script finished with success.");
3.112 +
3.113 + return (0);
3.114 +}
3.115 +
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/gmyth/tests/gmyth_test_program_info.c Tue May 08 16:05:47 2007 +0100
4.3 @@ -0,0 +1,123 @@
4.4 +#include <glib-object.h>
4.5 +
4.6 +#include "common.h"
4.7 +
4.8 +#include <gmyth/gmyth_uri.h>
4.9 +#include <gmyth/gmyth_backendinfo.h>
4.10 +#include <gmyth/gmyth_livetv.h>
4.11 +#include <gmyth/gmyth_programinfo.h>
4.12 +#include <gmyth/gmyth_common.h>
4.13 +
4.14 +#define URI_DEFAULT "myth://192.168.3.165:6543/livetv?channel=9"
4.15 +
4.16 +static gboolean
4.17 +test_program_info_setup ( gchar *uri )
4.18 +{
4.19 + GMythLiveTV *livetv = NULL;
4.20 + GMythStringList *str_list = NULL;
4.21 + GMythProgramInfo *program_info = NULL;
4.22 +
4.23 + gchar *channel_name = NULL;
4.24 + gboolean ret = TRUE;
4.25 + gboolean live_tv = FALSE;
4.26 +
4.27 + if ( NULL == uri )
4.28 + uri = g_strdup( URI_DEFAULT );
4.29 +
4.30 + GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri );
4.31 +
4.32 + GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri (uri);
4.33 + live_tv = gmyth_uri_is_livetv( gmyth_uri );
4.34 + if ( live_tv ) {
4.35 + livetv = gmyth_livetv_new (backend_info);
4.36 +
4.37 + gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
4.38 + if ( ch != NULL )
4.39 + channel_name = ch;
4.40 +
4.41 + if (channel_name != NULL) {
4.42 + if (gmyth_livetv_channel_name_setup (livetv, channel_name) == FALSE) {
4.43 + g_debug("LiveTV setup felt down on error.");
4.44 + ret = FALSE;
4.45 + goto init_failed;
4.46 + }
4.47 + } else {
4.48 + if (gmyth_livetv_setup (livetv) == FALSE) {
4.49 + g_debug("LiveTV setup felt down on error");
4.50 + ret = FALSE;
4.51 + goto init_failed;
4.52 + }
4.53 + }
4.54 + }
4.55 +
4.56 + g_debug( "uri = %s", uri);
4.57 +
4.58 + if ( ret == FALSE ) {
4.59 + g_debug("MythTV ProgramInfo request failed when setting up socket connection!");
4.60 + goto init_failed;
4.61 + }
4.62 +
4.63 + g_return_val_if_fail( livetv->proginfo != NULL, FALSE );
4.64 +
4.65 + g_debug( "Printing ProgramInfo... [%s]", gmyth_program_info_to_string( livetv->proginfo ) );
4.66 +
4.67 + str_list = gmyth_program_info_to_string_list( livetv->proginfo, str_list );
4.68 +
4.69 + g_return_val_if_fail( str_list != NULL && gmyth_string_list_length( str_list ) > 0, FALSE );
4.70 +
4.71 + program_info = gmyth_program_info_from_string_list( str_list );
4.72 +
4.73 + /* assert it IS the same program info */
4.74 + g_return_val_if_fail( gmyth_program_info_is_equals( program_info, livetv->proginfo ), FALSE );
4.75 +
4.76 + program_info->title = g_string_assign( program_info->title, "Another RaNdOm Title..." );
4.77 +
4.78 + /* assert it is not the same program info anymore */
4.79 + g_return_val_if_fail( !gmyth_program_info_is_equals( program_info, livetv->proginfo ), FALSE );
4.80 +
4.81 +init_failed:
4.82 + if ( str_list != NULL )
4.83 + g_object_unref( str_list );
4.84 +
4.85 + if ( program_info != NULL )
4.86 + g_object_unref( program_info );
4.87 +
4.88 + if ( livetv != NULL )
4.89 + g_object_unref(livetv);
4.90 +
4.91 + if ( gmyth_uri != NULL )
4.92 + g_object_unref( gmyth_uri );
4.93 +
4.94 + return ret;
4.95 +
4.96 +}
4.97 +
4.98 +gint
4.99 +main (gint args, const gchar **argv)
4.100 +{
4.101 + gboolean ret;
4.102 +
4.103 + g_type_init ();
4.104 +
4.105 + g_thread_init (NULL);
4.106 +
4.107 + fprintf(stdout, SYNC_STRING);
4.108 + fflush(NULL);
4.109 + getchar();
4.110 +
4.111 + if ( args > 1 )
4.112 + ret = test_program_info_setup ( argv[1] );
4.113 + else
4.114 + ret = test_program_info_setup( NULL );
4.115 +
4.116 + if ( !ret )
4.117 + g_debug ("Error when getting program info from the LiveTV instance!");
4.118 + else
4.119 + g_debug ("LiveTV setup test script finished with success.");
4.120 +
4.121 + return(0);
4.122 +}
4.123 +
4.124 +
4.125 +
4.126 +
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/gmyth/tests/test_file_download.py Tue May 08 16:05:47 2007 +0100
5.3 @@ -0,0 +1,10 @@
5.4 +#!/usr/bin/python
5.5 +
5.6 +#doc: test gmyth_file_transfer_* "read" methods
5.7 +
5.8 +from testing_tools import start, finish
5.9 +import sys
5.10 +
5.11 +p = start('gmyth_test_file_download', ['myth://192.168.3.165:6543/1000_20070330144500.nuv'])
5.12 +
5.13 +sys.exit(finish(p))
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/gmyth/tests/test_main.py Tue May 08 16:05:47 2007 +0100
6.3 @@ -0,0 +1,10 @@
6.4 +#!/usr/bin/python
6.5 +
6.6 +#doc: some gmyth_* testing methods
6.7 +
6.8 +from testing_tools import start, finish
6.9 +import sys
6.10 +
6.11 +p = start('test', ['myth://192.168.3.165:6543/1000_20070330144500.nuv'], 2)
6.12 +
6.13 +sys.exit(finish(p))
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/gmyth/tests/test_program_info.py Tue May 08 16:05:47 2007 +0100
7.3 @@ -0,0 +1,10 @@
7.4 +#!/usr/bin/python
7.5 +
7.6 +#doc: stress tests over gmyth_program_info_* methods
7.7 +
7.8 +from testing_tools import start, finish
7.9 +import sys
7.10 +
7.11 +p = start('gmyth_test_program_info', ['myth://192.168.3.165:6543/livetv?channel=1'], 2)
7.12 +
7.13 +sys.exit(finish(p))