Update APNGInspector class and add tests (fixes #2237)
BIN
test/files/apng/actl_wronglen.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
test/files/apng/actl_zero_frames.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
test/files/apng/broken.png
Normal file
|
After Width: | Height: | Size: 400 B |
0
test/files/apng/empty.png
Normal file
BIN
test/files/apng/iend_missing.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
test/files/apng/jpg.png
Normal file
|
After Width: | Height: | Size: 989 B |
BIN
test/files/apng/misaligned_chunks.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
test/files/apng/normal_apng.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
test/files/apng/not_apng.png
Normal file
|
After Width: | Height: | Size: 400 B |
BIN
test/files/apng/single_frame.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
64
test/unit/apng_inspector_test.rb
Normal file
@@ -0,0 +1,64 @@
|
||||
require "test_helper"
|
||||
|
||||
class DTextTest < ActiveSupport::TestCase
|
||||
def inspect(filename)
|
||||
apng = APNGInspector.new("#{Rails.root}/test/files/apng/#{filename}")
|
||||
apng.inspect!
|
||||
apng
|
||||
end
|
||||
context "APNG inspector" do
|
||||
should "correctly parse normal APNG file" do
|
||||
apng = inspect('normal_apng.png')
|
||||
assert_equal(3, apng.frames)
|
||||
assert_equal(true, apng.animated?)
|
||||
assert_equal(false, apng.corrupted?)
|
||||
end
|
||||
|
||||
should "recognize 1-frame APNG as animated" do
|
||||
apng = inspect('single_frame.png')
|
||||
assert_equal(1, apng.frames)
|
||||
assert_equal(true, apng.animated?)
|
||||
assert_equal(false, apng.corrupted?)
|
||||
end
|
||||
|
||||
should "correctly parse normal PNG file" do
|
||||
apng = inspect('not_apng.png')
|
||||
assert_equal(false, apng.animated?)
|
||||
assert_equal(false, apng.corrupted?)
|
||||
end
|
||||
|
||||
should "handle empty file" do
|
||||
apng = inspect('empty.png')
|
||||
assert_equal(false, apng.animated?)
|
||||
assert_equal(true, apng.corrupted?)
|
||||
end
|
||||
|
||||
should "handle corrupted files" do
|
||||
apng = inspect('iend_missing.png')
|
||||
assert_equal(false, apng.animated?)
|
||||
assert_equal(true, apng.corrupted?)
|
||||
apng = inspect('misaligned_chunks.png')
|
||||
assert_equal(false, apng.animated?)
|
||||
assert_equal(true, apng.corrupted?)
|
||||
apng = inspect('broken.png')
|
||||
assert_equal(false, apng.animated?)
|
||||
assert_equal(true, apng.corrupted?)
|
||||
end
|
||||
|
||||
should "handle incorrect acTL chunk" do
|
||||
apng = inspect('actl_wronglen.png')
|
||||
assert_equal(false, apng.animated?)
|
||||
assert_equal(true, apng.corrupted?)
|
||||
apng = inspect('actl_zero_frames.png')
|
||||
assert_equal(false, apng.animated?)
|
||||
assert_equal(true, apng.corrupted?)
|
||||
end
|
||||
|
||||
should "handle non-png files" do
|
||||
apng = inspect('jpg.png')
|
||||
assert_equal(false, apng.animated?)
|
||||
assert_equal(true, apng.corrupted?)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||