Skip to content

Commit

Permalink
Add test for reusing encoder after finalize (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 authored Dec 9, 2024
1 parent ad1f984 commit 709967d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/TestsForCodecPackages/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TestsForCodecPackages"
uuid = "c2e61002-3542-480d-8b3c-5f05cc4f8554"
authors = ["nhz2 <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
33 changes: 32 additions & 1 deletion lib/TestsForCodecPackages/src/TestsForCodecPackages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
4 changes: 3 additions & 1 deletion test/codecdoubleframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

2 comments on commit 709967d

@nhz2
Copy link
Member Author

@nhz2 nhz2 commented on 709967d Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register subdir=lib/TestsForCodecPackages

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/121167

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a TestsForCodecPackages-v0.1.1 -m "<description of version>" 709967d2953fe8174cdeae2c9d2ac07a0e5c846c
git push origin TestsForCodecPackages-v0.1.1

Please sign in to comment.