summaryrefslogtreecommitdiff
path: root/tests/test_remotefile.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_remotefile.c')
-rw-r--r--tests/test_remotefile.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test_remotefile.c b/tests/test_remotefile.c
new file mode 100644
index 0000000..750c4a0
--- /dev/null
+++ b/tests/test_remotefile.c
@@ -0,0 +1,59 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "comm.h"
+#include "calls.h"
+
+static void callback( DapiConnection* a1, int a2, int a3 )
+ {
+ (void) a1;
+ (void) a2;
+ (void) a3;
+ fprintf( stderr, "Unexpected async reply, ignoring.\n" );
+ }
+
+int main()
+ {
+ char* local;
+ int ok;
+ DapiConnection* conn = dapi_connect();
+ if( conn == NULL )
+ {
+ fprintf( stderr, "Cannot connect!\n" );
+ return 1;
+ }
+ dapi_setSyncCallback( conn, callback );
+ if( !dapi_Init( conn ))
+ {
+ fprintf( stderr, "Initialization failed!\n" );
+ return 2;
+ }
+ local = dapi_LocalFile( conn, "http://kde.org", "", 0 ); /* no download, should fail */
+ printf( "Local file1: %s - %s\n", local ? local : "?", local ? "Failed" : "Ok" );
+ if( local )
+ free( local );
+ local = dapi_LocalFile( conn, "http://kde.org", "", 1 );
+ printf( "Local file2: %s\n", local != NULL ? local : "Failed" );
+ if( local != NULL )
+ {
+ ok = dapi_UploadFile( conn, local, "http://kde.org", 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 );
+ }
+ system( "touch /tmp/remotefiletest.txt" );
+ /* local temporary will be ignored */
+ local = dapi_LocalFile( conn, "file:///tmp/remotefiletest.txt", "/tmp/remotefiletest2.txt", 1 );
+ 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( conn, local, "file:///tmp/remotefiletest.txt", 1 );
+ printf( "Upload3: %s\n", ok ? "Ok" : "Failed" );
+ free( local );
+ }
+ dapi_close( conn );
+ return 0;
+ }