-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathb3dm_test.go
More file actions
74 lines (64 loc) · 1.71 KB
/
b3dm_test.go
File metadata and controls
74 lines (64 loc) · 1.71 KB
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
package tile3d
import (
"bytes"
"os"
"testing"
)
func TestB3dmHeaderSize(t *testing.T) {
h := &B3dmHeader{}
if s := h.CalcSize(); s != 28 {
t.Errorf("B3dmHeader.CalcSize() = %d, want 28", s)
}
}
func TestB3dmNew(t *testing.T) {
m := NewB3dm()
if m == nil {
t.Fatal("NewB3dm() returned nil")
}
if string(m.Header.Magic[:]) != B3DM_MAGIC {
t.Errorf("magic = %s, want %s", m.Header.Magic, B3DM_MAGIC)
}
}
func TestB3dmFeatureTable(t *testing.T) {
m := NewB3dm()
m.SetFeatureTable(B3dmFeatureTableView{BatchLength: 10, RtcCenter: []float64{1, 2, 3}})
view := m.GetFeatureTableView()
if view.BatchLength != 10 {
t.Errorf("BatchLength = %d, want 10", view.BatchLength)
}
if len(view.RtcCenter) != 3 || view.RtcCenter[0] != 1 {
t.Errorf("RtcCenter = %v, want [1 2 3]", view.RtcCenter)
}
}
func TestB3dmReadWriteRoundTrip(t *testing.T) {
f, err := os.Open("./data/batchedWithBatchTableBinary.b3dm")
if err != nil {
t.Skip("test data not available:", err)
}
defer f.Close()
b3d := NewB3dm()
if err := b3d.Read(f); err != nil {
t.Skip("Read failed (expected with external test data):", err)
}
if string(b3d.Header.Magic[:]) != B3DM_MAGIC {
t.Errorf("magic = %s, want %s", b3d.Header.Magic, B3DM_MAGIC)
}
if b3d.Model == nil {
t.Error("Model is nil after reading")
} else {
var buf bytes.Buffer
if err := b3d.Write(&buf); err != nil {
t.Fatal("Write failed:", err)
}
if buf.Len() == 0 {
t.Error("Write produced empty output")
}
}
}
func TestB3dmDecode(t *testing.T) {
header := map[string]interface{}{"BATCH_LENGTH": float64(5)}
result := B3dmFeatureTableDecode(header, nil)
if result["BATCH_LENGTH"] != int32(5) {
t.Errorf("BATCH_LENGTH = %v, want 5", result["BATCH_LENGTH"])
}
}