Sha256: de5fd2d4adbbb04fb4e8a330ccea6b70da76c2a497c75f23b84196a75c7d8360

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require File.dirname(__FILE__) + '/test_helper.rb'
require 'rubygems'
require 'RMagick'

# Prereqs for this test:
# * Must be run from a command window with dimensions 1600x1200 pixels (160x60 characters, default font)
# * Screen res must be 1600x1200
# * Must have a maximised Firefox open
#
class Win32screenshotTest < Test::Unit::TestCase

  def test_should_capture_foreground
    width, height, bmp = Win32::Screenshot.foreground
    assert_equal 1280, width
    assert_equal 720,  height
    assert_image(bmp)
  end
  
  def test_should_capture_desktop
    width, height, bmp = Win32::Screenshot.desktop
    assert_equal 1600, width
    assert_equal 1200,  height
    assert_image(bmp)
  end

  def test_should_capture_window_by_title
    width, height, bmp = Win32::Screenshot.window(/Firefox/)
    assert_equal 1600, width
    assert_equal 1147,  height
    assert_image(bmp, "ff.png")
  end
  

  def assert_image(bmp, file=nil)
    assert_equal 'BM',  bmp[0..1]
    img = Magick::Image.from_blob(bmp)
    png = img[0].to_blob do
      self.format = 'PNG'
    end
    assert_equal "\211PNG",  png[0..3]
    File.open(file, "wb") {|io| io.write(png)} unless file.nil?
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
win32screenshot-0.0.2 test/win32screenshot_test.rb