Sha256: 8b3a6ddb8fdea847b6342177d5ab26f885deb9f1b575c45d50176b75024282f2

Contents?: true

Size: 1009 Bytes

Versions: 4

Compression:

Stored size: 1009 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

4 entries across 4 versions & 1 rubygems

Version Path
gir_ffi-0.15.3 test/gir_ffi/allocation_helper_test.rb
gir_ffi-0.15.2 test/gir_ffi/allocation_helper_test.rb
gir_ffi-0.15.1 test/gir_ffi/allocation_helper_test.rb
gir_ffi-0.15.0 test/gir_ffi/allocation_helper_test.rb