-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_test.go
More file actions
334 lines (272 loc) · 10 KB
/
stack_test.go
File metadata and controls
334 lines (272 loc) · 10 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project
package gotio
import (
"encoding/json"
"testing"
"github.com/Avalanche-io/gotio/opentime"
)
func TestStackCompositionKind(t *testing.T) {
stack := NewStack("test", nil, nil, nil, nil, nil)
if stack.CompositionKind() != "Stack" {
t.Errorf("CompositionKind = %s, want Stack", stack.CompositionKind())
}
}
func TestStackRangeOfChildAtIndex(t *testing.T) {
stack := NewStack("test", nil, nil, nil, nil, nil)
sr1 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(24, 24))
sr2 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(48, 24))
clip1 := NewClip("clip1", nil, &sr1, nil, nil, nil, "", nil)
clip2 := NewClip("clip2", nil, &sr2, nil, nil, nil, "", nil)
stack.AppendChild(clip1)
stack.AppendChild(clip2)
// In a stack, all children start at time 0
r1, err := stack.RangeOfChildAtIndex(0)
if err != nil {
t.Fatalf("RangeOfChildAtIndex(0) error: %v", err)
}
if r1.StartTime().Value() != 0 {
t.Errorf("Child 0 start time = %v, want 0", r1.StartTime().Value())
}
if r1.Duration().Value() != 24 {
t.Errorf("Child 0 duration = %v, want 24", r1.Duration().Value())
}
r2, err := stack.RangeOfChildAtIndex(1)
if err != nil {
t.Fatalf("RangeOfChildAtIndex(1) error: %v", err)
}
if r2.StartTime().Value() != 0 {
t.Errorf("Child 1 start time = %v, want 0", r2.StartTime().Value())
}
if r2.Duration().Value() != 48 {
t.Errorf("Child 1 duration = %v, want 48", r2.Duration().Value())
}
// Test invalid index
_, err = stack.RangeOfChildAtIndex(-1)
if err == nil {
t.Error("RangeOfChildAtIndex(-1) should error")
}
_, err = stack.RangeOfChildAtIndex(10)
if err == nil {
t.Error("RangeOfChildAtIndex(10) should error")
}
}
func TestStackAvailableRange(t *testing.T) {
stack := NewStack("test", nil, nil, nil, nil, nil)
// Empty stack
ar, err := stack.AvailableRange()
if err != nil {
t.Fatalf("AvailableRange error: %v", err)
}
if ar.Duration().Rate() != 0 {
t.Errorf("Empty stack should have zero duration")
}
// Add children with different durations
sr1 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(24, 24))
sr2 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(72, 24))
clip1 := NewClip("clip1", nil, &sr1, nil, nil, nil, "", nil)
clip2 := NewClip("clip2", nil, &sr2, nil, nil, nil, "", nil)
stack.AppendChild(clip1)
stack.AppendChild(clip2)
// Stack duration is the max of all children
ar, err = stack.AvailableRange()
if err != nil {
t.Fatalf("AvailableRange error: %v", err)
}
if ar.Duration().Value() != 72 {
t.Errorf("AvailableRange duration = %v, want 72", ar.Duration().Value())
}
}
func TestStackDuration(t *testing.T) {
stack := NewStack("test", nil, nil, nil, nil, nil)
sr1 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(48, 24))
sr2 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(96, 24))
clip1 := NewClip("clip1", nil, &sr1, nil, nil, nil, "", nil)
clip2 := NewClip("clip2", nil, &sr2, nil, nil, nil, "", nil)
stack.AppendChild(clip1)
stack.AppendChild(clip2)
dur, err := stack.Duration()
if err != nil {
t.Fatalf("Duration error: %v", err)
}
// Duration is max duration (96 frames = 4 seconds)
if dur.ToSeconds() != 4.0 {
t.Errorf("Duration = %v seconds, want 4.0", dur.ToSeconds())
}
// Test with source range
srStack := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(24, 24))
stack2 := NewStack("test2", &srStack, nil, nil, nil, nil)
stack2.AppendChild(clip1)
stack2.AppendChild(clip2)
dur, err = stack2.Duration()
if err != nil {
t.Fatalf("Duration error: %v", err)
}
// Source range overrides computed duration
if dur.Value() != 24 {
t.Errorf("Duration with source range = %v, want 24", dur.Value())
}
}
func TestStackChildAtTime(t *testing.T) {
stack := NewStack("test", nil, nil, nil, nil, nil)
sr1 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(24, 24))
sr2 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(48, 24))
clip1 := NewClip("clip1", nil, &sr1, nil, nil, nil, "", nil)
clip2 := NewClip("clip2", nil, &sr2, nil, nil, nil, "", nil)
stack.AppendChild(clip1)
stack.AppendChild(clip2)
// At time 0, both clips exist, should return topmost (clip2)
child, err := stack.ChildAtTime(opentime.NewRationalTime(0, 24), true)
if err != nil {
t.Fatalf("ChildAtTime error: %v", err)
}
if child.(*Clip).Name() != "clip2" {
t.Errorf("ChildAtTime(0) = %s, want clip2", child.(*Clip).Name())
}
// At time 30 frames (1.25 seconds), only clip2 exists
child, err = stack.ChildAtTime(opentime.NewRationalTime(30, 24), true)
if err != nil {
t.Fatalf("ChildAtTime error: %v", err)
}
if child.(*Clip).Name() != "clip2" {
t.Errorf("ChildAtTime(30) = %s, want clip2", child.(*Clip).Name())
}
// Outside range
child, err = stack.ChildAtTime(opentime.NewRationalTime(100, 24), true)
if err != nil {
t.Fatalf("ChildAtTime error: %v", err)
}
if child != nil {
t.Error("ChildAtTime outside range should return nil")
}
}
func TestStackChildrenInRange(t *testing.T) {
stack := NewStack("test", nil, nil, nil, nil, nil)
sr1 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(24, 24))
sr2 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(48, 24))
clip1 := NewClip("clip1", nil, &sr1, nil, nil, nil, "", nil)
clip2 := NewClip("clip2", nil, &sr2, nil, nil, nil, "", nil)
stack.AppendChild(clip1)
stack.AppendChild(clip2)
// Range 0-12 frames - both clips overlap
searchRange := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(12, 24))
children, err := stack.ChildrenInRange(searchRange)
if err != nil {
t.Fatalf("ChildrenInRange error: %v", err)
}
if len(children) != 2 {
t.Errorf("ChildrenInRange(0-12) = %d children, want 2", len(children))
}
// Range 24-48 frames - only clip2
searchRange = opentime.NewTimeRange(opentime.NewRationalTime(24, 24), opentime.NewRationalTime(24, 24))
children, err = stack.ChildrenInRange(searchRange)
if err != nil {
t.Fatalf("ChildrenInRange error: %v", err)
}
if len(children) != 1 {
t.Errorf("ChildrenInRange(24-48) = %d children, want 1", len(children))
}
}
func TestStackRangeOfAllChildren(t *testing.T) {
stack := NewStack("test", nil, nil, nil, nil, nil)
sr1 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(24, 24))
sr2 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(48, 24))
clip1 := NewClip("clip1", nil, &sr1, nil, nil, nil, "", nil)
clip2 := NewClip("clip2", nil, &sr2, nil, nil, nil, "", nil)
stack.AppendChild(clip1)
stack.AppendChild(clip2)
ranges, err := stack.RangeOfAllChildren()
if err != nil {
t.Fatalf("RangeOfAllChildren error: %v", err)
}
if len(ranges) != 2 {
t.Errorf("RangeOfAllChildren = %d entries, want 2", len(ranges))
}
// All children should start at 0
for _, r := range ranges {
if r.StartTime().Value() != 0 {
t.Errorf("Child start time = %v, want 0", r.StartTime().Value())
}
}
}
func TestStackClone(t *testing.T) {
stack := NewStack("test", nil, AnyDictionary{"key": "value"}, nil, nil, nil)
sr := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(24, 24))
clip := NewClip("clip", nil, &sr, nil, nil, nil, "", nil)
stack.AppendChild(clip)
clone := stack.Clone().(*Stack)
if clone.Name() != "test" {
t.Errorf("Clone name = %s, want test", clone.Name())
}
if len(clone.Children()) != 1 {
t.Errorf("Clone children count = %d, want 1", len(clone.Children()))
}
// Verify deep copy
clone.SetName("modified")
if stack.Name() == "modified" {
t.Error("Modifying clone affected original")
}
}
func TestStackIsEquivalentTo(t *testing.T) {
s1 := NewStack("test", nil, nil, nil, nil, nil)
s2 := NewStack("test", nil, nil, nil, nil, nil)
s3 := NewStack("different", nil, nil, nil, nil, nil)
if !s1.IsEquivalentTo(s2) {
t.Error("Identical stacks should be equivalent")
}
if s1.IsEquivalentTo(s3) {
t.Error("Different stacks should not be equivalent")
}
// Test with different children count
sr := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(24, 24))
clip := NewClip("clip", nil, &sr, nil, nil, nil, "", nil)
s1.AppendChild(clip)
if s1.IsEquivalentTo(s2) {
t.Error("Stacks with different children should not be equivalent")
}
// Test with non-Stack
track := NewTrack("track", nil, TrackKindVideo, nil, nil)
if s1.IsEquivalentTo(track) {
t.Error("Stack should not be equivalent to Track")
}
}
func TestStackJSON(t *testing.T) {
stack := NewStack("test_stack", nil, AnyDictionary{"note": "test"}, nil, nil, nil)
sr := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(48, 24))
clip := NewClip("clip", nil, &sr, nil, nil, nil, "", nil)
stack.AppendChild(clip)
data, err := json.Marshal(stack)
if err != nil {
t.Fatalf("Marshal error: %v", err)
}
stack2 := &Stack{}
if err := json.Unmarshal(data, stack2); err != nil {
t.Fatalf("Unmarshal error: %v", err)
}
if stack2.Name() != "test_stack" {
t.Errorf("Name mismatch: got %s", stack2.Name())
}
if len(stack2.Children()) != 1 {
t.Errorf("Children count mismatch: got %d", len(stack2.Children()))
}
}
func TestStackAvailableImageBounds(t *testing.T) {
stack := NewStack("test", nil, nil, nil, nil, nil)
// Test with empty stack
bounds, err := stack.AvailableImageBounds()
if err != nil {
t.Fatalf("AvailableImageBounds error: %v", err)
}
if bounds != nil {
t.Error("Empty stack should have nil bounds")
}
// Add a clip without image bounds
sr := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(24, 24))
clip := NewClip("clip", nil, &sr, nil, nil, nil, "", nil)
stack.AppendChild(clip)
bounds, err = stack.AvailableImageBounds()
if err != nil {
t.Fatalf("AvailableImageBounds error: %v", err)
}
// Clip without media reference has no bounds
}