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