code.pfad.fr/gohmekit@v0.2.1/hapip/characteristic/tlv8_test.go (about)

     1  package characteristic
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"code.pfad.fr/gohmekit/tlv8"
     8  	"gotest.tools/v3/assert"
     9  )
    10  
    11  func TestJSONMarshal(t *testing.T) {
    12  	s := SupportedVideoStreamConfigurationResponse{
    13  		Codecs: []struct {
    14  			Type       byte                   `tlv8:"1"`
    15  			Parameters []VideoCodecParameters `tlv8:"2"`
    16  			Attributes []VideoAttributes      `tlv8:"3"`
    17  		}{
    18  			{
    19  				Type: 0,
    20  				Parameters: []VideoCodecParameters{
    21  					{
    22  						ProfileID:         0,
    23  						Level:             0,
    24  						PacketizationMode: 0,
    25  					},
    26  				},
    27  				Attributes: []VideoAttributes{
    28  					{1920, 1080, 30}, // 1080p
    29  					{1280, 720, 30},  // 720p
    30  					{640, 360, 30},
    31  					{480, 270, 30},
    32  					{320, 180, 30},
    33  					{1280, 960, 30},
    34  					{1024, 768, 30}, // XVGA
    35  					{640, 480, 30},  // VGA
    36  					{480, 360, 30},  // HVGA
    37  					{320, 240, 15},  // QVGA (Apple Watch)
    38  				},
    39  			},
    40  		},
    41  	}
    42  	c := SupportedVideoStreamConfiguration(s)
    43  	v, err := c.Read(context.Background())
    44  	assert.NilError(t, err)
    45  
    46  	_, ok := v.([]byte)
    47  	t.Log(v)
    48  	assert.Check(t, ok)
    49  }
    50  
    51  func TestSupportedRTPConfigurationResponse(t *testing.T) {
    52  	response := SupportedRTPConfigurationResponse{
    53  		{
    54  			CryptoSuite: 0,
    55  			Separator:   struct{}{},
    56  		},
    57  		{
    58  			CryptoSuite: 1,
    59  			Separator:   struct{}{},
    60  		},
    61  	}
    62  	buf, err := tlv8.Marshal(response)
    63  	assert.NilError(t, err)
    64  	assert.DeepEqual(t, []byte{
    65  		2, 1, 0,
    66  		0, 0,
    67  		2, 1, 1,
    68  		0, 0,
    69  	}, buf)
    70  }