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