Sha256: cf937a98941e672b16c1e5d73a3f8eb277dacae8ed030c8833e88ec9a79459b7

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

# encoding: UTF-8

require './test_helper'
require 'test/unit'

class MemoryTest < Test::Unit::TestCase
  def memory(image = 'sample.png')
    data = image_data(image)
    FreeImage::Memory.new(data)
  end

  def test_wrap
    assert_not_nil(memory)
  end

  def test_format
    assert_equal(:png, memory.format)
  end

  def test_format_unknown
    assert_equal(:unknown, memory('not_an_image.txt').format)
  end

  def test_load
    bitmap = memory.open
    assert_kind_of(FreeImage::Bitmap, bitmap)
  end

  def test_load_unknown
    error = assert_raise(FreeImage::Error) do
      memory('not_an_image.txt').open
    end
    assert_equal("Cannot load :unknown image format",
                 error.message)
  end

  def test_load_wrong_format
    error = assert_raise(FreeImage::Error) do
      memory.open(:jpeg, 0)
    end
    assert_equal("Not a JPEG file: starts with 0x89 0x50", error.to_s)
  end

  def test_bytes
    bitmap1 = FreeImage::Bitmap.open(image_path('sample.png'))

    memory = FreeImage::Memory.new(image_data('sample.png'))
    bitmap2 = memory.open

    assert_equal(bitmap1.bits, bitmap2.bits)
  end

  def test_save
    dst = FreeImage::Memory.new

    bitmap = memory.open
    result = bitmap.save(dst, :png)

    assert(result)
    assert_not_nil(dst.memory.bytes)
    if defined?(Encoding)
      assert_equal(dst.memory.bytes.encoding, Encoding::BINARY)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
free-image-0.6.1 test/test_memory.rb
free-image-0.6.0 test/test_memory.rb
free-image-0.5.0 test/test_memory.rb