forked from suyashkumar/dicom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_internal_test.go
59 lines (53 loc) · 1.79 KB
/
parse_internal_test.go
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
package dicom
import (
"io/ioutil"
"os"
"strings"
"testing"
)
// TestParseUntilEOFConformsToParse runs both the dicom.ParseUntilEOF and the dicom.Parse APIs against each
// testdata file and ensures the outputs are the same.
// This test lives in parse_internal_test.go because this test cannot live in the dicom_test package, due
// to some dependencies on internal valuesets for diffing.
func TestParseUntilEOFConformsToParse(t *testing.T) {
files, err := ioutil.ReadDir("./testdata")
if err != nil {
t.Fatalf("unable to read testdata/: %v", err)
}
for _, f := range files {
f := f
if !f.IsDir() && strings.HasSuffix(f.Name(), ".dcm") {
t.Run(f.Name(), func(t *testing.T) {
t.Parallel()
// Read dataset with ParseUntilEOF
dcm := readTestdataFile(t, f.Name())
parse_eof_dataset, err := ParseUntilEOF(dcm, nil)
if err != nil {
t.Errorf("dicom.ParseUntilEOF(%s) unexpected error: %v", f.Name(), err)
}
// Read dataset with Parse
dcm2 := readTestdataFile(t, f.Name())
info, err := dcm2.Stat()
if err != nil {
t.Errorf("Unable to stat %s. Error: %v", f.Name(), err)
}
parse_dataset, err := Parse(dcm2, info.Size(), nil)
if err != nil {
t.Errorf("dicom.Parse(%s) unexpected error: %v", f.Name(), err)
}
// Ensure dataset read from ParseUntilEOF and Parse are the same.
if !parse_dataset.Equals(&parse_eof_dataset) {
t.Errorf("dicom.Parse and dicom.ParseUntilEOF do not result in the same dataset.\nParse Dataset: %v\n\n\nParse EOF Dataset: %v", parse_dataset, parse_eof_dataset)
}
})
}
}
}
func readTestdataFile(t *testing.T, name string) *os.File {
dcm, err := os.Open("./testdata/" + name)
if err != nil {
t.Errorf("Unable to open %s. Error: %v", name, err)
}
t.Cleanup(func() { dcm.Close() })
return dcm
}