Sha256: 4c533e8a30fef8485da9d1baa5dd2e7e7a32ced6c989e43c14e57fce4b4d0316

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true
require 'gir_ffi_test_helper'

describe GirFFI::ArgHelper do
  describe '.cast_from_pointer' do
    it 'handles class types' do
      klass = Class.new
      expect(klass).to receive(:wrap).with(:pointer_value).and_return :wrapped_value
      GirFFI::ArgHelper.cast_from_pointer(klass, :pointer_value).must_equal :wrapped_value
    end

    it 'handles negative :gint8' do
      ptr = FFI::Pointer.new(-127)
      GirFFI::ArgHelper.cast_from_pointer(:gint8, ptr).must_equal(-127)
    end

    it 'handles positive :gint8' do
      ptr = FFI::Pointer.new(128)
      GirFFI::ArgHelper.cast_from_pointer(:gint8, ptr).must_equal(128)
    end

    it 'handles :guint32' do
      ptr = FFI::Pointer.new(0xffffffff)
      GirFFI::ArgHelper.cast_from_pointer(:guint32, ptr).must_equal(0xffffffff)
    end
  end

  describe '.store' do
    describe 'when called with nil' do
      it 'returns a null pointer' do
        GirFFI::ArgHelper.store(nil).must_be :null?
      end
    end

    describe 'when called with a string' do
      it 'stores the string in GirFFI::ArgHelper::OBJECT_STORE' do
        str = 'Foo'
        ptr = GirFFI::ArgHelper.store(str)
        result = GirFFI::ArgHelper::OBJECT_STORE.fetch(ptr)
        result.must_equal str
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gir_ffi-0.10.2 test/gir_ffi/arg_helper_test.rb
gir_ffi-0.10.1 test/gir_ffi/arg_helper_test.rb
gir_ffi-0.10.0 test/gir_ffi/arg_helper_test.rb
gir_ffi-0.10.0.pre1 test/gir_ffi/arg_helper_test.rb