github.com/puellanivis/breton@v0.2.16/lib/mpeg/ts/dvb/table_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  	"github.com/puellanivis/breton/lib/mpeg/ts/psi"
     9  )
    10  
    11  var testSDT = []byte{
    12  	0x00,     // pointer_value
    13  	0x42,     // table_id
    14  	0xF0, 37, // section_syntax_indicator | private | section_length_bits
    15  	0x00, 0x01, // transport_stream_id
    16  	0xC1,       // reserved | version_number | current_indicator
    17  	0x00, 0x00, // section_number, last_section_number
    18  	0xff, 0x01, // original_network_id
    19  	0xff, // reserved
    20  
    21  	0x00, 0x01, // service_id = x0001
    22  	0xFC,     // reserved_future_use
    23  	0x80, 20, // running_status(0x4), descriptors_loop_length & 0xFF
    24  	0x48, // descriptor_tag(service_descriptor_tag)
    25  	18,   // descriptor_length
    26  	0x01, // service_type(DVB-TV)
    27  
    28  	6, 'F', 'F', 'm', 'p', 'e', 'g', // service_provider_name
    29  	9, 'S', 'e', 'r', 'v', 'i', 'c', 'e', '0', '1', // service_name
    30  
    31  	0xde, 0xad, 0xbe, 0xef, // fake CRC32
    32  }
    33  
    34  func TestSDT(t *testing.T) {
    35  	b := testSDT
    36  
    37  	p, err := psi.Unmarshal(b)
    38  	if err != nil {
    39  		t.Fatalf("Unmarshal: %+v", err)
    40  	}
    41  
    42  	sdt, ok := p.(*ServiceDescriptorTable)
    43  	if !ok {
    44  		t.Fatalf("wrong type, expected *ServiceDescriptorTable, got %T", p)
    45  	}
    46  
    47  	expected := &ServiceDescriptorTable{
    48  		Syntax: &psi.SectionSyntax{
    49  			TableIDExtension: 1,
    50  			Current:          true,
    51  		},
    52  		OriginalNetworkID: 0xff01,
    53  		Services: []*Service{
    54  			&Service{
    55  				ID:            1,
    56  				RunningStatus: Running,
    57  				Descriptors: []desc.Descriptor{
    58  					&ServiceDescriptor{
    59  						Type:     ServiceTypeTV,
    60  						Provider: "FFmpeg",
    61  						Name:     "Service01",
    62  					},
    63  				},
    64  			},
    65  		},
    66  		crc: 0xdeadbeef,
    67  	}
    68  
    69  	if !reflect.DeepEqual(sdt, expected) {
    70  		t.Fatalf("Unmarshal: expected %v, got %v", expected, sdt)
    71  	}
    72  
    73  	b, err = expected.Marshal()
    74  	if err != nil {
    75  		t.Fatalf("Marshal: %+v", err)
    76  	}
    77  
    78  	if !reflect.DeepEqual(b, testSDT) {
    79  		t.Errorf("Marshal: unexpected results\nexpected: [% 2X]\ngot:      [% 2X]", testSDT, b)
    80  	}
    81  }