-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencode_file_test.go
More file actions
42 lines (37 loc) · 1.02 KB
/
Copy pathencode_file_test.go
File metadata and controls
42 lines (37 loc) · 1.02 KB
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
package godicom
import (
"bytes"
"testing"
)
func TestEncodeFileReadBytesRoundtrip(t *testing.T) {
src, err := ReadFile(testFilePath("CT_small.dcm"), nil)
if err != nil {
t.Fatal(err)
}
encoded, err := EncodeFile(src, &WriteOptions{EnforceFileFormat: true})
if err != nil {
t.Fatal(err)
}
if len(encoded) < 132 || string(encoded[128:132]) != "DICM" {
t.Fatalf("missing DICM prefix, len=%d", len(encoded))
}
got, err := ReadBytes(encoded, nil)
if err != nil {
t.Fatal(err)
}
if got.Len() != src.Len() {
t.Fatalf("element count: got %d want %d", got.Len(), src.Len())
}
sop, _ := src.GetString(MustTag("SOPInstanceUID"))
gotSOP, ok := got.GetString(MustTag("SOPInstanceUID"))
if !ok || gotSOP != sop {
t.Fatalf("SOPInstanceUID=%q want %q", gotSOP, sop)
}
var buf bytes.Buffer
if err := src.Write(&buf, &WriteOptions{EnforceFileFormat: true}); err != nil {
t.Fatal(err)
}
if !bytes.Equal(buf.Bytes(), encoded) {
t.Fatalf("Write vs EncodeFile mismatch: %d vs %d bytes", buf.Len(), len(encoded))
}
}