From 353b02aa0646b8b4beb5ed6edb8598aa82ba4767 Mon Sep 17 00:00:00 2001 From: nhz2 Date: Wed, 4 Dec 2024 14:52:38 -0500 Subject: [PATCH] Add test for reusing encoder after finalize --- lib/TestsForCodecPackages/Project.toml | 2 +- .../src/TestsForCodecPackages.jl | 33 ++++++++++++++++++- test/Project.toml | 4 +++ test/codecdoubleframe.jl | 4 ++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/TestsForCodecPackages/Project.toml b/lib/TestsForCodecPackages/Project.toml index 0940f55..00b0e6b 100644 --- a/lib/TestsForCodecPackages/Project.toml +++ b/lib/TestsForCodecPackages/Project.toml @@ -1,7 +1,7 @@ name = "TestsForCodecPackages" uuid = "c2e61002-3542-480d-8b3c-5f05cc4f8554" authors = ["nhz2 "] -version = "0.1.0" +version = "0.1.1" [deps] Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/lib/TestsForCodecPackages/src/TestsForCodecPackages.jl b/lib/TestsForCodecPackages/src/TestsForCodecPackages.jl index bba8e9e..7924f6f 100644 --- a/lib/TestsForCodecPackages/src/TestsForCodecPackages.jl +++ b/lib/TestsForCodecPackages/src/TestsForCodecPackages.jl @@ -16,7 +16,8 @@ export test_roundtrip_seekstart, test_roundtrip_fileio, test_chunked_read, - test_chunked_write + test_chunked_write, + test_reuse_encoder function test_roundtrip_read(encoder, decoder) seed!(TEST_RANDOM_SEED) @@ -157,4 +158,34 @@ function test_chunked_write(Encoder, Decoder) finalize(encoder) end +function test_reuse_encoder(Encoder, Decoder) + seed!(TEST_RANDOM_SEED) + compressor = Encoder() + x = rand(UInt8, 1000) + TranscodingStreams.initialize(compressor) + ret1 = transcode(compressor, x) + TranscodingStreams.finalize(compressor) + + # compress again using the same compressor + TranscodingStreams.initialize(compressor) + ret2 = transcode(compressor, x) + ret3 = transcode(compressor, x) + TranscodingStreams.finalize(compressor) + + Test.@test transcode(Decoder, ret1) == x + Test.@test transcode(Decoder, ret2) == x + Test.@test transcode(Decoder, ret3) == x + Test.@test ret1 == ret2 + Test.@test ret1 == ret3 + + decompressor = Decoder() + TranscodingStreams.initialize(decompressor) + Test.@test transcode(decompressor, ret1) == x + TranscodingStreams.finalize(decompressor) + + TranscodingStreams.initialize(decompressor) + Test.@test transcode(decompressor, ret1) == x + TranscodingStreams.finalize(decompressor) +end + end # module TestsForCodecPackages diff --git a/test/Project.toml b/test/Project.toml index 6222272..afed488 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -6,3 +6,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TestsForCodecPackages = "c2e61002-3542-480d-8b3c-5f05cc4f8554" TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" + +[sources] +TranscodingStreams = {path = ".."} +TestsForCodecPackages = {path = "../lib/TestsForCodecPackages"} diff --git a/test/codecdoubleframe.jl b/test/codecdoubleframe.jl index 0d85b37..385dd15 100644 --- a/test/codecdoubleframe.jl +++ b/test/codecdoubleframe.jl @@ -13,7 +13,8 @@ using TestsForCodecPackages: test_roundtrip_seekstart, test_roundtrip_fileio, test_chunked_read, - test_chunked_write + test_chunked_write, + test_reuse_encoder # An insane codec for testing the codec APIs. struct DoubleFrameEncoder <: TranscodingStreams.Codec @@ -461,4 +462,5 @@ DoubleFrameDecoderStream(stream::IO; kwargs...) = TranscodingStream(DoubleFrameD test_roundtrip_fileio(DoubleFrameEncoder, DoubleFrameDecoder) test_chunked_read(DoubleFrameEncoder, DoubleFrameDecoder) test_chunked_write(DoubleFrameEncoder, DoubleFrameDecoder) + test_reuse_encoder(DoubleFrameEncoder, DoubleFrameDecoder) end