prepare testing for including samples

This commit is contained in:
Stani 2015-07-10 02:07:18 +02:00
parent f5ef2c0154
commit 10796a3100
4 changed files with 34 additions and 35 deletions

View file

@ -6,14 +6,13 @@ import (
"testing"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d.samples"
"github.com/llgcode/draw2d.samples/android"
"github.com/llgcode/draw2d.samples/frameimage"
"github.com/llgcode/draw2d.samples/gopher"
"github.com/llgcode/draw2d.samples/helloworld"
"github.com/llgcode/draw2d.samples/line"
"github.com/llgcode/draw2d.samples/linecapjoin"
"github.com/llgcode/draw2d.samples/postscript"
"github.com/llgcode/draw2d/samples/android"
"github.com/llgcode/draw2d/samples/frameimage"
"github.com/llgcode/draw2d/samples/gopher"
"github.com/llgcode/draw2d/samples/helloworld"
"github.com/llgcode/draw2d/samples/line"
"github.com/llgcode/draw2d/samples/linecapjoin"
"github.com/llgcode/draw2d/samples/postscript"
)
func TestSampleAndroid(t *testing.T) {
@ -26,9 +25,9 @@ func TestSampleGopher(t *testing.T) {
func TestSampleHelloWorld(t *testing.T) {
// Set the global folder for searching fonts
// The pdf backend needs for every ttf file its corresponding json
// file which is generated by gofpdf/makefont.
draw2d.SetFontFolder(samples.Dir("helloworld", "../"))
// The pdf backend needs for every ttf file its corresponding
// json/.z file which is generated by gofpdf/makefont.
draw2d.SetFontFolder("../resource/font")
test(t, helloworld.Main)
}

View file

@ -4,7 +4,6 @@
package draw2dpdf_test
import (
"os"
"testing"
"github.com/llgcode/draw2d"
@ -18,18 +17,20 @@ func test(t *testing.T, draw sample) {
dest := draw2dpdf.NewPdf("L", "mm", "A4")
gc := draw2dpdf.NewGraphicContext(dest)
// Draw sample
fn, err := draw(gc, "pdf")
output, err := draw(gc, "pdf")
if err != nil {
t.Errorf("Drawing %q failed: %v", fn, err)
t.Errorf("Drawing %q failed: %v", output, err)
return
}
/*
// Save to pdf only if it doesn't exist because of git
if _, err = os.Stat(fn); err == nil {
t.Skipf("Saving %q skipped, as it exists already. (Git would consider it modified.)", fn)
if _, err = os.Stat(output); err == nil {
t.Skipf("Saving %q skipped, as it exists already. (Git would consider it modified.)", output)
return
}
err = draw2dpdf.SaveToPdfFile(fn, dest)
*/
err = draw2dpdf.SaveToPdfFile(output, dest)
if err != nil {
t.Errorf("Saving %q failed: %v", fn, err)
t.Errorf("Saving %q failed: %v", output, err)
}
}

View file

@ -6,14 +6,13 @@ import (
"testing"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d.samples"
"github.com/llgcode/draw2d.samples/android"
"github.com/llgcode/draw2d.samples/frameimage"
"github.com/llgcode/draw2d.samples/gopher"
"github.com/llgcode/draw2d.samples/helloworld"
"github.com/llgcode/draw2d.samples/line"
"github.com/llgcode/draw2d.samples/linecapjoin"
"github.com/llgcode/draw2d.samples/postscript"
"github.com/llgcode/draw2d/samples/android"
"github.com/llgcode/draw2d/samples/frameimage"
"github.com/llgcode/draw2d/samples/gopher"
"github.com/llgcode/draw2d/samples/helloworld"
"github.com/llgcode/draw2d/samples/line"
"github.com/llgcode/draw2d/samples/linecapjoin"
"github.com/llgcode/draw2d/samples/postscript"
)
func TestSampleAndroid(t *testing.T) {
@ -26,7 +25,7 @@ func TestSampleGopher(t *testing.T) {
func TestSampleHelloWorld(t *testing.T) {
// Set the global folder for searching fonts
draw2d.SetFontFolder(samples.Dir("helloworld", ""))
draw2d.SetFontFolder("resource/font")
test(t, helloworld.Main)
}
@ -38,7 +37,7 @@ func TestSampleLine(t *testing.T) {
test(t, line.Main)
}
func TestSampleLineCap(t *testing.T) {
func TestSampleLineCapJoin(t *testing.T) {
test(t, linecapjoin.Main)
}

View file

@ -16,14 +16,14 @@ func test(t *testing.T, draw sample) {
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
gc := draw2d.NewGraphicContext(dest)
// Draw Android logo
fn, err := draw(gc, "png")
output, err := draw(gc, "png")
if err != nil {
t.Errorf("Drawing %q failed: %v", fn, err)
t.Errorf("Drawing %q failed: %v", output, err)
return
}
// Save to png
err = draw2d.SaveToPngFile(fn, dest)
err = draw2d.SaveToPngFile(output, dest)
if err != nil {
t.Errorf("Saving %q failed: %v", fn, err)
t.Errorf("Saving %q failed: %v", output, err)
}
}