address_darwin_test.go 1.3 KB

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