forked from klippa-app/go-pdfium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpdf_ppo.go
156 lines (132 loc) · 4.8 KB
/
fpdf_ppo.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package shared_tests
import (
"io/ioutil"
"github.com/michalderdak/go-pdfium/references"
"github.com/michalderdak/go-pdfium/requests"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("fpdf_ppo", func() {
BeforeEach(func() {
Locker.Lock()
})
AfterEach(func() {
Locker.Unlock()
})
Context("no document", func() {
When("is opened", func() {
It("returns an error when calling FPDF_ImportPages", func() {
FPDF_ImportPages, err := PdfiumInstance.FPDF_ImportPages(&requests.FPDF_ImportPages{})
Expect(err).To(MatchError("document not given"))
Expect(FPDF_ImportPages).To(BeNil())
})
It("returns an error when calling FPDF_CopyViewerPreferences", func() {
FPDF_CopyViewerPreferences, err := PdfiumInstance.FPDF_CopyViewerPreferences(&requests.FPDF_CopyViewerPreferences{})
Expect(err).To(MatchError("document not given"))
Expect(FPDF_CopyViewerPreferences).To(BeNil())
})
})
})
Context("a normal PDF file", func() {
var doc references.FPDF_DOCUMENT
BeforeEach(func() {
pdfData, err := ioutil.ReadFile(TestDataPath + "/testdata/test.pdf")
Expect(err).To(BeNil())
newDoc, err := PdfiumInstance.FPDF_LoadMemDocument(&requests.FPDF_LoadMemDocument{
Data: &pdfData,
})
Expect(err).To(BeNil())
doc = newDoc.Document
})
AfterEach(func() {
FPDF_CloseDocument, err := PdfiumInstance.FPDF_CloseDocument(&requests.FPDF_CloseDocument{
Document: doc,
})
Expect(err).To(BeNil())
Expect(FPDF_CloseDocument).To(Not(BeNil()))
})
When("is opened", func() {
When("no destination document is given", func() {
It("returns an error when calling FPDF_ImportPages", func() {
FPDF_ImportPages, err := PdfiumInstance.FPDF_ImportPages(&requests.FPDF_ImportPages{
Source: doc,
})
Expect(err).To(MatchError("document not given"))
Expect(FPDF_ImportPages).To(BeNil())
})
It("returns an error when calling FPDF_CopyViewerPreferences", func() {
FPDF_CopyViewerPreferences, err := PdfiumInstance.FPDF_CopyViewerPreferences(&requests.FPDF_CopyViewerPreferences{
Source: doc,
})
Expect(err).To(MatchError("document not given"))
Expect(FPDF_CopyViewerPreferences).To(BeNil())
})
})
Context("a second PDF file is opened", func() {
var doc2 references.FPDF_DOCUMENT
BeforeEach(func() {
pdfData, err := ioutil.ReadFile(TestDataPath + "/testdata/viewer_ref.pdf")
Expect(err).To(BeNil())
newDoc, err := PdfiumInstance.FPDF_LoadMemDocument(&requests.FPDF_LoadMemDocument{
Data: &pdfData,
})
Expect(err).To(BeNil())
doc2 = newDoc.Document
})
AfterEach(func() {
FPDF_CloseDocument, err := PdfiumInstance.FPDF_CloseDocument(&requests.FPDF_CloseDocument{
Document: doc2,
})
Expect(err).To(BeNil())
Expect(FPDF_CloseDocument).To(Not(BeNil()))
})
When("is opened", func() {
It("returns no error when FPDF_ImportPages is called", func() {
FPDF_ImportPages, err := PdfiumInstance.FPDF_ImportPages(&requests.FPDF_ImportPages{
Source: doc2,
Destination: doc,
})
Expect(err).To(BeNil())
Expect(FPDF_ImportPages).To(Not(BeNil()))
})
It("returns no error when FPDF_ImportPages is called with a valid pagerange", func() {
pageRange := "1"
FPDF_ImportPages, err := PdfiumInstance.FPDF_ImportPages(&requests.FPDF_ImportPages{
Source: doc2,
Destination: doc,
PageRange: &pageRange,
})
Expect(err).To(BeNil())
Expect(FPDF_ImportPages).To(Not(BeNil()))
})
It("returns no error when FPDF_ImportPages is called with an invalid pagerange", func() {
pageRange := "32"
FPDF_ImportPages, err := PdfiumInstance.FPDF_ImportPages(&requests.FPDF_ImportPages{
Source: doc2,
Destination: doc,
PageRange: &pageRange,
})
Expect(err).To(MatchError("import of pages failed"))
Expect(FPDF_ImportPages).To(BeNil())
})
It("returns an error when calling FPDF_CopyViewerPreferences with a source document that has no viewer preferences", func() {
FPDF_CopyViewerPreferences, err := PdfiumInstance.FPDF_CopyViewerPreferences(&requests.FPDF_CopyViewerPreferences{
Source: doc,
Destination: doc2,
})
Expect(err).To(MatchError("copy of viewer preferences failed"))
Expect(FPDF_CopyViewerPreferences).To(BeNil())
})
It("returns no error when calling FPDF_CopyViewerPreferences with a source document that has viewer preferences", func() {
FPDF_CopyViewerPreferences, err := PdfiumInstance.FPDF_CopyViewerPreferences(&requests.FPDF_CopyViewerPreferences{
Source: doc2,
Destination: doc,
})
Expect(err).To(BeNil())
Expect(FPDF_CopyViewerPreferences).To(Not(BeNil()))
})
})
})
})
})
})