-
Notifications
You must be signed in to change notification settings - Fork 4
/
acroform_test.go
118 lines (107 loc) · 2.35 KB
/
acroform_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package model
import (
"reflect"
"testing"
)
func TestCloneAcro(t *testing.T) {
a := AcroForm{
Fields: []*FormFieldDict{
{
FormFieldInheritable: FormFieldInheritable{FT: FormFieldText{}},
Widgets: []FormFieldWidget{{}},
},
},
NeedAppearances: true,
DR: ResourcesDict{ColorSpace: map[ColorSpaceName]ColorSpace{"eee": nil}},
}
cache := newCloneCache()
a2 := a.clone(cache)
if !reflect.DeepEqual(a, a2) {
t.Errorf("expected %v, got %v", a, a2)
}
}
func TestCloneForm(t *testing.T) {
a := &FormFieldDict{
FormFieldInheritable: FormFieldInheritable{FT: FormFieldText{}},
Widgets: []FormFieldWidget{
{
AnnotationDict: &AnnotationDict{
BaseAnnotation: BaseAnnotation{
Contents: "sldml",
Border: &Border{DashArray: []Fl{4, 5, 6, 8}},
},
Subtype: AnnotationWidget{
BS: &BorderStyle{
S: "sd24",
},
},
},
},
},
AA: FormFielAdditionalActions{
K: Action{ActionType: ActionJavaScript{JS: "sdlmsmd"}},
},
}
cache := newCloneCache()
a2 := a.clone(cache)
if !reflect.DeepEqual(a, a2) {
t.Errorf("expected %v, got %v", a, a2)
}
}
func TestResolve(t *testing.T) {
a1 := FormFieldDict{
T: "a1",
FormFieldInheritable: FormFieldInheritable{FT: FormFieldText{}},
}
a2 := a1
a2.T = "5"
a3 := a1
a3.T = ""
b := &FormFieldDict{
T: "first",
Kids: []*FormFieldDict{&a1, &a2, &a3},
FormFieldInheritable: FormFieldInheritable{
DA: "564",
},
}
a1.Parent = b
a2.Parent = b
a3.Parent = b
ac := AcroForm{
Fields: []*FormFieldDict{b},
}
m := ac.Flatten()
if L := len(m); L != 4 {
t.Errorf("expected 3 fields, got %d", L)
}
for _, f := range m {
if f.Merged.DA != "564" {
t.Error()
}
}
_, ok := m["first.2"]
if !ok {
t.Error()
}
}
func TestAppearanceKeys(t *testing.T) {
var f FormFieldDict
f.FT = FormFieldButton{}
f.Widgets = []FormFieldWidget{
{&AnnotationDict{BaseAnnotation: BaseAnnotation{AP: &AppearanceDict{N: AppearanceEntry{
"Yes": &XObjectForm{},
"Off": &XObjectForm{},
}}}}},
{&AnnotationDict{BaseAnnotation: BaseAnnotation{AP: &AppearanceDict{N: AppearanceEntry{
"Yes": &XObjectForm{},
"No": &XObjectForm{},
}}}}},
}
if !reflect.DeepEqual(f.AppearanceKeys(), []Name{"No", "Off", "Yes"}) {
t.Error()
}
f.Widgets = nil
if len(f.AppearanceKeys()) != 0 {
t.Error()
}
}