shareable: Fix tests

This commit is contained in:
Hajime Hoshi 2019-09-21 03:58:23 +09:00
parent d491cab465
commit ea52aa52bb
3 changed files with 33 additions and 13 deletions

View 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()
}

View File

@ -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)

View File

@ -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.