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