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