File: decoding_spec.rb

package info (click to toggle)
ruby-oily-png 1.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 616 kB
  • sloc: ansic: 884; ruby: 313; makefile: 25
file content (51 lines) | stat: -rw-r--r-- 2,226 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'spec_helper'

describe OilyPNG::PNGDecoding do

  it "should call ChunkyPNG::Color.pixel_bytesize in the pure ruby version" do
    ChunkyPNG::Color.should_receive(:pixel_bytesize).and_return(3)
    ChunkyPNG::Canvas.from_file(resource_file('square.png'))
  end

  it "should not call ChunkyPNG::Color.pixel_bytesize in the native version" do
    ChunkyPNG::Color.should_not_receive(:pixel_bytesize)
    OilyPNG::Canvas.from_file(resource_file('square.png'))
  end
  
  context 'decoding different filtering methods' do
    before(:all) { @reference = ChunkyPNG::Canvas.from_file(resource_file('nonsquare.png'))}
    
    it "should decode NONE filtering exactly the same as ChunkyPNG" do
      filtered_data = @reference.to_blob(:filtering => ChunkyPNG::FILTER_NONE)
      ChunkyPNG::Canvas.from_blob(filtered_data).should == OilyPNG::Canvas.from_blob(filtered_data)
    end
    
    it "should decode SUB filtering exactly the same as ChunkyPNG" do
      filtered_data = @reference.to_blob(:filtering => ChunkyPNG::FILTER_SUB)
      ChunkyPNG::Canvas.from_blob(filtered_data).should == OilyPNG::Canvas.from_blob(filtered_data)
    end
    
    it "should decode UP filtering exactly the same as ChunkyPNG" do
      filtered_data = @reference.to_blob(:filtering => ChunkyPNG::FILTER_UP)
      ChunkyPNG::Canvas.from_blob(filtered_data).should == OilyPNG::Canvas.from_blob(filtered_data)
    end
    
    it "should decode AVERAGE filtering exactly the same as ChunkyPNG" do
      filtered_data = @reference.to_blob(:filtering => ChunkyPNG::FILTER_AVERAGE)
      ChunkyPNG::Canvas.from_blob(filtered_data).should == OilyPNG::Canvas.from_blob(filtered_data)
    end
    
    it "should decode PAETH filtering exactly the same as ChunkyPNG" do
      filtered_data = @reference.to_blob(:filtering => ChunkyPNG::FILTER_PAETH)
      ChunkyPNG::Canvas.from_blob(filtered_data).should == OilyPNG::Canvas.from_blob(filtered_data)
    end
  end
  
  context 'decoding compatibility with ChunkyPNG' do
    resource_files.each do |file|
      it "should #{File.basename(file)} the same as ChunkyPNG" do
        OilyPNG::Canvas.from_file(file).pixels.should == ChunkyPNG::Canvas.from_file(file).pixels
      end
    end
  end
end