summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortduehr <tduehr@gmail.com>2014-01-29 20:39:06 -0600
committertduehr <tduehr@gmail.com>2014-06-05 21:41:01 -0500
commitd231369a7d1171e453dd94e392058f44809c11d4 (patch)
treec3271378aca8344ad7fadeb8adc3f494389f0593
parent1c54fdb13cea05ac4372f37c0668f6461af4bdd8 (diff)
downloadffi-d231369a7d1171e453dd94e392058f44809c11d4.tar.gz
add enum test to variadic spec
-rw-r--r--.travis.yml7
-rw-r--r--Rakefile1
-rw-r--r--spec/ffi/fixtures/VariadicTest.c37
-rw-r--r--spec/ffi/spec_helper.rb1
-rw-r--r--spec/ffi/variadic_spec.rb16
5 files changed, 54 insertions, 8 deletions
diff --git a/.travis.yml b/.travis.yml
index 2954ed9..5c2ef43 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,18 +7,11 @@ rvm:
- "2.1"
- "ruby-head"
- "rbx-2.1.1"
-<<<<<<< HEAD
- "rbx"
matrix:
allow_failures:
- rvm: "rbx-2.1.1"
- rvm: "rbx"
-=======
- - "rbx-head"
-matrix:
- allow_failures:
- - rvm: "rbx-2.1.1"
- rvm: "rbx-head"
->>>>>>> add rbx dependencies
- rvm: "1.8.7"
- rvm: "1.9.3"
diff --git a/Rakefile b/Rakefile
index bb7c87f..0609f94 100644
--- a/Rakefile
+++ b/Rakefile
@@ -112,6 +112,7 @@ CLOBBER.include FileList["lib/**/ffi_c.#{RbConfig::CONFIG['DLEXT']}"]
CLOBBER.include 'lib/ffi/types.conf'
CLOBBER.include 'conftest.dSYM'
CLOBBER.include 'pkg'
+CLOBBER.include 'spec/ffi/fixtures/libtest.dylib'
task :distclean => :clobber
diff --git a/spec/ffi/fixtures/VariadicTest.c b/spec/ffi/fixtures/VariadicTest.c
index fea6c3b..2f3d801 100644
--- a/spec/ffi/fixtures/VariadicTest.c
+++ b/spec/ffi/fixtures/VariadicTest.c
@@ -60,3 +60,40 @@ void pack_varargs(s64* buf, const char* fmt, ...)
va_end(ap);
}
+int pack_varargs2(s64* buf, int retval, const char* fmt, ...)
+{
+ va_list ap;
+ int c;
+ double d;
+ va_start(ap, fmt);
+ while ((c = *fmt++)) {
+ switch (c) {
+ case 'c':
+ case 's':
+ case 'i':
+ *buf++ = va_arg(ap, s32);
+ break;
+ case 'l':
+ *buf++ = va_arg(ap, long);
+ break;
+ case 'j':
+ *buf++ = va_arg(ap, s64);
+ break;
+ case 'f':
+ case 'd':
+ d = va_arg(ap, double);
+ memcpy(buf++, &d, sizeof(d));
+ break;
+ case 'C':
+ case 'S':
+ case 'I':
+ *buf++ = va_arg(ap, u32);
+ break;
+ case 'L':
+ *buf++ = va_arg(ap, unsigned long);
+ break;
+ }
+ }
+ va_end(ap);
+ return retval + 1;
+}
diff --git a/spec/ffi/spec_helper.rb b/spec/ffi/spec_helper.rb
index 291157d..3f472d8 100644
--- a/spec/ffi/spec_helper.rb
+++ b/spec/ffi/spec_helper.rb
@@ -64,7 +64,6 @@ def compile_library(path, lib)
end
if $?.exitstatus != 0
- puts "ERROR:\n#{output}"
raise "Unable to compile \"#{lib}\""
end
end
diff --git a/spec/ffi/variadic_spec.rb b/spec/ffi/variadic_spec.rb
index 1d08e4d..58d0ccf 100644
--- a/spec/ffi/variadic_spec.rb
+++ b/spec/ffi/variadic_spec.rb
@@ -10,8 +10,24 @@ describe "Function with variadic arguments" do
module LibTest
extend FFI::Library
ffi_lib TestLibrary::PATH
+ enum :enum_type1, [:c1, :c2]
+ enum :enum_type2, [:c3, 42, :c4]
attach_function :pack_varargs, [ :buffer_out, :string, :varargs ], :void
+ attach_function :pack_varargs2, [ :buffer_out, :enum_type1, :string, :varargs ], :enum_type1
end
+
+ it "takes enum arguments" do
+ buf = FFI::Buffer.new :long_long, 2
+ LibTest.pack_varargs(buf, "ii", :int, :c3, :int, :c4)
+ buf.get_int64(0).should == 42
+ buf.get_int64(8).should == 43
+ end
+
+ it "returns symbols for enums" do
+ buf = FFI::Buffer.new :long_long, 2
+ LibTest.pack_varargs2(buf, :c1, "ii", :int, :c3, :int, :c4).should eql(:c2)
+ end
+
[ 0, 127, -128, -1 ].each do |i|
it "call variadic with (:char (#{i})) argument" do
buf = FFI::Buffer.new :long_long