[svn r149] test file trunk
authorrenatofilho
Thu Nov 30 17:54:54 2006 +0000 (2006-11-30)
branchtrunk
changeset 148680e5d40ff1a
parent 147 5095b85ff808
child 149 4b1889efb573
[svn r149] test file
gmyth/configure.ac
gmyth/tests/Makefile.am
gmyth/tests/main.c
gmyth/tests/test_file_exists.c
     1.1 --- a/gmyth/configure.ac	Thu Nov 30 17:49:08 2006 +0000
     1.2 +++ b/gmyth/configure.ac	Thu Nov 30 17:54:54 2006 +0000
     1.3 @@ -213,6 +213,7 @@
     1.4  AC_OUTPUT([
     1.5  Makefile
     1.6  src/Makefile
     1.7 +tests/Makefile
     1.8  gmyth.pc])
     1.9  
    1.10  if test x"$enable_debug" != xno; then
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gmyth/tests/Makefile.am	Thu Nov 30 17:54:54 2006 +0000
     2.3 @@ -0,0 +1,18 @@
     2.4 +noinst_PROGRAMS = \
     2.5 +	test
     2.6 +
     2.7 +TESTS = \
     2.8 +	test
     2.9 +
    2.10 +test_SOURCES = \
    2.11 +	main.c
    2.12 +
    2.13 +test_LDADD = \
    2.14 +	$(MYSQL_LIBS) \
    2.15 +	$(top_builddir)/src/libgmyth.la
    2.16 +
    2.17 +AM_CPPFLAGS = \
    2.18 +	-I$(top_srcdir) \
    2.19 +	-I$(top_srcdir)/src \
    2.20 +	$(MYSQL_CFLAGS) \
    2.21 +	$(GLIB_CFLAGS)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/gmyth/tests/main.c	Thu Nov 30 17:54:54 2006 +0000
     3.3 @@ -0,0 +1,49 @@
     3.4 +#include <glib-object.h>
     3.5 +#include "gmyth.h"
     3.6 +
     3.7 +int
     3.8 +main (int args, const char **argv)
     3.9 +{
    3.10 +    const char *uri = argv[1];
    3.11 +    GMythURI *gmyth_uri = NULL;
    3.12 +    gboolean res;
    3.13 +    GMythBackendInfo *backend_info;
    3.14 +    g_type_init ();
    3.15 +    g_thread_init (NULL);
    3.16 +
    3.17 +    backend_info = gmyth_backend_info_new ();
    3.18 +    gmyth_uri = gmyth_uri_new_with_value (uri);
    3.19 +
    3.20 +    gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (gmyth_uri));
    3.21 +    gmyth_backend_info_set_port (backend_info, gmyth_uri_get_port (gmyth_uri));
    3.22 +    
    3.23 +    res = gmyth_util_file_exists (backend_info, uri);
    3.24 +    if (res == FALSE) {
    3.25 +        g_debug ("file not exists");
    3.26 +        return -1;
    3.27 +    }
    3.28 +    GMythFileTransfer *file_transfer = gmyth_file_transfer_new ();
    3.29 +    GString *hostname = g_string_new (uri);
    3.30 +    res = gmyth_file_transfer_open (file_transfer, hostname);
    3.31 +    if (res == FALSE) {
    3.32 +        g_debug ("Fail to open server");
    3.33 +        return  -1;
    3.34 +    }
    3.35 +
    3.36 +    guint64 filesize = gmyth_file_transfer_get_filesize (file_transfer);
    3.37 +    if (filesize <= 0) {
    3.38 +        g_debug ("filesize is 0");
    3.39 +        return -1;
    3.40 +    }
    3.41 +
    3.42 +    GByteArray *data = g_byte_array_new ();
    3.43 +    guint num = gmyth_file_transfer_read (file_transfer, data, filesize, FALSE);
    3.44 +    g_debug ("read %d bytes", num);
    3.45 +
    3.46 +    g_byte_array_free (data, TRUE);
    3.47 +    g_object_unref (file_transfer);
    3.48 +    g_object_unref (gmyth_uri);
    3.49 +    g_string_free (hostname, TRUE);
    3.50 +
    3.51 +    return 0;    
    3.52 +}
     4.1 --- a/gmyth/tests/test_file_exists.c	Thu Nov 30 17:49:08 2006 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,29 +0,0 @@
     4.4 -
     4.5 -#include <glib-object.h>
     4.6 -
     4.7 -#include "gmyth_util.h"
     4.8 -#include "gmyth_backendinfo.h"
     4.9 -
    4.10 -int
    4.11 -main (int args, const char **argv)
    4.12 -{
    4.13 -    const char *filename = argv[1];
    4.14 -
    4.15 -    gboolean res;
    4.16 -    GMythBackendInfo *backend_info;
    4.17 -
    4.18 -    g_type_init ();
    4.19 -
    4.20 -    backend_info = gmyth_backend_info_new ();
    4.21 -
    4.22 -    gmyth_backend_info_set_hostname (backend_info, "127.0.0.1");
    4.23 -    gmyth_backend_info_set_port (backend_info, 6543);
    4.24 -    
    4.25 -    g_print ("XXXXXXXX Testing if file %s exists in backend 127.0.0.1\n", filename);
    4.26 -    
    4.27 -    res = gmyth_util_file_exists (backend_info, filename);
    4.28 -
    4.29 -    g_print ("XXXXXXXX Result is: %d\n", res);
    4.30 -
    4.31 -    return 0;    
    4.32 -}