github.com/puellanivis/breton@v0.2.16/lib/mpeg/ts/dvb/descriptor_test.go (about) 1 package dvb 2 3 import ( 4 "reflect" 5 "testing" 6 7 desc "github.com/puellanivis/breton/lib/mpeg/ts/descriptor" 8 ) 9 10 var testServiceDescriptor = []byte{ 11 0x48, // descriptor_tag(service_descriptor_tag) 12 18, // descriptor_length 13 0x01, // service_type(DVB-TV) 14 15 6, 'F', 'F', 'm', 'p', 'e', 'g', // service_provider_name 16 9, 'S', 'e', 'r', 'v', 'i', 'c', 'e', '0', '1', // service_name 17 } 18 19 func TestServiceDescriptor(t *testing.T) { 20 const ( 21 provider = "FFmpeg" 22 name = "Service01" 23 ) 24 25 b := testServiceDescriptor 26 27 d, err := desc.Unmarshal(b) 28 if err != nil { 29 t.Fatalf("Unmarshal: %+v", err) 30 } 31 32 service, ok := d.(*ServiceDescriptor) 33 if !ok { 34 t.Fatalf("wrong type, expected *ServiceDescriptor, got %T", d) 35 } 36 37 if service.Type != ServiceTypeTV { 38 t.Errorf("wrong service type, expected x%02X got x%02X", uint8(ServiceTypeTV), uint8(service.Type)) 39 } 40 41 if service.Provider != provider { 42 t.Errorf("wrong provider name, expected %q got %q", provider, service.Provider) 43 } 44 45 if service.Name != name { 46 t.Errorf("wrong name name, expected %q got %q", name, service.Name) 47 } 48 49 b, err = service.Marshal() 50 if err != nil { 51 t.Fatalf("Marshal: %+v", err) 52 } 53 54 if !reflect.DeepEqual(b, testServiceDescriptor) { 55 t.Errorf("Marshal: unexpected results\nexpected: [% 2X]\ngot: [% 2X]", testServiceDescriptor, b) 56 } 57 }