|
1 | 1 | package video |
2 | 2 |
|
3 | | -import "testing" |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/go-gl/glfw/v3.2/glfw" |
| 8 | + "github.com/kivutar/glfont" |
| 9 | + "github.com/libretro/ludo/libretro" |
| 10 | +) |
4 | 11 |
|
5 | 12 | func TestXYWHTo4points(t *testing.T) { |
6 | 13 | type args struct { |
@@ -65,3 +72,97 @@ func TestXYWHTo4points(t *testing.T) { |
65 | 72 | }) |
66 | 73 | } |
67 | 74 | } |
| 75 | + |
| 76 | +type WindowMock struct{} |
| 77 | + |
| 78 | +func (m WindowMock) GetFramebufferSize() (width, height int) { return 320, 240 } |
| 79 | +func (m WindowMock) Destroy() {} |
| 80 | +func (m WindowMock) MakeContextCurrent() {} |
| 81 | +func (m WindowMock) SetSizeLimits(minw, minh, maxw, maxh int) {} |
| 82 | +func (m WindowMock) SetInputMode(mode glfw.InputMode, value int) {} |
| 83 | +func (m WindowMock) GetKey(key glfw.Key) glfw.Action { return 0 } |
| 84 | +func (m WindowMock) SetShouldClose(bool) {} |
| 85 | +func (m WindowMock) ShouldClose() bool { return false } |
| 86 | +func (m WindowMock) SetTitle(string) {} |
| 87 | +func (m WindowMock) SwapBuffers() {} |
| 88 | + |
| 89 | +func TestVideo_vertexArray(t *testing.T) { |
| 90 | + |
| 91 | + var myWindowMock WindowMock |
| 92 | + |
| 93 | + type fields struct { |
| 94 | + Window WindowInterface |
| 95 | + Geom libretro.GameGeometry |
| 96 | + Font *glfont.Font |
| 97 | + program uint32 |
| 98 | + roundedProgram uint32 |
| 99 | + borderProgram uint32 |
| 100 | + circleProgram uint32 |
| 101 | + demulProgram uint32 |
| 102 | + vao uint32 |
| 103 | + vbo uint32 |
| 104 | + texID uint32 |
| 105 | + white uint32 |
| 106 | + pitch int32 |
| 107 | + pixFmt uint32 |
| 108 | + pixType uint32 |
| 109 | + bpp int32 |
| 110 | + } |
| 111 | + type args struct { |
| 112 | + x float32 |
| 113 | + y float32 |
| 114 | + w float32 |
| 115 | + h float32 |
| 116 | + scale float32 |
| 117 | + } |
| 118 | + tests := []struct { |
| 119 | + name string |
| 120 | + fields fields |
| 121 | + args args |
| 122 | + want []float32 |
| 123 | + }{ |
| 124 | + { |
| 125 | + name: "Works", |
| 126 | + fields: fields{ |
| 127 | + Window: myWindowMock, |
| 128 | + }, |
| 129 | + args: args{ |
| 130 | + x: 10, |
| 131 | + y: 11, |
| 132 | + w: 300, |
| 133 | + h: 400, |
| 134 | + scale: 2, |
| 135 | + }, |
| 136 | + want: []float32{ |
| 137 | + -0.9375, -5.758333, 0, 1, |
| 138 | + -0.9375, 0.9083333, 0, 0, |
| 139 | + 2.8125, -5.758333, 1, 1, |
| 140 | + 2.8125, 0.9083333, 1, 0}, |
| 141 | + }, |
| 142 | + } |
| 143 | + for _, tt := range tests { |
| 144 | + t.Run(tt.name, func(t *testing.T) { |
| 145 | + video := &Video{ |
| 146 | + Window: tt.fields.Window, |
| 147 | + Geom: tt.fields.Geom, |
| 148 | + Font: tt.fields.Font, |
| 149 | + program: tt.fields.program, |
| 150 | + roundedProgram: tt.fields.roundedProgram, |
| 151 | + borderProgram: tt.fields.borderProgram, |
| 152 | + circleProgram: tt.fields.circleProgram, |
| 153 | + demulProgram: tt.fields.demulProgram, |
| 154 | + vao: tt.fields.vao, |
| 155 | + vbo: tt.fields.vbo, |
| 156 | + texID: tt.fields.texID, |
| 157 | + white: tt.fields.white, |
| 158 | + pitch: tt.fields.pitch, |
| 159 | + pixFmt: tt.fields.pixFmt, |
| 160 | + pixType: tt.fields.pixType, |
| 161 | + bpp: tt.fields.bpp, |
| 162 | + } |
| 163 | + if got := video.vertexArray(tt.args.x, tt.args.y, tt.args.w, tt.args.h, tt.args.scale); !reflect.DeepEqual(got, tt.want) { |
| 164 | + t.Errorf("Video.vertexArray() = %v, want %v", got, tt.want) |
| 165 | + } |
| 166 | + }) |
| 167 | + } |
| 168 | +} |
0 commit comments