test: add test to cover /Names in catalog
This commit is contained in:

committed by
Paul van Brouwershaven

parent
5a0cd0a9b9
commit
c34fd5f0cc
@@ -7,56 +7,64 @@ import (
|
|||||||
"github.com/digitorus/pdf"
|
"github.com/digitorus/pdf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var test_files = []struct {
|
||||||
|
file string
|
||||||
|
expected_catalog string
|
||||||
|
}{
|
||||||
|
{"../testfiles/testfile20.pdf", "11 0 obj\n<< /Type /Catalog /Version /2.0 /Pages 3 0 R /AcroForm << /Fields [10 0 R] /NeedAppearances false /SigFlags 1 >> /Perms << /UR3 0 0 R >> >>\nendobj\n"},
|
||||||
|
{"../testfiles/testfile21.pdf", "17 0 obj\n<< /Type /Catalog /Version /1.0 /Names 6 0 R /Pages 9 0 R /AcroForm << /Fields [16 0 R] /NeedAppearances false /SigFlags 1 >> /Perms << /UR3 0 0 R >> >>\nendobj\n"},
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateCatalog(t *testing.T) {
|
func TestCreateCatalog(t *testing.T) {
|
||||||
input_file, err := os.Open("../testfiles/testfile20.pdf")
|
for _, test_file := range test_files {
|
||||||
if err != nil {
|
input_file, err := os.Open(test_file.file)
|
||||||
t.Errorf("Failed to load test PDF")
|
if err != nil {
|
||||||
return
|
t.Errorf("Failed to load test PDF")
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
finfo, err := input_file.Stat()
|
finfo, err := input_file.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to load test PDF")
|
t.Errorf("Failed to load test PDF")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
size := finfo.Size()
|
size := finfo.Size()
|
||||||
|
|
||||||
rdr, err := pdf.NewReader(input_file, size)
|
rdr, err := pdf.NewReader(input_file, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to load test PDF")
|
t.Errorf("Failed to load test PDF")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
context := SignContext{
|
context := SignContext{
|
||||||
Filesize: size + 1,
|
Filesize: size + 1,
|
||||||
PDFReader: rdr,
|
PDFReader: rdr,
|
||||||
InputFile: input_file,
|
InputFile: input_file,
|
||||||
VisualSignData: VisualSignData{
|
VisualSignData: VisualSignData{
|
||||||
ObjectId: uint32(rdr.XrefInformation.ItemCount),
|
ObjectId: uint32(rdr.XrefInformation.ItemCount),
|
||||||
},
|
|
||||||
CatalogData: CatalogData{
|
|
||||||
ObjectId: uint32(rdr.XrefInformation.ItemCount) + 1,
|
|
||||||
},
|
|
||||||
InfoData: InfoData{
|
|
||||||
ObjectId: uint32(rdr.XrefInformation.ItemCount) + 2,
|
|
||||||
},
|
|
||||||
SignData: SignData{
|
|
||||||
Signature: SignDataSignature{
|
|
||||||
CertType: UsageRightsSignature,
|
|
||||||
DocMDPPerm: AllowFillingExistingFormFieldsAndSignaturesPerms,
|
|
||||||
},
|
},
|
||||||
},
|
CatalogData: CatalogData{
|
||||||
}
|
ObjectId: uint32(rdr.XrefInformation.ItemCount) + 1,
|
||||||
|
},
|
||||||
|
InfoData: InfoData{
|
||||||
|
ObjectId: uint32(rdr.XrefInformation.ItemCount) + 2,
|
||||||
|
},
|
||||||
|
SignData: SignData{
|
||||||
|
Signature: SignDataSignature{
|
||||||
|
CertType: UsageRightsSignature,
|
||||||
|
DocMDPPerm: AllowFillingExistingFormFieldsAndSignaturesPerms,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
catalog, err := context.createCatalog()
|
catalog, err := context.createCatalog()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s", err.Error())
|
t.Errorf("%s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_catalog := "11 0 obj\n<< /Type /Catalog /Version /2.0 /Pages 3 0 R /AcroForm << /Fields [10 0 R] /NeedAppearances false /SigFlags 1 >> /Perms << /UR3 0 0 R >> >>\nendobj\n"
|
if catalog != test_file.expected_catalog {
|
||||||
|
t.Errorf("Catalog mismatch, expected %s, but got %s", test_file.expected_catalog, catalog)
|
||||||
if catalog != expected_catalog {
|
}
|
||||||
t.Errorf("Catalog mismatch, expected %s, but got %s", expected_catalog, catalog)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
testfiles/testfile21.pdf
Normal file
BIN
testfiles/testfile21.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user