branches/gmyth-0.1b/tests/gmyth_test_connection.c
branchtrunk
changeset 320 22a17127789e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/branches/gmyth-0.1b/tests/gmyth_test_connection.c	Thu Feb 01 18:42:01 2007 +0000
     1.3 @@ -0,0 +1,74 @@
     1.4 +#include <glib-object.h>
     1.5 +
     1.6 +#include "gmyth_uri.h"
     1.7 +#include "gmyth_backendinfo.h"
     1.8 +#include "gmyth_socket.h"
     1.9 +#include "gmyth_query.h"
    1.10 +
    1.11 +static gboolean
    1.12 +test_backend_connection1 (GMythBackendInfo *backend_info)
    1.13 +{
    1.14 +    GMythSocket *socket = gmyth_socket_new ();
    1.15 +    if (gmyth_socket_connect_with_timeout (socket, 
    1.16 +	    gmyth_backend_info_get_hostname (backend_info),
    1.17 +	    gmyth_backend_info_get_port (backend_info), 4) == TRUE) {
    1.18 +	g_debug ("Socket connection success");
    1.19 +	return TRUE;
    1.20 +    } else {
    1.21 +	g_debug ("Connection failed");
    1.22 +	return FALSE;
    1.23 +    }
    1.24 +}
    1.25 +
    1.26 +static gboolean
    1.27 +test_backend_connection2 (GMythBackendInfo *backend_info)
    1.28 +{
    1.29 +    GMythSocket *socket = gmyth_socket_new ();
    1.30 +    if (gmyth_socket_connect_to_backend (socket,
    1.31 +	    gmyth_backend_info_get_hostname (backend_info),
    1.32 +	    gmyth_backend_info_get_port (backend_info), TRUE) == TRUE) {
    1.33 +
    1.34 +		    
    1.35 +	g_debug ("Backend socket connection success");
    1.36 +	return TRUE;
    1.37 +    } else {
    1.38 +	g_debug ("Connection failed");
    1.39 +	return FALSE;
    1.40 +    }
    1.41 +}
    1.42 +
    1.43 +static gboolean
    1.44 +test_mysql_connection1 (GMythBackendInfo *backend_info)
    1.45 +{
    1.46 +    GMythQuery *query = gmyth_query_new ();
    1.47 +
    1.48 +    if (gmyth_query_connect_with_timeout (query, backend_info, 3) == TRUE) {
    1.49 +	g_debug ("Mysql connection success");
    1.50 +	return TRUE;
    1.51 +    } else {
    1.52 +	g_debug ("Mysql connection failed");
    1.53 +	return FALSE;
    1.54 +    }
    1.55 +       
    1.56 +}
    1.57 +
    1.58 +
    1.59 +int
    1.60 +main (int args, const char **argv)
    1.61 +{
    1.62 +    const char* uri = argv[1];
    1.63 +
    1.64 +    GMythBackendInfo *backend_info;
    1.65 +    g_type_init ();
    1.66 +    //g_thread_init (NULL);
    1.67 +
    1.68 +    backend_info = gmyth_backend_info_new_with_uri (argv[1]);
    1.69 +
    1.70 +    test_backend_connection1 (backend_info);
    1.71 +    test_backend_connection2 (backend_info);
    1.72 +    test_mysql_connection1 (backend_info);
    1.73 +}
    1.74 +
    1.75 +
    1.76 +
    1.77 +