mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
test: Simplify code to get a test image
This commit is contained in:
parent
1b0e71765f
commit
1b35bbec9a
@ -15,6 +15,7 @@
|
||||
package ebiten_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"image"
|
||||
"image/color"
|
||||
@ -26,6 +27,7 @@ import (
|
||||
|
||||
. "github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/examples/resources/images"
|
||||
emath "github.com/hajimehoshi/ebiten/internal/math"
|
||||
)
|
||||
|
||||
@ -43,23 +45,8 @@ func TestMain(m *testing.M) {
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
var ebitenImageBin = ""
|
||||
|
||||
func openImage(path string) (image.Image, error) {
|
||||
file, err := readFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
img, _, err := image.Decode(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return img, nil
|
||||
}
|
||||
|
||||
func openEbitenImage(path string) (*Image, image.Image, error) {
|
||||
img, err := openImage(path)
|
||||
func openEbitenImage() (*Image, image.Image, error) {
|
||||
img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -91,7 +78,7 @@ func sameColors(c1, c2 color.RGBA, delta int) bool {
|
||||
}
|
||||
|
||||
func TestImagePixels(t *testing.T) {
|
||||
img0, img, err := openEbitenImage("testdata/ebiten.png")
|
||||
img0, img, err := openEbitenImage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -120,7 +107,7 @@ func TestImageComposition(t *testing.T) {
|
||||
img3Color := color.NRGBA{0x85, 0xa3, 0x08, 0xd3}
|
||||
|
||||
// TODO: Rename this to img0
|
||||
img1, _, err := openEbitenImage("testdata/ebiten.png")
|
||||
img1, _, err := openEbitenImage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -216,7 +203,7 @@ func TestImageSelf(t *testing.T) {
|
||||
t.Errorf("DrawImage must panic but not")
|
||||
}
|
||||
}()
|
||||
img, _, err := openEbitenImage("testdata/ebiten.png")
|
||||
img, _, err := openEbitenImage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -226,7 +213,7 @@ func TestImageSelf(t *testing.T) {
|
||||
|
||||
func TestImageScale(t *testing.T) {
|
||||
for _, scale := range []int{2, 3, 4} {
|
||||
img0, _, err := openEbitenImage("testdata/ebiten.png")
|
||||
img0, _, err := openEbitenImage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -258,7 +245,7 @@ func TestImageScale(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestImage90DegreeRotate(t *testing.T) {
|
||||
img0, _, err := openEbitenImage("testdata/ebiten.png")
|
||||
img0, _, err := openEbitenImage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -289,7 +276,7 @@ func TestImage90DegreeRotate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestImageDotByDotInversion(t *testing.T) {
|
||||
img0, _, err := openEbitenImage("testdata/ebiten.png")
|
||||
img0, _, err := openEbitenImage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -324,12 +311,12 @@ func TestImageReplacePixels(t *testing.T) {
|
||||
dummyImg, _ := NewImageFromImage(image.NewRGBA(image.Rect(0, 0, 16, 16)), FilterDefault)
|
||||
defer dummyImg.Dispose()
|
||||
|
||||
origImg, err := openImage("testdata/ebiten.png")
|
||||
_, origImg, err := openEbitenImage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
// Convert to RGBA
|
||||
// Convert to *image.RGBA just in case.
|
||||
img := image.NewRGBA(origImg.Bounds())
|
||||
draw.Draw(img, img.Bounds(), origImg, image.ZP, draw.Src)
|
||||
|
||||
@ -405,7 +392,7 @@ func min(a, b int) int {
|
||||
}
|
||||
|
||||
func TestImageCompositeModeLighter(t *testing.T) {
|
||||
img0, _, err := openEbitenImage("testdata/ebiten.png")
|
||||
img0, _, err := openEbitenImage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -443,7 +430,7 @@ func TestImageCompositeModeLighter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewImageFromEbitenImage(t *testing.T) {
|
||||
img, _, err := openEbitenImage("testdata/ebiten.png")
|
||||
img, _, err := openEbitenImage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -454,7 +441,7 @@ func TestNewImageFromEbitenImage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewImageFromSubImage(t *testing.T) {
|
||||
img, err := openImage("testdata/ebiten.png")
|
||||
_, img, err := openEbitenImage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
|
@ -1,116 +0,0 @@
|
||||
// Copyright 2014 Hajime Hoshi
|
||||
//
|
||||
// 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.
|
||||
|
||||
// +build js
|
||||
|
||||
package ebiten_test
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// NOTE: Please update if any of testdata/* is updated.
|
||||
var data = map[string]string{
|
||||
"testdata/ebiten.png": `
|
||||
iVBORw0KGgoAAAANSUhEUgAAADkAAAAaCAYAAAANIPQdAAAEJGlDQ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dk0z0R1COP7QMVW9xSLqVFkxPzdle
|
||||
b8Uo7X6p+PAXIJm1OZZB2unrbn74Z/WZqdcYAtNhLBRL1CO2o1YJoCG/8AaC
|
||||
5mAW7UA14uY4HBI/a5TUEK/apaiE8E4VCYLtuyUymHFet7PH3NymtpXqebtr
|
||||
29MH1wba8irLIGH2ppM+JtCsNWcABgPjCOfQnxiCh1QNsBeiPtUWDb8sJMGc
|
||||
3AyxRD+knMLWDQmB7HS7SGYi2zSdvl9Yifyk6fWc6Bp+6s9YUiwvu7Z3t4PE
|
||||
DgZsGNiiaWAHPUwyBA9blzhjWL+IFigGSK62cFIQSw2ASSQDcjQSfRczvYM/
|
||||
MBLeBc3Jh5ajnckO7MLPiY//WAHSzQxebKUmznda80OCsO1SHZljVxN1YBoe
|
||||
dRoVAMVeEi6ooQZZiA21U+hkS6Pfp9zAG8XiTvxU+PgY+7B0rt7x3Bp36cgb
|
||||
Z2VcGVYtIw7CBd1wq6Y7EJnuup8YRu6t7pFd5VuD/8dvPhSkirsycWC/VP9e
|
||||
MJP7uwad3xPtArWfvOOOID95cD444rX4v+sHr7yGb/8JabkxZC5Kp1sAAAAA
|
||||
SUVORK5CYII=`,
|
||||
}
|
||||
|
||||
func readFile(path string) (io.Reader, error) {
|
||||
// According to https://github.com/gopherjs/gopherjs/blob/master/doc/syscalls.md,
|
||||
// syscall can be available on the unstable version of npm.
|
||||
// Let's not use os package here.
|
||||
str, ok := data[path]
|
||||
if !ok {
|
||||
return nil, errors.New("ebiten_test: not found")
|
||||
}
|
||||
return base64.NewDecoder(base64.StdEncoding, strings.NewReader(str)), nil
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
// Copyright 2016 Hajime Hoshi
|
||||
//
|
||||
// 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.
|
||||
|
||||
// +build !js
|
||||
|
||||
package ebiten_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func readFile(path string) (io.Reader, error) {
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bytes.NewBuffer(b), nil
|
||||
}
|
BIN
testdata/ebiten.png
vendored
BIN
testdata/ebiten.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 3.3 KiB |
Loading…
Reference in New Issue
Block a user