Skip to content

Commit fbc136f

Browse files
committed
test error handling
1 parent d33f275 commit fbc136f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/test-c-interface.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
include("common.jl")
44
using JetReconstruction.C_JetReconstruction
5+
using Logging
56

67
# helper function make generic field-wise comparison
78
function struct_approx_equal(x::T, y::T) where {T}
@@ -166,3 +167,35 @@ end
166167
end
167168
end
168169
end
170+
171+
@testset "C-interface error handling" begin
172+
test_cone_size = 0.4
173+
test_recombination = RecombinationScheme.EScheme
174+
test_alg = JetAlgorithm.CA
175+
test_strategy = RecoStrategy.Best
176+
177+
jets_len = Csize_t(2)
178+
jets_ptr = Ptr{PseudoJet}(Libc.malloc(jets_len * sizeof(PseudoJet)))
179+
clustersequence_ptr = Ptr{C_JetReconstruction.C_ClusterSequence{PseudoJet}}(Libc.malloc(sizeof(C_JetReconstruction.C_ClusterSequence{PseudoJet})))
180+
ret = C_JetReconstruction.jetreconstruction_PseudoJet_init(jets_ptr, 0.0, 1.0, 2.0, 3.0,
181+
0) # incorrect cluster history index
182+
@test C_JetReconstruction.StatusCode.T(ret) == C_JetReconstruction.StatusCode.OK
183+
ret = C_JetReconstruction.jetreconstruction_PseudoJet_init(jets_ptr + sizeof(PseudoJet),
184+
1.0, 2.0, 3.0, 4.0,
185+
0) # incorrect cluster history index
186+
@test C_JetReconstruction.StatusCode.T(ret) == C_JetReconstruction.StatusCode.OK
187+
# running jet_reconstruct with input jets with incorrect cluster history indices should throw an exception
188+
# which should translate to status code other than ok and log error
189+
test_logger = TestLogger()
190+
with_logger(test_logger) do
191+
ret = C_JetReconstruction.jetreconstruction_jet_reconstruct(jets_ptr,
192+
jets_len,
193+
test_alg,
194+
test_cone_size,
195+
test_strategy,
196+
test_recombination,
197+
clustersequence_ptr)
198+
end
199+
@test test_logger.logs[1].level == Logging.Error
200+
@test C_JetReconstruction.StatusCode.T(ret) != C_JetReconstruction.StatusCode.OK
201+
end

0 commit comments

Comments
 (0)