libgo: update to go1.9
[official-gcc.git] / libgo / misc / cgo / test / issue6612.go
blob15a12fab38fa6d4cc7db7471b4f09cdc08b78e15
1 // Copyright 2013 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.
5 // golang.org/issue/6612
6 // Test new scheme for deciding whether C.name is an expression, type, constant.
7 // Clang silences some warnings when the name is a #defined macro, so test those too
8 // (even though we now use errors exclusively, not warnings).
10 package cgotest
13 void myfunc(void) {}
14 int myvar = 5;
15 const char *mytext = "abcdef";
16 typedef int mytype;
17 enum {
18 myenum = 1234,
21 #define myfunc_def myfunc
22 #define myvar_def myvar
23 #define mytext_def mytext
24 #define mytype_def mytype
25 #define myenum_def myenum
26 #define myint_def 12345
27 #define myfloat_def 1.5
28 #define mystring_def "hello"
30 import "C"
32 import "testing"
34 func testNaming(t *testing.T) {
35 C.myfunc()
36 C.myfunc_def()
37 if v := C.myvar; v != 5 {
38 t.Errorf("C.myvar = %d, want 5", v)
40 if v := C.myvar_def; v != 5 {
41 t.Errorf("C.myvar_def = %d, want 5", v)
43 if s := C.GoString(C.mytext); s != "abcdef" {
44 t.Errorf("C.mytext = %q, want %q", s, "abcdef")
46 if s := C.GoString(C.mytext_def); s != "abcdef" {
47 t.Errorf("C.mytext_def = %q, want %q", s, "abcdef")
49 if c := C.myenum; c != 1234 {
50 t.Errorf("C.myenum = %v, want 1234", c)
52 if c := C.myenum_def; c != 1234 {
53 t.Errorf("C.myenum_def = %v, want 1234", c)
56 const c = C.myenum
57 if c != 1234 {
58 t.Errorf("C.myenum as const = %v, want 1234", c)
62 const c = C.myenum_def
63 if c != 1234 {
64 t.Errorf("C.myenum as const = %v, want 1234", c)
67 if c := C.myint_def; c != 12345 {
68 t.Errorf("C.myint_def = %v, want 12345", c)
71 const c = C.myint_def
72 if c != 12345 {
73 t.Errorf("C.myint as const = %v, want 12345", c)
77 if c := C.myfloat_def; c != 1.5 {
78 t.Errorf("C.myint_def = %v, want 1.5", c)
81 const c = C.myfloat_def
82 if c != 1.5 {
83 t.Errorf("C.myint as const = %v, want 1.5", c)
87 if s := C.mystring_def; s != "hello" {
88 t.Errorf("C.mystring_def = %q, want %q", s, "hello")