2008-06-02 18:42:10 -04:00
|
|
|
require 'abstract_unit'
|
2011-02-09 05:36:44 -05:00
|
|
|
require 'active_support/core_ext/object/blank'
|
2008-06-02 18:42:10 -04:00
|
|
|
|
2012-01-05 20:12:46 -05:00
|
|
|
class GzipTest < ActiveSupport::TestCase
|
2008-06-02 18:42:10 -04:00
|
|
|
def test_compress_should_decompress_to_the_same_value
|
|
|
|
assert_equal "Hello World", ActiveSupport::Gzip.decompress(ActiveSupport::Gzip.compress("Hello World"))
|
2012-09-22 05:07:50 -04:00
|
|
|
assert_equal "Hello World", ActiveSupport::Gzip.decompress(ActiveSupport::Gzip.compress("Hello World", Zlib::NO_COMPRESSION))
|
|
|
|
assert_equal "Hello World", ActiveSupport::Gzip.decompress(ActiveSupport::Gzip.compress("Hello World", Zlib::BEST_SPEED))
|
|
|
|
assert_equal "Hello World", ActiveSupport::Gzip.decompress(ActiveSupport::Gzip.compress("Hello World", Zlib::BEST_COMPRESSION))
|
|
|
|
assert_equal "Hello World", ActiveSupport::Gzip.decompress(ActiveSupport::Gzip.compress("Hello World", nil, Zlib::FILTERED))
|
|
|
|
assert_equal "Hello World", ActiveSupport::Gzip.decompress(ActiveSupport::Gzip.compress("Hello World", nil, Zlib::HUFFMAN_ONLY))
|
|
|
|
assert_equal "Hello World", ActiveSupport::Gzip.decompress(ActiveSupport::Gzip.compress("Hello World", nil, nil))
|
2008-06-02 18:42:10 -04:00
|
|
|
end
|
2011-02-09 04:23:45 -05:00
|
|
|
|
|
|
|
def test_compress_should_return_a_binary_string
|
|
|
|
compressed = ActiveSupport::Gzip.compress('')
|
|
|
|
|
2011-12-24 07:57:54 -05:00
|
|
|
assert_equal Encoding.find('binary'), compressed.encoding
|
2011-02-09 04:23:45 -05:00
|
|
|
assert !compressed.blank?, "a compressed blank string should not be blank"
|
|
|
|
end
|
2012-09-22 05:07:50 -04:00
|
|
|
|
|
|
|
def test_compress_should_return_gzipped_string_by_compression_level
|
|
|
|
source_string = "Hello World"*100
|
|
|
|
|
|
|
|
gzipped_by_speed = ActiveSupport::Gzip.compress(source_string, Zlib::BEST_SPEED)
|
|
|
|
assert_equal 1, Zlib::GzipReader.new(StringIO.new(gzipped_by_speed)).level
|
|
|
|
|
|
|
|
gzipped_by_best_compression = ActiveSupport::Gzip.compress(source_string, Zlib::BEST_COMPRESSION)
|
|
|
|
assert_equal 9, Zlib::GzipReader.new(StringIO.new(gzipped_by_best_compression)).level
|
|
|
|
|
|
|
|
assert_equal true, (gzipped_by_best_compression.bytesize < gzipped_by_speed.bytesize)
|
|
|
|
end
|
2011-02-09 05:36:44 -05:00
|
|
|
end
|