Sha256: 929c4d6c3d6d2360fe54a43b3b2653daf907c6c7a05b40ece81acf0e5d3753b0

Contents?: true

Size: 1.49 KB

Versions: 9

Compression:

Stored size: 1.49 KB

Contents

#
# This file is part of ruby-ffi.
#
# This code is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License version 3 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
# version 3 for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# version 3 along with this work.  If not, see <http://www.gnu.org/licenses/>.
#

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

describe FFI::Struct, ' with an initialize function' do
  it "should call the initialize function" do
    class StructWithInitialize < FFI::Struct
      layout :string, :string
      attr_accessor :magic
      def initialize
        super
        self.magic = 42
      end
    end
    StructWithInitialize.new.magic.should == 42
  end
end

describe FFI::ManagedStruct, ' with an initialize function' do
  it "should call the initialize function" do
    class ManagedStructWithInitialize < FFI::ManagedStruct
      layout :string, :string
      attr_accessor :magic
      def initialize
        super FFI::MemoryPointer.new(:pointer).put_int(0, 0x1234).get_pointer(0)
        self.magic = 42
      end
      def self.release;end
    end
    ManagedStructWithInitialize.new.magic.should == 42
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ffi-1.0.10 spec/ffi/struct_initialize_spec.rb
ffi-1.0.9-x86-mingw32 spec/ffi/struct_initialize_spec.rb
ffi-1.0.9 spec/ffi/struct_initialize_spec.rb
ffi-1.0.7-x86-mingw32 spec/ffi/struct_initialize_spec.rb
ffi-1.0.7 spec/ffi/struct_initialize_spec.rb
ffi-1.0.6-x86-mingw32 spec/ffi/struct_initialize_spec.rb
ffi-1.0.6 spec/ffi/struct_initialize_spec.rb
ffi-1.0.5-x86-mingw32 spec/ffi/struct_initialize_spec.rb
ffi-1.0.5 spec/ffi/struct_initialize_spec.rb