-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathintegration_tests.rs
219 lines (198 loc) · 8.41 KB
/
integration_tests.rs
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
extern crate dicom_dictionary_parser as dict_parser;
// Note: this contains tests against the "part06.xml" file that this lib was
// coded against as well as tests against a downloaded version of part 6 to
// prove that it still works for the current format.
fn parser_from_file() -> dict_parser::Parser {
let part6_contents = include_bytes!("part06.xml");
dict_parser::Parser::with_part6_file_contents(
String::from_utf8_lossy(part6_contents).to_string(),
)
}
#[test]
fn parse_data_element_registry_from_file() {
let parser = parser_from_file();
match parser.parse_data_element_registry() {
Ok(elements) => {
assert_eq!(elements.len(), 4266);
let item_delimitation_item = &elements[4264];
assert_eq!(item_delimitation_item.tag, "(FFFE,E00D)");
assert_eq!(item_delimitation_item.name, "Item Delimitation Item");
assert_eq!(
item_delimitation_item.keyword,
"Item\u{200b}Delimitation\u{200b}Item"
);
assert_eq!(item_delimitation_item.vr, "");
assert_eq!(item_delimitation_item.vm, "1");
assert!(item_delimitation_item.comment.is_none());
let escape_triplet = &elements[3298];
assert_eq!(escape_triplet.tag, "(1000,xxx0)");
let unnamed_element = &elements[537];
assert_eq!(unnamed_element.tag, "(0018,0061)");
assert!(unnamed_element.name.is_empty());
assert!(unnamed_element.keyword.is_empty());
assert_eq!(unnamed_element.vr, "DS");
assert_eq!(unnamed_element.vm, "1");
assert_eq!(unnamed_element.comment, Some("RET".to_string()));
}
Err(e) => assert!(false, e.to_string()),
}
}
#[test]
fn parse_file_meta_element_registry_from_file() {
let parser = parser_from_file();
match parser.parse_file_meta_element_registry() {
Ok(elements) => {
assert_eq!(elements.len(), 12);
let transfer_syntax_uid = &elements[4];
assert_eq!(transfer_syntax_uid.tag, "(0002,0010)");
assert_eq!(transfer_syntax_uid.name, "Transfer Syntax UID");
assert_eq!(
transfer_syntax_uid.keyword,
"Transfer\u{200b}Syntax\u{200b}UID"
);
assert_eq!(transfer_syntax_uid.vr, "UI");
assert_eq!(transfer_syntax_uid.vm, "1");
assert!(transfer_syntax_uid.comment.is_none());
}
Err(e) => assert!(false, e.to_string()),
}
}
#[test]
fn parse_data_element_registry_from_downloaded_dict() {
let parser = dict_parser::Parser::new().unwrap();
match parser.parse_data_element_registry() {
Ok(elements) => {
// 1000 is pretty random... just checking that we have
// successfully parsed quite a bit of data. exact test
// is done against an actual xml file above
assert!(elements.len() > 1000);
// checking some random data elements
let length_to_end = &elements[0];
assert_eq!(length_to_end.tag, "(0008,0001)");
assert_eq!(length_to_end.name, "Length to End");
assert_eq!(length_to_end.keyword, "Length\u{200b}To\u{200b}End");
assert_eq!(length_to_end.vr, "UL");
assert_eq!(length_to_end.vm, "1");
assert_eq!(length_to_end.comment, Some("RET".to_string()));
let specific_character_set = &elements[1];
assert_eq!(specific_character_set.tag, "(0008,0005)");
assert_eq!(specific_character_set.vm, "1-n");
assert!(specific_character_set.comment.is_none());
}
Err(e) => assert!(false, e.to_string()),
}
}
#[test]
fn parse_file_meta_element_registry_from_downloaded_dict() {
let parser = dict_parser::Parser::new().unwrap();
match parser.parse_file_meta_element_registry() {
Ok(elements) => {
// 10 is pretty random... just checking that we have
// successfully parsed quite a bit of data. exact test
// is done against an actual xml file above
assert!(elements.len() > 10);
// checking some random file meta elements
let file_meta_information_group_length = &elements[0];
assert_eq!(file_meta_information_group_length.tag, "(0002,0000)");
assert_eq!(
file_meta_information_group_length.name,
"File Meta Information Group Length"
);
assert_eq!(
file_meta_information_group_length.keyword,
"File\u{200b}Meta\u{200b}Information\u{200b}Group\u{200b}Length"
);
assert_eq!(file_meta_information_group_length.vr, "UL");
assert_eq!(file_meta_information_group_length.vm, "1");
assert!(file_meta_information_group_length.comment.is_none());
}
Err(e) => assert!(false, e.to_string()),
}
}
#[test]
fn parse_directory_structuring_element_registry_from_file() {
let parser = parser_from_file();
match parser.parse_directory_structuring_element_registry() {
Ok(elements) => {
assert_eq!(elements.len(), 19);
let item_delimitation_item = &elements[5];
assert_eq!(item_delimitation_item.tag, "(0004,1212)");
assert_eq!(item_delimitation_item.name, "File-set Consistency Flag");
assert_eq!(
item_delimitation_item.keyword,
"File\u{200b}Set\u{200b}Consistency\u{200b}Flag"
);
assert_eq!(item_delimitation_item.vr, "US");
assert_eq!(item_delimitation_item.vm, "1");
assert!(item_delimitation_item.comment.is_none());
}
Err(e) => assert!(false, e.to_string()),
}
}
#[test]
fn parse_directory_structuring_element_registry_from_downloaded_dict() {
let parser = dict_parser::Parser::new().unwrap();
match parser.parse_directory_structuring_element_registry() {
Ok(elements) => {
// 10 is pretty random... just checking that we have
// successfully parsed quite a bit of data. exact test
// is done against an actual xml file above
assert!(elements.len() > 10);
// checking some random element
let file_set_id = &elements[0];
assert_eq!(file_set_id.tag, "(0004,1130)");
assert_eq!(file_set_id.name, "File-set ID");
assert_eq!(file_set_id.keyword, "File\u{200b}Set\u{200b}ID");
assert_eq!(file_set_id.vr, "CS");
assert_eq!(file_set_id.vm, "1");
assert!(file_set_id.comment.is_none());
}
Err(e) => assert!(false, e.to_string()),
}
}
#[test]
fn parse_unique_identifier_registry_from_file() {
let parser = parser_from_file();
match parser.parse_unique_identifier_registry() {
Ok(uids) => {
assert_eq!(uids.len(), 400);
let implicit_little_endian = &uids[1];
assert_eq!(implicit_little_endian.value, "1.2.840.10008.1.2");
assert_eq!(
implicit_little_endian.full_name,
"Implicit VR Little Endian: Default Transfer Syntax for DICOM"
);
assert_eq!(
implicit_little_endian.normalized_name,
"Implicit VR Little Endian"
);
assert_eq!(
implicit_little_endian.kind,
dict_parser::Kind::TransferSyntax
);
}
Err(e) => assert!(false, e.to_string()),
}
}
#[test]
fn parse_unique_identifier_registry_from_downloaded_dict() {
let parser = dict_parser::Parser::new().unwrap();
match parser.parse_unique_identifier_registry() {
Ok(uids) => {
// 100 is pretty random... just checking that we have
// successfully parsed quite a bit of data. exact test
// is done against an actual xml file above
assert!(uids.len() > 100);
// checking some random element
let verification_sop_class = &uids[0];
assert_eq!(verification_sop_class.value, "1.2.840.10008.1.1");
assert_eq!(verification_sop_class.full_name, "Verification SOP Class");
assert_eq!(
verification_sop_class.normalized_name,
"Verification SOP Class"
);
assert_eq!(verification_sop_class.kind, dict_parser::Kind::SopClass);
}
Err(e) => assert!(false, e.to_string()),
}
}