Sha256: aaae7c29751b4964524bf69ac60f6ccce701e83221ab22e8d0b83b0cadd8b19e
Contents?: true
Size: 1.87 KB
Versions: 2
Compression:
Stored size: 1.87 KB
Contents
require 'spec_helper' module NNCore describe "nn_recv" do context "given an initialized library and" do context "given a valid connected sender and receiver socket pair" do before(:each) do @socket = LibNanomsg.nn_socket(AF_SP, NN_PAIR) @sender = LibNanomsg.nn_socket(AF_SP, NN_PAIR) @endpoint = LibNanomsg.nn_bind(@socket, "inproc://some_endpoint") LibNanomsg.nn_connect(@sender, "inproc://some_endpoint") end after(:each) do LibNanomsg.nn_close(@socket) LibNanomsg.nn_close(@sender) end context "given a pre-allocated buffer" do it "returns the number of bytes received" do string = "ABC" LibNanomsg.nn_send(@sender, string, string.size, 0) buffer = FFI::MemoryPointer.new(5) nbytes = LibNanomsg.nn_recv(@socket, buffer, 5, 0) nbytes.should == 3 buffer.read_string.should == string end end context "given no pre-allocated buffer" do it "returns the number of bytes received and returns the buffer" do string = "ABC" LibNanomsg.nn_send(@sender, string, string.size, 0) buffer = FFI::MemoryPointer.new(:pointer) nbytes = LibNanomsg.nn_recv(@socket, buffer, NN_MSG, 0) nbytes.should == 3 # important to pass +nbytes+ to #read_string since the sent string # is not null-terminated buffer.get_pointer(0).read_string(nbytes).should == string end end end context "given an invalid socket" do it "returns -1 and sets nn_errno to EBADF" do rc = LibNanomsg.nn_send(0, "ABC", 3, 0) rc.should == -1 LibNanomsg.nn_errno.should == EBADF end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nn-core-0.2.1 | spec/nn_recv_spec.rb |
nn-core-0.1.6 | spec/nn_recv_spec.rb |