Sha256: 793b2a022b2577c8bc899b450afb77b8f6b9b60c596ec50824e58746499ae64a

Contents?: true

Size: 801 Bytes

Versions: 3

Compression:

Stored size: 801 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"))
require 'ffi'

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)
    time.should be_kind_of(Integer)
  end
  
  it "correctly populates a struct for gettimeofday" do
    t = Timeval.new
    time = LibC.gettimeofday(t.pointer, nil)
    t[:tv_sec].should be_kind_of(Numeric)
    t[:tv_usec].should be_kind_of(Numeric)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffi-1.9.5-x64-mingw32 spec/ffi/rbx/attach_function_spec.rb
ffi-1.9.5-x86-mingw32 spec/ffi/rbx/attach_function_spec.rb
ffi-1.9.5 spec/ffi/rbx/attach_function_spec.rb