github.com/hlts2/go@v0.0.0-20170904000733-812b34efaed8/misc/cgo/test/issue18720.go (about) 1 // Copyright 2017 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 cgotest 6 7 /* 8 #define HELLO "hello" 9 #define WORLD "world" 10 #define HELLO_WORLD HELLO "\000" WORLD 11 12 struct foo { char c; }; 13 #define SIZE_OF(x) sizeof(x) 14 #define SIZE_OF_FOO SIZE_OF(struct foo) 15 #define VAR1 VAR 16 #define VAR var 17 int var = 5; 18 19 #define ADDR &var 20 21 #define CALL fn() 22 int fn(void) { 23 return ++var; 24 } 25 */ 26 import "C" 27 import "testing" 28 29 func test18720(t *testing.T) { 30 if got, want := C.HELLO_WORLD, "hello\000world"; got != want { 31 t.Errorf("C.HELLO_WORLD == %q, expected %q", got, want) 32 } 33 34 if got, want := C.VAR1, C.int(5); got != want { 35 t.Errorf("C.VAR1 == %v, expected %v", got, want) 36 } 37 38 if got, want := *C.ADDR, C.int(5); got != want { 39 t.Errorf("*C.ADDR == %v, expected %v", got, want) 40 } 41 42 if got, want := C.CALL, C.int(6); got != want { 43 t.Errorf("C.CALL == %v, expected %v", got, want) 44 } 45 46 if got, want := C.CALL, C.int(7); got != want { 47 t.Errorf("C.CALL == %v, expected %v", got, want) 48 } 49 50 // Issue 20125. 51 if got, want := C.SIZE_OF_FOO, 1; got != want { 52 t.Errorf("C.SIZE_OF_FOO == %v, expected %v", got, want) 53 } 54 }