diff options
author | Lubos Lunak <l.lunak@ suse.cz> | 2006-03-02 00:40:23 +0000 |
---|---|---|
committer | Lubos Lunak <l.lunak@ suse.cz> | 2006-03-02 00:40:23 +0000 |
commit | 1429fedeb44aca08d5b0307ef3574a0af34055c4 (patch) | |
tree | 3a8b5dceb48c681975fe2f4ce26d36bc87c094fb /tests |
Initial dapi commit.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 31 | ||||
-rw-r--r-- | tests/test_async.c | 52 | ||||
-rw-r--r-- | tests/test_calls.c | 33 | ||||
-rw-r--r-- | tests/test_comm.c | 45 | ||||
-rw-r--r-- | tests/test_mailto.c | 37 | ||||
-rw-r--r-- | tests/test_remotefile.c | 59 | ||||
-rw-r--r-- | tests/test_runasuser.c | 33 | ||||
-rw-r--r-- | tests/test_screensaving.c | 37 |
8 files changed, 327 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..496dbfa --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,31 @@ +bin_PROGRAMS = test_comm test_calls test_runasuser test_screensaving test_mailto test_remotefile test_async + +test_comm_SOURCES = test_comm.c +test_comm_LDADD = ../lib/libdapi.la +test_comm_LDFLAGS = $(all_libraries) + +test_calls_SOURCES = test_calls.c +test_calls_LDADD = ../lib/libdapi.la +test_calls_LDFLAGS = $(all_libraries) + +test_runasuser_SOURCES = test_runasuser.c +test_runasuser_LDADD = ../lib/libdapi.la +test_runasuser_LDFLAGS = $(all_libraries) + +test_screensaving_SOURCES = test_screensaving.c +test_screensaving_LDADD = ../lib/libdapi.la +test_screensaving_LDFLAGS = $(all_libraries) + +test_mailto_SOURCES = test_mailto.c +test_mailto_LDADD = ../lib/libdapi.la +test_mailto_LDFLAGS = $(all_libraries) + +test_remotefile_SOURCES = test_remotefile.c +test_remotefile_LDADD = ../lib/libdapi.la +test_remotefile_LDFLAGS = $(all_libraries) + +test_async_SOURCES = test_async.c +test_async_LDADD = ../lib/libdapi.la +test_async_LDFLAGS = $(all_libraries) + +INCLUDES = $(all_includes) -I$(top_srcdir)/lib diff --git a/tests/test_async.c b/tests/test_async.c new file mode 100644 index 0000000..b805e41 --- /dev/null +++ b/tests/test_async.c @@ -0,0 +1,52 @@ +#include <stdio.h> + +#include "comm.h" +#include "calls.h" + +static int seq1; + +static void callback( DapiConnection* conn, int comm, int seq ) + { + if( comm != DAPI_REPLY_BUTTONORDER + || seq != seq1 ) + { + fprintf( stderr, "Unexpected async reply, ignoring.\n" ); + } + else + { + int ord; + if( !dapi_readReplyButtonOrder( conn, &ord )) + { + fprintf( stderr, "Failed to read async reply!\n" ); + } + else + { + printf( "Order async: %d (%s)\n", ord, ord == 0 ? "Failed" : ord == 1 ? "Ok/Cancel" : "Cancel/Ok" ); + } + } + } + +int main() + { + int ord; + 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; + } + /* first write a command request without waiting for a reply, this + means that the following blocking dapi_ButtonOrder() call will first need to process + an async answer */ + seq1 = dapi_writeCommandButtonOrder( conn ); + ord = dapi_ButtonOrder( conn ); + printf( "Order: %d (%s)\n", ord, ord == 0 ? "Failed" : ord == 1 ? "Ok/Cancel" : "Cancel/Ok" ); + dapi_close( conn ); + return 0; + } diff --git a/tests/test_calls.c b/tests/test_calls.c new file mode 100644 index 0000000..50ccd2a --- /dev/null +++ b/tests/test_calls.c @@ -0,0 +1,33 @@ +#include <stdio.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() + { + int ord; + 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; + } + ord = dapi_ButtonOrder( conn ); + printf( "Order: %d (%s)\n", ord, ord == 0 ? "Failed" : ord == 1 ? "Ok/Cancel" : "Cancel/Ok" ); + dapi_close( conn ); + return 0; + } diff --git a/tests/test_comm.c b/tests/test_comm.c new file mode 100644 index 0000000..edf64ef --- /dev/null +++ b/tests/test_comm.c @@ -0,0 +1,45 @@ +#include <stdio.h> + +#include "comm.h" + +int main() + { + int command, seq, seq2; + int ok; + DapiConnection* conn = dapi_connect(); + if( conn == NULL ) + { + fprintf( stderr, "Cannot connect!\n" ); + return 1; + } + seq = dapi_writeCommandInit( conn ); + if( !dapi_readCommand( conn, &command, &seq2 ) || seq != seq2 ) + { + fprintf( stderr, "Incorrect init reply!\n" ); + return 2; + } + if( !dapi_readReplyInit( conn, &ok )) + { + fprintf( stderr, "Incorrect init reply data!\n" ); + return 2; + } + if( !ok ) + { + fprintf( stderr, "Initialization failed!\n" ); + return 2; + } + seq = dapi_writeCommandOpenUrl( conn, "http://kde.org" ); + if( !dapi_readCommand( conn, &command, &seq2 ) || seq != seq2 ) + { + fprintf( stderr, "Incorrect open url reply!\n" ); + return 2; + } + if( !dapi_readReplyOpenUrl( conn, &ok )) + { + fprintf( stderr, "Incorrect open url reply data!\n" ); + return 2; + } + printf( "Result: %s\n", ok ? "Ok" : "failed" ); + dapi_close( conn ); + return 0; + } diff --git a/tests/test_mailto.c b/tests/test_mailto.c new file mode 100644 index 0000000..30cb54b --- /dev/null +++ b/tests/test_mailto.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdlib.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() + { + int ok; + const char* attachments[] = { "/tmp/mailtotest.txt", NULL }; + 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; + } + system( "touch /tmp/mailtotest.txt" ); + ok = dapi_MailTo( conn, "Test mail", "Hi,\n\nthis is a test mail.\n", + "l.lunak@suse.cz, l.lunak@kde.org", NULL, "portland@lists.freedesktop.org", attachments ); + printf( "Result: %s\n", ok == 1 ? "Ok" : "Failed" ); + dapi_close( conn ); + return 0; + } 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; + } diff --git a/tests/test_runasuser.c b/tests/test_runasuser.c new file mode 100644 index 0000000..3198a7e --- /dev/null +++ b/tests/test_runasuser.c @@ -0,0 +1,33 @@ +#include <stdio.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() + { + 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; + } + ok = dapi_RunAsUser( conn, "", "xterm -title test" ); + printf( "Result: %s\n", ok == 1 ? "Ok" : "Failed" ); + dapi_close( conn ); + return 0; + } diff --git a/tests/test_screensaving.c b/tests/test_screensaving.c new file mode 100644 index 0000000..b74d49d --- /dev/null +++ b/tests/test_screensaving.c @@ -0,0 +1,37 @@ +#include <stdio.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() + { + 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; + } + ok = dapi_SuspendScreensaving( conn, 1 ); + printf( "Result1: %s\n", ok == 1 ? "Ok" : "Failed" ); + sleep( 10 ); + ok = dapi_SuspendScreensaving( conn, 0 ); + printf( "Result2: %s\n", ok == 1 ? "Ok" : "Failed" ); + dapi_close( conn ); + return 0; + } |