# HG changeset patch # User rosfran # Date 1178636747 -3600 # Node ID de71b8478b27682767a14b91fce71f47f6918582 # Parent 90bb7f60e0b960092a993f4df77729a46ac20b3e [svn r643] Added test to file local transfers, livetv common error setups, and program info utility functions. diff -r 90bb7f60e0b9 -r de71b8478b27 gmyth/tests/Makefile.am --- a/gmyth/tests/Makefile.am Tue May 08 15:32:18 2007 +0100 +++ b/gmyth/tests/Makefile.am Tue May 08 16:05:47 2007 +0100 @@ -27,7 +27,8 @@ gmyth_test_http \ gmyth_test_filetransfer \ gmyth_test_filelocal \ - gmyth_test_file_download + gmyth_test_file_download \ + gmyth_test_program_info TESTS = \ relink.py \ @@ -44,6 +45,7 @@ test_filelocal.py \ test_file_download.py \ test_livetv_stress.py \ + test_program_info.py \ coverage.py TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) @@ -84,6 +86,9 @@ gmyth_test_file_download_SOURCES = \ gmyth_test_file_download.c +gmyth_test_program_info_SOURCES = \ + gmyth_test_program_info.c + CLEANFILES = $(BUILT_SOURCES) \ *.gcda \ *.gcno \ diff -r 90bb7f60e0b9 -r de71b8478b27 gmyth/tests/coverage.py --- a/gmyth/tests/coverage.py Tue May 08 15:32:18 2007 +0100 +++ b/gmyth/tests/coverage.py Tue May 08 16:05:47 2007 +0100 @@ -13,7 +13,7 @@ return a.groups()[0] def remove_all_gcov_info(base_dir): - os.system('for gfile in `find ' + base_dir + ' -name \"*.gcov\" --print`; do rm -f $gfile; done') + os.system('for gfile in `find ' + base_dir + ' -name \"*.gcov\" -print`; do rm -f $gfile; done') def gen_cov_info(build_dir): # remove all the useless GCOV information diff -r 90bb7f60e0b9 -r de71b8478b27 gmyth/tests/gmyth_test_file_download.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/gmyth_test_file_download.c Tue May 08 16:05:47 2007 +0100 @@ -0,0 +1,112 @@ +#include + +#include "common.h" + +#include +#include +#include +#include +#include +#include + +#define URI_FILE_TRANSFER_DEFAULT "myth://192.168.3.165:6543/" + +static gboolean +test_file_download_setup( gchar *uri ) { + GMythFile *file = NULL; + GMythFileReadResult result; + gint64 num_bytes; + GByteArray *file_buffer = g_byte_array_new (); + gboolean ret = TRUE; + gboolean is_local = FALSE; + + if ( NULL == uri) + uri = g_strdup( URI_FILE_TRANSFER_DEFAULT ); + + GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri); + + GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri(uri); + + /* Check if the file is local to this specific client renderer, and tries to open + * a local connection + */ + if ( gmyth_uri_is_local_file(gmyth_uri)) { + g_debug( "Opening local file connection to download..."); + file = GMYTH_FILE(gmyth_file_local_new(backend_info)); + ret = gmyth_file_local_open( GMYTH_FILE_LOCAL( file ) ); + } else { + g_debug( "Opening remote file connection to download..."); + file = GMYTH_FILE(gmyth_file_transfer_new(backend_info)); + ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(file), uri); + } + + if (NULL == file) { + g_debug("FileTransfer is NULL"); + ret = FALSE; + goto init_failed; + } + + g_debug( "uri = %s", uri); + + if (ret == FALSE) { + g_debug("MythTV FileTransfer request failed when setting up socket connection!"); + goto init_failed; + } + + g_debug( "MythTV FileTransfer filesize = %lld", + num_bytes = gmyth_file_get_filesize( file ) ); + + is_local = gmyth_uri_is_local_file(gmyth_uri); + + do + { + + if ( is_local ) + result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(file), + file_buffer, + num_bytes, FALSE ); + else + result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(file), + file_buffer, + num_bytes, FALSE ); + + } while ( result == GMYTH_FILE_READ_OK ); + +init_failed: + + if ( file != NULL) + g_object_unref(file); + + if ( gmyth_uri != NULL) + g_object_unref( gmyth_uri); + + if ( backend_info != NULL) + g_object_unref( backend_info); + + return ret; + +} + +gint +main(gint args, const gchar **argv) { + gboolean ret = FALSE; + + g_type_init(); + + g_thread_init(NULL); + + fprintf(stdout, SYNC_STRING); + fflush(NULL); + getchar(); + + if ( args > 1) + ret = test_file_download_setup( argv[1]); + + if ( !ret) + g_debug("Error when running LiveTV setup test script!"); + else + g_debug("LiveTV setup test script finished with success."); + + return (0); +} + diff -r 90bb7f60e0b9 -r de71b8478b27 gmyth/tests/gmyth_test_program_info.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/gmyth_test_program_info.c Tue May 08 16:05:47 2007 +0100 @@ -0,0 +1,123 @@ +#include + +#include "common.h" + +#include +#include +#include +#include +#include + +#define URI_DEFAULT "myth://192.168.3.165:6543/livetv?channel=9" + +static gboolean +test_program_info_setup ( gchar *uri ) +{ + GMythLiveTV *livetv = NULL; + GMythStringList *str_list = NULL; + GMythProgramInfo *program_info = NULL; + + gchar *channel_name = NULL; + gboolean ret = TRUE; + gboolean live_tv = FALSE; + + if ( NULL == uri ) + uri = g_strdup( URI_DEFAULT ); + + GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri ); + + GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri (uri); + live_tv = gmyth_uri_is_livetv( gmyth_uri ); + if ( live_tv ) { + livetv = gmyth_livetv_new (backend_info); + + gchar* ch = gmyth_uri_get_channel_name( gmyth_uri ); + if ( ch != NULL ) + channel_name = ch; + + if (channel_name != NULL) { + if (gmyth_livetv_channel_name_setup (livetv, channel_name) == FALSE) { + g_debug("LiveTV setup felt down on error."); + ret = FALSE; + goto init_failed; + } + } else { + if (gmyth_livetv_setup (livetv) == FALSE) { + g_debug("LiveTV setup felt down on error"); + ret = FALSE; + goto init_failed; + } + } + } + + g_debug( "uri = %s", uri); + + if ( ret == FALSE ) { + g_debug("MythTV ProgramInfo request failed when setting up socket connection!"); + goto init_failed; + } + + g_return_val_if_fail( livetv->proginfo != NULL, FALSE ); + + g_debug( "Printing ProgramInfo... [%s]", gmyth_program_info_to_string( livetv->proginfo ) ); + + str_list = gmyth_program_info_to_string_list( livetv->proginfo, str_list ); + + g_return_val_if_fail( str_list != NULL && gmyth_string_list_length( str_list ) > 0, FALSE ); + + program_info = gmyth_program_info_from_string_list( str_list ); + + /* assert it IS the same program info */ + g_return_val_if_fail( gmyth_program_info_is_equals( program_info, livetv->proginfo ), FALSE ); + + program_info->title = g_string_assign( program_info->title, "Another RaNdOm Title..." ); + + /* assert it is not the same program info anymore */ + g_return_val_if_fail( !gmyth_program_info_is_equals( program_info, livetv->proginfo ), FALSE ); + +init_failed: + if ( str_list != NULL ) + g_object_unref( str_list ); + + if ( program_info != NULL ) + g_object_unref( program_info ); + + if ( livetv != NULL ) + g_object_unref(livetv); + + if ( gmyth_uri != NULL ) + g_object_unref( gmyth_uri ); + + return ret; + +} + +gint +main (gint args, const gchar **argv) +{ + gboolean ret; + + g_type_init (); + + g_thread_init (NULL); + + fprintf(stdout, SYNC_STRING); + fflush(NULL); + getchar(); + + if ( args > 1 ) + ret = test_program_info_setup ( argv[1] ); + else + ret = test_program_info_setup( NULL ); + + if ( !ret ) + g_debug ("Error when getting program info from the LiveTV instance!"); + else + g_debug ("LiveTV setup test script finished with success."); + + return(0); +} + + + + diff -r 90bb7f60e0b9 -r de71b8478b27 gmyth/tests/test_file_download.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/test_file_download.py Tue May 08 16:05:47 2007 +0100 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +#doc: test gmyth_file_transfer_* "read" methods + +from testing_tools import start, finish +import sys + +p = start('gmyth_test_file_download', ['myth://192.168.3.165:6543/1000_20070330144500.nuv']) + +sys.exit(finish(p)) diff -r 90bb7f60e0b9 -r de71b8478b27 gmyth/tests/test_main.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/test_main.py Tue May 08 16:05:47 2007 +0100 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +#doc: some gmyth_* testing methods + +from testing_tools import start, finish +import sys + +p = start('test', ['myth://192.168.3.165:6543/1000_20070330144500.nuv'], 2) + +sys.exit(finish(p)) diff -r 90bb7f60e0b9 -r de71b8478b27 gmyth/tests/test_program_info.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/test_program_info.py Tue May 08 16:05:47 2007 +0100 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +#doc: stress tests over gmyth_program_info_* methods + +from testing_tools import start, finish +import sys + +p = start('gmyth_test_program_info', ['myth://192.168.3.165:6543/livetv?channel=1'], 2) + +sys.exit(finish(p))