| 1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
|
| 5 |
use super::*; |
| 6 |
use address::Address; |
| 7 |
use std::str::FromStr; |
| 8 |
#[test] |
| 9 |
fn test_sdp_parser_internal_error_unknown_address_type() { |
| 10 |
let error = SdpParserInternalError::UnknownAddressType("foo".to_string()); |
| 11 |
assert_eq!( |
| 12 |
format!("{error}"), |
| 13 |
format!("{}: {}", INTERNAL_ERROR_MESSAGE_UNKNOWN_ADDRESS_TYPE, "foo") |
| 14 |
); |
| 15 |
assert!(error.source().is_none()); |
| 16 |
} |
| 17 |
#[test] |
| 18 |
fn test_sdp_parser_internal_error_address_type_mismatch() { |
| 19 |
let error = SdpParserInternalError::AddressTypeMismatch { |
| 20 |
found: AddressType::IpV4, |
| 21 |
expected: AddressType::IpV6, |
| 22 |
}; |
| 23 |
assert_eq!( |
| 24 |
format!("{error}"), |
| 25 |
format!( |
| 26 |
"{}: {}, {}", |
| 27 |
INTERNAL_ERROR_MESSAGE_ADDRESS_TYPE_MISMATCH, |
| 28 |
AddressType::IpV4, |
| 29 |
AddressType::IpV6 |
| 30 |
) |
| 31 |
); |
| 32 |
assert!(error.source().is_none()); |
| 33 |
} |
| 34 |
|
| 35 |
#[test] |
| 36 |
fn test_sdp_parser_internal_error_generic() { |
| 37 |
let generic = SdpParserInternalError::Generic("generic message".to_string()); |
| 38 |
assert_eq!(format!("{generic}"), "Parsing error: generic message"); |
| 39 |
assert!(generic.source().is_none()); |
| 40 |
} |
| 41 |
|
| 42 |
#[test] |
| 43 |
fn test_sdp_parser_internal_error_unsupported() { |
| 44 |
let unsupported = |
| 45 |
SdpParserInternalError::Unsupported("unsupported internal message".to_string()); |
| 46 |
assert_eq!( |
| 47 |
format!("{unsupported}"), |
| 48 |
"Unsupported parsing error: unsupported internal message" |
| 49 |
); |
| 50 |
assert!(unsupported.source().is_none()); |
| 51 |
} |
| 52 |
|
| 53 |
#[test] |
| 54 |
fn test_sdp_parser_internal_error_integer() { |
| 55 |
let v = "12a"; |
| 56 |
let integer = v.parse::<u64>(); |
| 57 |
assert!(integer.is_err()); |
| 58 |
let int_err = SdpParserInternalError::Integer(integer.err().unwrap()); |
| 59 |
assert_eq!( |
| 60 |
format!("{int_err}"), |
| 61 |
"Integer parsing error: invalid digit found in string" |
| 62 |
); |
| 63 |
assert!(int_err.source().is_some()); |
| 64 |
} |
| 65 |
|
| 66 |
#[test] |
| 67 |
fn test_sdp_parser_internal_error_float() { |
| 68 |
let v = "12.2a"; |
| 69 |
let float = v.parse::<f32>(); |
| 70 |
assert!(float.is_err()); |
| 71 |
let int_err = SdpParserInternalError::Float(float.err().unwrap()); |
| 72 |
assert_eq!( |
| 73 |
format!("{int_err}"), |
| 74 |
"Float parsing error: invalid float literal" |
| 75 |
); |
| 76 |
assert!(int_err.source().is_some()); |
| 77 |
} |
| 78 |
|
| 79 |
#[test] |
| 80 |
fn test_sdp_parser_internal_error_address() { |
| 81 |
let v = "127.0.0.500"; |
| 82 |
let addr_err = Address::from_str(v).err().unwrap(); |
| 83 |
assert_eq!( |
| 84 |
format!("{addr_err}"), |
| 85 |
"Domain name parsing error: invalid IPv4 address" |
| 86 |
); |
| 87 |
assert!(addr_err.source().is_some()); |
| 88 |
} |
| 89 |
|
| 90 |
#[test] |
| 91 |
fn test_sdp_parser_error_line() { |
| 92 |
let line1 = SdpParserError::Line { |
| 93 |
error: SdpParserInternalError::Generic("test message".to_string()), |
| 94 |
line: "test line".to_string(), |
| 95 |
line_number: 13, |
| 96 |
}; |
| 97 |
assert_eq!( |
| 98 |
format!("{line1}"), |
| 99 |
"Line error: Parsing error: test message in line(13): test line" |
| 100 |
); |
| 101 |
assert!(line1.source().is_some()); |
| 102 |
} |
| 103 |
|
| 104 |
#[test] |
| 105 |
fn test_sdp_parser_error_unsupported() { |
| 106 |
let unsupported1 = SdpParserError::Unsupported { |
| 107 |
error: SdpParserInternalError::Generic("unsupported value".to_string()), |
| 108 |
line: "unsupported line".to_string(), |
| 109 |
line_number: 21, |
| 110 |
}; |
| 111 |
assert_eq!( |
| 112 |
format!("{unsupported1}"), |
| 113 |
"Unsupported: Parsing error: unsupported value in line(21): unsupported line" |
| 114 |
); |
| 115 |
assert!(unsupported1.source().is_some()); |
| 116 |
} |
| 117 |
|
| 118 |
#[test] |
| 119 |
fn test_sdp_parser_error_sequence() { |
| 120 |
let sequence1 = SdpParserError::Sequence { |
| 121 |
message: "sequence message".to_string(), |
| 122 |
line_number: 42, |
| 123 |
}; |
| 124 |
assert_eq!( |
| 125 |
format!("{sequence1}"), |
| 126 |
"Sequence error in line(42): sequence message" |
| 127 |
); |
| 128 |
assert!(sequence1.source().is_none()); |
| 129 |
} |