Skip to content

Commit ef50d66

Browse files
committed
Fixed string attribute reading, added a unittest for that
1 parent 2819dcb commit ef50d66

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

src/minc2_io.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ function read_attribute(h::VolumeHandle,
596596
# TODO: make sure it's a good assumption
597597
if attr_type[] == minc2_simple.MINC2_STRING
598598
# remove trailing 0?
599-
_buf = Vector{UInt8}(undef,attr_length[]+1)
599+
_buf = Vector{UInt8}(undef,attr_length[])
600600
@minc2_check minc2_simple.minc2_read_attribute(h.x[], group, attribute, _buf, attr_length[])
601601
return String(_buf)
602602
elseif attr_type[] == minc2_simple.MINC2_FLOAT
777 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vfonov:gonzalo:2022.03.24.14.04.08:1124386:1

test/runtests.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ using Tables
1212

1313
@testset "Reading attributes" begin
1414
h=Minc2.open_minc_file("input/t1_z+_byte_cor.mnc")
15-
@test length(Minc2.read_attribute(h,"","history")) == 777
16-
@test length(Minc2.read_attribute(h,"","ident")) == 45
17-
### TODO: add tests for more attributes
15+
@test Minc2.read_attribute(h,"","history") == String(read("input/t1_z+_byte_cor.history.txt"))
16+
@test Minc2.read_attribute(h,"","ident") == String(read("input/t1_z+_byte_cor.ident.txt"))
17+
Minc2.close_minc_file(h)
18+
end
19+
20+
@testset "Reading attributes 2" begin
21+
h=Minc2.open_minc_file("input/3DDoubleImage_double_byte.mnc")
22+
@test Minc2.read_attribute(h,"acquisition","StdString") == "Test std::string\0"
1823
Minc2.close_minc_file(h)
1924
end
2025

0 commit comments

Comments
 (0)