| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include "librist/librist.h" |
| 11 |
|
| 12 |
#include <stdio.h> |
| 13 |
#include <string.h> |
| 14 |
|
| 15 |
static int expect_prefix(const char *url, const char *want_prefix, int want_rtp) |
| 16 |
{ |
| 17 |
struct rist_udp_config *cfg = NULL; |
| 18 |
int ret = rist_parse_udp_address2(url, &cfg); |
| 19 |
if (ret != 0 || cfg == NULL) { |
| 20 |
fprintf(stderr, "FAIL: rist_parse_udp_address2(%s) ret=%d cfg=%p\n", |
| 21 |
url, ret, (void *)cfg); |
| 22 |
if (cfg) |
| 23 |
rist_udp_config_free2(&cfg); |
| 24 |
return 1; |
| 25 |
} |
| 26 |
int bad = 0; |
| 27 |
if (strcmp(cfg->prefix, want_prefix) != 0) { |
| 28 |
fprintf(stderr, "FAIL: %s -> prefix=\"%s\" (want \"%s\")\n", |
| 29 |
url, cfg->prefix, want_prefix); |
| 30 |
bad = 1; |
| 31 |
} |
| 32 |
if (cfg->rtp != want_rtp) { |
| 33 |
fprintf(stderr, "FAIL: %s -> rtp=%d (want %d)\n", url, cfg->rtp, want_rtp); |
| 34 |
bad = 1; |
| 35 |
} |
| 36 |
rist_udp_config_free2(&cfg); |
| 37 |
return bad; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
static int expect_no_crash(const char *url) |
| 43 |
{ |
| 44 |
struct rist_udp_config *cfg = NULL; |
| 45 |
int ret = rist_parse_udp_address2(url, &cfg); |
| 46 |
(void)ret; |
| 47 |
if (cfg) |
| 48 |
rist_udp_config_free2(&cfg); |
| 49 |
return 0; |
| 50 |
} |
| 51 |
|
| 52 |
int main(void) |
| 53 |
{ |
| 54 |
int failures = 0; |
| 55 |
|
| 56 |
|
| 57 |
failures += expect_prefix("udp://127.0.0.1:1234", "udp", 0); |
| 58 |
failures += expect_prefix("rtp://127.0.0.1:1234", "rtp", 1); |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
failures += expect_no_crash("/127.0.0.1:1234"); |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
failures += expect_no_crash("averylongschemename://host:1234"); |
| 67 |
failures += expect_no_crash("0123456789abcdef0123456789/host"); |
| 68 |
|
| 69 |
if (failures) { |
| 70 |
fprintf(stderr, "%d failure(s)\n", failures); |
| 71 |
return 1; |
| 72 |
} |
| 73 |
printf("all udp prefix parse cases passed\n"); |
| 74 |
return 0; |
| 75 |
} |