diff options
Diffstat (limited to 'spec/ffi/fixtures/FunctionTest.c')
-rw-r--r-- | spec/ffi/fixtures/FunctionTest.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/spec/ffi/fixtures/FunctionTest.c b/spec/ffi/fixtures/FunctionTest.c index 5310ab0..a37373a 100644 --- a/spec/ffi/fixtures/FunctionTest.c +++ b/spec/ffi/fixtures/FunctionTest.c @@ -6,14 +6,16 @@ #ifdef _WIN32 #include <windows.h> -#define sleep(x) Sleep((x)*1000) #endif #ifndef _WIN32 #include <unistd.h> #include <pthread.h> +#include <stdlib.h> #endif +#include "PipeHelper.h" + int testAdd(int a, int b) { return a + b; @@ -24,10 +26,41 @@ int testFunctionAdd(int a, int b, int (*f)(int, int)) return f(a, b); }; -void testBlocking(int seconds) { - sleep(seconds); +struct testBlockingData { + FD_TYPE pipe1[2]; + FD_TYPE pipe2[2]; }; +struct testBlockingData *testBlockingOpen() +{ + struct testBlockingData *self = malloc(sizeof(struct testBlockingData)); + + if( pipeHelperCreatePipe(self->pipe1) == -1 ) return NULL; + if( pipeHelperCreatePipe(self->pipe2) == -1 ) return NULL; + return self; +} + +char testBlockingWR(struct testBlockingData *self, char c) { + if( pipeHelperWriteChar(self->pipe1[1], c) != 1) + return 0; + return pipeHelperReadChar(self->pipe2[0], 10); +} + +char testBlockingRW(struct testBlockingData *self, char c) { + char d = pipeHelperReadChar(self->pipe1[0], 10); + if( pipeHelperWriteChar(self->pipe2[1], c) != 1) + return 0; + return d; +} + +void testBlockingClose(struct testBlockingData *self) { + pipeHelperClosePipe(self->pipe1[0]); + pipeHelperClosePipe(self->pipe1[1]); + pipeHelperClosePipe(self->pipe2[0]); + pipeHelperClosePipe(self->pipe2[1]); + free(self); +} + struct async_data { void (*fn)(int); int value; |