-
Notifications
You must be signed in to change notification settings - Fork 0
/
openslide_test.go
126 lines (111 loc) · 3.15 KB
/
openslide_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
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
package gopenslide
import (
"fmt"
"io"
"log"
"math"
"net/http"
"os"
"strings"
"testing"
)
func init() {
// make sure testData exists
os.Mkdir("testData", os.ModePerm)
// download test data
if _, err := os.Stat("testData/JP2K-33003-1.svs"); err == nil {
fmt.Printf("Test Data already available moving on")
} else {
wsi1 := "https://openslide.cs.cmu.edu/download/openslide-testdata/Aperio/JP2K-33003-1.svs"
out, err := os.Create("testData/JP2K-33003-1.svs")
if err != nil {
log.Fatalf("error creating test data file %v", err)
}
defer out.Close()
resp, err := http.Get(wsi1)
if err != nil {
log.Fatalf("error downloading test data file %v", err)
}
defer resp.Body.Close()
n, err := io.Copy(out, resp.Body)
if err != nil {
log.Fatalf("error saving downloaded test data file %v", err)
}
log.Printf("successfully downloaded %d bytes of test file \n", n)
}
}
func Test_WSI_empty(t *testing.T) {
wsi, err := OpenWSI("")
if err == nil {
t.Fatalf("Expected this to fail and return error but got nill as error")
}
if wsi.osr != nil {
t.Fatalf("expected this to be nil but it is something %#v", wsi)
}
}
func Test_WSI_not_found(t *testing.T) {
wsi, err := OpenWSI("somethign that is not there")
if err == nil {
t.Fatalf("Expected this to fail and return error but got nill as error")
}
if !strings.Contains(err.Error(), "Not Found") {
t.Fatalf("Expected a Not Found error but got %s", err.Error())
}
if wsi.osr != nil {
t.Fatalf("expected this to be nil but it is something %#v", wsi)
}
}
func Test_WSI(t *testing.T) {
wsi, err := OpenWSI("testData/JP2K-33003-1.svs")
if err != nil {
t.Fatalf("What now %v", err)
}
if wsi.osr == nil {
t.Fatalf("expected this not to be nil but it is ")
}
if wsi.GetLevelCount() != 3 {
t.Fatalf("expected this to be 9 but it is %d", wsi.GetLevelCount())
}
if wsi.GetLevelDownsample(0) != 1.0 {
t.Fatalf("expected this to be 1.0 but it is %f", wsi.GetLevelDownsample(0))
}
if math.Ceil(wsi.GetLevelDownsample(1)*1000000) != 4000375 {
t.Fatalf("expected this to be 4.000375 but it is %f", wsi.GetLevelDownsample(1))
}
if math.Ceil(wsi.GetLevelDownsample(2)*1000000) != 8001791 {
t.Fatalf("expected this to be 8.001790 but it is %f", math.Ceil(wsi.GetLevelDownsample(2)*1000000))
}
w, h, err := wsi.GetLevelDimensions(0)
if err != nil {
t.Fatalf("expected this to be nil but it is %v", err)
}
if w != 15374 {
t.Fatalf("expected this to be 97792 but it is %d", w)
}
if h != 17497 {
t.Fatalf("expected this to be 221184 but it is %d", h)
}
region, err := wsi.ReadRegion(0, 0, 0, 100, 100)
if err != nil {
t.Fatalf("expected this to be nil but it is %v", err)
}
if len(region) != 40000 {
t.Fatalf("expected this to be 40000 but it is %d", len(region))
}
if region[0] != 255 {
t.Fatalf("expected this to be 0 but it is %d", region[0])
}
props := wsi.GetPropertyNames()
if len(props) != 2 {
t.Fatalf("expected this to be 2 but it is %d", len(props))
}
//aperio.AppMag: 40
//aperio.DSR ID: homer
for _, p := range props {
v := wsi.GetPropertyValue(p)
if v == "" {
t.Fatalf("expected this to be something but it is empty")
}
fmt.Printf("%s: %s\n", p, v)
}
}