# HG changeset patch # User renatofilho # Date 1164909294 0 # Node ID 680e5d40ff1a2f020140a4392d6adcdd9e2a88fa # Parent 5095b85ff808731e15f09e69e535f5f9292ccad3 [svn r149] test file diff -r 5095b85ff808 -r 680e5d40ff1a gmyth/configure.ac --- a/gmyth/configure.ac Thu Nov 30 17:49:08 2006 +0000 +++ b/gmyth/configure.ac Thu Nov 30 17:54:54 2006 +0000 @@ -213,6 +213,7 @@ AC_OUTPUT([ Makefile src/Makefile +tests/Makefile gmyth.pc]) if test x"$enable_debug" != xno; then diff -r 5095b85ff808 -r 680e5d40ff1a gmyth/tests/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/Makefile.am Thu Nov 30 17:54:54 2006 +0000 @@ -0,0 +1,18 @@ +noinst_PROGRAMS = \ + test + +TESTS = \ + test + +test_SOURCES = \ + main.c + +test_LDADD = \ + $(MYSQL_LIBS) \ + $(top_builddir)/src/libgmyth.la + +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/src \ + $(MYSQL_CFLAGS) \ + $(GLIB_CFLAGS) diff -r 5095b85ff808 -r 680e5d40ff1a gmyth/tests/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/main.c Thu Nov 30 17:54:54 2006 +0000 @@ -0,0 +1,49 @@ +#include +#include "gmyth.h" + +int +main (int args, const char **argv) +{ + const char *uri = argv[1]; + GMythURI *gmyth_uri = NULL; + gboolean res; + GMythBackendInfo *backend_info; + g_type_init (); + g_thread_init (NULL); + + backend_info = gmyth_backend_info_new (); + gmyth_uri = gmyth_uri_new_with_value (uri); + + gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (gmyth_uri)); + gmyth_backend_info_set_port (backend_info, gmyth_uri_get_port (gmyth_uri)); + + res = gmyth_util_file_exists (backend_info, uri); + if (res == FALSE) { + g_debug ("file not exists"); + return -1; + } + GMythFileTransfer *file_transfer = gmyth_file_transfer_new (); + GString *hostname = g_string_new (uri); + res = gmyth_file_transfer_open (file_transfer, hostname); + if (res == FALSE) { + g_debug ("Fail to open server"); + return -1; + } + + guint64 filesize = gmyth_file_transfer_get_filesize (file_transfer); + if (filesize <= 0) { + g_debug ("filesize is 0"); + return -1; + } + + GByteArray *data = g_byte_array_new (); + guint num = gmyth_file_transfer_read (file_transfer, data, filesize, FALSE); + g_debug ("read %d bytes", num); + + g_byte_array_free (data, TRUE); + g_object_unref (file_transfer); + g_object_unref (gmyth_uri); + g_string_free (hostname, TRUE); + + return 0; +} diff -r 5095b85ff808 -r 680e5d40ff1a gmyth/tests/test_file_exists.c --- a/gmyth/tests/test_file_exists.c Thu Nov 30 17:49:08 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ - -#include - -#include "gmyth_util.h" -#include "gmyth_backendinfo.h" - -int -main (int args, const char **argv) -{ - const char *filename = argv[1]; - - gboolean res; - GMythBackendInfo *backend_info; - - g_type_init (); - - backend_info = gmyth_backend_info_new (); - - gmyth_backend_info_set_hostname (backend_info, "127.0.0.1"); - gmyth_backend_info_set_port (backend_info, 6543); - - g_print ("XXXXXXXX Testing if file %s exists in backend 127.0.0.1\n", filename); - - res = gmyth_util_file_exists (backend_info, filename); - - g_print ("XXXXXXXX Result is: %d\n", res); - - return 0; -}