From 71c1aba4fe34ce97fc9ea7523d747f3a590016bc Mon Sep 17 00:00:00 2001 From: Stani Date: Wed, 1 Jul 2015 10:34:23 +0200 Subject: [PATCH] separate out test function and refactor line sample --- pdf2d/samples_test.go | 26 +++++++------------------- pdf2d/test_test.go | 28 ++++++++++++++++++++++++++++ samples_test.go | 28 +++++++--------------------- test_test.go | 27 +++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 40 deletions(-) create mode 100644 pdf2d/test_test.go create mode 100644 test_test.go diff --git a/pdf2d/samples_test.go b/pdf2d/samples_test.go index 9772ef6..302c78e 100644 --- a/pdf2d/samples_test.go +++ b/pdf2d/samples_test.go @@ -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) +} diff --git a/pdf2d/test_test.go b/pdf2d/test_test.go new file mode 100644 index 0000000..609cd35 --- /dev/null +++ b/pdf2d/test_test.go @@ -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) + } +} diff --git a/samples_test.go b/samples_test.go index cf8bf78..ae68c14 100644 --- a/samples_test.go +++ b/samples_test.go @@ -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) +} diff --git a/test_test.go b/test_test.go new file mode 100644 index 0000000..8d6d674 --- /dev/null +++ b/test_test.go @@ -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) + } +}