win32screenshot 0.0.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,68 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Win32::Screenshot::Image do
4
+
5
+ before :all do
6
+ IO.popen("calc")
7
+ @calc = RAutomation::Window.new(:title => /calculator/i).pid
8
+ @image = Win32::Screenshot::Take.of(:window, :pid => @calc)
9
+ end
10
+
11
+ describe "stores raw bitmap data" do
12
+ it "#bitmap" do
13
+ @image.bitmap[0..1].should == 'BM'
14
+ end
15
+ end
16
+
17
+ describe "saving the image to the disk" do
18
+ context "saving to the bmp format" do
19
+ it "#write" do
20
+ file_path = @temp_dir + '/image.bmp'
21
+ expect {@image.write(file_path)}.to_not raise_exception
22
+ File.open(file_path, "rb") {|io| io.read}[0..1].should == "BM"
23
+ end
24
+ end
25
+
26
+ context "saving to the png format" do
27
+ it "#write" do
28
+ file_path = @temp_dir + '/image.png'
29
+ expect {@image.write(file_path)}.to_not raise_exception
30
+ File.open(file_path, "rb") {|io| io.read}[0..3].should == "\211PNG"
31
+ end
32
+ end
33
+
34
+ context "trying to save to the unknown format" do
35
+ it "#write" do
36
+ file_path = @temp_dir + '/image.notknown'
37
+ expect {@image.write(file_path)}.
38
+ to raise_exception("File '#{file_path}' has to have one of the following extensions: #{Win32::Screenshot::Image::FORMATS.join(", ")}")
39
+ File.should_not exist(file_path)
40
+ end
41
+ end
42
+
43
+ context "trying to save with the filename without an extension" do
44
+ it "#write" do
45
+ file_path = @temp_dir + '/image'
46
+ expect {@image.write(file_path)}.
47
+ to raise_exception("File '#{file_path}' has to have one of the following extensions: #{Win32::Screenshot::Image::FORMATS.join(", ")}")
48
+ File.should_not exist(file_path)
49
+ end
50
+ end
51
+
52
+ context "not allowing to overwrite existing files" do
53
+ it "#write" do
54
+ file_path = @temp_dir + '/invalid-image.png'
55
+ content = "invalid content"
56
+ File.open(file_path, "w") {|io| io.write content}
57
+ expect {@image.write(file_path)}.to raise_exception("File already exists: #{file_path}!")
58
+ File.size(file_path).should == content.size
59
+ end
60
+ end
61
+ end
62
+
63
+ after :all do
64
+ # kill in a jruby friendly way
65
+ system("taskkill /PID #{@calc} > nul")
66
+ end
67
+
68
+ end
@@ -0,0 +1,137 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Win32::Screenshot::Take do
4
+
5
+ before :all do
6
+ Dir.chdir("c:/program files/Internet Explorer") { IO.popen(".\\iexplore about:blank") }
7
+ IO.popen("calc")
8
+ @iexplore = RAutomation::Window.new(:title => /internet explorer/i).pid
9
+ @calc = RAutomation::Window.new(:title => /calculator/i).pid
10
+ end
11
+
12
+ it "captures foreground" do
13
+ image = Win32::Screenshot::Take.of(:foreground)
14
+ save_and_verify_image(image, 'foreground')
15
+ hwnd = Win32::Screenshot::BitmapMaker.foreground_window
16
+ [image.width, image.height].should == Win32::Screenshot::BitmapMaker.dimensions_for(hwnd)
17
+ end
18
+
19
+ it "captures area of the foreground" do
20
+ image = Win32::Screenshot::Take.of(:foreground, :area => [30, 30, 100, 150])
21
+ save_and_verify_image(image, 'foreground_area')
22
+ image.width.should == 70
23
+ image.height.should == 120
24
+ end
25
+
26
+ it "doesn't allow to capture area of the foreground with invalid coordinates" do
27
+ expect {Win32::Screenshot::Take.of(:foreground, :area => [0, 0, -1, 100])}.
28
+ to raise_exception("specified coordinates (x1: 0, y1: 0, x2: -1, y2: 100) are invalid - cannot be negative!")
29
+ end
30
+
31
+ it "captures desktop" do
32
+ image = Win32::Screenshot::Take.of(:desktop)
33
+ save_and_verify_image(image, 'desktop')
34
+ hwnd = Win32::Screenshot::BitmapMaker.desktop_window
35
+ [image.width, image.height].should == Win32::Screenshot::BitmapMaker.dimensions_for(hwnd)
36
+ end
37
+
38
+ it "captures area of the desktop" do
39
+ image = Win32::Screenshot::Take.of(:desktop, :area => [30, 30, 100, 150])
40
+ save_and_verify_image(image, 'desktop_area')
41
+ image.width.should == 70
42
+ image.height.should == 120
43
+ end
44
+
45
+ it "doesn't allow to capture area of the desktop with invalid coordinates" do
46
+ expect {Win32::Screenshot::Take.of(:desktop, :area => [0, 0, -1, 100])}.
47
+ to raise_exception("specified coordinates (x1: 0, y1: 0, x2: -1, y2: 100) are invalid - cannot be negative!")
48
+ end
49
+
50
+ it "captures maximized window" do
51
+ window = RAutomation::Window.new(:pid => @iexplore)
52
+ window.maximize
53
+ image = Win32::Screenshot::Take.of(:window, :pid => @iexplore)
54
+ save_and_verify_image(image, 'iexplore_max')
55
+ [image.width, image.height].should == Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd)
56
+ end
57
+
58
+ it "captures minimized window" do
59
+ window = RAutomation::Window.new(:pid => @calc)
60
+ window.minimize
61
+ image = Win32::Screenshot::Take.of(:window, :pid => @calc)
62
+ save_and_verify_image(image, 'calc_min')
63
+ [image.width, image.height].should == Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd)
64
+ end
65
+
66
+ it "captures small window" do
67
+ title = /Internet Explorer/
68
+ resize(title)
69
+ image = Win32::Screenshot::Take.of(:window, :pid => @iexplore)
70
+ save_and_verify_image(image, 'iexplore_resized')
71
+
72
+ # we should get the size of the picture because
73
+ # screenshot doesn't include titlebar and the size
74
+ # varies between different themes and Windows versions
75
+ window = RAutomation::Window.new(:pid => @iexplore)
76
+ [image.width, image.height].should == Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd)
77
+ end
78
+
79
+ it "captures area of the window" do
80
+ image = Win32::Screenshot::Take.of(:window, :pid => @calc, :area => [30, 30, 100, 150])
81
+ save_and_verify_image(image, 'calc_area')
82
+ image.width.should == 70
83
+ image.height.should == 120
84
+ end
85
+
86
+ it "captures by RAutomation::Window" do
87
+ window = RAutomation::Window.new(:pid => @calc)
88
+ image = Win32::Screenshot::Take.of(:window, :rautomation => window)
89
+ save_and_verify_image(image, 'calc_rautomation')
90
+ [image.width, image.height].should == Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd)
91
+ end
92
+
93
+ it "captures child windows" do
94
+ window = RAutomation::Window.new(:pid => @iexplore).child(:class => "Internet Explorer_Server")
95
+ image = Win32::Screenshot::Take.of(:window, :rautomation => window)
96
+ save_and_verify_image(image, 'iexplore_child')
97
+ [image.width, image.height].should == Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd)
98
+ end
99
+
100
+ it "captures whole window if window size is specified as coordinates" do
101
+ window = RAutomation::Window.new(:pid => @calc)
102
+ expected_width, expected_height = Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd)
103
+ image = Win32::Screenshot::Take.of(:window, :rautomation => window, :area => [0, 0, expected_width, expected_height])
104
+ save_and_verify_image(image, 'calc_area_full_window')
105
+ image.width.should == expected_width
106
+ image.height.should == expected_height
107
+ end
108
+
109
+ it "doesn't allow to capture area of the window with negative coordinates" do
110
+ expect {Win32::Screenshot::Take.of(:window, :pid => @calc, :area => [0, 0, -1, 100])}.
111
+ to raise_exception("specified coordinates (x1: 0, y1: 0, x2: -1, y2: 100) are invalid - cannot be negative!")
112
+ end
113
+
114
+ it "doesn't allow to capture area of the window if coordinates are the same" do
115
+ expect {Win32::Screenshot::Take.of(:window, :pid => @calc, :area => [10, 0, 10, 20])}.
116
+ to raise_exception("specified coordinates (x1: 10, y1: 0, x2: 10, y2: 20) are invalid - cannot be x1 >= x2 or y1 >= y2!")
117
+ end
118
+
119
+ it "doesn't allow to capture area of the window if second coordinate is smaller than first one" do
120
+ expect {Win32::Screenshot::Take.of(:window, :pid => @calc, :area => [0, 10, 10, 9])}.
121
+ to raise_exception("specified coordinates (x1: 0, y1: 10, x2: 10, y2: 9) are invalid - cannot be x1 >= x2 or y1 >= y2!")
122
+ end
123
+
124
+ it "doesn't allow to capture area of the window with too big coordinates" do
125
+ window = RAutomation::Window.new(:pid => @calc)
126
+ expected_width, expected_height = Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd)
127
+ expect {Win32::Screenshot::Take.of(:window, :pid => @calc, :area => [0, 0, 10, 1000])}.
128
+ to raise_exception("specified coordinates (x1: 0, y1: 0, x2: 10, y2: 1000) are invalid - maximum x2: #{expected_width} and y2: #{expected_height}!")
129
+ end
130
+
131
+ after :all do
132
+ [@iexplore, @calc].each do |pid|
133
+ # kill them in a jruby friendly way
134
+ system("taskkill /PID #{pid} > nul")
135
+ end
136
+ end
137
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{win32screenshot}
8
- s.version = "0.0.8"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jarmo Pertman", "Aslak Helles\303\270y"]
12
- s.date = %q{2010-12-13}
12
+ s.date = %q{2010-12-17}
13
13
  s.description = %q{Capture Screenshots on Windows with Ruby}
