Sha256: c18ff2365b22259563e3b3c9d08d5cb9ed2f442f0a1e3ab91388b0be3a504c59

Contents?: true

Size: 1.36 KB

Versions: 13

Compression:

Stored size: 1.36 KB

Contents

require 'gir_ffi_test_helper'

describe GLib::Bytes do
  it 'can succesfully be created with GLib::Bytes.new' do
    bytes = GLib::Bytes.new [1, 2, 3]
    bytes.must_be_instance_of GLib::Bytes
  end

  it 'has a working #get_size method' do
    bytes = GLib::Bytes.new [1, 2, 3]
    bytes.get_size.must_equal 3
  end

  it 'has a working #get_data method' do
    bytes = GLib::Bytes.new [1, 2, 3]
    bytes.get_data.to_a.must_equal [1, 2, 3]
  end

  it 'has a working #each method' do
    a = []
    bytes = GLib::Bytes.new [1, 2, 3]
    bytes.each do |v|
      a.unshift v
    end
    a.must_equal [3, 2, 1]
  end

  it 'has a working #to_a method' do
    bytes = GLib::Bytes.new [1, 2, 3]
    bytes.to_a.must_equal [1, 2, 3]
  end

  describe '.from' do
    it 'creates a GLib::Bytes object form an array of small integers' do
      bytes = GLib::Bytes.from [1, 2, 3]
      bytes.must_be_instance_of GLib::Bytes
      bytes.to_a.must_equal [1, 2, 3]
    end

    it 'returns its argument if given a GLib::Bytes object' do
      bytes = GLib::Bytes.new [1, 2, 3]
      result = GLib::Bytes.from bytes
      assert result.equal?(bytes)
    end

    it 'wraps its argument if given a pointer' do
      bytes = GLib::Bytes.new [1, 2, 3]
      ptr = bytes.to_ptr
      result = GLib::Bytes.from ptr
      result.to_a.must_equal [1, 2, 3]
      result.to_ptr.must_equal ptr
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gir_ffi-0.9.2 test/ffi-glib/bytes_test.rb
gir_ffi-0.9.1 test/ffi-glib/bytes_test.rb
gir_ffi-0.9.0 test/ffi-glib/bytes_test.rb
gir_ffi-0.8.6 test/ffi-glib/bytes_test.rb
gir_ffi-0.8.5 test/ffi-glib/bytes_test.rb
gir_ffi-0.8.4 test/ffi-glib/bytes_test.rb
gir_ffi-0.8.3 test/ffi-glib/bytes_test.rb
gir_ffi-0.8.2 test/ffi-glib/bytes_test.rb
gir_ffi-0.8.1 test/ffi-glib/bytes_test.rb
gir_ffi-0.8.0 test/ffi-glib/bytes_test.rb
gir_ffi-0.7.10 test/ffi-glib/bytes_test.rb
gir_ffi-0.7.9 test/ffi-glib/bytes_test.rb
gir_ffi-0.7.8 test/ffi-glib/bytes_test.rb