|
2 | 2 |
|
3 | 3 | include("common.jl") |
4 | 4 | using JetReconstruction.C_JetReconstruction |
| 5 | +using Logging |
5 | 6 |
|
6 | 7 | # helper function make generic field-wise comparison |
7 | 8 | function struct_approx_equal(x::T, y::T) where {T} |
|
166 | 167 | end |
167 | 168 | end |
168 | 169 | 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