summaryrefslogtreecommitdiff
path: root/tests/test_remotefile.c
blob: 303e32bf022207cbdd1cead2e92af333da7e92b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <dapi/comm.h>
#include <dapi/calls.h>

int main()
    {
    char* local;
    int ok;
    DapiConnection* conn = dapi_connectAndInit();
    if( conn == NULL )
        {
        fprintf( stderr, "Cannot connect!\n" );
        return 1;
        }
    local = dapi_LocalFile_Window( conn, "http://kde.org", "",  0, 0 ); /* no download, should fail */
    printf( "Local file1: %s - %s\n", local ? local : "?", local ? "Failed" : "Ok" );
    if( local )
        free( local );
    local = dapi_LocalFile_Window( conn, "http://kde.org", "", 1, 0 );
    printf( "Local file2: %s\n", local != NULL ? local : "Failed" );
    if( local != NULL )
        {
        ok = dapi_UploadFile_Window( conn, local, "http://kde.org", 0, 0 ); /* will fail */
        printf( "Upload2: %s\n", ok ? "Ok - ???" : "Failed - ok" );
        ok = dapi_RemoveTemporaryLocalFile( conn, local );
        printf( "Temporary2: %s\n", ok ? "Ok" : "Failed" );
        free( local );
        }
    if(system( "touch /tmp/remotefiletest.txt" ))
	return perror("system()"), 1;
    /* local temporary will be ignored */
    local = dapi_LocalFile_Window( conn, "file:///tmp/remotefiletest.txt", "/tmp/remotefiletest2.txt", 1, 0 );
    printf( "Local file3: %s\n", local != NULL ? local : "Failed" );
    if( local != NULL )
        {
        /* should be a no-op, as it's the same file */
        ok = dapi_UploadFile_Window( conn, local, "file:///tmp/remotefiletest.txt", 1, 0 );
        printf( "Upload3: %s\n", ok ? "Ok" : "Failed" );
        free( local );
        }
    dapi_close( conn );
    return 0;
    }