14
14
  s.email = ["jarmo.p@gmail.com", "aslak.hellesoy@gmail.com"]
15
15
  s.extra_rdoc_files = [
@@ -19,18 +19,40 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
+ ".rspec",
23
+ ".yardopts",
22
24
  "History.rdoc",
23
25
  "LICENSE",
24
26
  "README.rdoc",
25
27
  "Rakefile",
26
28
  "VERSION",
29
+ "ext/CORE_RL_bzlib_.dll",
30
+ "ext/CORE_RL_jpeg_.dll",
31
+ "ext/CORE_RL_lcms_.dll",
32
+ "ext/CORE_RL_magick_.dll",
33
+ "ext/CORE_RL_png_.dll",
34
+ "ext/CORE_RL_ttf_.dll",
35
+ "ext/CORE_RL_wand_.dll",
36
+ "ext/CORE_RL_zlib_.dll",
37
+ "ext/ImageMagick-License.txt",
38
+ "ext/X11.dll",
39
+ "ext/identify.exe",
40
+ "ext/modules/coders/IM_MOD_RL_bmp_.dll",
41
+ "ext/modules/coders/IM_MOD_RL_gif_.dll",
42
+ "ext/modules/coders/IM_MOD_RL_jpeg_.dll",
43
+ "ext/modules/coders/IM_MOD_RL_png_.dll",
44
+ "ext/mogrify.exe",
45
+ "ext/msvcr100.dll",
46
+ "ext/vcomp100.dll",
27
47
  "lib/win32/screenshot.rb",
28
48
  "lib/win32/screenshot/bitmap_maker.rb",
29
- "lib/win32/util.rb",
30
- "spec/spec.opts",
49
+ "lib/win32/screenshot/extensions/rautomation/adapter/ffi/functions.rb",
50
+ "lib/win32/screenshot/extensions/rautomation/adapter/ffi/window.rb",
51
+ "lib/win32/screenshot/image.rb",
52
+ "lib/win32/screenshot/take.rb",
31
53
  "spec/spec_helper.rb",
32
- "spec/win32_screenshot_spec.rb",
33
- "spec/win32_screenshot_util_spec.rb",
54
+ "spec/win32/screenshot/image_spec.rb",
55
+ "spec/win32/screenshot/take_spec.rb",
34
56
  "win32screenshot.gemspec"
35
57
  ]
