main.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2014 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 main
  5. import (
  6. "fmt"
  7. "os"
  8. "reflect"
  9. )
  10. // Test that the struct field in anonunion.go was promoted.
  11. var v1 T
  12. var v2 = v1.L
  13. // Test that P, Q, and R all point to byte.
  14. var v3 = Issue8478{P: (*byte)(nil), Q: (**byte)(nil), R: (***byte)(nil)}
  15. // Test that N, A and B are fully defined
  16. var v4 = N{}
  17. var v5 = A{}
  18. var v6 = B{}
  19. // Test that S is fully defined
  20. var v7 = S{}
  21. // Test that #define'd type is fully defined
  22. var _ = issue38649{X: 0}
  23. // Test that prefixes do not cause duplicate field names.
  24. var _ = Issue48396{Fd: 1, Bpf_fd: 2}
  25. func main() {
  26. pass := true
  27. // The Go translation of bitfields should not have any of the
  28. // bitfield types. The order in which bitfields are laid out
  29. // in memory is implementation defined, so we can't easily
  30. // know how a bitfield should correspond to a Go type, even if
  31. // it appears to be aligned correctly.
  32. bitfieldType := reflect.TypeOf(bitfields{})
  33. check := func(name string) {
  34. _, ok := bitfieldType.FieldByName(name)
  35. if ok {
  36. fmt.Fprintf(os.Stderr, "found unexpected bitfields field %s\n", name)
  37. pass = false
  38. }
  39. }
  40. check("Short1")
  41. check("Short2")
  42. check("Short3")
  43. if !pass {
  44. os.Exit(1)
  45. }
  46. }