Skip to content
This repository
tree: e749866e77
Fetching contributors…

Cannot retrieve contributors at this time

file 26 lines (21 sloc) 0.798 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
require File.expand_path('../spec_helper', __FILE__)

describe "Managed Struct" do
  it "raises an error if release() is not defined" do
    lambda {
      FFISpecs::NoRelease.new(FFISpecs::LibTest.ptr_from_address(0x12345678))
    }.should raise_error(NoMethodError)
  end

  it "is the right class" do
    ptr = FFISpecs::WhatClassAmI.new(FFISpecs::LibTest.ptr_from_address(0x12345678))
    ptr.should be_kind_of(FFISpecs::WhatClassAmI)
  end

  it "releases memory properly" do
    loop_count = 30
    wiggle_room = 2

    FFISpecs::PleaseReleaseMe.should_receive(:release).at_least(loop_count - wiggle_room).times
    loop_count.times do
      s = FFISpecs::PleaseReleaseMe.new(FFISpecs::LibTest.ptr_from_address(0x12345678))
    end

    FFISpecs::PleaseReleaseMe.wait_gc loop_count
  end
end
Something went wrong with that request. Please try again.