Rename examples/util to test/util

This commit is contained in:
harukasan 2015-01-09 14:27:06 +09:00
parent ab5b4615ca
commit 3b802598e8
5 changed files with 5 additions and 5 deletions

View file

@ -1,7 +1,7 @@
package main
import (
"github.com/harukasan/go-libwebp/examples/util"
"github.com/harukasan/go-libwebp/test/util"
"github.com/harukasan/go-libwebp/webp"
)

View file

@ -4,7 +4,7 @@ import (
"bufio"
"image"
"github.com/harukasan/go-libwebp/examples/util"
"github.com/harukasan/go-libwebp/test/util"
"github.com/harukasan/go-libwebp/webp"
)

View file

@ -1,80 +0,0 @@
// Package util contains utility code for demosntration of go-libwebp.
package util
import (
"bufio"
"image"
"image/png"
"io"
"io/ioutil"
"os"
"path/filepath"
)
// GetExFilePath returns the path of specified example file.
func GetExFilePath(name string) string {
return filepath.Join(os.Getenv("GOPATH"), "src/github.com/harukasan/go-libwebp/examples/images", name)
}
// GetOutFilePath returns the path of specified out file.
func GetOutFilePath(name string) string {
return filepath.Join(os.Getenv("GOPATH"), "src/github.com/harukasan/go-libwebp/examples/out", name)
}
// OpenFile opens specified example file
func OpenFile(name string) (io io.Reader) {
io, err := os.Open(GetExFilePath(name))
if err != nil {
panic(err)
}
return
}
// ReadFile reads and returns data bytes of specified example file.
func ReadFile(name string) (data []byte) {
data, err := ioutil.ReadFile(GetExFilePath(name))
if err != nil {
panic(err)
}
return
}
// CreateFile opens specified example file
func CreateFile(name string) (f *os.File) {
f, err := os.Create(GetOutFilePath(name))
if err != nil {
panic(err)
}
return
}
// WritePNG encodes and writes image into PNG file.
func WritePNG(img image.Image, name string) {
f, err := os.Create(GetOutFilePath(name))
if err != nil {
panic(err)
}
b := bufio.NewWriter(f)
defer func() {
b.Flush()
f.Close()
}()
if err := png.Encode(b, img); err != nil {
panic(err)
}
return
}
// ReadPNG reads and decodes png data into image.Image
func ReadPNG(name string) (img image.Image) {
io, err := os.Open(GetExFilePath(name))
if err != nil {
panic(err)
}
img, err = png.Decode(io)
if err != nil {
panic(err)
}
return
}

View file

@ -1,54 +0,0 @@
package util_test
import (
"testing"
"github.com/harukasan/go-libwebp/examples/util"
)
var PNGFiles = []string{
"butterfly.png",
"cosmos.png",
"fizyplankton.png",
"kinkaku.png",
"yellow-rose-3.png",
}
var WebPFiles = []string{
"butterfly.webp",
"cosmos.webp",
"fizyplankton.webp",
"kinkaku.webp",
"yellow-rose-3.webp",
}
func TestOpenFile(t *testing.T) {
for _, file := range PNGFiles {
util.OpenFile(file)
}
for _, file := range WebPFiles {
util.OpenFile(file)
}
}
func TestReadFile(t *testing.T) {
for _, file := range PNGFiles {
util.ReadFile(file)
}
for _, file := range WebPFiles {
util.ReadFile(file)
}
}
func TestCreateFile(t *testing.T) {
f := util.CreateFile("util_test")
f.Write([]byte{'o', 'k'})
f.Close()
}
func TestReadWritePNG(t *testing.T) {
for _, file := range PNGFiles {
png := util.ReadPNG(file)
util.WritePNG(png, "util_test_"+file)
}
}