summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWayne Meissner <wmeissner@gmail.com>2012-11-10 17:01:08 +1000
committerWayne Meissner <wmeissner@gmail.com>2012-11-10 17:01:08 +1000
commit439b18603518b549f5a247a0c760fd6915c78ac4 (patch)
treec83ad6ccd0146d84f9f2b61df609cba97b3443ee
parent8193194445be526d64ec3b8a514b3b884da877b4 (diff)
downloadffi-439b18603518b549f5a247a0c760fd6915c78ac4.tar.gz
Add Pointer#write_bytes spec
-rw-r--r--spec/ffi/buffer_spec.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/ffi/buffer_spec.rb b/spec/ffi/buffer_spec.rb
index 096d44a..d87d618 100644
--- a/spec/ffi/buffer_spec.rb
+++ b/spec/ffi/buffer_spec.rb
@@ -171,6 +171,43 @@ describe "Reading/Writing binary strings" do
str = "hello\0world"
buf = FFI::Buffer.new 1024
lambda { buf.put_bytes(0, str, -1, 12); }.should raise_error
+ end
+
+ it "Buffer#write_bytes" do
+ str = "hello\0world"
+ buf = FFI::Buffer.new 1024
+ buf.write_bytes(str)
+ s2 = buf.get_bytes(0, 11)
+ s2.should eq str
+ end
+ it "Buffer#write_bytes with index and length" do
+ str = "hello\0world"
+ buf = FFI::Buffer.new 1024
+ buf.write_bytes(str, 5, 6)
+ s2 = buf.get_bytes(0, 6)
+ s2.should eq str[5..-1]
+ end
+ it "Buffer#write_bytes with only index" do
+ str = "hello\0world"
+ buf = FFI::Buffer.new 1024
+ buf.write_bytes(str, 5)
+ s2 = buf.get_bytes(0, 6)
+ s2.should eq str[5..-1]
+ end
+ it "Buffer#write_bytes with index > str.length" do
+ str = "hello\0world"
+ buf = FFI::Buffer.new 1024
+ lambda { buf.write_bytes(str, 12) }.should raise_error
+ end
+ it "Buffer#put_bytes with length > str.length" do
+ str = "hello\0world"
+ buf = FFI::Buffer.new 1024
+ lambda { buf.put_bytes(0, str, 0, 12) }.should raise_error
+ end
+ it "Buffer#write_bytes with negative index" do
+ str = "hello\0world"
+ buf = FFI::Buffer.new 1024
+ lambda { buf.write_bytes(str, -1, 12) }.should raise_error
end
end
describe "Reading/Writing ascii strings" do