Skip to content

Commit 0ee5c96

Browse files
committed
[object] Fix information group length calculation
- file meta information group length is not included - refactor object smoke_test to test writing and reading - add builder test
1 parent 1b7e4b9 commit 0ee5c96

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

object/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ mod tests {
202202

203203
#[test]
204204
fn smoke_test() {
205+
const FILE_NAME: &str = ".smoke-test.dcm";
206+
205207
let meta = FileMetaTableBuilder::new()
206208
.transfer_syntax(dicom_transfer_syntax_registry::entries::EXPLICIT_VR_LITTLE_ENDIAN.uid())
207209
.media_storage_sop_class_uid("1.2.840.10008.5.1.4.1.1.1")
@@ -212,7 +214,12 @@ mod tests {
212214
let obj = RootDicomObject::new_empty_with_meta(
213215
meta);
214216

215-
obj.write_to_file(".smoke-test.dcm").unwrap();
216-
let _ = std::fs::remove_file(".smoke-test.dcm");
217+
obj.write_to_file(FILE_NAME).unwrap();
218+
219+
let obj2 = RootDicomObject::open_file(FILE_NAME).unwrap();
220+
221+
assert_eq!(obj, obj2);
222+
223+
let _ = std::fs::remove_file(FILE_NAME);
217224
}
218225
}

object/src/meta.rs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,10 @@ impl FileMetaTableBuilder {
528528
let information_group_length = match self.information_group_length {
529529
Some(e) => e,
530530
None => {
531-
// determine the expected meta group size based on the given fields
532-
12 + 14 +
531+
// determine the expected meta group size based on the given fields.
532+
// FileMetaInformationGroupLength is not included here
533+
534+
14 +
533535
8 + dicom_len(&media_storage_sop_class_uid) +
534536
8 + dicom_len(&media_storage_sop_instance_uid) +
535537
8 + dicom_len(&transfer_syntax) +
@@ -563,7 +565,7 @@ impl FileMetaTableBuilder {
563565

564566
#[cfg(test)]
565567
mod tests {
566-
use super::FileMetaTable;
568+
use super::{FileMetaTableBuilder, FileMetaTable};
567569
use dicom_core::value::Value;
568570
use dicom_core::{dicom_value, DataElement, Tag, VR};
569571

@@ -646,6 +648,39 @@ mod tests {
646648
assert_eq!(table, gt);
647649
}
648650

651+
#[test]
652+
fn create_meta_table_with_builder() {
653+
let table = FileMetaTableBuilder::new()
654+
.information_version([0, 1])
655+
.media_storage_sop_class_uid("1.2.840.10008.5.1.4.1.1.1")
656+
.media_storage_sop_instance_uid("1.2.3.4.5.12345678.1234567890.1234567.123456789.1234567")
657+
.transfer_syntax("1.2.840.10008.1.2.1")
658+
.implementation_class_uid("1.2.345.6.7890.1.234")
659+
.implementation_version_name("RUSTY_DICOM_269")
660+
.source_application_entity_title("")
661+
.build()
662+
.unwrap();
663+
664+
let gt = FileMetaTable {
665+
information_group_length: 200,
666+
information_version: [0u8, 1u8],
667+
media_storage_sop_class_uid: "1.2.840.10008.5.1.4.1.1.1\0".to_owned(),
668+
media_storage_sop_instance_uid:
669+
"1.2.3.4.5.12345678.1234567890.1234567.123456789.1234567\0".to_owned(),
670+
transfer_syntax: "1.2.840.10008.1.2.1\0".to_owned(),
671+
implementation_class_uid: "1.2.345.6.7890.1.234".to_owned(),
672+
implementation_version_name: Some("RUSTY_DICOM_269 ".to_owned()),
673+
source_application_entity_title: Some("".to_owned()),
674+
sending_application_entity_title: None,
675+
receiving_application_entity_title: None,
676+
private_information_creator_uid: None,
677+
private_information: None,
678+
};
679+
680+
assert_eq!(table.information_group_length, gt.information_group_length);
681+
assert_eq!(table, gt);
682+
}
683+
649684
#[test]
650685
fn read_meta_table_into_iter() {
651686
let table = FileMetaTable {

0 commit comments

Comments
 (0)