forked from cucy/unipdf1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_test.go
98 lines (77 loc) · 2.19 KB
/
file_test.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
/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.md', which is part of this source code package.
*/
package model
import (
"github.com/stretchr/testify/require"
"github.com/unidoc/unipdf/v3/core"
"strings"
"testing"
)
func TestUrlFileSpec(t *testing.T) {
rawText := `
1 0 obj
<</Type /Filespec
/FS /URL
/F (ftp://www.beatles.com/Movies/AbbeyRoad.mov)
>>
endobj
`
r := NewReaderForText(rawText)
err := r.ParseIndObjSeries()
require.NoError(t, err)
// Load the field from object number 1.
obj, err := r.parser.LookupByNumber(1)
require.NoError(t, err)
ind, ok := obj.(*core.PdfIndirectObject)
require.True(t, ok)
fileSpec, err := NewPdfFilespecFromObj(ind)
require.NoError(t, err)
require.Equal(t, "URL", fileSpec.FS.String())
require.Equal(t, "ftp://www.beatles.com/Movies/AbbeyRoad.mov", fileSpec.F.String())
outDict, ok := core.GetDict(fileSpec.ToPdfObject())
if !ok {
t.Fatalf("error")
}
contains := strings.Contains(
strings.Replace(rawText, "\n", "", -1),
outDict.WriteString())
require.True(t, contains, "generated output doesn't match the expected output")
}
func TestPdfFileSpec(t *testing.T) {
rawText := `
1 0 obj
<</Type /Filespec
/F (VideoIssue1.mov)
/UF (VideoIssue2.mov)
/DOS (VIDEOISSUE.MOV)
/Mac (VideoIssue3.mov)
/Unix (VideoIssue4.mov)
>>
endobj
`
r := NewReaderForText(rawText)
err := r.ParseIndObjSeries()
require.NoError(t, err)
// Load the field from object number 1.
obj, err := r.parser.LookupByNumber(1)
require.NoError(t, err)
ind, ok := obj.(*core.PdfIndirectObject)
require.True(t, ok)
fileSpec, err := NewPdfFilespecFromObj(ind)
require.NoError(t, err)
require.Equal(t, "VideoIssue1.mov", fileSpec.F.String())
require.Equal(t, "VideoIssue2.mov", fileSpec.UF.String())
require.Equal(t, "VIDEOISSUE.MOV", fileSpec.DOS.String())
require.Equal(t, "VideoIssue3.mov", fileSpec.Mac.String())
require.Equal(t, "VideoIssue4.mov", fileSpec.Unix.String())
outDict, ok := core.GetDict(fileSpec.ToPdfObject())
if !ok {
t.Fatalf("error")
}
contains := strings.Contains(
strings.Replace(rawText, "\n", "", -1),
outDict.WriteString())
require.True(t, contains, "generated output doesn't match the expected output")
}