libgo: update to Go1.10rc2
[official-gcc.git] / libgo / misc / cgo / test / issue4029.go
blob8e468d367d1ec9d9ad21ae6b564e64293bc93057
1 // Copyright 2012 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 // +build !windows
7 package cgotest
9 /*
10 #include <stdint.h>
11 #include <dlfcn.h>
12 #cgo linux LDFLAGS: -ldl
14 extern uintptr_t dlopen4029(char*, int);
15 extern uintptr_t dlsym4029(uintptr_t, char*);
16 extern int dlclose4029(uintptr_t);
18 extern void call4029(uintptr_t arg);
20 import "C"
22 import (
23 "testing"
26 var callbacks int
28 //export IMPIsOpaque
29 func IMPIsOpaque() {
30 callbacks++
33 //export IMPInitWithFrame
34 func IMPInitWithFrame() {
35 callbacks++
38 //export IMPDrawRect
39 func IMPDrawRect() {
40 callbacks++
43 //export IMPWindowResize
44 func IMPWindowResize() {
45 callbacks++
48 func test4029(t *testing.T) {
49 loadThySelf(t, "IMPWindowResize")
50 loadThySelf(t, "IMPDrawRect")
51 loadThySelf(t, "IMPInitWithFrame")
52 loadThySelf(t, "IMPIsOpaque")
53 if callbacks != 4 {
54 t.Errorf("got %d callbacks, expected 4", callbacks)
58 func loadThySelf(t *testing.T, symbol string) {
59 this_process := C.dlopen4029(nil, C.RTLD_NOW)
60 if this_process == 0 {
61 t.Error("dlopen:", C.GoString(C.dlerror()))
62 return
64 defer C.dlclose4029(this_process)
66 symbol_address := C.dlsym4029(this_process, C.CString(symbol))
67 if symbol_address == 0 {
68 t.Error("dlsym:", C.GoString(C.dlerror()))
69 return
71 t.Log(symbol, symbol_address)
72 C.call4029(symbol_address)