From a9af99781845aa3b935dd8b2e081721c91e5232f Mon Sep 17 00:00:00 2001 From: Kenta Sato Date: Fri, 30 Mar 2018 17:16:45 +0900 Subject: [PATCH 1/3] add some tests ported from TranscodingStreams.jl --- test/runtests.jl | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index b7c072b..55db31c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,6 +6,7 @@ else using Test end import TranscodingStreams: + TranscodingStreams, TranscodingStream, test_roundtrip_read, test_roundtrip_write, @@ -222,3 +223,76 @@ end @test_throws ArgumentError DeflateCompressor(windowbits=16) @test_throws ArgumentError DeflateDecompressor(windowbits=16) end + +# Test APIs of TranscodingStreams.jl using the gzip compressor/decompressor. +@testset "TranscodingStreams" begin + TranscodingStreams.test_chunked_read(GzipCompressor, GzipDecompressor) + TranscodingStreams.test_chunked_write(GzipCompressor, GzipDecompressor) + TranscodingStreams.test_roundtrip_fileio(GzipCompressor, GzipDecompressor) + + @testset "seek" begin + data = transcode(GzipCompressor, Vector(b"abracadabra")) + stream = TranscodingStream(GzipDecompressor(), IOBuffer(data)) + seekstart(stream) + @test read(stream, 3) == b"abr" + seekstart(stream) + @test read(stream, 3) == b"abr" + seekend(stream) + #@test eof(stream) + end + + @testset "panic" begin + stream = TranscodingStream(GzipDecompressor(), IOBuffer("some invalid data")) + @test_throws ErrorException read(stream) + @test_throws ArgumentError eof(stream) + end + + testfile = joinpath(dirname(@__FILE__), "abra.gzip") + + @testset "open" begin + open(CodecZlib.GzipDecompressorStream, testfile) do stream + @test read(stream) == b"abracadabra" + end + end + + @testset "stats" begin + size = filesize(testfile) + stream = CodecZlib.GzipDecompressorStream(open(testfile)) + stats = TranscodingStreams.stats(stream) + @test stats.in == 0 + @test stats.out == 0 + @test stats.transcoded_in == 0 + @test stats.transcoded_out == 0 + read(stream, UInt8) + stats = TranscodingStreams.stats(stream) + @test stats.in == size + @test stats.out == 1 + @test stats.transcoded_in == size + @test stats.transcoded_out == 11 + close(stream) + @test_throws ArgumentError TranscodingStreams.stats(stream) + + buf = IOBuffer() + stream = CodecZlib.GzipCompressorStream(buf) + stats = TranscodingStreams.stats(stream) + @test stats.in == 0 + @test stats.out == 0 + @test stats.transcoded_in == 0 + @test stats.transcoded_out == 0 + write(stream, b"abracadabra") + stats = TranscodingStreams.stats(stream) + @test stats.in == 11 + @test stats.out == 0 + @test stats.transcoded_in == 0 + @test stats.transcoded_out == 0 + write(stream, TranscodingStreams.TOKEN_END) + flush(stream) + stats = TranscodingStreams.stats(stream) + @test stats.in == 11 + @test stats.out == position(buf) + @test stats.transcoded_in == 11 + @test stats.transcoded_out == position(buf) + close(stream) + @test_throws ArgumentError TranscodingStreams.stats(stream) + end +end From d51543b97e0a709f8ac204f38c40712b45d3c444 Mon Sep 17 00:00:00 2001 From: Kenta Sato Date: Fri, 30 Mar 2018 17:17:47 +0900 Subject: [PATCH 2/3] fixup! add some tests ported from TranscodingStreams.jl --- test/runtests.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 55db31c..9266d9e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -250,14 +250,14 @@ end testfile = joinpath(dirname(@__FILE__), "abra.gzip") @testset "open" begin - open(CodecZlib.GzipDecompressorStream, testfile) do stream + open(GzipDecompressorStream, testfile) do stream @test read(stream) == b"abracadabra" end end @testset "stats" begin size = filesize(testfile) - stream = CodecZlib.GzipDecompressorStream(open(testfile)) + stream = GzipDecompressorStream(open(testfile)) stats = TranscodingStreams.stats(stream) @test stats.in == 0 @test stats.out == 0 @@ -273,7 +273,7 @@ end @test_throws ArgumentError TranscodingStreams.stats(stream) buf = IOBuffer() - stream = CodecZlib.GzipCompressorStream(buf) + stream = GzipCompressorStream(buf) stats = TranscodingStreams.stats(stream) @test stats.in == 0 @test stats.out == 0 From ae865672d2730f56a61415e3778965c237ec7f22 Mon Sep 17 00:00:00 2001 From: Kenta Sato Date: Fri, 30 Mar 2018 17:18:16 +0900 Subject: [PATCH 3/3] fixup! fixup! add some tests ported from TranscodingStreams.jl --- test/abra.gz | Bin 0 -> 29 bytes test/runtests.jl | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 test/abra.gz diff --git a/test/abra.gz b/test/abra.gz new file mode 100644 index 0000000000000000000000000000000000000000..fd3ecd49268125a8158ab80d01b26082ce775ecf GIT binary patch literal 29 kcmb2|=3sb!+BlMd+1p3U%g4{hlO>2@`_EV6+zbp10D=z)KmY&$ literal 0 HcmV?d00001 diff --git a/test/runtests.jl b/test/runtests.jl index 9266d9e..2b21ae2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -247,7 +247,7 @@ end @test_throws ArgumentError eof(stream) end - testfile = joinpath(dirname(@__FILE__), "abra.gzip") + testfile = joinpath(dirname(@__FILE__), "abra.gz") @testset "open" begin open(GzipDecompressorStream, testfile) do stream