From 30adcdba9403376f8605d841cc2f85b9e67a55c6 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 23 Dec 2014 01:51:16 +0900 Subject: [PATCH] Add test for NewImageFromImage --- image_test.go | 63 ++++++++++++++++++++++++++++++++++++++++++++ testdata/ebiten.png | Bin 0 -> 3383 bytes 2 files changed, 63 insertions(+) create mode 100644 image_test.go create mode 100644 testdata/ebiten.png diff --git a/image_test.go b/image_test.go new file mode 100644 index 000000000..1e7cfe835 --- /dev/null +++ b/image_test.go @@ -0,0 +1,63 @@ +/* +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. +*/ + +package ebiten_test + +import ( + . "." + "image" + "image/color" + _ "image/png" + "os" + "testing" +) + +func TestNewImageFromImage(t *testing.T) { + file, err := os.Open("testdata/ebiten.png") + if err != nil { + t.Fatal(err) + return + } + defer file.Close() + + img, _, err := image.Decode(file) + if err != nil { + t.Fatal(err) + return + } + + eimg, err := NewImageFromImage(img, FilterNearest) + if err != nil { + t.Fatal(err) + return + } + + if got := eimg.Bounds().Size(); got != img.Bounds().Size() { + t.Errorf("img size: got %d; want %d", got, img.Bounds().Size()) + } + + for j := 0; j < eimg.Bounds().Size().Y; j++ { + for i := 0; i < eimg.Bounds().Size().X; i++ { + got := eimg.At(i, j) + want := color.RGBAModel.Convert(img.At(i, j)) + if got != want { + t.Errorf("img(%d, %d): got %#v; want %#v", i, j, got, want) + } + } + } +} + +// TODO: Add more tests (e.g. DrawImage with color matrix) diff --git a/testdata/ebiten.png b/testdata/ebiten.png new file mode 100644 index 0000000000000000000000000000000000000000..4ed07b852f4664e0b5850bbb6811eb25b518b409 GIT binary patch literal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