-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbatch_table_test.go
More file actions
83 lines (77 loc) · 2.07 KB
/
batch_table_test.go
File metadata and controls
83 lines (77 loc) · 2.07 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
75
76
77
78
79
80
81
82
83
package tile3d
import (
"bytes"
"strings"
"testing"
)
func TestBatchTableReadJSON(t *testing.T) {
bt := &BatchTable{}
jsonStr := `{"names": {"byteOffset": 0, "componentType": "UNSIGNED_BYTE", "type": "SCALAR"}}`
reader := strings.NewReader(jsonStr)
err := bt.readJSONHeader(reader)
if err != nil {
t.Fatal("readJSONHeader failed:", err)
}
if bt.Header["names"] == nil {
t.Error("names should not be nil")
}
ref, ok := bt.Header["names"].(BinaryBodyReference)
if !ok {
t.Fatal("names should be BinaryBodyReference")
}
if ref.ComponentType != "UNSIGNED_BYTE" {
t.Errorf("ComponentType = %s, want UNSIGNED_BYTE", ref.ComponentType)
}
}
func TestBatchTableWriteJSON(t *testing.T) {
bt := &BatchTable{Header: map[string]interface{}{"test": "value"}}
var buf bytes.Buffer
err := bt.writeJSONHeader(&buf)
if err != nil {
t.Fatal("writeJSONHeader failed:", err)
}
if buf.Len() == 0 {
t.Error("writeJSONHeader produced empty output")
}
}
func TestBatchTableCalcSize(t *testing.T) {
bt := &BatchTable{Header: map[string]interface{}{"test": float64(1)}}
h := &B3dmHeader{}
size := bt.CalcSize(h)
if size <= 0 {
t.Errorf("CalcSize() = %d, want > 0", size)
}
}
func TestBatchTableGetProperty(t *testing.T) {
bt := &BatchTable{Data: map[string]interface{}{
"name": []uint8{1, 2, 3},
"id": []uint32{100, 200},
}}
if bt.GetProperty("name", 0) == nil {
t.Error("GetProperty('name', 0) should not be nil")
}
if bt.GetProperty("nonexistent", 0) != nil {
t.Error("GetProperty('nonexistent', 0) should be nil")
}
}
func TestTransformBinaryBodyReference(t *testing.T) {
m := map[string]interface{}{
"prop": map[string]interface{}{
"byteOffset": float64(16),
"componentType": "FLOAT",
"type": "VEC3",
},
"scalar": float64(42),
}
result := transformBinaryBodyReference(m)
ref, ok := result["prop"].(BinaryBodyReference)
if !ok {
t.Fatal("prop should be BinaryBodyReference")
}
if ref.ByteOffset != 16 {
t.Errorf("ByteOffset = %d, want 16", ref.ByteOffset)
}
if result["scalar"] != float64(42) {
t.Error("scalar should be preserved")
}
}