@@ -342,6 +342,54 @@ func TestBytesView(t *testing.T) {
342342 ok : false ,
343343 value : 0 ,
344344 },
345+ bytesViewTest [uint16 ]{
346+ desc : "Convert BytesView to uint16" ,
347+ input : nlmsg .BytesView ([]byte {7 , 0 }),
348+ ok : true ,
349+ value : 7 ,
350+ },
351+ bytesViewTest [uint16 ]{
352+ desc : "Failed convert BytesView to uint16" ,
353+ input : nlmsg .BytesView ([]byte {7 }),
354+ ok : false ,
355+ value : 0 ,
356+ },
357+ bytesViewTest [int16 ]{
358+ desc : "Convert BytesView to int16" ,
359+ input : nlmsg .BytesView ([]byte {8 , 0 }),
360+ ok : true ,
361+ value : 8 ,
362+ },
363+ bytesViewTest [int16 ]{
364+ desc : "Failed convert BytesView to int16" ,
365+ input : nlmsg .BytesView ([]byte {8 }),
366+ ok : false ,
367+ value : 0 ,
368+ },
369+ bytesViewTest [uint8 ]{
370+ desc : "Convert BytesView to uint8" ,
371+ input : nlmsg .BytesView ([]byte {7 }),
372+ ok : true ,
373+ value : 7 ,
374+ },
375+ bytesViewTest [uint8 ]{
376+ desc : "Failed convert BytesView to uint8" ,
377+ input : nlmsg .BytesView ([]byte {}),
378+ ok : false ,
379+ value : 0 ,
380+ },
381+ bytesViewTest [int8 ]{
382+ desc : "Convert BytesView to int8" ,
383+ input : nlmsg .BytesView ([]byte {8 | uint8 (0x1 )<< 7 }),
384+ ok : true ,
385+ value : 8 ,
386+ },
387+ bytesViewTest [int8 ]{
388+ desc : "Failed convert BytesView to int8" ,
389+ input : nlmsg .BytesView ([]byte {}),
390+ ok : false ,
391+ value : 0 ,
392+ },
345393 }
346394 for _ , test := range tests {
347395 switch test .(type ) {
@@ -369,6 +417,42 @@ func TestBytesView(t *testing.T) {
369417 if ok && value != tst .value {
370418 t .Errorf ("%v: BytesView.Int32() got %v, want %v" , tst .desc , value , tst .value )
371419 }
420+ case bytesViewTest [uint16 ]:
421+ tst := test .(bytesViewTest [uint16 ])
422+ value , ok := tst .input .Uint16 ()
423+ if ok != tst .ok {
424+ t .Errorf ("%v: BytesView.Uint16() got ok = %v, want %v" , tst .desc , ok , tst .ok )
425+ }
426+ if ok && value != tst .value {
427+ t .Errorf ("%v: BytesView.Uint16() got %v, want %v" , tst .desc , value , tst .value )
428+ }
429+ case bytesViewTest [int16 ]:
430+ tst := test .(bytesViewTest [int16 ])
431+ value , ok := tst .input .Int16 ()
432+ if ok != tst .ok {
433+ t .Errorf ("%v: BytesView.Int16() got ok = %v, want %v" , tst .desc , ok , tst .ok )
434+ }
435+ if ok && value != tst .value {
436+ t .Errorf ("%v: BytesView.Int16() got %v, want %v" , tst .desc , value , tst .value )
437+ }
438+ case bytesViewTest [uint8 ]:
439+ tst := test .(bytesViewTest [uint8 ])
440+ value , ok := tst .input .Uint8 ()
441+ if ok != tst .ok {
442+ t .Errorf ("%v: BytesView.Uint8() got ok = %v, want %v" , tst .desc , ok , tst .ok )
443+ }
444+ if ok && value != tst .value {
445+ t .Errorf ("%v: BytesView.Uint8() got %v, want %v" , tst .desc , value , tst .value )
446+ }
447+ case bytesViewTest [int8 ]:
448+ tst := test .(bytesViewTest [int8 ])
449+ value , ok := tst .input .Int8 ()
450+ if ok != tst .ok {
451+ t .Errorf ("%v: BytesView.Int8() got ok = %v, want %v" , tst .desc , ok , tst .ok )
452+ }
453+ if ok && value != tst .value {
454+ t .Errorf ("%v: BytesView.Int8() got %v, want %v" , tst .desc , value , tst .value )
455+ }
372456 default :
373457 t .Errorf ("BytesView %T not support" , t )
374458 }
0 commit comments