diff options
author | Andrew Neitsch <andrew@neitsch.ca> | 2016-06-04 13:54:32 -0600 |
---|---|---|
committer | Andrew Neitsch <andrew@neitsch.ca> | 2016-06-04 13:54:32 -0600 |
commit | 61b7833df75a5144de7207eb149c8691a5110d1b (patch) | |
tree | 4bedf0c0d6a5a719ceac8b698970315fae628913 | |
parent | 2810df43147bc0c1d851e40559a468a423d5c84e (diff) | |
download | ffi-61b7833df75a5144de7207eb149c8691a5110d1b.tar.gz |
Make testBlockingXXva do something with varargs
-rw-r--r-- | spec/ffi/fixtures/FunctionTest.c | 27 | ||||
-rw-r--r-- | spec/ffi/variadic_spec.rb | 4 |
2 files changed, 19 insertions, 12 deletions
diff --git a/spec/ffi/fixtures/FunctionTest.c b/spec/ffi/fixtures/FunctionTest.c index e44e21f..6dfbeec 100644 --- a/spec/ffi/fixtures/FunctionTest.c +++ b/spec/ffi/fixtures/FunctionTest.c @@ -62,15 +62,25 @@ void testBlockingClose(struct testBlockingData *self) { free(self); } -char testBlockingWRva(struct testBlockingData *self, char c, ...) { - /* Process argument list but ignore values */ - va_list args; - va_start(args, c); +static char sum_varargs(va_list args) { + char sum = 0; char arg; while ((arg = va_arg(args, char)) != 0) { - continue; + sum += arg; } va_end(args); + return sum; +} + +/* Write c to pipe1 and return the value read from pipe2, or 0 if there’s + * an error such as a timeout, or if c does not equal the sum of the + * zero-terminated list of char arguments. */ +char testBlockingWRva(struct testBlockingData *self, char c, ...) { + va_list args; + va_start(args, c); + if (sum_varargs(args) != c) { + return 0; + } if( pipeHelperWriteChar(self->pipe1[1], c) != 1) return 0; @@ -78,14 +88,11 @@ char testBlockingWRva(struct testBlockingData *self, char c, ...) { } char testBlockingRWva(struct testBlockingData *self, char c, ...) { - /* Process argument list but ignore values */ va_list args; va_start(args, c); - char arg; - while ((arg = va_arg(args, char)) != 0) { - continue; + if (sum_varargs(args) != c) { + return 0; } - va_end(args); char d = pipeHelperReadChar(self->pipe1[0], 10); if( pipeHelperWriteChar(self->pipe2[1], c) != 1) diff --git a/spec/ffi/variadic_spec.rb b/spec/ffi/variadic_spec.rb index 0b19d16..1b42266 100644 --- a/spec/ffi/variadic_spec.rb +++ b/spec/ffi/variadic_spec.rb @@ -36,8 +36,8 @@ describe "Function with variadic arguments" do handle = LibTest.testBlockingOpen expect(handle).not_to be_null begin - thWR = Thread.new { LibTest.testBlockingWRva(handle, 63, :char, 0) } - thRW = Thread.new { LibTest.testBlockingRWva(handle, 64, :char, 0) } + thWR = Thread.new { LibTest.testBlockingWRva(handle, 63, :char, 40, :char, 23, :char, 0) } + thRW = Thread.new { LibTest.testBlockingRWva(handle, 64, :char, 40, :char, 24, :char, 0) } expect(thWR.value).to eq(64) expect(thRW.value).to eq(63) ensure |