Line data Source code
1 : /**
2 : * @file test_dc_config.c
3 : * @brief Unit tests for the static DC endpoint table.
4 : */
5 :
6 : #include "test_helpers.h"
7 : #include "app/dc_config.h"
8 :
9 : #include <string.h>
10 :
11 1 : static void test_lookup_default(void) {
12 1 : const DcEndpoint *ep = dc_lookup(DEFAULT_DC_ID);
13 1 : ASSERT(ep != NULL, "default DC must be found");
14 1 : ASSERT(ep->id == DEFAULT_DC_ID, "id matches");
15 1 : ASSERT(ep->host != NULL && strlen(ep->host) > 0, "host non-empty");
16 1 : ASSERT(ep->port > 0, "port > 0");
17 : }
18 :
19 1 : static void test_lookup_all_five(void) {
20 6 : for (int id = 1; id <= 5; id++) {
21 5 : const DcEndpoint *ep = dc_lookup(id);
22 5 : ASSERT(ep != NULL, "DC 1..5 all resolvable");
23 5 : ASSERT(ep->id == id, "id matches");
24 : }
25 : }
26 :
27 1 : static void test_lookup_unknown(void) {
28 1 : ASSERT(dc_lookup(0) == NULL, "DC 0 is unknown");
29 1 : ASSERT(dc_lookup(6) == NULL, "DC 6 is unknown");
30 1 : ASSERT(dc_lookup(-1) == NULL, "negative DC unknown");
31 1 : ASSERT(dc_lookup(999) == NULL, "DC 999 unknown");
32 : }
33 :
34 1 : void run_dc_config_tests(void) {
35 1 : RUN_TEST(test_lookup_default);
36 1 : RUN_TEST(test_lookup_all_five);
37 1 : RUN_TEST(test_lookup_unknown);
38 1 : }
|