GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 19 / 0 / 19
Functions: 100.0% 5 / 0 / 5
Branches: 100.0% 10 / 0 / 10

events/src/events.c
Line Branch Exec Source
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2026 Manuel Hernández Méndez
5 *
6 * Authors:
7 * Manuel Hernández Méndez <maherme.dev@gmail.com>
8 */
9
10 #include "events.h"
11
12 static event_cb_t callbacks[EVENT_COUNT];
13
14 void
15 5 eventRegister(event_type_t type, event_cb_t cb)
16 {
17
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 4 taken 3 times.
5 if (type < 0 || type >= EVENT_COUNT)
18 {
19 2 return;
20 }
21
22
2/2
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 1 time.
3 if (!callbacks[type])
23 {
24 2 callbacks[type] = cb;
25 }
26 }
27
28 void
29 4 eventEmit(event_type_t type)
30 {
31
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 4 taken 2 times.
4 if (type < 0 || type >= EVENT_COUNT)
32 {
33 2 return;
34 }
35
36
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 1 time.
2 if (callbacks[type])
37 {
38 1 callbacks[type]();
39 }
40 }
41
42 #ifdef UNIT_TESTING
43 #include <stddef.h>
44
45 event_cb_t
46 2 helperUT_eventGetCallback(event_type_t type)
47 {
48 2 return callbacks[type];
49 }
50
51 void
52 1 helperUT_eventSetCallback(event_type_t type, event_cb_t cb)
53 {
54 1 callbacks[type] = cb;
55 1 }
56
57 void
58 6 helperUT_eventsClear(void)
59 {
60
2/2
✓ Branch 4 → 3 taken 18 times.
✓ Branch 4 → 5 taken 6 times.
24 for (int i = 0; i < EVENT_COUNT; i++)
61 {
62 18 callbacks[i] = NULL;
63 }
64 6 }
65 #endif /* UNIT_TESTING */
66