aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/llgcode/draw2d/draw2dpdf/test_test.go
blob: 801ff36315b8b95db3b1209ad00ce93fa5b39665 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2015 The draw2d Authors. All rights reserved.
// created: 26/06/2015 by Stani Michiels

// Package draw2dpdf_test gives test coverage with the command:
// go test -cover ./... | grep -v "no test"
// (It should be run from its parent draw2d directory.)
package draw2dpdf_test

import (
	"testing"

	"github.com/llgcode/draw2d"
	"github.com/llgcode/draw2d/draw2dpdf"
)

type sample func(gc draw2d.GraphicContext, ext string) (string, error)

func test(t *testing.T, draw sample) {
	// Initialize the graphic context on an pdf document
	dest := draw2dpdf.NewPdf("L", "mm", "A4")
	gc := draw2dpdf.NewGraphicContext(dest)
	// Draw sample
	output, err := draw(gc, "pdf")
	if err != nil {
		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(output); err == nil {
			t.Skipf("Saving %q skipped, as it exists already. (Git would consider it modified.)", output)
			return
		}
	*/
	err = draw2dpdf.SaveToPdfFile(output, dest)
	if err != nil {
		t.Errorf("Saving %q failed: %v", output, err)
	}
}