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(6) == NULL, "DC 6 is unknown");
29 1 : ASSERT(dc_lookup(999) == NULL, "DC 999 unknown");
30 : }
31 :
32 1 : static void test_lookup_zero_wildcard(void) {
33 : /* dc=0 is a wildcard for Telegram test servers; maps to DEFAULT_DC_ID endpoint. */
34 1 : const DcEndpoint *ep = dc_lookup(0);
35 1 : ASSERT(ep != NULL, "DC 0 must resolve to DEFAULT_DC_ID endpoint");
36 1 : ASSERT(ep->port > 0, "DC 0 endpoint has valid port");
37 : }
38 :
39 1 : static void test_lookup_negative_test_dcs(void) {
40 : /* Negative IDs are used by Telegram test DCs (p_q_inner_data_dc convention). */
41 6 : for (int id = -5; id <= -1; id++) {
42 5 : const DcEndpoint *ep = dc_lookup(id);
43 5 : ASSERT(ep != NULL, "negative DC -1..-5 must resolve");
44 5 : ASSERT(ep->port > 0, "negative DC endpoint has valid port");
45 : }
46 : }
47 :
48 1 : void run_dc_config_tests(void) {
49 1 : RUN_TEST(test_lookup_default);
50 1 : RUN_TEST(test_lookup_all_five);
51 1 : RUN_TEST(test_lookup_unknown);
52 1 : RUN_TEST(test_lookup_zero_wildcard);
53 1 : RUN_TEST(test_lookup_negative_test_dcs);
54 1 : }
|