separate out test function and refactor line sample

This commit is contained in:
Stani 2015-07-01 10:34:23 +02:00
parent 0144ae516b
commit 71c1aba4fe
4 changed files with 69 additions and 40 deletions

View File

@ -1,35 +1,19 @@
// See also test_test.go
package pdf2d_test
import (
"testing"
"github.com/stanim/draw2d"
"github.com/stanim/draw2d/pdf2d"
"github.com/stanim/draw2d.samples"
"github.com/stanim/draw2d.samples/android"
"github.com/stanim/draw2d.samples/frameimage"
"github.com/stanim/draw2d.samples/gopher"
"github.com/stanim/draw2d.samples/helloworld"
"github.com/stanim/draw2d.samples/line"
)
func test(t *testing.T, sample draw2d.Sample) {
// Initialize the graphic context on an RGBA image
dest := pdf2d.NewPdf("L", "mm", "A4")
gc := pdf2d.NewGraphicContext(dest)
// Draw Android logo
fn, err := sample(gc, "pdf")
if err != nil {
t.Errorf("Drawing %q failed: %v", fn, err)
return
}
// Save to png
err = pdf2d.SaveToPdfFile(fn, dest)
if err != nil {
t.Errorf("Saving %q failed: %v", fn, err)
}
}
func TestSampleAndroid(t *testing.T) {
test(t, android.Main)
}
@ -49,3 +33,7 @@ func TestSampleHelloWorld(t *testing.T) {
func TestSampleFrameImage(t *testing.T) {
test(t, frameimage.Main)
}
func TestSampleLine(t *testing.T) {
test(t, line.Main)
}

28
pdf2d/test_test.go Normal file
View File

@ -0,0 +1,28 @@
// Package pdf2d_test gives test coverage with the command:
// go test -cover ./... | grep -v "no test"
// (It should be run from its parent draw2d directory.)
package pdf2d_test
import (
"testing"
"github.com/stanim/draw2d"
"github.com/stanim/draw2d/pdf2d"
)
func test(t *testing.T, sample draw2d.Sample) {
// Initialize the graphic context on an pdf document
dest := pdf2d.NewPdf("L", "mm", "A4")
gc := pdf2d.NewGraphicContext(dest)
// Draw Android logo
fn, err := sample(gc, "pdf")
if err != nil {
t.Errorf("Drawing %q failed: %v", fn, err)
return
}
// Save to png
err = pdf2d.SaveToPdfFile(fn, dest)
if err != nil {
t.Errorf("Saving %q failed: %v", fn, err)
}
}

View File

@ -1,37 +1,19 @@
// Package draw2d_test gives test coverage with the command:
// go test -cover ./... | grep -v "no test"
// See also test_test.go
package draw2d_test
import (
"image"
"testing"
"github.com/stanim/draw2d"
"github.com/stanim/draw2d.samples"
"github.com/stanim/draw2d.samples/android"
"github.com/stanim/draw2d.samples/frameimage"
"github.com/stanim/draw2d.samples/gopher"
"github.com/stanim/draw2d.samples/helloworld"
"github.com/stanim/draw2d.samples/line"
)
func test(t *testing.T, draw draw2d.Sample) {
// Initialize the graphic context on an RGBA image
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
gc := draw2d.NewGraphicContext(dest)
// Draw Android logo
fn, err := draw(gc, "png")
if err != nil {
t.Errorf("Drawing %q failed: %v", fn, err)
return
}
// Save to png
err = draw2d.SaveToPngFile(fn, dest)
if err != nil {
t.Errorf("Saving %q failed: %v", fn, err)
}
}
func TestSampleAndroid(t *testing.T) {
test(t, android.Main)
}
@ -49,3 +31,7 @@ func TestSampleHelloWorld(t *testing.T) {
func TestSampleFrameImage(t *testing.T) {
test(t, frameimage.Main)
}
func TestSampleLine(t *testing.T) {
test(t, line.Main)
}

27
test_test.go Normal file
View File

@ -0,0 +1,27 @@
// Package draw2d_test gives test coverage with the command:
// go test -cover ./... | grep -v "no test"
package draw2d_test
import (
"image"
"testing"
"github.com/stanim/draw2d"
)
func test(t *testing.T, draw draw2d.Sample) {
// Initialize the graphic context on an RGBA image
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
gc := draw2d.NewGraphicContext(dest)
// Draw Android logo
fn, err := draw(gc, "png")
if err != nil {
t.Errorf("Drawing %q failed: %v", fn, err)
return
}
// Save to png
err = draw2d.SaveToPngFile(fn, dest)
if err != nil {
t.Errorf("Saving %q failed: %v", fn, err)
}
}