...

Package testutils

Overview ▾

Package testutils provides test methods that are not intended to be exported.

Variables

Errors.

var (
    ErrRenderNotSupported = errors.New("rendering PDF files is not supported on this system")
)

func CompareDictionariesDeep

func CompareDictionariesDeep(d1, d2 *core.PdfObjectDictionary) bool

CompareDictionariesDeep does a deep comparison of `d1` and `d2` and returns true if equal.

func CompareImages

func CompareImages(img1, img2 image.Image) (bool, error)

CompareImages compares the specified images at pixel level.

func ComparePNGFiles

func ComparePNGFiles(file1, file2 string) (bool, error)

ComparePNGFiles compares the specified PNG files.

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies the `src` file to `dst`.

func HashFile

func HashFile(file string) (string, error)

HashFile generates an MD5 hash from the contents of the specified file.

func ParseIndirectObjects

func ParseIndirectObjects(rawpdf string) (map[int64]core.PdfObject, error)

ParseIndirectObjects parses a sequence of indirect/stream objects sequentially from a `rawpdf` text. Great for testing.

func ReadPNG

func ReadPNG(file string) (image.Image, error)

ReadPNG reads and returns the specified PNG file.

func RenderPDFToPNGs

func RenderPDFToPNGs(pdfPath string, dpi int, outpathTpl string) error

RenderPDFToPNGs uses ghostscript (gs) to render the specified PDF file into a set of PNG images (one per page). PNG images will be named xxx-N.png where N is the number of page, starting from 1.

func RunRenderTest

func RunRenderTest(t *testing.T, pdfPath, outputDir, baselineRenderPath string, saveBaseline bool)

RunRenderTest renders the PDF file specified by `pdfPath` to the `outputDir` and compares the output PNG files to the golden files found at the `baselineRenderPath` location. If the specified PDF file is new (there are no golden files) and the `saveBaseline` parameter is set to true, the output render files are saved to the `baselineRenderPath`.