[svn r646] Added test and verifies for the installed tools. trunk
authorrosfran
Wed May 09 16:02:01 2007 +0100 (2007-05-09)
branchtrunk
changeset 640d22475d73fd5
parent 639 b2ebfaeb18c1
child 641 d917eb0698bd
[svn r646] Added test and verifies for the installed tools.
gmyth/tests/Makefile.am
gmyth/tests/gmyth_test_monitor_handler.c
gmyth/tests/test_monitor_handler.py
     1.1 --- a/gmyth/tests/Makefile.am	Wed May 09 16:01:14 2007 +0100
     1.2 +++ b/gmyth/tests/Makefile.am	Wed May 09 16:02:01 2007 +0100
     1.3 @@ -28,7 +28,8 @@
     1.4  	gmyth_test_filetransfer \
     1.5  	gmyth_test_filelocal \
     1.6  	gmyth_test_file_download \
     1.7 -	gmyth_test_program_info
     1.8 +	gmyth_test_program_info \
     1.9 +	gmyth_test_monitor_handler
    1.10  
    1.11  TESTS = \
    1.12  	relink.py \
    1.13 @@ -46,7 +47,12 @@
    1.14  	test_file_download.py \
    1.15  	test_livetv_stress.py \
    1.16  	test_program_info.py \
    1.17 +	test_monitor_handler.py
    1.18 +
    1.19 +if HAVE_GENHTML
    1.20 +TESTS += \
    1.21  	coverage.py
    1.22 +endif
    1.23  
    1.24  TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir)
    1.25  
    1.26 @@ -89,8 +95,16 @@
    1.27  gmyth_test_program_info_SOURCES = \
    1.28  	gmyth_test_program_info.c
    1.29  
    1.30 -CLEANFILES = $(BUILT_SOURCES) \
    1.31 +CLEANFILES = $(BUILT_SOURCES)
    1.32 +
    1.33 +if HAVE_GCOV
    1.34 +CLEANFILES += \
    1.35  	*.gcda \
    1.36  	*.gcno \
    1.37  	*.gcov
    1.38 +endif
    1.39  
    1.40 +if HAVE_GPROF
    1.41 +CLEANFILES += gmon.out
    1.42 +endif
    1.43 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gmyth/tests/gmyth_test_monitor_handler.c	Wed May 09 16:02:01 2007 +0100
     2.3 @@ -0,0 +1,156 @@
     2.4 +#include <glib-object.h>
     2.5 +
     2.6 +#include "common.h"
     2.7 +
     2.8 +#include <gmyth/gmyth_uri.h>
     2.9 +#include <gmyth/gmyth_backendinfo.h>
    2.10 +#include <gmyth/gmyth_livetv.h>
    2.11 +#include <gmyth/gmyth_monitor_handler.h>
    2.12 +#include <gmyth/gmyth_common.h>
    2.13 +
    2.14 +#define URI_DEFAULT	"myth://192.168.3.165:6543/livetv?channel=9"
    2.15 +
    2.16 +/**
    2.17 + * The GObject signal handler function, from which all status messages 
    2.18 + * from the Monitor Handler will be advertized, all time it receives
    2.19 + * LiveTV status messages from the MythTV backend
    2.20 + * 
    2.21 + * @param monitor a GMythMonitorHandler instance
    2.22 + * @param msg_code the MythTV's server numeric status code
    2.23 + * @param message the message's string description
    2.24 + * @param user_data pointer to the GMythLiveTV instance (NULL in the tests)
    2.25 + */
    2.26 +static void
    2.27 +gmyth_livetv_monitor_signal_handler (GMythMonitorHandler * monitor,
    2.28 +                                     gint msg_code, gchar * message,
    2.29 +                                     gpointer user_data)
    2.30 +{
    2.31 +    g_debug
    2.32 +        ("LIVETV Signal handler ( msg = %s, code = %d, live_tv param = %s, user_data = %s )\n",
    2.33 +         message, msg_code, "NULL",
    2.34 +         user_data != NULL ? "" : "NULL");
    2.35 +
    2.36 +}
    2.37 +
    2.38 +/**
    2.39 + * Starts the Monitor Handler to this GMythLiveTV session, in order
    2.40 + * to receive the status messages from the MythTV's backend server 
    2.41 + * 
    2.42 + * @param live_tv the GMythLiveTV instance
    2.43 + * 
    2.44 + * @return <code>true</code> if the Monitor Handler start-up process
    2.45 + * 	   had been concluded succcesfully 
    2.46 + */
    2.47 +static gboolean
    2.48 +gmyth_test_monitor_handler_start (GMythBackendInfo * backend_info, GMythMonitorHandler * * monitor)
    2.49 +{
    2.50 +
    2.51 +    gboolean res = TRUE;
    2.52 +
    2.53 +    if (*monitor != NULL)
    2.54 +    {
    2.55 +        g_object_unref (*monitor);
    2.56 +        *monitor = NULL;
    2.57 +    }
    2.58 +
    2.59 +    *monitor = gmyth_monitor_handler_new ();
    2.60 +
    2.61 +    res =
    2.62 +        gmyth_monitor_handler_open (*monitor,
    2.63 +                                    backend_info->hostname,
    2.64 +                                    backend_info->port);
    2.65 +
    2.66 +    if (res == TRUE)
    2.67 +    {
    2.68 +        g_debug
    2.69 +            ("Connect MythTV Monitor event socket! Trying to start the message handler...");
    2.70 +
    2.71 +        res = gmyth_monitor_handler_start (*monitor);
    2.72 +
    2.73 +        if (res)
    2.74 +        {
    2.75 +            g_debug
    2.76 +                ("MythTV Monitor event socket connected and listening!");
    2.77 +            g_signal_connect (G_OBJECT (*monitor),
    2.78 +                              "backend-events-handler",
    2.79 +                              (GCallback) gmyth_livetv_monitor_signal_handler,
    2.80 +                              NULL);
    2.81 +        }
    2.82 +        else
    2.83 +        {
    2.84 +            g_debug
    2.85 +                ("Problems when trying to start MythTV Monitor event socket!");
    2.86 +            goto error;
    2.87 +        }
    2.88 +    }
    2.89 +
    2.90 +  error:
    2.91 +    return res;
    2.92 +
    2.93 +}
    2.94 +
    2.95 +static gboolean
    2.96 +test_monitor_handler_setup ( gchar *uri )
    2.97 +{
    2.98 +  gboolean ret = TRUE;
    2.99 +  GMythMonitorHandler *monitor;
   2.100 +  
   2.101 +  if ( NULL == uri )
   2.102 +    uri = g_strdup( URI_DEFAULT );
   2.103 +
   2.104 +  GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri );
   2.105 +
   2.106 +  GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri (uri);
   2.107 +  g_debug( "uri = %s", uri);
   2.108 +
   2.109 +  ret = gmyth_test_monitor_handler_start( backend_info, &monitor );
   2.110 +
   2.111 +  if ( ret == FALSE )
   2.112 +  {
   2.113 +	g_debug( "MonitorHandler couldn't start!\n" );
   2.114 +	goto init_failed;
   2.115 +  }
   2.116 + 
   2.117 +init_failed:
   2.118 +    if ( monitor != NULL )
   2.119 +        g_object_unref(monitor);
   2.120 +  
   2.121 +     if ( gmyth_uri != NULL )
   2.122 +        g_object_unref( gmyth_uri );
   2.123 +
   2.124 +    if ( backend_info != NULL )
   2.125 +       g_object_unref( backend_info );
   2.126 +
   2.127 +    return ret;
   2.128 +    
   2.129 +}
   2.130 +
   2.131 +gint
   2.132 +main (gint args, const gchar **argv)
   2.133 +{
   2.134 +    gboolean ret;
   2.135 +
   2.136 +    g_type_init ();
   2.137 +    
   2.138 +    g_thread_init (NULL);
   2.139 +
   2.140 +    fprintf(stdout, SYNC_STRING);
   2.141 +    fflush(NULL);
   2.142 +    getchar();
   2.143 +    
   2.144 +    if ( args > 1 )
   2.145 +	ret = test_monitor_handler_setup ( argv[1] );
   2.146 +    else
   2.147 +    	ret = test_monitor_handler_setup ( NULL );
   2.148 +    
   2.149 +    if ( !ret )
   2.150 +        g_debug ("Error when running Monitor Handler setup test script!");
   2.151 +    else
   2.152 +        g_debug ("MonitorHandler setup test script setup with success.");
   2.153 +
   2.154 +    return(0);
   2.155 +}
   2.156 +
   2.157 +
   2.158 +
   2.159 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/gmyth/tests/test_monitor_handler.py	Wed May 09 16:02:01 2007 +0100
     3.3 @@ -0,0 +1,18 @@
     3.4 +#!/usr/bin/python
     3.5 +
     3.6 +#doc: stress tests over gmyth_monitor_handler_* methods
     3.7 +
     3.8 +from testing_tools import start, finish
     3.9 +import sys
    3.10 +
    3.11 +p = start('gmyth_test_monitor_handler', ['myth://192.168.3.165:6543/livetv?channel=1'], 2)
    3.12 +
    3.13 +finish(p)
    3.14 +
    3.15 +p = start('gmyth_test_monitor_handler', ['myth://192.168.3.165:6543/livetv?channel=1'], 2)
    3.16 +
    3.17 +finish(p)
    3.18 +
    3.19 +p = start('gmyth_test_monitor_handler', ['myth://192.168.3.165:6543/livetv?channel=1'], 2)
    3.20 +
    3.21 +sys.exit(finish(p))