2015-07-06 22:25:24 +00:00
|
|
|
// Package draw2dpdf_test gives test coverage with the command:
|
2015-07-01 08:34:23 +00:00
|
|
|
// go test -cover ./... | grep -v "no test"
|
|
|
|
// (It should be run from its parent draw2d directory.)
|
2015-07-06 22:25:24 +00:00
|
|
|
package draw2dpdf_test
|
2015-07-01 08:34:23 +00:00
|
|
|
|
|
|
|
import (
|
2015-07-01 12:44:01 +00:00
|
|
|
"os"
|
2015-07-01 08:34:23 +00:00
|
|
|
"testing"
|
|
|
|
|
2015-07-06 22:07:44 +00:00
|
|
|
"github.com/llgcode/draw2d"
|
2015-07-06 22:25:24 +00:00
|
|
|
"github.com/llgcode/draw2d/draw2dpdf"
|
2015-07-01 08:34:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func test(t *testing.T, sample draw2d.Sample) {
|
|
|
|
// Initialize the graphic context on an pdf document
|
2015-07-06 22:25:24 +00:00
|
|
|
dest := draw2dpdf.NewPdf("L", "mm", "A4")
|
|
|
|
gc := draw2dpdf.NewGraphicContext(dest)
|
2015-07-01 18:27:41 +00:00
|
|
|
// Draw sample
|
2015-07-01 08:34:23 +00:00
|
|
|
fn, err := sample(gc, "pdf")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Drawing %q failed: %v", fn, err)
|
|
|
|
return
|
|
|
|
}
|
2015-07-01 12:44:01 +00:00
|
|
|
// 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)
|
|
|
|
return
|
|
|
|
}
|
2015-07-06 22:25:24 +00:00
|
|
|
err = draw2dpdf.SaveToPdfFile(fn, dest)
|
2015-07-01 08:34:23 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Saving %q failed: %v", fn, err)
|
|
|
|
}
|
|
|
|
}
|