Add testfiles folder, add reader test

This commit is contained in:
Jeroen Bobbeldijk
2017-09-17 13:26:39 +02:00
parent e8dd57bc2a
commit bf2aa2ea02
3 changed files with 88 additions and 0 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
.idea
testfiles/*.pdf

87
sign/sign_test.go Normal file
View File

@@ -0,0 +1,87 @@
package sign
import (
"testing"
"io/ioutil"
"fmt"
"os"
"path/filepath"
"bitbucket.org/digitorus/pdf"
)
func TestReaderCanReadPDF(t *testing.T) {
files, err := ioutil.ReadDir("../testfiles")
if err != nil {
t.Errorf("%s", err.Error())
return
}
for _, f := range files {
ext := filepath.Ext(f.Name())
if ext != ".pdf" {
fmt.Printf("Skipping file %s", f.Name())
continue
}
input_file, err := os.Open("../testfiles/" + f.Name())
if err != nil {
t.Errorf("%s: %s", f.Name(), err.Error())
return
}
finfo, err := input_file.Stat()
if err != nil {
input_file.Close()
t.Errorf("%s: %s", f.Name(), err.Error())
return
}
size := finfo.Size()
_, err = pdf.NewReader(input_file, size)
if err != nil {
input_file.Close()
t.Errorf("%s: %s", f.Name(), err.Error())
return
}
}
}
func TestSignPDF(t *testing.T) {
files, err := ioutil.ReadDir("../testfiles")
if err != nil {
t.Errorf("%s", err.Error())
return
}
for _, f := range files {
ext := filepath.Ext(f.Name())
if ext != ".pdf" {
fmt.Printf("Skipping file %s", f.Name())
continue
}
input_file, err := os.Open("../testfiles/" + f.Name())
if err != nil {
t.Errorf("%s: %s", f.Name(), err.Error())
return
}
finfo, err := input_file.Stat()
if err != nil {
input_file.Close()
t.Errorf("%s: %s", f.Name(), err.Error())
return
}
size := finfo.Size()
_, err = pdf.NewReader(input_file, size)
if err != nil {
input_file.Close()
t.Errorf("%s: %s", f.Name(), err.Error())
return
}
// @todo: implement signer.
}
}

0
testfiles/.gitkeep Normal file
View File