| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#include "librist/librist.h" |
| 15 |
#include "librist/peer.h" |
| 16 |
|
| 17 |
#include <stdio.h> |
| 18 |
#include <string.h> |
| 19 |
|
| 20 |
#define SENTINEL 0x5a5a5a5a |
| 21 |
|
| 22 |
static int check(int version, int expect_split_set, int expect_profile_set, |
| 23 |
int expect_rtt_set) |
| 24 |
{ |
| 25 |
struct rist_peer_config cfg; |
| 26 |
memset(&cfg, 0, sizeof(cfg)); |
| 27 |
cfg.split_mode = SENTINEL; |
| 28 |
cfg.merge_mode = SENTINEL; |
| 29 |
cfg.profile = (enum rist_profile)SENTINEL; |
| 30 |
cfg.profile_set = SENTINEL; |
| 31 |
cfg.rtt_drop = SENTINEL; |
| 32 |
cfg.rtt_restore = SENTINEL; |
| 33 |
cfg.rtt_drop_settle = SENTINEL; |
| 34 |
cfg.rtt_drop_trickle = SENTINEL; |
| 35 |
|
| 36 |
if (rist_peer_config_defaults_set_versioned(&cfg, version) != 0) { |
| 37 |
fprintf(stderr, "FAIL: versioned(v=%d) returned error\n", version); |
| 38 |
return 1; |
| 39 |
} |
| 40 |
|
| 41 |
int failures = 0; |
| 42 |
if (cfg.version != version) { |
| 43 |
fprintf(stderr, "FAIL: v=%d recorded version=%d\n", |
| 44 |
version, cfg.version); |
| 45 |
failures++; |
| 46 |
} |
| 47 |
|
| 48 |
int split_written = (cfg.split_mode != SENTINEL) || |
| 49 |
(cfg.merge_mode != SENTINEL); |
| 50 |
if (split_written != expect_split_set) { |
| 51 |
fprintf(stderr, "FAIL: v=%d split/merge written=%d (want %d)\n", |
| 52 |
version, split_written, expect_split_set); |
| 53 |
failures++; |
| 54 |
} |
| 55 |
|
| 56 |
int profile_written = ((int)cfg.profile != (int)(enum rist_profile)SENTINEL) || |
| 57 |
(cfg.profile_set != SENTINEL); |
| 58 |
if (profile_written != expect_profile_set) { |
| 59 |
fprintf(stderr, "FAIL: v=%d profile written=%d (want %d)\n", |
| 60 |
version, profile_written, expect_profile_set); |
| 61 |
failures++; |
| 62 |
} |
| 63 |
|
| 64 |
int rtt_written = (cfg.rtt_drop != SENTINEL) || (cfg.rtt_restore != SENTINEL) || |
| 65 |
(cfg.rtt_drop_settle != SENTINEL) || (cfg.rtt_drop_trickle != SENTINEL); |
| 66 |
if (rtt_written != expect_rtt_set) { |
| 67 |
fprintf(stderr, "FAIL: v=%d rtt fields written=%d (want %d)\n", |
| 68 |
version, rtt_written, expect_rtt_set); |
| 69 |
failures++; |
| 70 |
} |
| 71 |
return failures; |
| 72 |
} |
| 73 |
|
| 74 |
int main(void) |
| 75 |
{ |
| 76 |
int failures = 0; |
| 77 |
|
| 78 |
failures += check(0, 0, 0, 0); |
| 79 |
failures += check(1, 1, 0, 0); |
| 80 |
failures += check(3, 1, 0, 0); |
| 81 |
failures += check(4, 1, 1, 0); |
| 82 |
failures += check(5, 1, 1, 0); |
| 83 |
failures += check(6, 1, 1, 1); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
struct rist_peer_config cfg; |
| 88 |
memset(&cfg, 0, sizeof(cfg)); |
| 89 |
if (rist_peer_config_defaults_set(&cfg) != 0) { |
| 90 |
fprintf(stderr, "FAIL: defaults_set returned error\n"); |
| 91 |
failures++; |
| 92 |
} else if (cfg.version != RIST_PEER_CONFIG_VERSION) { |
| 93 |
fprintf(stderr, |
| 94 |
"FAIL: defaults_set recorded version=%d (want %d)\n", |
| 95 |
cfg.version, RIST_PEER_CONFIG_VERSION); |
| 96 |
failures++; |
| 97 |
} |
| 98 |
|
| 99 |
if (failures == 0) { |
| 100 |
printf("OK\n"); |
| 101 |
return 0; |
| 102 |
} |
| 103 |
fprintf(stderr, "Total failures: %d\n", failures); |
| 104 |
return 1; |
| 105 |
} |