forked from qmuntal/gltf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidator_test.go
130 lines (127 loc) · 8.01 KB
/
validator_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
package gltf
import (
"testing"
val "github.com/go-playground/validator"
)
func TestValidateDocument(t *testing.T) {
tests := []struct {
name string
doc *Document
wantErr bool
}{
{"Document.Asset.Version", new(Document), true},
{"Document.Accessors[0].ComponentType", &Document{Asset: Asset{Version: "1.0"},
Accessors: []Accessor{{ComponentType: 1, Count: 1, Type: "SCALAR"}}}, true},
{"Document.Accessors[0].Count", &Document{Asset: Asset{Version: "1.0"},
Accessors: []Accessor{{ComponentType: Byte, Count: 0, Type: "SCALAR"}}}, true},
{"Document.Accessors[0].Type", &Document{Asset: Asset{Version: "1.0"},
Accessors: []Accessor{{ComponentType: Byte, Count: 1, Type: "OTHER"}}}, true},
{"Document.Accessors[0].Max", &Document{Asset: Asset{Version: "1.0"},
Accessors: []Accessor{{ComponentType: Byte, Count: 1, Type: "SCALAR", Max: make([]float64, 17)}}}, true},
{"Document.Accessors[0].Min", &Document{Asset: Asset{Version: "1.0"},
Accessors: []Accessor{{ComponentType: Byte, Count: 1, Type: "SCALAR", Min: make([]float64, 17)}}}, true},
{"Document.Accessors[0].Sparse.Count", &Document{Asset: Asset{Version: "1.0"},
Accessors: []Accessor{{ComponentType: Byte, Count: 1, Type: "SCALAR",
Sparse: &Sparse{Count: 0}}}}, true},
{"Document.Accessors[0].Sparse.Indices.ComponentType", &Document{Asset: Asset{Version: "1.0"},
Accessors: []Accessor{{ComponentType: Byte, Count: 1, Type: "SCALAR",
Sparse: &Sparse{Count: 1, Indices: SparseIndices{ComponentType: 1}}}}}, true},
{"Document.Buffers[0].URI", &Document{Asset: Asset{Version: "1.0"},
Buffers: []Buffer{{ByteLength: 1, URI: "a.bin"}}}, false},
{"Document.Buffers[0].ByteLength", &Document{Asset: Asset{Version: "1.0"},
Buffers: []Buffer{{ByteLength: 0, URI: "http://web.com"}}}, true},
{"Document.BufferViews[0].ByteLength", &Document{Asset: Asset{Version: "1.0"},
BufferViews: []BufferView{{ByteLength: 0}}}, true},
{"Document.BufferViews[0].ByteStride", &Document{Asset: Asset{Version: "1.0"},
BufferViews: []BufferView{{ByteLength: 1, ByteStride: 3}}}, true},
{"Document.BufferViews[0].ByteStride", &Document{Asset: Asset{Version: "1.0"},
BufferViews: []BufferView{{ByteLength: 1, ByteStride: 253}}}, true},
{"Document.BufferViews[0].Target", &Document{Asset: Asset{Version: "1.0"},
BufferViews: []BufferView{{ByteLength: 1, ByteStride: 4, Target: 2}}}, true},
{"Document.Scenes[0].Nodes", &Document{Asset: Asset{Version: "1.0"},
Scenes: []Scene{{Nodes: []uint32{1, 1}}}}, true},
{"Document.Nodes[0].Children", &Document{Asset: Asset{Version: "1.0"},
Nodes: []Node{{Children: []uint32{1, 1}}}}, true},
{"Document.Nodes[0].Rotation[0]", &Document{Asset: Asset{Version: "1.0"},
Nodes: []Node{{Rotation: [4]float64{2, 1, 1, 1}}}}, true},
{"Document.Nodes[0].Rotation[1]", &Document{Asset: Asset{Version: "1.0"},
Nodes: []Node{{Rotation: [4]float64{1, -2, 1, 1}}}}, true},
{"Document.Skins[0].Joints", &Document{Asset: Asset{Version: "1.0"},
Skins: []Skin{{Joints: []uint32{1, 1}}}}, true},
{"Document.Cameras[0].Type", &Document{Asset: Asset{Version: "1.0"},
Cameras: []Camera{{Type: "incorrect"}}}, true},
{"Document.Cameras[0].Orthographic.Znear", &Document{Asset: Asset{Version: "1.0"},
Cameras: []Camera{{Type: OrthographicType, Orthographic: &Orthographic{Znear: -1, Zfar: 1}}}}, true},
{"Document.Cameras[0].Orthographic.Zfar", &Document{Asset: Asset{Version: "1.0"},
Cameras: []Camera{{Type: OrthographicType, Orthographic: &Orthographic{Znear: 1, Zfar: 1}}}}, true},
{"Document.Meshes[0].Primitives", &Document{Asset: Asset{Version: "1.0"},
Meshes: []Mesh{{Primitives: make([]Primitive, 0)}}}, true},
{"Document.Meshes[0].Primitives[0].Mode", &Document{Asset: Asset{Version: "1.0"},
Meshes: []Mesh{{Primitives: []Primitive{{Mode: 7}}}}}, true},
{"Document.Meshes[0].Primitives[0].Targets[0][OTHER]", &Document{Asset: Asset{Version: "1.0"},
Meshes: []Mesh{{Primitives: []Primitive{{Targets: []Attribute{{"OTHER": 1}}}}}}}, true},
{"Document.Materials[0].EmissiveFactor[0]", &Document{Asset: Asset{Version: "1.0"},
Materials: []Material{{EmissiveFactor: [3]float64{-1, 1, 1}}}}, true},
{"Document.Materials[0].EmissiveFactor[1]", &Document{Asset: Asset{Version: "1.0"},
Materials: []Material{{AlphaMode: Opaque, EmissiveFactor: [3]float64{1, 2, 1}}}}, true},
{"Document.Materials[0].AlphaMode", &Document{Asset: Asset{Version: "1.0"},
Materials: []Material{{AlphaMode: "OTHER"}}}, true},
{"Document.Materials[0].PBRMetallicRoughness.BaseColorFactor[0]", &Document{Asset: Asset{Version: "1.0"},
Materials: []Material{{AlphaMode: Opaque,
PBRMetallicRoughness: &PBRMetallicRoughness{BaseColorFactor: [4]float64{-1, 0, 0, 0}}}}}, true},
{"Document.Materials[0].PBRMetallicRoughness.BaseColorFactor[1]", &Document{Asset: Asset{Version: "1.0"},
Materials: []Material{{AlphaMode: Opaque,
PBRMetallicRoughness: &PBRMetallicRoughness{BaseColorFactor: [4]float64{1, 2, 0, 0}}}}}, true},
{"Document.Materials[0].PBRMetallicRoughness.MetallicFactor", &Document{Asset: Asset{Version: "1.0"},
Materials: []Material{{AlphaMode: Opaque,
PBRMetallicRoughness: &PBRMetallicRoughness{MetallicFactor: 2}}}}, true},
{"Document.Materials[0].PBRMetallicRoughness.MetallicFactor", &Document{Asset: Asset{Version: "1.0"},
Materials: []Material{{AlphaMode: Opaque,
PBRMetallicRoughness: &PBRMetallicRoughness{MetallicFactor: -1}}}}, true},
{"Document.Materials[0].PBRMetallicRoughness.RoughnessFactor", &Document{Asset: Asset{Version: "1.0"},
Materials: []Material{{AlphaMode: Opaque,
PBRMetallicRoughness: &PBRMetallicRoughness{RoughnessFactor: 2}}}}, true},
{"Document.Materials[0].PBRMetallicRoughness.RoughnessFactor", &Document{Asset: Asset{Version: "1.0"},
Materials: []Material{{AlphaMode: Opaque,
PBRMetallicRoughness: &PBRMetallicRoughness{RoughnessFactor: -1}}}}, true},
{"Document.Samplers[0].MagFilter", &Document{Asset: Asset{Version: "1.0"},
Samplers: []Sampler{{MagFilter: 1, MinFilter: MinLinear, WrapS: ClampToEdge, WrapT: ClampToEdge}}}, true},
{"Document.Samplers[0].MinFilter", &Document{Asset: Asset{Version: "1.0"},
Samplers: []Sampler{{MagFilter: MagLinear, MinFilter: 1, WrapS: ClampToEdge, WrapT: ClampToEdge}}}, true},
{"Document.Samplers[0].WrapS", &Document{Asset: Asset{Version: "1.0"},
Samplers: []Sampler{{MagFilter: MagLinear, MinFilter: MinLinear, WrapS: 1, WrapT: ClampToEdge}}}, true},
{"Document.Samplers[0].WrapT", &Document{Asset: Asset{Version: "1.0"},
Samplers: []Sampler{{MagFilter: MagLinear, MinFilter: MinLinear, WrapS: ClampToEdge, WrapT: 1}}}, true},
{"Document.Images[0].URI", &Document{Asset: Asset{Version: "1.0"},
Images: []Image{{URI: "a.png"}}}, false},
{"Document.Images[0].MimeType", &Document{Asset: Asset{Version: "1.0"},
Images: []Image{{BufferView: 1}}}, true},
{"Document.Animations[0].Channels", &Document{Asset: Asset{Version: "1.0"},
Animations: []Animation{{Samplers: []AnimationSampler{{}}}}}, true},
{"Document.Animations[0].Channels[0].Target.Path", &Document{Asset: Asset{Version: "1.0"},
Animations: []Animation{{Channels: []Channel{{Target: ChannelTarget{Path: "other"}}}, Samplers: []AnimationSampler{{}}}}}, true},
{"Document.Animations[0].Samplers[0].Interpolation", &Document{Asset: Asset{Version: "1.0"},
Animations: []Animation{{Channels: []Channel{{Target: ChannelTarget{Path: "translation"}}},
Samplers: []AnimationSampler{{Interpolation: "OTHER"}}}}}, true},
{"ok", &Document{
ExtensionsUsed: []string{"one", "another"},
ExtensionsRequired: []string{"that", "this"},
Asset: Asset{Copyright: "glTF", Generator: "qmuntal", Version: "1.0", MinVersion: "0.5"},
}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.doc.Validate()
if (err != nil) != tt.wantErr {
t.Errorf("Document.Validate() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.wantErr {
errVal := err.(val.ValidationErrors)[0].Namespace()
if errVal != tt.name {
t.Errorf("Document.Validate() error = %v, wantErr %v", errVal, tt.name)
}
}
})
}
}