Sha256: b76057297802baeb9610bdf8ba6fe619aa3bb9297e74730c7e80b0f576ad2177

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))

require 'ffi-glib/strv'

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
      ptr = GirFFI::InPointer.from_array :utf8, ["one", "two", "three"]
      strv = GLib::Strv.new ptr
      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

5 entries across 5 versions & 1 rubygems

Version Path
gir_ffi-0.4.0 test/ffi-glib/strv_test.rb
gir_ffi-0.3.2 test/ffi-glib/strv_test.rb
gir_ffi-0.3.1 test/ffi-glib/strv_test.rb
gir_ffi-0.3.0 test/ffi-glib/strv_test.rb
gir_ffi-0.2.3 test/ffi-glib/strv_test.rb