This repository has been archived by the owner on Nov 16, 2017. It is now read-only.
forked from gillesdemey/go-dicom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery_test.go
65 lines (62 loc) · 1.57 KB
/
query_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
60
61
62
63
64
65
package dicom_test
import (
"github.com/yasushi-saito/go-dicom"
"testing"
)
func TestParse0(t *testing.T) {
ds, err := dicom.ReadDataSetFromFile("examples/I_000013.dcm", dicom.ReadOptions{})
if err != nil {
t.Fatal(err)
}
studyUID := "1.2.840.113857.1907.192833.1115.220048"
match, elem, err := dicom.Query(ds, dicom.MustNewElement(dicom.TagStudyInstanceUID, studyUID))
if !match || err != nil {
t.Error(err)
}
if elem.MustGetString() != studyUID {
t.Error(elem)
}
}
func TestParseDate(t *testing.T) {
goodDateRanges := []struct {
str string
startISO8601 string
endISO8601 string
}{
{"20170927-20170929","2017-09-27","2017-09-29"},
{"-20170929","0000-01-01","2017-09-29"},
{"20170927-","2017-09-27","9999-12-31"},
}
for _, r := range goodDateRanges {
s, e, err := dicom.ParseDate(r.str)
if err != nil {
t.Error(err)
}
if s.String() != r.startISO8601 || e.String() != r.endISO8601 {
t.Errorf("%+v: %+v %+v", r, s, e)
}
}
goodDates := []struct {
str string
iso8601 string
}{
{"20170101", "2017-01-01"},
{"2017.02.03", "2017-02-03"},
}
for _, goodDate := range goodDates {
s, e, err := dicom.ParseDate(goodDate.str)
if err != nil {
t.Errorf("%v: err %v", goodDate, err)
}
if s.String() != goodDate.iso8601 || e.Year != dicom.InvalidYear {
t.Errorf("%v: wrong value %v", goodDate, s.String())
}
}
badDates := []string{"2017.0101", "2017.01", "2017X01.02", "201X0405"}
for _, badDate := range badDates {
_, _, err := dicom.ParseDate(badDate)
if err == nil {
t.Errorf("%s: this should have failed", badDate)
}
}
}