golang.org/x/net@v0.25.1-0.20240516223405-c87a5b62e243/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  	"syscall"
    10  	"testing"
    11  )
    12  
    13  type parseAddrsOnDarwinTest struct {
    14  	attrs uint
    15  	fn    func(int, []byte) (int, Addr, error)
    16  	b     []byte
    17  	as    []Addr
    18  }
    19  
    20  var parseAddrsOnDarwinLittleEndianTests = []parseAddrsOnDarwinTest{
    21  	{
    22  		syscall.RTA_DST | syscall.RTA_GATEWAY | syscall.RTA_NETMASK,
    23  		parseKernelInetAddr,
    24  		[]byte{
    25  			0x10, 0x2, 0x0, 0x0, 0xc0, 0xa8, 0x56, 0x0,
    26  			0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
    27  
    28  			0x14, 0x12, 0x4, 0x0, 0x6, 0x0, 0x0, 0x0,
    29  			0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
    30  			0x0, 0x0, 0x0, 0x0,
    31  
    32  			0x7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    33  		},
    34  		[]Addr{
    35  			&Inet4Addr{IP: [4]byte{192, 168, 86, 0}},
    36  			&LinkAddr{Index: 4},
    37  			&Inet4Addr{IP: [4]byte{255, 255, 255, 255}},
    38  			nil,
    39  			nil,
    40  			nil,
    41  			nil,
    42  			nil,
    43  		},
    44  	},
    45  }
    46  
    47  func TestParseAddrsOnDarwin(t *testing.T) {
    48  	tests := parseAddrsOnDarwinLittleEndianTests
    49  	if nativeEndian != littleEndian {
    50  		t.Skip("no test for non-little endian machine yet")
    51  	}
    52  
    53  	for i, tt := range tests {
    54  		as, err := parseAddrs(tt.attrs, tt.fn, tt.b)
    55  		if err != nil {
    56  			t.Error(i, err)
    57  			continue
    58  		}
    59  		if !reflect.DeepEqual(as, tt.as) {
    60  			t.Errorf("#%d: got %+v; want %+v", i, as, tt.as)
    61  			continue
    62  		}
    63  	}
    64  }