summaryrefslogtreecommitdiff
path: root/contrib/gofpdi/gofpdi_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gofpdi/gofpdi_test.go')
-rw-r--r--contrib/gofpdi/gofpdi_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/contrib/gofpdi/gofpdi_test.go b/contrib/gofpdi/gofpdi_test.go
index 1ecc5ca..77db338 100644
--- a/contrib/gofpdi/gofpdi_test.go
+++ b/contrib/gofpdi/gofpdi_test.go
@@ -5,6 +5,8 @@ import (
"github.com/jung-kurt/gofpdf"
"github.com/jung-kurt/gofpdf/internal/example"
"io"
+ "sync"
+ "testing"
)
func ExampleGofpdiImporter() {
@@ -39,6 +41,29 @@ func ExampleGofpdiImporter() {
// Successfully generated ../../pdf/contrib_gofpdi_Importer.pdf
}
+func TestGofpdiConcurrent(t *testing.T) {
+ wg := sync.WaitGroup{}
+ for i := 0; i < 100; i++ {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ pdf := gofpdf.New("P", "mm", "A4", "")
+ rs, _ := getTemplatePdf()
+ imp := NewImporter()
+ tpl := imp.ImportPageFromStream(pdf, &rs, 1, "/MediaBox")
+ pdf.AddPage()
+ tpl = imp.ImportPageFromStream(pdf, &rs, 1, "/MediaBox")
+ imp.UseImportedTemplate(pdf, tpl, 0, 0, 210.0, 297.0)
+ // write to bytes buffer
+ buf := bytes.Buffer{}
+ if err := pdf.Output(&buf); err != nil {
+ t.Fail()
+ }
+ }()
+ }
+ wg.Wait()
+}
+
func getTemplatePdf() (io.ReadSeeker, error) {
tpdf := gofpdf.New("P", "pt", "A4", "")
tpdf.AddPage()