Sha256: d2393b8b763914441830d5d065cc3a0bb341f745f171d486314c6bbd3b982e8a

Contents?: true

Size: 1003 Bytes

Versions: 9

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

require 'gir_ffi_test_helper'

describe GirFFI::AllocationHelper do
  describe '.free_after' do
    before do
      allow(GirFFI::LibC).to receive(:free)
    end

    it 'frees the passed-in pointer' do
      ptr = double('pointer', null?: false)
      GirFFI::AllocationHelper.free_after(ptr) {}
      expect(GirFFI::LibC).to have_received(:free).with(ptr)
    end

    it 'does not free a passed-in null pointer' do
      ptr = double('pointer', null?: true)
      GirFFI::AllocationHelper.free_after(ptr) {}
      expect(GirFFI::LibC).not_to have_received(:free)
    end

    it 'yields ptr to the block' do
      ptr = double('pointer', null?: false)
      foo = nil
      GirFFI::AllocationHelper.free_after(ptr) { |it| foo = it }
      foo.must_equal ptr
    end

    it 'returns the result of the block' do
      ptr = double('pointer', null?: false)
      result = GirFFI::AllocationHelper.free_after(ptr) { 'bar' }
      result.must_equal 'bar'
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gir_ffi-0.14.1 test/gir_ffi/allocation_helper_test.rb
gir_ffi-0.14.0 test/gir_ffi/allocation_helper_test.rb
gir_ffi-0.13.1 test/gir_ffi/allocation_helper_test.rb
gir_ffi-0.13.0 test/gir_ffi/allocation_helper_test.rb
gir_ffi-0.12.1 test/gir_ffi/allocation_helper_test.rb
gir_ffi-0.12.0 test/gir_ffi/allocation_helper_test.rb
gir_ffi-0.11.4 test/gir_ffi/allocation_helper_test.rb
gir_ffi-0.11.3 test/gir_ffi/allocation_helper_test.rb
gir_ffi-0.11.2 test/gir_ffi/allocation_helper_test.rb