github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/golang.org/x/net/route/address_darwin_test.go (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package route
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  type parseAddrsOnDarwinTest struct {
    13  	attrs uint
    14  	fn    func(int, []byte) (int, Addr, error)
    15  	b     []byte
    16  	as    []Addr
    17  }
    18  
    19  var parseAddrsOnDarwinLittleEndianTests = []parseAddrsOnDarwinTest{
    20  	{
    21  		sysRTA_DST | sysRTA_GATEWAY | sysRTA_NETMASK,
    22  		parseKernelInetAddr,
    23  		[]byte{
    24  			0x10, 0x2, 0x0, 0x0, 0xc0, 0xa8, 0x56, 0x0,
    25  			0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
    26  
    27  			0x14, 0x12, 0x4, 0x0, 0x6, 0x0, 0x0, 0x0,
    28  			0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
    29  			0x0, 0x0, 0x0, 0x0,
    30  
    31  			0x7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    32  		},
    33  		[]Addr{
    34  			&Inet4Addr{IP: [4]byte{192, 168, 86, 0}},
    35  			&LinkAddr{Index: 4},
    36  			&Inet4Addr{IP: [4]byte{255, 255, 255, 255}},
    37  			nil,
    38  			nil,
    39  			nil,
    40  			nil,
    41  			nil,
    42  		},
    43  	},
    44  }
    45  
    46  func TestParseAddrsOnDarwin(t *testing.T) {
    47  	tests := parseAddrsOnDarwinLittleEndianTests
    48  	if nativeEndian != littleEndian {
    49  		t.Skip("no test for non-little endian machine yet")
    50  	}
    51  
    52  	for i, tt := range tests {
    53  		as, err := parseAddrs(tt.attrs, tt.fn, tt.b)
    54  		if err != nil {
    55  			t.Error(i, err)
    56  			continue
    57  		}
    58  		if !reflect.DeepEqual(as, tt.as) {
    59  			t.Errorf("#%d: got %+v; want %+v", i, as, tt.as)
    60  			continue
    61  		}
    62  	}
    63  }