mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
shareable: Fix tests
This commit is contained in:
parent
d491cab465
commit
ea52aa52bb
31
internal/shareable/export_test.go
Normal file
31
internal/shareable/export_test.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright 2019 The Ebiten Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package shareable
|
||||||
|
|
||||||
|
func MakeImagesSharedForTesting() {
|
||||||
|
makeImagesShared()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Image) IsSharedForTesting() bool {
|
||||||
|
backendsM.Lock()
|
||||||
|
defer backendsM.Unlock()
|
||||||
|
return i.isShared()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Image) EnsureNotSharedForTesting() {
|
||||||
|
backendsM.Lock()
|
||||||
|
defer backendsM.Unlock()
|
||||||
|
i.ensureNotShared()
|
||||||
|
}
|
@ -79,10 +79,6 @@ func makeImagesShared() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeImagesSharedForTesting() {
|
|
||||||
makeImagesShared()
|
|
||||||
}
|
|
||||||
|
|
||||||
type backend struct {
|
type backend struct {
|
||||||
restorable *restorable.Image
|
restorable *restorable.Image
|
||||||
|
|
||||||
@ -186,12 +182,6 @@ func (i *Image) isShared() bool {
|
|||||||
return i.node != nil
|
return i.node != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) IsSharedForTesting() bool {
|
|
||||||
backendsM.Lock()
|
|
||||||
defer backendsM.Unlock()
|
|
||||||
return i.isShared()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Image) ensureNotShared() {
|
func (i *Image) ensureNotShared() {
|
||||||
if i.backend == nil {
|
if i.backend == nil {
|
||||||
i.allocate(false)
|
i.allocate(false)
|
||||||
|
@ -371,11 +371,10 @@ func TestDisposeImmediately(t *testing.T) {
|
|||||||
// This tests restorable.Image.ClearPixels is called but ReplacePixels is not called.
|
// This tests restorable.Image.ClearPixels is called but ReplacePixels is not called.
|
||||||
|
|
||||||
img0 := NewImage(16, 16)
|
img0 := NewImage(16, 16)
|
||||||
vs := make([]float32, graphics.VertexFloatNum)
|
img0.EnsureNotSharedForTesting()
|
||||||
img0.PutVertex(vs, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1)
|
|
||||||
|
|
||||||
img1 := NewImage(16, 16)
|
img1 := NewImage(16, 16)
|
||||||
img1.PutVertex(vs, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1)
|
img1.EnsureNotSharedForTesting()
|
||||||
|
|
||||||
// img0 and img1 should share the same backend in 99.9999% possibility.
|
// img0 and img1 should share the same backend in 99.9999% possibility.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user