Skip to content

Commit

Permalink
Unify assert_eq!(…)/assert_ne!(…) to take args in order of `…!(ac…
Browse files Browse the repository at this point in the history
…tual, expected)`

While there isn't an explicit convention for this in Rust the stdlib docs all use `…!(actual, expected)`, making it a sort of implicit convention.
  • Loading branch information
regexident committed Jan 4, 2023
1 parent 958c0c4 commit a18ae19
Show file tree
Hide file tree
Showing 78 changed files with 751 additions and 751 deletions.
26 changes: 13 additions & 13 deletions data/src/data_channel/data_channel_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,12 @@ async fn test_data_channel_buffered_amount() -> Result<()> {
}

let n = dc0.write(&Bytes::new()).await?;
assert_eq!(0, n, "data length should match");
assert_eq!(1, dc0.buffered_amount(), "incorrect bufferedAmount");
assert_eq!(n, 0, "data length should match");
assert_eq!(dc0.buffered_amount(), 1, "incorrect bufferedAmount");

let n = dc0.write(&Bytes::from_static(&[0])).await?;
assert_eq!(1, n, "data length should match");
assert_eq!(2, dc0.buffered_amount(), "incorrect bufferedAmount");
assert_eq!(n, 1, "data length should match");
assert_eq!(dc0.buffered_amount(), 2, "incorrect bufferedAmount");

bridge_process_at_least_one(&br).await;

