-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer_test.go
78 lines (69 loc) · 2.54 KB
/
renderer_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
package tmx_test
import (
"fmt"
"os"
"image/png"
. "github.com/manyminds/tmx"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Test public renderer", func() {
Context("Test render", func() {
validateMapWithImage := func(mapFile, imageFile string, elapsedTime int64) {
f, err := os.Open(mapFile)
Expect(err).ToNot(HaveOccurred())
testMap, err := NewMap(f)
Expect(err).ToNot(HaveOccurred())
c := NewImageCanvasFromMap(*testMap)
renderer := NewRenderer(*testMap, c)
err = renderer.Render(elapsedTime)
Expect(err).ToNot(HaveOccurred())
// this code generates reference images if necessary
/*
*
* target, err := os.Create(imageFile)
* if err != nil {
* target, err = os.Open(imageFile)
* if err != nil {
* log.Fatal(err)
* }
* }
* defer target.Close()
*
* err = png.Encode(target, c.Image())
* if err != nil {
* log.Fatal(err)
* }
*
*/
f, err = os.Open(imageFile)
Expect(err).ToNot(HaveOccurred())
expected, err := png.Decode(f)
Expect(err).ToNot(HaveOccurred())
Expect(expected).To(EqualImage(c.Image()))
}
It("should render all layers when visible gzip", func() {
validateMapWithImage("./testfiles/simple_example.tmx", "./testfiles/simple_example_expected.png", 0)
})
It("should render only visible images zlib", func() {
validateMapWithImage("./testfiles/simple_example_zlib.tmx", "./testfiles/simple_example_zlib_expected.png", 0)
})
It("should render non squared uncompressed maps", func() {
validateMapWithImage("./testfiles/uncompressed_not_square.tmx", "./testfiles/uncompressed_not_square.png", 0)
})
It("renders animated tiles", func() {
validateMapWithImage("./testfiles/animated_example_zlib.tmx", "./testfiles/animated_example_zlib_01.png", 0)
validateMapWithImage("./testfiles/animated_example_zlib.tmx", "./testfiles/animated_example_zlib_02.png", 101)
validateMapWithImage("./testfiles/animated_example_zlib.tmx", "./testfiles/animated_example_zlib_03.png", 201)
validateMapWithImage("./testfiles/animated_example_zlib.tmx", "./testfiles/animated_example_zlib_04.png", 301)
})
})
Context("Test flip mode", func() {
It("will have a working String", func() {
Expect(fmt.Sprintf("%s", FlipNone)).To(Equal("None"))
Expect(fmt.Sprintf("%s", FlipHorizontal)).To(Equal("Horizontal"))
Expect(fmt.Sprintf("%s", FlipVertical)).To(Equal("Vertical"))
Expect(fmt.Sprintf("%s", FlipDiagonal)).To(Equal("Diagonal"))
})
})
})