|
1 | 1 | require 'spec_helper.rb'
|
2 | 2 |
|
3 |
| -if Vips::at_least_libvips?(8, 9) |
4 |
| - RSpec.describe Vips::Source do |
5 |
| - it 'can create a source from a descriptor' do |
6 |
| - source = Vips::Source.new_from_descriptor(0) |
| 3 | +RSpec.describe Vips::Source, version: [8, 9] do |
| 4 | + it 'can create a source from a descriptor' do |
| 5 | + source = Vips::Source.new_from_descriptor(0) |
7 | 6 |
|
8 |
| - expect(source) |
9 |
| - end |
| 7 | + expect(source) |
| 8 | + end |
10 | 9 |
|
11 |
| - it 'can create a source from a filename' do |
12 |
| - source = Vips::Source.new_from_file simg('wagon.jpg') |
| 10 | + it 'can create a source from a filename' do |
| 11 | + source = Vips::Source.new_from_file simg('wagon.jpg') |
13 | 12 |
|
14 |
| - expect(source) |
15 |
| - end |
| 13 | + expect(source) |
| 14 | + end |
16 | 15 |
|
17 |
| - it 'can\'t create a source from a bad filename' do |
18 |
| - expect { |
19 |
| - Vips::Source.new_from_file simg('banana.jpg') |
20 |
| - }.to raise_exception(Vips::Error) |
21 |
| - end |
| 16 | + it 'can\'t create a source from a bad filename' do |
| 17 | + expect { |
| 18 | + Vips::Source.new_from_file simg('banana.jpg') |
| 19 | + }.to raise_exception(Vips::Error) |
| 20 | + end |
22 | 21 |
|
23 |
| - it 'can create a source from an area of memory' do |
24 |
| - str = File.open(simg('wagon.jpg'), 'rb').read |
25 |
| - source = Vips::Source.new_from_memory str |
| 22 | + it 'can create a source from an area of memory' do |
| 23 | + str = File.open(simg('wagon.jpg'), 'rb').read |
| 24 | + source = Vips::Source.new_from_memory str |
26 | 25 |
|
27 |
| - expect(source) |
28 |
| - end |
| 26 | + expect(source) |
| 27 | + end |
29 | 28 |
|
30 |
| - it 'sources have filenames and nicks' do |
31 |
| - source = Vips::Source.new_from_file simg('wagon.jpg') |
| 29 | + it 'sources have filenames and nicks' do |
| 30 | + source = Vips::Source.new_from_file simg('wagon.jpg') |
32 | 31 |
|
33 |
| - expect(source.filename).to eq(simg('wagon.jpg')) |
34 |
| - expect(source.nick) |
35 |
| - end |
| 32 | + expect(source.filename).to eq(simg('wagon.jpg')) |
| 33 | + expect(source.nick) |
| 34 | + end |
36 | 35 |
|
37 |
| - it 'can load an image from filename source' do |
38 |
| - source = Vips::Source.new_from_file simg('wagon.jpg') |
39 |
| - image = Vips::Image.new_from_source source, '' |
| 36 | + it 'can load an image from filename source' do |
| 37 | + source = Vips::Source.new_from_file simg('wagon.jpg') |
| 38 | + image = Vips::Image.new_from_source source, '' |
40 | 39 |
|
41 |
| - expect(image) |
42 |
| - expect(image.width).to eq(685) |
43 |
| - expect(image.height).to eq(478) |
44 |
| - expect(image.bands).to eq(3) |
45 |
| - expect(image.avg).to be_within(0.001).of(109.789) |
| 40 | + expect(image) |
| 41 | + expect(image.width).to eq(685) |
| 42 | + expect(image.height).to eq(478) |
| 43 | + expect(image.bands).to eq(3) |
| 44 | + expect(image.avg).to be_within(0.001).of(109.789) |
46 | 45 |
|
47 |
| - end |
48 | 46 | end
|
49 | 47 | end
|
50 | 48 |
|
51 |
| -if Vips::at_least_libvips?(8, 9) |
52 |
| - RSpec.describe Vips::Target do |
53 |
| - it 'can create a target to a filename' do |
54 |
| - target = Vips::Target.new_to_file timg('x.jpg') |
55 |
| - |
56 |
| - expect(target) |
57 |
| - end |
58 |
| - |
59 |
| - it 'can create a target to a descriptor' do |
60 |
| - target = Vips::Target.new_to_descriptor 1 |
61 |
| - |
62 |
| - expect(target) |
63 |
| - end |
64 |
| - |
65 |
| - it 'can create a target to a memory area' do |
66 |
| - target = Vips::Target.new_to_memory |
67 |
| - |
68 |
| - expect(target) |
69 |
| - end |
70 |
| - |
71 |
| - it 'can\'t create a target to a bad filename' do |
72 |
| - expect { |
73 |
| - Vips::Target.new_to_file '/banana/monkey' |
74 |
| - }.to raise_exception(Vips::Error) |
75 |
| - end |
76 |
| - |
77 |
| - it 'can save an image to a filename target' do |
78 |
| - source = Vips::Source.new_from_file simg('wagon.jpg') |
79 |
| - image = Vips::Image.new_from_source source, '' |
80 |
| - filename = timg('x4.png') |
81 |
| - target = Vips::Target.new_to_file filename |
82 |
| - image.write_to_target target, '.png' |
83 |
| - |
84 |
| - image = Vips::Image.new_from_file filename |
85 |
| - expect(image) |
86 |
| - expect(image.width).to eq(685) |
87 |
| - expect(image.height).to eq(478) |
88 |
| - expect(image.bands).to eq(3) |
89 |
| - expect(image.avg).to be_within(0.001).of(109.789) |
90 |
| - end |
91 |
| - |
92 |
| - it 'can save an image to a memory target' do |
93 |
| - source = Vips::Source.new_from_file simg('wagon.jpg') |
94 |
| - image = Vips::Image.new_from_source source, '' |
95 |
| - target = Vips::Target.new_to_memory |
96 |
| - image.write_to_target target, '.png' |
97 |
| - memory = target.get('blob') |
98 |
| - |
99 |
| - image = Vips::Image.new_from_buffer memory, '' |
100 |
| - expect(image) |
101 |
| - expect(image.width).to eq(685) |
102 |
| - expect(image.height).to eq(478) |
103 |
| - expect(image.bands).to eq(3) |
104 |
| - expect(image.avg).to be_within(0.001).of(109.789) |
105 |
| - end |
| 49 | +RSpec.describe Vips::Target, version: [8, 9] do |
| 50 | + it 'can create a target to a filename' do |
| 51 | + target = Vips::Target.new_to_file timg('x.jpg') |
| 52 | + |
| 53 | + expect(target) |
| 54 | + end |
| 55 | + |
| 56 | + it 'can create a target to a descriptor' do |
| 57 | + target = Vips::Target.new_to_descriptor 1 |
| 58 | + |
| 59 | + expect(target) |
| 60 | + end |
| 61 | + |
| 62 | + it 'can create a target to a memory area' do |
| 63 | + target = Vips::Target.new_to_memory |
106 | 64 |
|
| 65 | + expect(target) |
107 | 66 | end
|
| 67 | + |
| 68 | + it 'can\'t create a target to a bad filename' do |
| 69 | + expect { |
| 70 | + Vips::Target.new_to_file '/banana/monkey' |
| 71 | + }.to raise_exception(Vips::Error) |
| 72 | + end |
| 73 | + |
| 74 | + it 'can save an image to a filename target' do |
| 75 | + source = Vips::Source.new_from_file simg('wagon.jpg') |
| 76 | + image = Vips::Image.new_from_source source, '' |
| 77 | + filename = timg('x4.png') |
| 78 | + target = Vips::Target.new_to_file filename |
| 79 | + image.write_to_target target, '.png' |
| 80 | + |
| 81 | + image = Vips::Image.new_from_file filename |
| 82 | + expect(image) |
| 83 | + expect(image.width).to eq(685) |
| 84 | + expect(image.height).to eq(478) |
| 85 | + expect(image.bands).to eq(3) |
| 86 | + expect(image.avg).to be_within(0.001).of(109.789) |
| 87 | + end |
| 88 | + |
| 89 | + it 'can save an image to a memory target' do |
| 90 | + source = Vips::Source.new_from_file simg('wagon.jpg') |
| 91 | + image = Vips::Image.new_from_source source, '' |
| 92 | + target = Vips::Target.new_to_memory |
| 93 | + image.write_to_target target, '.png' |
| 94 | + memory = target.get('blob') |
| 95 | + |
| 96 | + image = Vips::Image.new_from_buffer memory, '' |
| 97 | + expect(image) |
| 98 | + expect(image.width).to eq(685) |
| 99 | + expect(image.height).to eq(478) |
| 100 | + expect(image.bands).to eq(3) |
| 101 | + expect(image.avg).to be_within(0.001).of(109.789) |
| 102 | + end |
| 103 | + |
108 | 104 | end
|
109 | 105 |
|
110 |
| -if Vips::at_least_libvips?(8, 9) |
111 |
| - RSpec.describe Vips::SourceCustom do |
112 |
| - it 'can create a custom source' do |
113 |
| - source = Vips::SourceCustom.new |
114 |
| - |
115 |
| - expect(source) |
116 |
| - end |
117 |
| - |
118 |
| - it 'can load a custom source' do |
119 |
| - file = File.open simg('wagon.jpg'), "rb" |
120 |
| - source = Vips::SourceCustom.new |
121 |
| - source.on_read { |length| file.read length } |
122 |
| - source.on_seek { |offset, whence| file.seek(offset, whence) } |
123 |
| - image = Vips::Image.new_from_source source, "" |
124 |
| - |
125 |
| - expect(image) |
126 |
| - expect(image.width).to eq(685) |
127 |
| - expect(image.height).to eq(478) |
128 |
| - expect(image.bands).to eq(3) |
129 |
| - expect(image.avg).to be_within(0.001).of(109.789) |
130 |
| - end |
131 |
| - |
132 |
| - it 'on_seek is optional' do |
133 |
| - file = File.open simg('wagon.jpg'), "rb" |
134 |
| - source = Vips::SourceCustom.new |
135 |
| - source.on_read { |length| file.read length } |
136 |
| - image = Vips::Image.new_from_source source, "" |
137 |
| - |
138 |
| - expect(image) |
139 |
| - expect(image.width).to eq(685) |
140 |
| - expect(image.height).to eq(478) |
141 |
| - expect(image.bands).to eq(3) |
142 |
| - expect(image.avg).to be_within(0.001).of(109.789) |
143 |
| - end |
144 |
| - |
145 |
| - it 'can create a user output stream' do |
146 |
| - target = Vips::TargetCustom.new |
147 |
| - |
148 |
| - expect(target) |
149 |
| - end |
150 |
| - |
151 |
| - it 'can write an image to a user output stream' do |
152 |
| - filename = timg('x5.png') |
153 |
| - file = File.open filename, "wb" |
154 |
| - target = Vips::TargetCustom.new |
155 |
| - target.on_write { |chunk| file.write(chunk) } |
156 |
| - target.on_finish { file.close } |
157 |
| - image = Vips::Image.new_from_file simg('wagon.jpg') |
158 |
| - image.write_to_target target, ".png" |
159 |
| - |
160 |
| - image = Vips::Image.new_from_file filename |
161 |
| - expect(image) |
162 |
| - expect(image.width).to eq(685) |
163 |
| - expect(image.height).to eq(478) |
164 |
| - expect(image.bands).to eq(3) |
165 |
| - expect(image.avg).to be_within(0.001).of(109.789) |
166 |
| - end |
| 106 | +RSpec.describe Vips::SourceCustom, version: [8, 9] do |
| 107 | + it 'can create a custom source' do |
| 108 | + source = Vips::SourceCustom.new |
| 109 | + |
| 110 | + expect(source) |
| 111 | + end |
| 112 | + |
| 113 | + it 'can load a custom source' do |
| 114 | + file = File.open simg('wagon.jpg'), "rb" |
| 115 | + source = Vips::SourceCustom.new |
| 116 | + source.on_read { |length| file.read length } |
| 117 | + source.on_seek { |offset, whence| file.seek(offset, whence) } |
| 118 | + image = Vips::Image.new_from_source source, "" |
| 119 | + |
| 120 | + expect(image) |
| 121 | + expect(image.width).to eq(685) |
| 122 | + expect(image.height).to eq(478) |
| 123 | + expect(image.bands).to eq(3) |
| 124 | + expect(image.avg).to be_within(0.001).of(109.789) |
| 125 | + end |
| 126 | + |
| 127 | + it 'on_seek is optional' do |
| 128 | + file = File.open simg('wagon.jpg'), "rb" |
| 129 | + source = Vips::SourceCustom.new |
| 130 | + source.on_read { |length| file.read length } |
| 131 | + image = Vips::Image.new_from_source source, "" |
| 132 | + |
| 133 | + expect(image) |
| 134 | + expect(image.width).to eq(685) |
| 135 | + expect(image.height).to eq(478) |
| 136 | + expect(image.bands).to eq(3) |
| 137 | + expect(image.avg).to be_within(0.001).of(109.789) |
| 138 | + end |
| 139 | + |
| 140 | + it 'can create a user output stream' do |
| 141 | + target = Vips::TargetCustom.new |
| 142 | + |
| 143 | + expect(target) |
| 144 | + end |
167 | 145 |
|
| 146 | + it 'can write an image to a user output stream' do |
| 147 | + filename = timg('x5.png') |
| 148 | + file = File.open filename, "wb" |
| 149 | + target = Vips::TargetCustom.new |
| 150 | + target.on_write { |chunk| file.write(chunk) } |
| 151 | + target.on_finish { file.close } |
| 152 | + image = Vips::Image.new_from_file simg('wagon.jpg') |
| 153 | + image.write_to_target target, ".png" |
| 154 | + |
| 155 | + image = Vips::Image.new_from_file filename |
| 156 | + expect(image) |
| 157 | + expect(image.width).to eq(685) |
| 158 | + expect(image.height).to eq(478) |
| 159 | + expect(image.bands).to eq(3) |
| 160 | + expect(image.avg).to be_within(0.001).of(109.789) |
168 | 161 | end
|
169 | 162 |
|
170 | 163 | end
|
0 commit comments