gmyth/tests/gmyth_test_program_info.c
author renatofilho
Fri May 25 18:22:59 2007 +0100 (2007-05-25)
branchtrunk
changeset 714 03f2acbda6b1
child 750 312d6bc514f3
permissions -rw-r--r--
[svn r720] try parse newsegment with byte 0
     1 #include <glib-object.h>
     2 
     3 #include "common.h"
     4 
     5 #include <gmyth/gmyth_uri.h>
     6 #include <gmyth/gmyth_backendinfo.h>
     7 #include <gmyth/gmyth_livetv.h>
     8 #include <gmyth/gmyth_programinfo.h>
     9 #include <gmyth/gmyth_common.h>
    10 
    11 #define URI_DEFAULT	"myth://192.168.3.165:6543/livetv?channel=9"
    12 
    13 static gboolean
    14 test_program_info_setup ( gchar *uri )
    15 {
    16   GMythLiveTV *livetv = NULL;
    17   GMythStringList *str_list = NULL;
    18   GMythProgramInfo *program_info = NULL;
    19 
    20   gchar *channel_name = NULL;
    21   gboolean ret = TRUE;
    22   gboolean live_tv = FALSE;
    23   
    24   if ( NULL == uri )
    25     uri = g_strdup( URI_DEFAULT );
    26 
    27   GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri );
    28 
    29   GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri (uri);
    30   live_tv = gmyth_uri_is_livetv( gmyth_uri );
    31   if ( live_tv ) {
    32     livetv = gmyth_livetv_new (backend_info);
    33     
    34     gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
    35     if ( ch != NULL )
    36         channel_name = ch;
    37         
    38     if (channel_name != NULL) {
    39       if (gmyth_livetv_channel_name_setup (livetv, channel_name) == FALSE) {
    40         g_debug("LiveTV setup felt down on error.");
    41         ret = FALSE;
    42         goto init_failed;
    43       }
    44     } else {
    45       if (gmyth_livetv_setup (livetv) == FALSE) {
    46         g_debug("LiveTV setup felt down on error");
    47         ret = FALSE;
    48         goto init_failed;
    49       }
    50     }
    51   }
    52 
    53   g_debug( "uri = %s", uri);
    54 
    55   if ( ret == FALSE ) {
    56       g_debug("MythTV ProgramInfo request failed when setting up socket connection!");
    57       goto init_failed;
    58   }
    59 
    60   g_return_val_if_fail( livetv->proginfo != NULL, FALSE );
    61 
    62   g_debug( "Printing  ProgramInfo... [%s]", gmyth_program_info_to_string( livetv->proginfo ) );
    63 
    64   str_list = gmyth_program_info_to_string_list( livetv->proginfo, str_list );
    65 
    66   g_return_val_if_fail( str_list != NULL && gmyth_string_list_length( str_list ) > 0, FALSE );
    67 
    68   program_info = gmyth_program_info_from_string_list( str_list );
    69 
    70  /* assert it IS the same program info */
    71   g_return_val_if_fail( gmyth_program_info_is_equals( program_info, livetv->proginfo ), FALSE );
    72 
    73   program_info->title = g_string_assign( program_info->title, "Another RaNdOm Title..." );
    74 
    75   /* assert it is not the same program info anymore */
    76   g_return_val_if_fail( !gmyth_program_info_is_equals( program_info, livetv->proginfo ), FALSE );
    77 
    78 init_failed:
    79     if ( str_list != NULL )
    80     	g_object_unref( str_list );
    81 
    82     if ( program_info != NULL )
    83     	g_object_unref( program_info );
    84 
    85     if ( livetv != NULL )
    86         g_object_unref(livetv);
    87  
    88     if ( gmyth_uri != NULL )
    89         g_object_unref( gmyth_uri );
    90 
    91     return ret;
    92     
    93 }
    94 
    95 gint
    96 main (gint args, const gchar **argv)
    97 {
    98     gboolean ret;
    99 
   100     g_type_init ();
   101     
   102     g_thread_init (NULL);
   103 
   104     fprintf(stdout, SYNC_STRING);
   105     fflush(NULL);
   106     getchar();
   107     
   108     if ( args > 1 )
   109 	ret = test_program_info_setup ( argv[1] );
   110     else
   111     	ret = test_program_info_setup( NULL );
   112     
   113     if ( !ret )
   114         g_debug ("Error when getting program info from the LiveTV instance!");
   115     else
   116         g_debug ("LiveTV setup test script finished with success.");
   117 
   118     return(0);
   119 }
   120 
   121 
   122 
   123