-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhttp_test.go
71 lines (59 loc) · 1.98 KB
/
http_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
package gfx
import (
"image"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetPNG(t *testing.T) {
ts := testServer(palettedPNGHandler)
defer ts.Close()
m, err := GetPNG(ts.URL)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
p := m.(image.PalettedImage)
if got, want := p.Bounds(), IR(0, 0, 6, 6); !got.Eq(want) {
t.Fatalf("p.Bounds() = %v, want %v", got, want)
}
for _, tc := range []struct {
x int
y int
i uint8
}{
{0, 0, 0},
{2, 4, 6},
} {
if got, want := p.ColorIndexAt(tc.x, tc.y), tc.i; got != want {
t.Fatalf("p.ColorIndexAt(%d, %d) = %v, want %v", tc.x, tc.y, got, want)
}
}
}
func TestGetTileset(t *testing.T) {
ts := testServer(palettedPNGHandler)
defer ts.Close()
tileset, err := GetTileset(PaletteAmmo8, Pt(3, 3), ts.URL)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got, want := len(tileset.Tiles), 4; got != want {
t.Fatalf("len(tileset.Tiles) = %d, want %d", got, want)
}
}
func testServer(hf http.HandlerFunc) *httptest.Server {
return httptest.NewServer(hf)
}
func palettedPNGHandler(w http.ResponseWriter, r *http.Request) {
w.Write(palettedPNGData)
}
var palettedPNGData = []byte{
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x04, 0x03, 0x00, 0x00, 0x00, 0x12, 0xe2, 0xf2,
0x7b, 0x00, 0x00, 0x00, 0x24, 0x50, 0x4c, 0x54, 0x45, 0x18, 0x14, 0x25, 0x00, 0x99, 0xdb, 0x12,
0x4e, 0x89, 0x3e, 0x89, 0x48, 0xe4, 0x3b, 0x44, 0x26, 0x5c, 0x42, 0xfe, 0xae, 0x34, 0xf7, 0x76,
0x22, 0x2c, 0xe8, 0xf5, 0x63, 0xc7, 0x4d, 0xff, 0xff, 0xff, 0x19, 0x3c, 0x3e, 0xc5, 0xc7, 0x7e,
0x7a, 0x00, 0x00, 0x00, 0x20, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63, 0x60, 0xe0, 0xb4, 0x64,
0xe0, 0x62, 0x0e, 0x66, 0x60, 0x60, 0xdd, 0xca, 0xe0, 0x9e, 0x21, 0xc4, 0xe0, 0x9e, 0xa8, 0xc8,
0xe0, 0x9e, 0x24, 0x01, 0x00, 0x23, 0xc5, 0x03, 0xa8, 0x32, 0xa9, 0x7a, 0x6f, 0x00, 0x00, 0x00,
0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
}