From ea52aa52bb94f8446bad8a148622acf957297e0e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 21 Sep 2019 03:58:23 +0900 Subject: [PATCH] shareable: Fix tests --- internal/shareable/export_test.go | 31 ++++++++++++++++++++++++++++ internal/shareable/shareable.go | 10 --------- internal/shareable/shareable_test.go | 5 ++--- 3 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 internal/shareable/export_test.go diff --git a/internal/shareable/export_test.go b/internal/shareable/export_test.go new file mode 100644 index 000000000..1b7437e89 --- /dev/null +++ b/internal/shareable/export_test.go @@ -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() +} diff --git a/internal/shareable/shareable.go b/internal/shareable/shareable.go index 8c74f69c7..52a7cd3e5 100644 --- a/internal/shareable/shareable.go +++ b/internal/shareable/shareable.go @@ -79,10 +79,6 @@ func makeImagesShared() { } } -func MakeImagesSharedForTesting() { - makeImagesShared() -} - type backend struct { restorable *restorable.Image @@ -186,12 +182,6 @@ func (i *Image) isShared() bool { return i.node != nil } -func (i *Image) IsSharedForTesting() bool { - backendsM.Lock() - defer backendsM.Unlock() - return i.isShared() -} - func (i *Image) ensureNotShared() { if i.backend == nil { i.allocate(false) diff --git a/internal/shareable/shareable_test.go b/internal/shareable/shareable_test.go index 3a70a4636..feb2076fe 100644 --- a/internal/shareable/shareable_test.go +++ b/internal/shareable/shareable_test.go @@ -371,11 +371,10 @@ func TestDisposeImmediately(t *testing.T) { // This tests restorable.Image.ClearPixels is called but ReplacePixels is not called. img0 := NewImage(16, 16) - vs := make([]float32, graphics.VertexFloatNum) - img0.PutVertex(vs, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1) + img0.EnsureNotSharedForTesting() 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.