branches/gmyth-0.1b/tests/main.c
branchtrunk
changeset 358 06009f72d657
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/branches/gmyth-0.1b/tests/main.c	Tue Feb 13 23:17:35 2007 +0000
     1.3 @@ -0,0 +1,49 @@
     1.4 +#include <glib-object.h>
     1.5 +#include "gmyth.h"
     1.6 +
     1.7 +int
     1.8 +main (int args, const char **argv)
     1.9 +{
    1.10 +    const char *uri = argv[1];
    1.11 +    GMythURI *gmyth_uri = NULL;
    1.12 +    gboolean res;
    1.13 +    GMythBackendInfo *backend_info;
    1.14 +    g_type_init ();
    1.15 +    g_thread_init (NULL);
    1.16 +
    1.17 +    backend_info = gmyth_backend_info_new ();
    1.18 +    gmyth_uri = gmyth_uri_new_with_value (uri);
    1.19 +
    1.20 +    gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (gmyth_uri));
    1.21 +    gmyth_backend_info_set_port (backend_info, gmyth_uri_get_port (gmyth_uri));
    1.22 +    
    1.23 +    res = gmyth_util_file_exists (backend_info, uri);
    1.24 +    if (res == FALSE) {
    1.25 +        g_debug ("file not exists");
    1.26 +        return -1;
    1.27 +    }
    1.28 +    GMythFileTransfer *file_transfer = gmyth_file_transfer_new ();
    1.29 +    GString *hostname = g_string_new (uri);
    1.30 +    res = gmyth_file_transfer_open (file_transfer, hostname);
    1.31 +    if (res == FALSE) {
    1.32 +        g_debug ("Fail to open server");
    1.33 +        return  -1;
    1.34 +    }
    1.35 +
    1.36 +    guint64 filesize = gmyth_file_transfer_get_filesize (file_transfer);
    1.37 +    if (filesize <= 0) {
    1.38 +        g_debug ("filesize is 0");
    1.39 +        return -1;
    1.40 +    }
    1.41 +
    1.42 +    GByteArray *data = g_byte_array_new ();
    1.43 +    guint num = gmyth_file_transfer_read (file_transfer, data, filesize, FALSE);
    1.44 +    g_debug ("read %d bytes", num);
    1.45 +
    1.46 +    g_byte_array_free (data, TRUE);
    1.47 +    g_object_unref (file_transfer);
    1.48 +    g_object_unref (gmyth_uri);
    1.49 +    g_string_free (hostname, TRUE);
    1.50 +
    1.51 +    return 0;    
    1.52 +}