36
58
  s.homepage = %q{http://github.com/jarmo/win32screenshot}
@@ -40,8 +62,8 @@ Gem::Specification.new do |s|
40
62
  s.summary = %q{Capture Screenshots on Windows with Ruby}
41
63
  s.test_files = [
42
64
  "spec/spec_helper.rb",
43
- "spec/win32_screenshot_spec.rb",
44
- "spec/win32_screenshot_util_spec.rb"
65
+ "spec/win32/screenshot/image_spec.rb",
66
+ "spec/win32/screenshot/take_spec.rb"
45
67
  ]
46
68
 
47
69
  if s.respond_to? :specification_version then
@@ -50,20 +72,20 @@ Gem::Specification.new do |s|
50
72
 
51
73
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
74
  s.add_runtime_dependency(%q<ffi>, ["~> 0"])
53
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
54
- s.add_development_dependency(%q<os>, [">= 0"])
55
- s.add_development_dependency(%q<rmagick>, [">= 0"])
75
+ s.add_runtime_dependency(%q<mini_magick>, ["~> 3.1"])
76
+ s.add_runtime_dependency(%q<rautomation>, ["~> 0.2"])
77
+ s.add_development_dependency(%q<rspec>, ["~> 2.3"])
56
78
  else
57
79
  s.add_dependency(%q<ffi>, ["~> 0"])
58
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
59
- s.add_dependency(%q<os>, [">= 0"])
60
- s.add_dependency(%q<rmagick>, [">= 0"])
80
+ s.add_dependency(%q<mini_magick>, ["~> 3.1"])
81
+ s.add_dependency(%q<rautomation>, ["~> 0.2"])
82
+ s.add_dependency(%q<rspec>, ["~> 2.3"])
61
83
  end
62
84
  else
63
85
  s.add_dependency(%q<ffi>, ["~> 0"])
64
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
65
- s.add_dependency(%q<os>, [">= 0"])
66
- s.add_dependency(%q<rmagick>, [">= 0"])
86
+ s.add_dependency(%q<mini_magick>, ["~> 3.1"])
87
+ s.add_dependency(%q<rautomation>, ["~> 0.2"])
88
+ s.add_dependency(%q<rspec>, ["~> 2.3"])
67
89
  end
68
90
  end
69
91
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32screenshot
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 8
10
- version: 0.0.8
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jarmo Pertman
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-13 00:00:00 +02:00
19
+ date: 2010-12-17 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -34,47 +34,48 @@ dependencies:
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
37
- name: rspec
37
+ name: mini_magick
38
38
  prerelease: false
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
- - - ">="
42
+ - - ~>
43
43
  - !ruby/object:Gem::Version
44
- hash: 13
44
+ hash: 5
45
45
  segments:
46
+ - 3
46
47
  - 1
47
- - 2
48
- - 9
49
- version: 1.2.9
50
- type: :development
48
+ version: "3.1"
49
+ type: :runtime
51
50
  version_requirements: *id002
52
51
  - !ruby/object:Gem::Dependency
53
- name: os
52
+ name: rautomation
54
53
  prerelease: false
55
54
  requirement: &id003 !ruby/object:Gem::Requirement
56
55
  none: false
57
56
  requirements:
58
- - - ">="
57
+ - - ~>
59
58
  - !ruby/object:Gem::Version
60
- hash: 3
59
+ hash: 15
61
60
  segments:
62
61
  - 0
63
- version: "0"
64
- type: :development
62
+ - 2
63
+ version: "0.2"
64
+ type: :runtime
65
65
  version_requirements: *id003
66
66
  - !ruby/object:Gem::Dependency
67
- name: rmagick
67
+ name: rspec
68
68
  prerelease: false
69
69
  requirement: &id004 !ruby/object:Gem::Requirement
70
70
  none: false
71
71
  requirements:
72
- - - ">="
72
+ - - ~>
73
73
  - !ruby/object:Gem::Version
74
- hash: 3
74
+ hash: 5
75
75
  segments:
76
- - 0
77
- version: "0"
76
+ - 2
77
+ - 3
78
+ version: "2.3"
78
79
  type: :development
79
80
  version_requirements: *id004
80
81
  description: Capture Screenshots on Windows with Ruby
@@ -91,18 +92,40 @@ extra_rdoc_files:
91
92
  files:
92
93
  - .document
93
94
  - .gitignore
95
+ - .rspec
96
+ - .yardopts
94
97
  - History.rdoc
95
98
  - LICENSE
96
99
  - README.rdoc
97
100
  - Rakefile
98
101
  - VERSION
102
+ - ext/CORE_RL_bzlib_.dll
103
+ - ext/CORE_RL_jpeg_.dll
104
+ - ext/CORE_RL_lcms_.dll
105
+ - ext/CORE_RL_magick_.dll
106
+ - ext/CORE_RL_png_.dll
107
+ - ext/CORE_RL_ttf_.dll
108
+ - ext/CORE_RL_wand_.dll
109
+ - ext/CORE_RL_zlib_.dll
110
+ - ext/ImageMagick-License.txt
111
+ - ext/X11.dll
112
+ - ext/identify.exe
113
+ - ext/modules/coders/IM_MOD_RL_bmp_.dll
114
+ - ext/modules/coders/IM_MOD_RL_gif_.dll
115
+ - ext/modules/coders/IM_MOD_RL_jpeg_.dll
116
+ - ext/modules/coders/IM_MOD_RL_png_.dll
117
+ - ext/mogrify.exe
118
+ - ext/msvcr100.dll
119
+ - ext/vcomp100.dll
99
120
  - lib/win32/screenshot.rb
100
121
  - lib/win32/screenshot/bitmap_maker.rb
101
- - lib/win32/util.rb
102
- - spec/spec.opts
122
+ - lib/win32/screenshot/extensions/rautomation/adapter/ffi/functions.rb
123
+ - lib/win32/screenshot/extensions/rautomation/adapter/ffi/window.rb
124
+ - lib/win32/screenshot/image.rb
125
+ - lib/win32/screenshot/take.rb
103
126
  - spec/spec_helper.rb
104
- - spec/win32_screenshot_spec.rb
105
- - spec/win32_screenshot_util_spec.rb
127
+ - spec/win32/screenshot/image_spec.rb
128
+ - spec/win32/screenshot/take_spec.rb
106
129
  - win32screenshot.gemspec
107
130
  has_rdoc: true
108
131
  homepage: http://github.com/jarmo/win32screenshot
@@ -141,5 +164,5 @@ specification_version: 3
141
164
  summary: Capture Screenshots on Windows with Ruby
142
165
  test_files:
143
166
  - spec/spec_helper.rb
144
- - spec/win32_screenshot_spec.rb
145
- - spec/win32_screenshot_util_spec.rb
167
+ - spec/win32/screenshot/image_spec.rb
168
+ - spec/win32/screenshot/take_spec.rb