diff -r 000000000000 -r 22a17127789e branches/gmyth-0.1b/tests/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/branches/gmyth-0.1b/tests/main.c Thu Feb 01 18:42:01 2007 +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; +}