Debian Codegraph @

test/rist/unit/test_url_udp_versioned_params.c

raw symbols SCIP
1 /* librist. SPDX-License-Identifier: BSD-2-Clause
2 *
3 * ?multiplex-mode= / ?rtp-ptype= URL parsing exercised through the public
4 * rist_parse_udp_address2 API. Both are guarded on RIST_UDP_CONFIG_VERSION,
5 * so every case parses at whatever version the library was built with and a
6 * bump cannot leave them unreachable. Intentionally avoids cmocka so it runs
7 * anywhere the public library does. */
8
9 #include "librist/librist.h"
10 #include "librist/headers.h"
11
12 #include <stdio.h>
13
14 /* A want of -1 leaves that field unchecked. Returns the failure count. */
15 static int expect_url(const char *url, int want_mode, int want_ptype)
16 {
17 struct rist_udp_config *cfg = NULL;
18 int ret = rist_parse_udp_address2(url, &cfg);
19
20 if (ret != 0 || cfg == NULL) {
21 fprintf(stderr, "FAIL: %s rejected (ret=%d) at version %d\n",
22 url, ret, RIST_UDP_CONFIG_VERSION);
23 if (cfg)
24 rist_udp_config_free2(&cfg);
25 return 1;
26 }
27
28 int bad = 0;
29 if (want_mode >= 0 && (int)cfg->multiplex_mode != want_mode) {
30 fprintf(stderr, "FAIL: %s -> multiplex_mode=%d (want %d)\n",
31 url, (int)cfg->multiplex_mode, want_mode);
32 bad = 1;
33 }
34 if (want_ptype >= 0 && (int)cfg->rtp_ptype != want_ptype) {
35 fprintf(stderr, "FAIL: %s -> rtp_ptype=%d (want %d)\n",
36 url, (int)cfg->rtp_ptype, want_ptype);
37 bad = 1;
38 }
39 rist_udp_config_free2(&cfg);
40 return bad;
41 }
42
43 int main(void)
44 {
45 int failures = 0;
46
47 /* The version the parser stamps on a fresh config has to be one the
48 * gates below accept, or every guarded parameter is unreachable. */
49 if (RIST_UDP_CONFIG_VERSION < 1) {
50 fprintf(stderr, "FAIL: RIST_UDP_CONFIG_VERSION=%d\n",
51 RIST_UDP_CONFIG_VERSION);
52 return 1;
53 }
54
55 failures += expect_url("udp://127.0.0.1:1234?multiplex-mode=0", 0, -1);
56 failures += expect_url("udp://127.0.0.1:1234?multiplex-mode=1", 1, -1);
57 failures += expect_url("udp://127.0.0.1:1234?multiplex-mode=2", 2, -1);
58 failures += expect_url("udp://127.0.0.1:1234?rtp-ptype=33", -1, 33);
59
60 /* Alongside unguarded parameters, in either order. */
61 failures += expect_url("udp://224.0.0.1:31001?stream-id=1968&multiplex-mode=1", 1, -1);
62 failures += expect_url("udp://224.0.0.1:31001?multiplex-mode=1&stream-id=1968", 1, -1);
63 failures += expect_url("udp://224.0.0.1:31001?stream-id=1968&multiplex-mode=1&rtp-ptype=33", 1, 33);
64
65 /* Absent parameters leave the zeroed defaults. */
66 failures += expect_url("udp://127.0.0.1:1234", 0, 0);
67
68 if (failures == 0) {
69 printf("OK\n");
70 return 0;
71 }
72 fprintf(stderr, "Total failures: %d\n", failures);
73 return 1;
74 }