Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for FilterPipeline and UnknownFilter, fix bug #904

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/filters/filters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function Base.getindex(f::FilterPipeline, ::Type{UnknownFilter}, i::Integer, cd_
namebuf = Array{UInt8}(undef, 256)
config = Ref{Cuint}()
id = API.h5p_get_filter(f.plist, i-1, flags, cd_nelmts, cd_values, length(namebuf), namebuf, config)
if cd_nelmts[] < length(cd_values)
if cd_nelmts[] > length(cd_values)
resize!(cd_values, cd_nelmts[])
return getindex(f, UnknownFilter, i, cd_values)
end
Expand Down
15 changes: 15 additions & 0 deletions test/filter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ using HDF5.Filters
using Test
using H5Zblosc, H5Zlz4, H5Zbzip2, H5Zzstd

using HDF5.Filters: UnknownFilter

@testset "filter" begin

# Create a new file
Expand Down Expand Up @@ -108,4 +110,17 @@ h5open(fn, "r") do f
@test f["filtshufdef"][] == data
end

# Filter Pipeline test for UnknownFilter
FILTERS_backup = copy(HDF5.Filters.FILTERS)
Copy link
Member

Choose a reason for hiding this comment

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

Question, why back up FILTERS then restore it again?

Copy link
Member Author

@mkitti mkitti Feb 9, 2022

Choose a reason for hiding this comment

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

We empty FILTERS in the next line. I do not want that to affect subsequent tests, so I back it up and restore it to its original state.

We empty FILTERS so that FilterPipeline will think the LZ4 filter is Unknown.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Thanks.

empty!(HDF5.Filters.FILTERS)
h5open(fn, "w") do f
data = collect(1:128)
filter = UnknownFilter(H5Z_FILTER_LZ4, 0, Cuint[0, 2, 4, 6, 8, 10], "Unknown LZ4", 0)
musm marked this conversation as resolved.
Show resolved Hide resolved
ds, dt = create_dataset(f, "data", data, chunk=(32,), filters=filter)
dcpl = HDF5.get_create_properties(ds)
pipeline = HDF5.Filters.FilterPipeline(dcpl)
@test pipeline[1].data == filter.data
end
merge!(HDF5.Filters.FILTERS, FILTERS_backup)

end # @testset "filter"