From fdeabdc76590d856e1994d5bc0814b82e2018843 Mon Sep 17 00:00:00 2001 From: Alberto Barradas Date: Wed, 8 Jan 2025 15:45:04 +0100 Subject: [PATCH 1/5] Add tests for string markers --- test/Project.toml | 1 + test/runtests.jl | 35 ++++++++++++++++++++++++++++++++++ test/testdata/test_chunk3.xdf | Bin 0 -> 1482 bytes 3 files changed, 36 insertions(+) create mode 100644 test/testdata/test_chunk3.xdf diff --git a/test/Project.toml b/test/Project.toml index a9fed57..dc7f079 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,3 +1,4 @@ [deps] Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index b3b3b32..cad490f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -69,3 +69,38 @@ end @test endswith(streams[2]["footer"], "") @test size(streams[2]["data"]) == (27815, 8) end + +@testset "strings" begin + file = "./test/testdata/test_chunk3.xdf" + @testset "strings.sha256" begin + open(file) do f + @test bytes2hex(sha256(f)) == + "c730991efa078906117aa2accdca5f0ea11c54f43c3884770eba21e5a72edb82" + end + end + @testset "strings.read_xdf" begin + using XDF: XDF + streams = XDF.read_xdf(file) + end + # @testset "strings.dejitter" begin + # using XDF: XDF + # streams = XDF.read_xdf(file) + # s1 = streams[3735928559] + # @test s1["type"] == "Marker" + # @test s1["nchannels"] == 2 + # @test s1["srate"] == 1000.0 + # @test s1["dtype"] == String + # @test size(s1["data"]) == (1, 2) + # @test s1["data"] == ["Marker 0A" "Marker 0A"] + # s2 = streams[46202862] + # @test s2["type"] == "EEG" + # @test s2["nchannels"] == 64 + # @test s2["srate"] == 1000.0 + # @test s2["dtype"] == Float64 + # @test size(s2["data"]) == (1, 64) + # @test sum(s2["data"]) == 0.0 + # sgs = [XDF.dejitter(streams[k])["segments"] for k in keys(streams)] + # @test sgs[1] == [(1, 1)] + # @test sgs[2] == [(1, 1)] + # end +end diff --git a/test/testdata/test_chunk3.xdf b/test/testdata/test_chunk3.xdf new file mode 100644 index 0000000000000000000000000000000000000000..eebfbb2c80eacfc78517b4e92fade704e311b1fd GIT binary patch literal 1482 zcma!WakFByVq~zfugJ|&C`&CW&dkrVRWj5wP_nnP$;?a3x3htY+5rV^^kEzueXu0s zH7164{|_+X)1Q}^n`#%FnwR2|Sd!>$qYviWlvEa^+PS*A+vtN?Hpv-@d3mWh@yYq6 zc_nscCN}!0A~t#XxtV#1Iq}6si6yCah6V;e*Px2Q%}C2H%1tb>OUW-y%1K2w3Myff zT$BnlBqbiG$Pj1@5*OyL>r4#q_pQB0l)rovi?UOTP&@_`!sa(4DtN89q$o2l9bpjh z9us0^a9-+m=k!-c{>^+>-HMw}KVifo#v;PRz`zWSTNXwJ1_llw1_DC|Ff~ey*brdU zVg~07)KtO92}$t^295}(6SjoKD8>R#RcT-#;V^3^2<+Ss5(nit4Dm^91WTB-%%b9w z_>#=r)Z&uF+yZc(Mi;ZmNkmhlXJBAxqmL$RQw%g9Cly)@0p(Hnu+jnOCPJkHy8WPX K23?GrZUO)<^ILEL literal 0 HcmV?d00001 From 0c5cd2736f9a89b31eb35a81402b3c8681265c38 Mon Sep 17 00:00:00 2001 From: Alberto Barradas Date: Wed, 8 Jan 2025 16:14:07 +0100 Subject: [PATCH 2/5] Update tests --- test/runtests.jl | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index cad490f..dc11187 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using XDF, Downloads, Test +using XDF, Downloads, Test, SHA @testset "Minimal XDF file" begin url = "https://github.com/xdf-modules/example-files/blob/master/minimal.xdf?raw=true" @@ -82,25 +82,25 @@ end using XDF: XDF streams = XDF.read_xdf(file) end - # @testset "strings.dejitter" begin - # using XDF: XDF - # streams = XDF.read_xdf(file) - # s1 = streams[3735928559] - # @test s1["type"] == "Marker" - # @test s1["nchannels"] == 2 - # @test s1["srate"] == 1000.0 - # @test s1["dtype"] == String - # @test size(s1["data"]) == (1, 2) - # @test s1["data"] == ["Marker 0A" "Marker 0A"] - # s2 = streams[46202862] - # @test s2["type"] == "EEG" - # @test s2["nchannels"] == 64 - # @test s2["srate"] == 1000.0 - # @test s2["dtype"] == Float64 - # @test size(s2["data"]) == (1, 64) - # @test sum(s2["data"]) == 0.0 - # sgs = [XDF.dejitter(streams[k])["segments"] for k in keys(streams)] - # @test sgs[1] == [(1, 1)] - # @test sgs[2] == [(1, 1)] - # end + @testset "strings.markers" begin + using XDF: XDF + streams = XDF.read_xdf(file) + s1 = streams[3735928559] + @test s1["type"] == "Marker" + @test s1["nchannels"] == 2 + @test s1["srate"] == 1000.0 + @test s1["dtype"] == String + @test size(s1["data"]) == (1, 2) + @test s1["data"] == ["Marker 0A" "Marker 0A"] + s2 = streams[46202862] + @test s2["type"] == "EEG" + @test s2["nchannels"] == 64 + @test s2["srate"] == 1000.0 + @test s2["dtype"] == Float64 + @test size(s2["data"]) == (1, 64) + @test sum(s2["data"]) == 0.0 + # sgs = [XDF.dejitter(streams[k])["segments"] for k in keys(streams)] + # @test sgs[1] == [(1, 1)] + # @test sgs[2] == [(1, 1)] + end end From d6d38e6fa19aec32f8a26ab8af0c5e8af57b8c40 Mon Sep 17 00:00:00 2001 From: Alberto Barradas Date: Thu, 9 Jan 2025 13:39:27 +0100 Subject: [PATCH 3/5] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8ba32e..805f71c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [UNRELEASED] - 2025-01-08 +### ✨ Added +- Add tests for string markers from issue xdf-modules/libxdf#19 (([#13](https://github.com/cbrnr/XDF.jl/pull/13) by [Alberto Barradas](https://github.com/abcsds))) + ## [0.2.0] - 2022-02-23 - Add support for string markers and string streams ([#2](https://github.com/cbrnr/XDF.jl/pull/2) by [Alberto Barradas](https://github.com/abcsds) and [Clemens Brunner](https://github.com/cbrnr)) - Make header and footer XML available in "xml" key ([#4](https://github.com/cbrnr/XDF.jl/pull/4) by [Alberto Barradas](https://github.com/abcsds)) From 981cc5061a4ddca28ead08871f1ce39cafffc094 Mon Sep 17 00:00:00 2001 From: Alberto Barradas Date: Thu, 9 Jan 2025 22:45:35 +0100 Subject: [PATCH 4/5] Fix #10 --- .gitignore | 3 +++ src/XDF.jl | 4 +++- test/runtests.jl | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ba39cc5..02c521c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ Manifest.toml +Dockerfile +.vscode/ +.venv/ diff --git a/src/XDF.jl b/src/XDF.jl index 53d0b6c..1c1627d 100644 --- a/src/XDF.jl +++ b/src/XDF.jl @@ -123,7 +123,9 @@ function read_xdf(filename::AbstractString, sync::Bool=true) streams[id]["time"][index[id]] = previous + delta end if streams[id]["dtype"] === String - streams[id]["data"][index[id], :] .= String(read(io, read_varlen_int(io))) + for j in 1:nchannels + streams[id]["data"][index[id], j] = String(read(io, read_varlen_int(io))) + end else streams[id]["data"][index[id], :] = reinterpret(dtype, read(io, sizeof(dtype) * nchannels)) end diff --git a/test/runtests.jl b/test/runtests.jl index dc11187..c41b6fa 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -91,7 +91,7 @@ end @test s1["srate"] == 1000.0 @test s1["dtype"] == String @test size(s1["data"]) == (1, 2) - @test s1["data"] == ["Marker 0A" "Marker 0A"] + @test s1["data"] == ["Marker 0A" "Marker 0B"] s2 = streams[46202862] @test s2["type"] == "EEG" @test s2["nchannels"] == 64 From b0cf0f4743265743502b67d9325dbbe4d00e46ad Mon Sep 17 00:00:00 2001 From: Alberto Barradas Date: Tue, 14 Jan 2025 10:04:16 +0100 Subject: [PATCH 5/5] Fix chunk3.xdf location reference. --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 01cffe8..965db44 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -73,7 +73,7 @@ end end @testset "strings" begin - file = "./test/testdata/test_chunk3.xdf" + file = "./testdata/test_chunk3.xdf" @testset "strings.sha256" begin open(file) do f @test bytes2hex(sha256(f)) ==