Debian Codegraph @

test/rist/unit/test_url_srp_compat_parse.c

raw symbols SCIP
1 /* librist. SPDX-License-Identifier: BSD-2-Clause
2 *
3 * Intentionally avoids cmocka so it runs anywhere the public library
4 * does. */
5
6 #include "librist/librist.h"
7 #include "librist/peer.h"
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 static int expect_legacy(const char *url, int want)
14 {
15 struct rist_peer_config *cfg = NULL;
16 int ret = rist_parse_address2(url, &cfg);
17 if (ret != 0 || cfg == NULL) {
18 fprintf(stderr,
19 "FAIL: rist_parse_address2(%s) ret=%d cfg=%p\n",
20 url, ret, (void *)cfg);
21 if (cfg)
22 rist_peer_config_free2(&cfg);
23 return 1;
24 }
25 if (cfg->srp_compat_legacy != want) {
26 fprintf(stderr,
27 "FAIL: %s -> srp_compat_legacy=%d (want %d)\n",
28 url, cfg->srp_compat_legacy, want);
29 rist_peer_config_free2(&cfg);
30 return 1;
31 }
32 rist_peer_config_free2(&cfg);
33 return 0;
34 }
35
36 static int expect_parse_error(const char *url)
37 {
38 struct rist_peer_config *cfg = NULL;
39 int ret = rist_parse_address2(url, &cfg);
40 if (ret == 0) {
41 fprintf(stderr,
42 "FAIL: %s expected parse error, got success\n", url);
43 if (cfg)
44 rist_peer_config_free2(&cfg);
45 return 1;
46 }
47 if (cfg)
48 rist_peer_config_free2(&cfg);
49 return 0;
50 }
51
52 int main(void)
53 {
54 int failures = 0;
55
56 failures += expect_legacy("rist://@127.0.0.1:1234", 0);
57 failures += expect_legacy("rist://@127.0.0.1:1234?srp-compat=0", 0);
58 failures += expect_legacy("rist://@127.0.0.1:1234?srp-compat=1", 1);
59
60 failures += expect_parse_error("rist://@127.0.0.1:1234?srp-compat=legacy");
61 failures += expect_parse_error("rist://@127.0.0.1:1234?srp-compat=auto");
62 failures += expect_parse_error("rist://@127.0.0.1:1234?srp-compat=2");
63 failures += expect_parse_error("rist://@127.0.0.1:1234?srp-compat=-1");
64 failures += expect_parse_error("rist://@127.0.0.1:1234?srp-compat=1foo");
65 failures += expect_parse_error("rist://@127.0.0.1:1234?srp-compat=garbage");
66
67 if (failures == 0) {
68 printf("OK\n");
69 return 0;
70 }
71 fprintf(stderr, "Total failures: %d\n", failures);
72 return 1;
73 }