Skip to content

Commit 0aa93c4

Browse files
jmatssrainliu
authored andcommitted
Add unit tests for RTCIceCandidateInit
1 parent ddb330a commit 0aa93c4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/ice_transport/ice_candidate.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,45 @@ pub struct RTCIceCandidateInit {
175175
pub sdp_mline_index: Option<u16>,
176176
pub username_fragment: Option<String>,
177177
}
178+
179+
#[cfg(test)]
180+
mod test {
181+
use super::*;
182+
183+
#[test]
184+
fn test_ice_candidate_serialization() {
185+
let tests = vec![
186+
(
187+
RTCIceCandidateInit {
188+
candidate: "candidate:abc123".to_string(),
189+
sdp_mid: Some("0".to_string()),
190+
sdp_mline_index: Some(0),
191+
username_fragment: Some("def".to_string()),
192+
},
193+
r#"{"candidate":"candidate:abc123","sdpMid":"0","sdpMLineIndex":0,"usernameFragment":"def"}"#,
194+
),
195+
(
196+
RTCIceCandidateInit {
197+
candidate: "candidate:abc123".to_string(),
198+
sdp_mid: None,
199+
sdp_mline_index: None,
200+
username_fragment: None,
201+
},
202+
r#"{"candidate":"candidate:abc123","sdpMid":null,"sdpMLineIndex":null,"usernameFragment":null}"#,
203+
),
204+
];
205+
206+
for (candidate_init, expected_string) in tests {
207+
let result = serde_json::to_string(&candidate_init);
208+
assert!(result.is_ok(), "testCase: marshal err: {:?}", result);
209+
let candidate_data = result.unwrap();
210+
assert_eq!(candidate_data, expected_string, "string is not expected");
211+
212+
let result = serde_json::from_str::<RTCIceCandidateInit>(&candidate_data);
213+
assert!(result.is_ok(), "testCase: unmarshal err: {:?}", result);
214+
if let Ok(actual_candidate_init) = result {
215+
assert_eq!(candidate_init, actual_candidate_init);
216+
}
217+
}
218+
}
219+
}

0 commit comments

Comments
 (0)