1 use super::*;
2 
3 use crate::candidate::candidate_host::CandidateHostConfig;
4 use crate::candidate::candidate_peer_reflexive::CandidatePeerReflexiveConfig;
5 use crate::candidate::candidate_relay::CandidateRelayConfig;
6 use crate::candidate::candidate_server_reflexive::CandidateServerReflexiveConfig;
7 
host_candidate() -> Result<CandidateBase>8 pub(crate) fn host_candidate() -> Result<CandidateBase> {
9     CandidateHostConfig {
10         base_config: CandidateBaseConfig {
11             network: "udp".to_owned(),
12             address: "0.0.0.0".to_owned(),
13             component: COMPONENT_RTP,
14             ..Default::default()
15         },
16         ..Default::default()
17     }
18     .new_candidate_host()
19 }
20 
prflx_candidate() -> Result<CandidateBase>21 pub(crate) fn prflx_candidate() -> Result<CandidateBase> {
22     CandidatePeerReflexiveConfig {
23         base_config: CandidateBaseConfig {
24             network: "udp".to_owned(),
25             address: "0.0.0.0".to_owned(),
26             component: COMPONENT_RTP,
27             ..Default::default()
28         },
29         ..Default::default()
30     }
31     .new_candidate_peer_reflexive()
32 }
33 
srflx_candidate() -> Result<CandidateBase>34 pub(crate) fn srflx_candidate() -> Result<CandidateBase> {
35     CandidateServerReflexiveConfig {
36         base_config: CandidateBaseConfig {
37             network: "udp".to_owned(),
38             address: "0.0.0.0".to_owned(),
39             component: COMPONENT_RTP,
40             ..Default::default()
41         },
42         ..Default::default()
43     }
44     .new_candidate_server_reflexive()
45 }
46 
relay_candidate() -> Result<CandidateBase>47 pub(crate) fn relay_candidate() -> Result<CandidateBase> {
48     CandidateRelayConfig {
49         base_config: CandidateBaseConfig {
50             network: "udp".to_owned(),
51             address: "0.0.0.0".to_owned(),
52             component: COMPONENT_RTP,
53             ..Default::default()
54         },
55         ..Default::default()
56     }
57     .new_candidate_relay()
58 }
59 
60 #[test]
test_candidate_pair_priority() -> Result<()>61 fn test_candidate_pair_priority() -> Result<()> {
62     let tests = vec![
63         (
64             CandidatePair::new(
65                 Arc::new(host_candidate()?),
66                 Arc::new(host_candidate()?),
67                 false,
68             ),
69             9151314440652587007,
70         ),
71         (
72             CandidatePair::new(
73                 Arc::new(host_candidate()?),
74                 Arc::new(host_candidate()?),
75                 true,
76             ),
77             9151314440652587007,
78         ),
79         (
80             CandidatePair::new(
81                 Arc::new(host_candidate()?),
82                 Arc::new(prflx_candidate()?),
83                 true,
84             ),
85             7998392936314175488,
86         ),
87         (
88             CandidatePair::new(
89                 Arc::new(host_candidate()?),
90                 Arc::new(prflx_candidate()?),
91                 false,
92             ),
93             7998392936314175487,
94         ),
95         (
96             CandidatePair::new(
97                 Arc::new(host_candidate()?),
98                 Arc::new(srflx_candidate()?),
99                 true,
100             ),
101             7277816996102668288,
102         ),
103         (
104             CandidatePair::new(
105                 Arc::new(host_candidate()?),
106                 Arc::new(srflx_candidate()?),
107                 false,
108             ),
109             7277816996102668287,
110         ),
111         (
112             CandidatePair::new(
113                 Arc::new(host_candidate()?),
114                 Arc::new(relay_candidate()?),
115                 true,
116             ),
117             72057593987596288,
118         ),
119         (
120             CandidatePair::new(
121                 Arc::new(host_candidate()?),
122                 Arc::new(relay_candidate()?),
123                 false,
124             ),
125             72057593987596287,
126         ),
127     ];
128 
129     for (pair, want) in tests {
130         let got = pair.priority();
131         assert_eq!(
132             got, want,
133             "CandidatePair({pair}).Priority() = {got}, want {want}"
134         );
135     }
136 
137     Ok(())
138 }
139 
140 #[test]
test_candidate_pair_equality() -> Result<()>141 fn test_candidate_pair_equality() -> Result<()> {
142     let pair_a = CandidatePair::new(
143         Arc::new(host_candidate()?),
144         Arc::new(srflx_candidate()?),
145         true,
146     );
147     let pair_b = CandidatePair::new(
148         Arc::new(host_candidate()?),
149         Arc::new(srflx_candidate()?),
150         false,
151     );
152 
153     assert_eq!(pair_a, pair_b, "Expected {pair_a} to equal {pair_b}");
154 
155     Ok(())
156 }
157