Expand All @@ -467,8 +467,8 @@ async fn test_data_channel_buffered_amount() -> Result<()> {

dc0.set_buffered_amount_low_threshold(1500);
assert_eq!(
1500,
dc0.buffered_amount_low_threshold(),
1500,
"incorrect bufferedAmountLowThreshold"
);
let n_cbs2 = Arc::clone(&n_cbs);
Expand Down Expand Up @@ -549,28 +549,28 @@ async fn test_stats() -> Result<()> {
let mut bytes_sent = 0;

let n = dc0.write(&Bytes::from(sbuf.clone())).await?;
assert_eq!(sbuf.len(), n, "data length should match");
assert_eq!(n, sbuf.len(), "data length should match");
bytes_sent += n;

assert_eq!(dc0.bytes_sent(), bytes_sent);
assert_eq!(dc0.messages_sent(), 1);

let n = dc0.write(&Bytes::from(sbuf.clone())).await?;
assert_eq!(sbuf.len(), n, "data length should match");
assert_eq!(n, sbuf.len(), "data length should match");
bytes_sent += n;

assert_eq!(dc0.bytes_sent(), bytes_sent);
assert_eq!(dc0.messages_sent(), 2);

let n = dc0.write(&Bytes::from_static(&[0])).await?;
assert_eq!(1, n, "data length should match");
assert_eq!(n, 1, "data length should match");
bytes_sent += n;

assert_eq!(dc0.bytes_sent(), bytes_sent);
assert_eq!(dc0.messages_sent(), 3);

let n = dc0.write(&Bytes::from_static(&[])).await?;
assert_eq!(0, n, "data length should match");
assert_eq!(n, 0, "data length should match");
bytes_sent += n;

assert_eq!(dc0.bytes_sent(), bytes_sent);
Expand All @@ -581,28 +581,28 @@ async fn test_stats() -> Result<()> {
let mut bytes_read = 0;

let n = dc1.read(&mut rbuf[..]).await?;
assert_eq!(sbuf.len(), n, "data length should match");
assert_eq!(n, sbuf.len(), "data length should match");
bytes_read += n;

assert_eq!(dc1.bytes_received(), bytes_read);
assert_eq!(dc1.messages_received(), 1);

let n = dc1.read(&mut rbuf[..]).await?;
assert_eq!(sbuf.len(), n, "data length should match");
assert_eq!(n, sbuf.len(), "data length should match");
bytes_read += n;

assert_eq!(dc1.bytes_received(), bytes_read);
assert_eq!(dc1.messages_received(), 2);

let n = dc1.read(&mut rbuf[..]).await?;
assert_eq!(1, n, "data length should match");
assert_eq!(n, 1, "data length should match");
bytes_read += n;

assert_eq!(dc1.bytes_received(), bytes_read);
assert_eq!(dc1.messages_received(), 3);

let n = dc1.read(&mut rbuf[..]).await?;
assert_eq!(0, n, "data length should match");
assert_eq!(n, 0, "data length should match");
bytes_read += n;

assert_eq!(dc1.bytes_received(), bytes_read);
Expand Down
9 changes: 3 additions & 6 deletions data/src/message/message_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@ fn test_message_unmarshal_ack_success() -> Result<()> {
fn test_message_unmarshal_invalid_message_type() {
let mut bytes = Bytes::from_static(&[0x01]);
let expected = Error::InvalidMessageType(0x01);
let actual = Message::unmarshal(&mut bytes);
if let Err(err) = actual {
assert_eq!(expected, err);
} else {
panic!("expected err, but got ok");
}
let result = Message::unmarshal(&mut bytes);
let actual = result.expect_err("expected err, but got ok");
assert_eq!(actual, expected);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions dtls/src/crypto/crypto_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn test_generate_key_signature() -> Result<()> {
)?;

assert_eq!(
expected_signature, signature,
signature, expected_signature,
"Signature generation failed \nexp {:?} \nactual {:?} ",
expected_signature, signature
);
Expand Down Expand Up @@ -134,8 +134,8 @@ fn test_ccm_encryption_and_decryption() -> Result<()> {
let cipher_text = ccm.encrypt(&rlh, &raw)?;

assert_eq!(
[0, 27],
&cipher_text[RECORD_LAYER_HEADER_SIZE - 2..RECORD_LAYER_HEADER_SIZE],
[0, 27],
"RecordLayer size updating failed \nexp: {:?} \nactual {:?} ",
[0, 27],
&cipher_text[RECORD_LAYER_HEADER_SIZE - 2..RECORD_LAYER_HEADER_SIZE]
Expand Down
38 changes: 19 additions & 19 deletions ice/src/external_ip_mapper/external_ip_mapper_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ fn test_external_ip_mapper_new_external_ip_mapper() -> Result<()> {
assert_eq!(m.candidate_type, CandidateType::Host, "should match");
assert!(m.ipv4_mapping.ip_sole.is_some());
assert!(m.ipv6_mapping.ip_sole.is_none());
assert_eq!(0, m.ipv4_mapping.ip_map.len(), "should match");
assert_eq!(0, m.ipv6_mapping.ip_map.len(), "should match");
assert_eq!(m.ipv4_mapping.ip_map.len(), 0, "should match");
assert_eq!(m.ipv6_mapping.ip_map.len(), 0, "should match");

// IPv4 with no explicit local IP, using CandidateTypeServerReflexive
let m =
Expand All @@ -40,29 +40,29 @@ fn test_external_ip_mapper_new_external_ip_mapper() -> Result<()> {
);
assert!(m.ipv4_mapping.ip_sole.is_some());
assert!(m.ipv6_mapping.ip_sole.is_none());
assert_eq!(0, m.ipv4_mapping.ip_map.len(), "should match");
assert_eq!(0, m.ipv6_mapping.ip_map.len(), "should match");
assert_eq!(m.ipv4_mapping.ip_map.len(), 0, "should match");
assert_eq!(m.ipv6_mapping.ip_map.len(), 0, "should match");

// IPv4 with no explicit local IP, defaults to CandidateTypeHost
let m = ExternalIpMapper::new(CandidateType::Unspecified, &["2601:4567::5678".to_owned()])?
.unwrap();
assert_eq!(CandidateType::Host, m.candidate_type, "should match");
assert_eq!(m.candidate_type, CandidateType::Host, "should match");
assert!(m.ipv4_mapping.ip_sole.is_none());
assert!(m.ipv6_mapping.ip_sole.is_some());
assert_eq!(0, m.ipv4_mapping.ip_map.len(), "should match");
assert_eq!(0, m.ipv6_mapping.ip_map.len(), "should match");
assert_eq!(m.ipv4_mapping.ip_map.len(), 0, "should match");
assert_eq!(m.ipv6_mapping.ip_map.len(), 0, "should match");

// IPv4 and IPv6 in the mix
let m = ExternalIpMapper::new(
CandidateType::Unspecified,
&["1.2.3.4".to_owned(), "2601:4567::5678".to_owned()],
)?
.unwrap();
assert_eq!(CandidateType::Host, m.candidate_type, "should match");
assert_eq!(m.candidate_type, CandidateType::Host, "should match");
assert!(m.ipv4_mapping.ip_sole.is_some());
assert!(m.ipv6_mapping.ip_sole.is_some());
assert_eq!(0, m.ipv4_mapping.ip_map.len(), "should match");
assert_eq!(0, m.ipv6_mapping.ip_map.len(), "should match");
assert_eq!(m.ipv4_mapping.ip_map.len(), 0, "should match");
assert_eq!(m.ipv6_mapping.ip_map.len(), 0, "should match");

// Unsupported candidate type - CandidateTypePeerReflexive
let result = ExternalIpMapper::new(CandidateType::PeerReflexive, &["1.2.3.4".to_owned()]);
Expand Down Expand Up @@ -105,11 +105,11 @@ fn test_external_ip_mapper_new_external_ip_mapper_with_explicit_local_ip() -> Re
// IPv4 with explicit local IP, defaults to CandidateTypeHost
let m = ExternalIpMapper::new(CandidateType::Unspecified, &["1.2.3.4/10.0.0.1".to_owned()])?
.unwrap();
assert_eq!(CandidateType::Host, m.candidate_type, "should match");
assert_eq!(m.candidate_type, CandidateType::Host, "should match");
assert!(m.ipv4_mapping.ip_sole.is_none());
assert!(m.ipv6_mapping.ip_sole.is_none());
assert_eq!(1, m.ipv4_mapping.ip_map.len(), "should match");
assert_eq!(0, m.ipv6_mapping.ip_map.len(), "should match");
assert_eq!(m.ipv4_mapping.ip_map.len(), 1, "should match");
assert_eq!(m.ipv6_mapping.ip_map.len(), 0, "should match");

// Cannot assign two ext IPs for one local IPv4
let result = ExternalIpMapper::new(
Expand Down Expand Up @@ -179,11 +179,11 @@ fn test_external_ip_mapper_find_external_ip_without_explicit_local_ip() -> Resul

// find external IPv4
let ext_ip = m.find_external_ip("10.0.0.1")?;
assert_eq!("1.2.3.4", ext_ip.to_string(), "should match");
assert_eq!(ext_ip.to_string(), "1.2.3.4", "should match");

// find external IPv6
let ext_ip = m.find_external_ip("fe80::0001")?; // use '0001' instead of '1' on purpse
assert_eq!("2200::1", ext_ip.to_string(), "should match");
assert_eq!(ext_ip.to_string(), "2200::1", "should match");

// Bad local IP string
let result = m.find_external_ip("really.bad");
Expand All @@ -208,20 +208,20 @@ fn test_external_ip_mapper_find_external_ip_with_explicit_local_ip() -> Result<(

// find external IPv4
let ext_ip = m.find_external_ip("10.0.0.1")?;
assert_eq!("1.2.3.4", ext_ip.to_string(), "should match");
assert_eq!(ext_ip.to_string(), "1.2.3.4", "should match");

let ext_ip = m.find_external_ip("10.0.0.2")?;
assert_eq!("1.2.3.5", ext_ip.to_string(), "should match");
assert_eq!(ext_ip.to_string(), "1.2.3.5", "should match");

let result = m.find_external_ip("10.0.0.3");
assert!(result.is_err(), "should fail");

// find external IPv6
let ext_ip = m.find_external_ip("fe80::0001")?; // use '0001' instead of '1' on purpse
assert_eq!("2200::1", ext_ip.to_string(), "should match");
assert_eq!(ext_ip.to_string(), "2200::1", "should match");

let ext_ip = m.find_external_ip("fe80::0002")?; // use '0002' instead of '2' on purpse
assert_eq!("2200::2", ext_ip.to_string(), "should match");
assert_eq!(ext_ip.to_string(), "2200::2", "should match");

let result = m.find_external_ip("fe80::3");
assert!(result.is_err(), "should fail");
Expand Down
2 changes: 1 addition & 1 deletion ice/src/mdns/mdns_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async fn test_multicast_dns_static_host_name() -> Result<()> {
..Default::default()
};
if let Err(err) = Agent::new(cfg0).await {
assert_eq!(Error::ErrInvalidMulticastDnshostName, err);
assert_eq!(err, Error::ErrInvalidMulticastDnshostName);
} else {
panic!("expected error, but got ok");
}
Expand Down
2 changes: 1 addition & 1 deletion ice/src/network_type/network_type_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ fn test_network_type_to_string() {
];

for (network_type, expected_string) in tests {
assert_eq!(expected_string, network_type.to_string());
assert_eq!(network_type.to_string(), expected_string);
}
}
2 changes: 1 addition & 1 deletion ice/src/priority/priority_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn test_priority_get_from() -> Result<()> {
let mut p = PriorityAttr::default();
let result = p.get_from(&m);
if let Err(err) = result {
assert_eq!(stun::Error::ErrAttributeNotFound, err, "unexpected error");
assert_eq!(err, stun::Error::ErrAttributeNotFound, "unexpected error");
} else {
panic!("expected error, but got ok");
}
Expand Down
4 changes: 2 additions & 2 deletions ice/src/state/state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ fn test_connected_state_string() -> Result<()> {

for (connection_state, expected_string) in tests {
assert_eq!(
expected_string,
connection_state.to_string(),
expected_string,
"testCase: {} vs {}",
expected_string,
connection_state,
Expand All @@ -38,8 +38,8 @@ fn test_gathering_state_string() -> Result<()> {

for (gathering_state, expected_string) in tests {
assert_eq!(
expected_string,
gathering_state.to_string(),
expected_string,
"testCase: {} vs {}",
expected_string,
gathering_state,
Expand Down
18 changes: 9 additions & 9 deletions ice/src/tcp_type/tcp_type_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ use crate::error::Result;

#[test]
fn test_tcp_type() -> Result<()> {
//assert_eq!(TCPType::Unspecified, tcpType)
assert_eq!(TcpType::Active, TcpType::from("active"));
assert_eq!(TcpType::Passive, TcpType::from("passive"));
assert_eq!(TcpType::SimultaneousOpen, TcpType::from("so"));
assert_eq!(TcpType::Unspecified, TcpType::from("something else"));
//assert_eq!(tcpType, TCPType::Unspecified)
assert_eq!(TcpType::from("active"), TcpType::Active);
assert_eq!(TcpType::from("passive"), TcpType::Passive);
assert_eq!(TcpType::from("so"), TcpType::SimultaneousOpen);
assert_eq!(TcpType::from("something else"), TcpType::Unspecified);

assert_eq!("unspecified", TcpType::Unspecified.to_string());
assert_eq!("active", TcpType::Active.to_string());
assert_eq!("passive", TcpType::Passive.to_string());
assert_eq!("so", TcpType::SimultaneousOpen.to_string());
assert_eq!(TcpType::Unspecified.to_string(), "unspecified");
assert_eq!(TcpType::Active.to_string(), "active");
assert_eq!(TcpType::Passive.to_string(), "passive");
assert_eq!(TcpType::SimultaneousOpen.to_string(), "so");

Ok(())
}
10 changes: 5 additions & 5 deletions ice/src/url/url_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ fn test_parse_url_success() -> Result<()> {
{
let url = Url::parse_url(raw_url)?;

assert_eq!(expected_scheme, url.scheme, "testCase: {:?}", raw_url);
assert_eq!(url.scheme, expected_scheme, "testCase: {:?}", raw_url);
assert_eq!(
expected_url_string,
url.to_string(),
"testCase: {:?}",
raw_url
);
assert_eq!(expected_secure, url.is_secure(), "testCase: {:?}", raw_url);
assert_eq!(expected_host, url.host, "testCase: {:?}", raw_url);
assert_eq!(expected_port, url.port, "testCase: {:?}", raw_url);
assert_eq!(expected_proto, url.proto, "testCase: {:?}", raw_url);
assert_eq!(url.is_secure(), expected_secure, "testCase: {:?}", raw_url);
assert_eq!(url.host, expected_host, "testCase: {:?}", raw_url);
assert_eq!(url.port, expected_port, "testCase: {:?}", raw_url);
assert_eq!(url.proto, expected_proto, "testCase: {:?}", raw_url);
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions interceptor/src/nack/generator/generator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn test_generator_interceptor() -> Result<()> {
.await
.expect("A read packet")
.expect("Not an error");
assert_eq!(seq_num, r.header.sequence_number);
assert_eq!(r.header.sequence_number, seq_num);
}

tokio::time::sleep(INTERVAL * 2).await; // wait for at least 2 nack packets
Expand All @@ -54,8 +54,8 @@ async fn test_generator_interceptor() -> Result<()> {
.await
.expect("Write rtcp");
if let Some(p) = r[0].as_any().downcast_ref::<TransportLayerNack>() {
assert_eq!(13, p.nacks[0].packet_id);
assert_eq!(0b10, p.nacks[0].lost_packets); // we want packets: 13, 15 (not packet 17, because skipLastN is setReceived to 2)
assert_eq!(p.nacks[0].packet_id, 13);
assert_eq!(p.nacks[0].lost_packets, 0b10); // we want packets: 13, 15 (not packet 17, because skipLastN is setReceived to 2)
} else {
assert!(false, "single packet RTCP Compound Packet expected");
}
Expand Down
4 changes: 2 additions & 2 deletions interceptor/src/nack/responder/responder_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn test_responder_interceptor() -> Result<()> {
let p = timeout_or_fail(Duration::from_millis(10), stream.written_rtp())
.await
.expect("A packet");
assert_eq!(seq_num, p.header.sequence_number);
assert_eq!(p.header.sequence_number, seq_num);
}

stream
Expand All @@ -58,7 +58,7 @@ async fn test_responder_interceptor() -> Result<()> {
for seq_num in [11, 12, 15] {
if let Ok(r) = tokio::time::timeout(Duration::from_millis(50), stream.written_rtp()).await {
if let Some(p) = r {
assert_eq!(seq_num, p.header.sequence_number);
assert_eq!(p.header.sequence_number, seq_num);
} else {
assert!(
false,
Expand Down
Loading

0 comments on commit a18ae19

Please sign in to comment.