This repository has been archived by the owner on Mar 24, 2018. It is now read-only.
/
NativeOpenGlSuite.go
72 lines (53 loc) · 1.8 KB
/
NativeOpenGlSuite.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
package native
import (
"path"
gogl "github.com/go-gl/gl"
glfw "github.com/go-gl/glfw3"
gles "github.com/dertseha/golgo/gles2"
"github.com/dertseha/golgo/native"
"github.com/dertseha/golgo/util"
testUtil "github.com/dertseha/golgo/test/util"
check "gopkg.in/check.v1"
)
type NativeOpenGlSuite struct {
width int
height int
window *glfw.Window
gl gles.OpenGl
}
func NewNativeOpenGlSuite(width, height int) NativeOpenGlSuite {
return NativeOpenGlSuite{width: width, height: height}
}
func (suite *NativeOpenGlSuite) Width() int {
return suite.width
}
func (suite *NativeOpenGlSuite) Height() int {
return suite.height
}
func (suite *NativeOpenGlSuite) OpenGl() gles.OpenGl {
return suite.gl
}
func (suite *NativeOpenGlSuite) SetUpTest(c *check.C) {
glfw.Init()
glfw.WindowHint(glfw.ContextVersionMajor, 2)
glfw.WindowHint(glfw.ContextVersionMinor, 0)
window, _ := glfw.CreateWindow(suite.width, suite.height, "Native OpenGL Test", nil, nil)
window.MakeContextCurrent()
glfw.SwapInterval(1)
gogl.Init()
suite.window = window
suite.gl = native.CreateGles2Wrapper()
}
func (suite *NativeOpenGlSuite) TearDownTest(c *check.C) {
suite.window.Destroy()
glfw.Terminate()
}
func (suite *NativeOpenGlSuite) ThenScreenShouldMatchReference(c *check.C, refName string) {
screenshotPath := path.Join(testUtil.GetProjectRootPath(), "test", "screenshots", "native", c.TestName()+"."+refName)
referencePath := path.Join(testUtil.GetProjectRootPath(), "test", "resources", refName)
liveImg, glError := util.ReadPixels(suite.gl, 0, 0, suite.width, suite.height)
c.Assert(glError, check.Equals, gles.NO_ERROR)
testUtil.SaveImage(screenshotPath, liveImg)
confidence := testUtil.GetMatch(referencePath, liveImg)
c.Check(confidence >= 0.99, check.Equals, true, check.Commentf("Confidence == %f", confidence))
}