GCC Code Coverage Report


Directory: src/
File: clock_mock_binding.h
Date: 2026-03-03 09:43:10
Exec Total Coverage
Lines: 16 19 84.2%
Functions: 3 5 60.0%
Branches: 1 2 50.0%

Line Branch Exec Source
1 /***************************************
2 Auteur : Thibaut Oprinsen
3 Mail : thibaut.oprinsen@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #ifndef CLOCKMOCK_BINDING_H
8 #define CLOCKMOCK_BINDING_H
9
10 #include "PClockMock.h"
11
12 #include <ctime>
13 #include <nanobind/nanobind.h>
14 #include <nanobind/stl/string.h>
15 #include <nanobind/stl/chrono.h>
16
17 namespace nb = nanobind;
18
19 3 inline void make_clock_mock_binding(nb::module_ &m) {
20 nb::module_ m_clock_mock = m.def_submodule("clock_mock", "Clock mock utilities for testing");
21
22 6 nb::class_<PClockMock>(m_clock_mock, "PClockMock")
23 // Constructor
24 6 .def(nb::init<>())
25
26 // Clock API methods
27 6 .def("now", &PClockMock::now,
28 "Get the mocked current time")
29
30 3 .def("sleep", [](const PClockMock &c, time_t ellapsedTime) {
31 c.sleep(ellapsedTime);
32 },
33 "Sleep for the given elapsed time (no real sleep in mock)")
34
35 // Mock API methods
36 3 .def("setCurrentTime", [](PClockMock &c, time_t currentTime) {
37 3 c.setCurrentTime(currentTime);
38 3 },
39 "Set the mocked current time")
40
41 8 .def("setMockPrefix", [](PClockMock &c, const std::string &prefix) {
42 2 c.setMockPrefix(prefix);
43 2 },
44 "Set the mock prefix for logging")
45
46 3 .def("resetIndex", &PClockMock::resetIndex,
47 "Reset the mock index to start from the beginning of the mock data")
48
49 6 .def("close", &PClockMock::close,
50 "Close the mock and release resources");
51
52 // Static methods
53
1/2
✓ Branch 0 (163→164) taken 3 times.
✗ Branch 1 (163→167) not taken.
3 m_clock_mock.def("phoenix_createMockBackend", [](PClockMock &c, const std::string & prefix) -> bool {
54 return phoenix_createMockBackend(c, prefix);
55 },
56 3 nb::arg("c"), nb::arg("prefix") = "",
57 "Create the mock backend with the given prefix");
58 3 }
59
60 #endif // CLOCKMOCK_BINDING_H
61