Sha256: 4aedcf82b7be0c842a37cf5571884091ccd4870cb2f954d1541fbc138ced597a

Contents?: true

Size: 799 Bytes

Versions: 7

Compression:

Stored size: 799 Bytes

Contents

#
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#

require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))

class Timeval < FFI::Struct
  layout :tv_sec, :ulong, 0, :tv_usec, :ulong, 4  
end

module LibC
  extend FFI::Library
  ffi_lib FFI::Library::LIBC

  attach_function :gettimeofday, [:pointer, :pointer], :int
end

describe FFI::Library, "#attach_function" do
  it "correctly returns a value for gettimeofday" do
    t = Timeval.new
    time = LibC.gettimeofday(t.pointer, nil)
    expect(time).to be_kind_of(Integer)
  end
  
  it "correctly populates a struct for gettimeofday" do
    t = Timeval.new
    time = LibC.gettimeofday(t.pointer, nil)
    expect(t[:tv_sec]).to be_kind_of(Numeric)
    expect(t[:tv_usec]).to be_kind_of(Numeric)
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
vagrant-cloudstack-1.1.0 vendor/bundle/gems/ffi-1.9.8/spec/ffi/rbx/attach_function_spec.rb
ffi-1.9.8-x64-mingw32 spec/ffi/rbx/attach_function_spec.rb
ffi-1.9.8-x86-mingw32 spec/ffi/rbx/attach_function_spec.rb
ffi-1.9.8 spec/ffi/rbx/attach_function_spec.rb
ffi-1.9.6-x86-mingw32 spec/ffi/rbx/attach_function_spec.rb
ffi-1.9.6-x64-mingw32 spec/ffi/rbx/attach_function_spec.rb
ffi-1.9.6 spec/ffi/rbx/attach_function_spec.rb