diff --git a/scte35/state.go b/scte35/state.go index af1818f..8c6dc21 100644 --- a/scte35/state.go +++ b/scte35/state.go @@ -156,8 +156,6 @@ func (s *state) ProcessDescriptor(desc SegmentationDescriptor) ([]SegmentationDe SegDescProgramStartInProgress: s.open = append(s.open, desc) // in signals - // SegDescProgramEnd treated individually since it is expected to normally - // close program resumption AND program start case SegDescProgramEnd: if len(closed) == 0 { err = gots.ErrSCTE35MissingOut diff --git a/scte35/state_test.go b/scte35/state_test.go index 41b36b9..c2aff0c 100644 --- a/scte35/state_test.go +++ b/scte35/state_test.go @@ -125,16 +125,19 @@ var scteDesc10Signal = "/DBFAAAAABeOAP/wBQb+WxdHNQAvAi1DVUVJACSqm3/9ABNP17wMGURJ var scteDesc11Signal = "/DBAAAAAABeOAP/wBQb+bmg4eQAqAihDVUVJACSqm3+9DBlESVNDMjIwNTY1XzAwMl8wMV81NzFBLTA2EQEB/G8f5w==" // 0x20 ChapterStart var scteDesc20Signal = "/DBAAAAAAtaWAAAABQb/d5cVcgAqAihDVUVJ/////3//AALEr24BFGJyYXZvX0VQMDExMzQ0MTkwMTIyIAEA4BXDFw==" +var scteDesc20Signal1= "/DA/AAB6tBn0AP/wBQb/+aPMhwApAh1DVUVJYh5C/n+fAQ5FUDAxMjMxOTU3MDk1MCABZAAIQ1VFSQAAAABYSAjC" // 0x21 ChapterEnd var scteDesc21Signal = "/DBAAAAAAtaWAAAABQb/elu5JQAqAihDVUVJ/////3//AALEr24BFGJyYXZvX0VQMDExMzQ0MTkwMTIyIQEA1Kv4MQ==" // 0x22 BreakStart var scteDesc22Signal = "/DBAAAAAAtaWAAAABQb/elu5JQAqAihDVUVJ/////3//AAEgZ5IBFGJyYXZvX0VQMDExMzQ0MTkwMTIyIgIERTkzgA==" -// 0x23 BreakStart +var scteDesc22Signal1 ="/DAsAAAAAAAAAP/wBQb+Uq7jaQAWAhRDVUVJAAABAH//AAGhbPAAACIAAL5jGRA=" +// 0x23 BreakEnd var scteDesc23Signal = "/DBAAAAAAtaWAAAABQb/e3rvuQAqAihDVUVJ/////3//AAEgZ5IBFGJyYXZvX0VQMDExMzQ0MTkwMTIyIwIEzcrAYA==" // 0x30 ProviderAdStart -var scteDesc30Signal = "/DBIAAAAAtaWAAAABQb/elu5JQAyAjBDVUVJ/////3//AAApJfYPHHVybjpuYmN1bmkuY29tOmJyYzo1MjE1NDkxMTkwAgS9D8Yj" +var scteDesc30Signal = "/DBPAAAAAAAAAP/wBQb/xHJKjwA5AAVTQVBTCwIwQ1VFSf////9//wAAKSd/Dxx1cm46bmJjdW5pLmNvbTpicmM6NTM5NjM4MjY2MAYCNMFiCw==" +var scteDesc30Signal1 = "/DA2AAB6tBn0AP/wBQb//bDBCQAgAhRDVUVJYh5C/n+fAQVDMjQ3MDABAQAIQ1VFSQAAAACc3JW8" // 0x31 ProviderAdEnd -var scteDesc31Signal = "/DBIAAAAAtaWAAAABQb/elu5JQAyAjBDVUVJ/////3//AAApJfYPHHVybjpuYmN1bmkuY29tOmJyYzo1MjE1NDkxMTkwAgS9D8Yj" +var scteDesc31Signal = "/DBPAAAAAAAAAP/wBQb/xJt8QAA5AAVTQVBTCwIwQ1VFSf////9//wAAKSd/Dxx1cm46bmJjdW5pLmNvbTpicmM6NTM5NjM4MjY2MQYCW++KKQ==" // 0x34 ProviderPlacementOpportunityStart var scteDesc34Signal = "/DBfAAAAAAAA///wBQb/iRp43QBJAhxDVUVJ6tzJ0n//AAEhrJQICAAFH4Lq3MnSNAIDAilDVUVJAAAAAH+/DBpWTU5VAWCXNGVv9BHsmxsOQM8vwoUB+olIUQEAAKn6Lds=" // 0x35 ProviderPlacementOpportunityEnd @@ -145,8 +148,9 @@ var scteDesc36Signal ="/DBLAAEs/S0UAP/wBQb+AAAAAAA1AjNDVUVJT///9X//AACky4AJH1NJR var scteDesc40Signal = "/DB7AAFfzZzVAP/wBQb+AAAAAABlAlJDVUVJAABeUX+XDUMJIUJMQUNLT1VUOjI1dU5ZeEl3UXVXclI5WUxDR2I0Y2c9PQ4eY29tY2FzdDpsaW5lYXI6bGljZW5zZXJvdGF0aW9uQAAAAg9DVUVJAABeUX+XAABBAAB1H+6A" // 0x44 ProviderAdBlockStart var scteDesc44Signal = "/DCJAAGqtdGtAP/wBQb/AAAAAQBzAnFDVUVJQAFfVH//AAApMuANXQ8edXJuOmNvbWNhc3Q6YWx0Y29uOmFkZHJlc3NhYmxlDyx1cm46bWVybGluOmxpbmVhcjpzdHJlYW06Mzg0OTU3MzQ4MjgzNzU2NTE2MwkNUE86MTA3MzgzMTc2NEQAAAAA5o/+Nw==" +var scteDesc44Signal1 ="/DCfAAGab0HiAP/wBQb/AAAAAQCJAodDVUVJQAFfVH//AAApMuANcw8edXJuOmNvbWNhc3Q6YWx0Y29uOmFkZHJlc3NhYmxlDyx1cm46bWVybGluOmxpbmVhcjpzdHJlYW06Mzg0OTU3MzQ4MjgzNzU2NTE2MwkNUE86MTA3MzgzMTc2NAkKQlJFQUs6MTIzNAgIAAAAADeUEfJEAQMAAAu+e9A=" // 0x45 ProviderAdBlockEnd -var scteDesc45Signal = "/DCJAAGtnMd/AP/wBQb/AAAAAQBzAnFDVUVJQAFfVH//AAApMuANXQ8edXJuOmNvbWNhc3Q6YWx0Y29uOmFkZHJlc3NhYmxlDyx1cm46bWVybGluOmxpbmVhcjpzdHJlYW06Mzg0OTU3MzQ4MjgzNzU2NTE2MwkNUE86MTA3MzgzMTc2NEQAAAAAAy6WZA==" +var scteDesc45Signal = "/DCEAAGq3wk7AP/wBQb/AAAAAQBuAmxDVUVJQAFfVH+/DV0PHnVybjpjb21jYXN0OmFsdGNvbjphZGRyZXNzYWJsZQ8sdXJuOm1lcmxpbjpsaW5lYXI6c3RyZWFtOjM4NDk1NzM0ODI4Mzc1NjUxNjMJDVBPOjEwNzM4MzE3NjRFAAAAAHbwDu4=" // 0x50 NetworkStart var scteDesc50Signal = "/DBQAAAAAAAAAABwBQb/LrIZ4QA6AhtDVUVJQAAAAH+fCgwUd4vl4/YAAAAAAABQAAACG0NVRUlAAAABf48KDBR3vd4u/wAAAAAAAFEAAF4PZmg=" // 0x51 NetworkEnd @@ -768,6 +772,9 @@ func Test11ClosingLogic(t *testing.T) { t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } closed, err = state.ProcessDescriptor(outSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } if len(closed) != 0 { t.Errorf("No events should have been closed (%d were)", len(closed)) } @@ -802,7 +809,7 @@ func Test11ClosingLogic(t *testing.T) { closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) if err != nil { - t.Errorf("ProcessDescriptor returned an error: %s", err.Error()) + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) } if len(closed) != 3 { t.Errorf("Three events should have been closed (%d were)", len(closed)) @@ -823,6 +830,9 @@ func Test11Closing22(t *testing.T) { } closed, err := state.ProcessDescriptor(outSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } if len(closed) != 0 { t.Errorf("No events should have been closed (%d were)", len(closed)) } @@ -941,4 +951,658 @@ func Test11Closing34_36_40_44(t *testing.T) { if len(state.Open()) != 0 { t.Errorf("There should be no open signal (have %d)", len(state.Open())) } +} + +// Tests closing logic of 0x45 +func Test45ClosingLogic(t *testing.T) { + state := NewState() + + //0x44 + scteDesc44SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc44Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc44SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // 0x45 - closes 0x44 and 0x30 + scteDesc45SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc45Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc45SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 2 { + t.Errorf("2 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be no open signals (have %d)", len(state.Open())) + } +} +// Tests closing logic of 0x44 +func Test44ClosingLogic(t *testing.T) { + state := NewState() + + // 0x44 + scteDesc44SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc44Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc44SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // Different 0x44 - closes the earlier 0x44 and 0x30 + scteDesc44SignalBytes1, _ := base64.StdEncoding.DecodeString(scteDesc44Signal1) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc44SignalBytes1...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 2 { + t.Errorf("2 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { // the last 0x44 sent should still be open + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } +} + +// Tests closing logic of 0x23 +func Test23ClosingLogic_30_34_36_44(t *testing.T) { + state := NewState() + + // 0x34 + scteDesc34SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc34Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc34SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x36 + scteDesc36SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc36Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc36SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // 0x44 + scteDesc44SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc44Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc44SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 3 { + t.Errorf("There should be 3 open signals (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 4 { + t.Errorf("There should be 4 open signals (have %d)", len(state.Open())) + } + + // 0x23 - This should close 0x30, 0x34, 0x36, 0x44 + scteDesc23SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc23Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc23SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 4 { + t.Errorf("4 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be 0 open signals (have %d)", len(state.Open())) + } +} + +func Test23Closing22Logic(t *testing.T){ + state := NewState() + + // 0x22 + scteDesc22SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc22Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc22SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x23 - This should close 0x22 + scteDesc23SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc23Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc23SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("1 event should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be 0 open signals (have %d)", len(state.Open())) + } +} + +func Test22ClosingLogic_30_34_36_44_22(t *testing.T){ + state := NewState() + + // 0x36 + scteDesc36SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc36Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc36SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x34 + scteDesc34SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc34Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc34SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // 0x44 + scteDesc44SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc44Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc44SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 3 { + t.Errorf("There should be 3 open signals (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 4 { + t.Errorf("There should be 4 open signals (have %d)", len(state.Open())) + } + + // 0x22 - should close 0x30, 0x34, 0x36, 0x44 + scteDesc22SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc22Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc22SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 4 { + t.Errorf("4 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // New 0x22 - should close the last 0x22 + scteDesc22SignalBytes1 , _ := base64.StdEncoding.DecodeString(scteDesc22Signal1) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc22SignalBytes1...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("1 event should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } +} + +func Test31ClosingLogic(t *testing.T){ + state := NewState() + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x31 + scteDesc31SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc31Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc31SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be 0 open signals (have %d)", len(state.Open())) + } +} + +func Test30Closing30Logic(t *testing.T){ + state := NewState() + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x30 - new one, will close the old 0x30 + scteDesc30SignalBytes1 , _ := base64.StdEncoding.DecodeString(scteDesc30Signal1) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes1...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("1 event should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } +} + +func Test21ClosingLogic_30_34_36(t *testing.T){ + state := NewState() + + // 0x34 + scteDesc34SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc34Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc34SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x36 + scteDesc36SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc36Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc36SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 3 { + t.Errorf("There should be 3 open signals (have %d)", len(state.Open())) + } + + // 0x21 - This should close 0x30, 0x34, 0x36 + scteDesc21SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc21Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc21SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 3 { + t.Errorf("3 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be 0 open signals (have %d)", len(state.Open())) + } +} + +func Test21Closing20Logic(t *testing.T){ + state := NewState() + + // 0x20 + scteDesc20SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc20Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc20SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x21 - This should close 0x20 + scteDesc21SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc21Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc21SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("1 event should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be 0 open signals (have %d)", len(state.Open())) + } +} + +func Test20ClosingLogic_20_30_34_36(t *testing.T){ + state := NewState() + + // 0x36 + scteDesc36SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc36Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc36SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x34 + scteDesc34SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc34Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc34SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 3 { + t.Errorf("There should be 3 open signals (have %d)", len(state.Open())) + } + + // 0x20 - should close 0x30, 0x34, 0x36 + scteDesc20SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc20Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc20SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 3 { + t.Errorf("3 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // New 0x20 - should close the last 0x20 + scteDesc20SignalBytes1 , _ := base64.StdEncoding.DecodeString(scteDesc20Signal1) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc20SignalBytes1...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("1 event should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } } \ No newline at end of file