forked from ixmilia/dxf-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader_test.go
160 lines (144 loc) · 4.75 KB
/
header_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
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
157
158
159
160
package dxf
import (
"fmt"
"testing"
)
func TestReadNonDefaultHeaderVersion(t *testing.T) {
header := parseHeader(t,
NewStringCodePair(9, "$UNSUPPORTED_HEADER_VARIABLE"),
NewStringCodePair(1, "UNSUPPORTED_VALUE"),
NewStringCodePair(9, "$ACADVER"),
NewStringCodePair(1, "AC1014"),
NewStringCodePair(9, "$ACADMAINTVER"),
NewShortCodePair(70, 6),
NewStringCodePair(9, "$UNSUPPORTED_HEADER_VARIABLE"),
NewStringCodePair(1, "UNSUPPORTED_VALUE"),
)
assertEqInt(t, int(R14), int(header.Version))
assertEqInt(t, 6, int(header.MaintenanceVersion))
}
func TestWriteVersionSpecificVariables(t *testing.T) {
header := *NewHeader()
// value is present >= R14
header.Version = R14
assertContainsCodePairs(t, []CodePair{
NewStringCodePair(9, "$ACADMAINTVER"),
}, fileCodePairsFromHeader(t, header))
// value is missing < R14
header.Version = R13
assertNotContainsCodePairs(t, []CodePair{
NewStringCodePair(9, "$ACADMAINTVER"),
}, fileCodePairsFromHeader(t, header))
}
func TestReadHeaderFlag(t *testing.T) {
header := parseHeader(t,
NewStringCodePair(9, "$OSMODE"),
NewShortCodePair(70, 1),
)
assert(t, header.EndPointSnap(), "expected OSMODE.EndPointSnap")
assert(t, !header.MidPointSnap(), "expected !OSMODE.MidPointSnap")
assert(t, !header.CenterSnap(), "expected !OSMODE.CenterSnap")
assert(t, !header.NodeSnap(), "expected !OSMODE.NodeSnap")
assert(t, !header.QuadrantSnap(), "expected !OSMODE.QuadrantSnap")
assert(t, !header.IntersectionSnap(), "expected !OSMODE.IntersectionSnap")
assert(t, !header.InsertionSnap(), "expected !OSMODE.InsertionSnap")
assert(t, !header.PerpendicularSnap(), "expected !OSMODE.PerpendicularSnap")
assert(t, !header.TangentSnap(), "expected !OSMODE.TangentSnap")
assert(t, !header.NearestSnap(), "expected !OSMODE.NearestSnap")
assert(t, !header.ApparentIntersectionSnap(), "expected !OSMODE.ApparentIntersectionSnap")
assert(t, !header.ExtensionSnap(), "expected !OSMODE.ExtensionSnap")
assert(t, !header.ParallelSnap(), "expected !OSMODE.ParallelSnap")
}
func TestWriteHeaderFlag(t *testing.T) {
header := *NewHeader()
header.SetEndPointSnap(true)
header.SetMidPointSnap(false)
header.SetCenterSnap(false)
header.SetNodeSnap(false)
header.SetQuadrantSnap(false)
header.SetIntersectionSnap(false)
header.SetInsertionSnap(false)
header.SetPerpendicularSnap(false)
header.SetTangentSnap(false)
header.SetNearestSnap(false)
header.SetApparentIntersectionSnap(false)
header.SetExtensionSnap(false)
header.SetParallelSnap(false)
assertContainsCodePairs(t, []CodePair{
NewStringCodePair(9, "$OSMODE"),
NewShortCodePair(70, 1),
}, fileCodePairsFromHeader(t, header))
}
func TestReadPoint(t *testing.T) {
header := parseHeader(t,
NewStringCodePair(9, "$INSBASE"),
NewDoubleCodePair(10, 1.0),
NewDoubleCodePair(20, 2.0),
NewDoubleCodePair(30, 3.0),
)
expected := Point{1.0, 2.0, 3.0}
assert(t, header.InsertionBase == expected, fmt.Sprintf("expected %s, got %s", expected.String(), header.InsertionBase.String()))
}
func TestWritePoint(t *testing.T) {
header := *NewHeader()
header.InsertionBase = Point{1.0, 2.0, 3.0}
assertContainsCodePairs(t, []CodePair{
NewStringCodePair(9, "$INSBASE"),
NewDoubleCodePair(10, 1.0),
NewDoubleCodePair(20, 2.0),
NewDoubleCodePair(30, 3.0),
}, fileCodePairsFromHeader(t, header))
}
func TestReadEnumValue(t *testing.T) {
header := parseHeader(t,
NewStringCodePair(9, "$DRAGMODE"),
NewShortCodePair(70, 2),
)
assertEqShort(t, int16(2), int16(header.DragMode))
}
func TestWriteEnumValue(t *testing.T) {
header := *NewHeader()
header.DragMode = DragModeAuto
assertContainsCodePairs(t, []CodePair{
NewStringCodePair(9, "$DRAGMODE"),
NewShortCodePair(70, 2),
}, fileCodePairsFromHeader(t, header))
}
func TestReadHandleValue(t *testing.T) {
header := parseHeader(t,
NewStringCodePair(9, "$DRAGVS"),
NewStringCodePair(349, "FF"),
)
assertEqUInt64(t, uint64(255), uint64(header.SolidVisualStylePointer))
}
func TestWriteHandleValue(t *testing.T) {
header := *NewHeader()
header.Version = R2007 // min version R2007
header.SolidVisualStylePointer = Handle(255)
assertContainsCodePairs(t, []CodePair{
NewStringCodePair(9, "$DRAGVS"),
NewStringCodePair(349, "FF"),
}, fileCodePairsFromHeader(t, header))
}
func parseHeader(t *testing.T, codePairs ...CodePair) Header {
allPairs := []CodePair{
NewStringCodePair(0, "SECTION"),
NewStringCodePair(2, "HEADER"),
}
allPairs = append(allPairs, codePairs...)
allPairs = append(allPairs,
NewStringCodePair(0, "ENDSEC"),
NewStringCodePair(0, "EOF"),
)
drawing := parseFromCodePairs(t, allPairs...)
return drawing.Header
}
func fileCodePairsFromHeader(t *testing.T, h Header) []CodePair {
drawing := *NewDrawing()
drawing.Header = h
codePairs, err := drawing.CodePairs()
if err != nil {
t.Error(err)
}
return codePairs
}