Sha256: 458588f7774956e0e80b5df1dde835e115f77859244ab6dab5e4521791c6cb5f

Contents?: true

Size: 1.07 KB

Versions: 22

Compression:

Stored size: 1.07 KB

Contents

require 'base_test_helper'

describe GLib::Strv do
  it "wraps a pointer" do
    strv = GLib::Strv.new :some_pointer
    assert_equal :some_pointer, strv.to_ptr
  end

  describe "::wrap" do
    it "takes a pointer and returns a GLib::Strv wrapping it" do
      strv = GLib::Strv.wrap :some_pointer
      assert_instance_of GLib::Strv, strv
      assert_equal :some_pointer, strv.to_ptr
    end
  end

  describe "#each" do
    it "yields each string element" do
      ary = ["one", "two", "three"]
      ptrs = ary.map {|a| FFI::MemoryPointer.from_string(a)}
      ptrs << nil
      block = FFI::MemoryPointer.new(:pointer, ptrs.length)
      block.write_array_of_pointer ptrs

      strv = GLib::Strv.new block
      arr = []
      strv.each do |str|
        arr << str
      end
      assert_equal ["one", "two", "three"], arr
    end

    it "yields zero times for a Strv wrapping a null pointer" do
      strv = GLib::Strv.new FFI::Pointer.new(0)
      strv.each do |str|
        flunk
      end
    end
  end

  it "includes Enumerable" do
    GLib::Strv.must_include Enumerable
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
gir_ffi-0.7.7 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.7.6 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.7.5 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.7.4 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.7.3 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.7.2 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.7.1 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.7.0 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.6.7 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.6.6 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.6.5 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.6.4 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.6.3 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.6.2 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.6.1 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.6.0 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.5.2 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.5.1 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.5.0 test/gir_ffi-base/glib/strv_test.rb
gir_ffi-0.4.3 test/gir_ffi-base/glib/strv_test.rb