github.com/akaros/go-akaros@v0.0.0-20181004170632-85005d477eab/misc/cgo/test/issue4029.go (about) 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. 4 5 // +build !windows 6 7 package cgotest 8 9 /* 10 #include <dlfcn.h> 11 #cgo linux LDFLAGS: -ldl 12 #cgo akaros LDFLAGS: -ldl 13 */ 14 import "C" 15 16 import ( 17 "fmt" 18 "testing" 19 ) 20 21 //export IMPIsOpaque 22 func IMPIsOpaque() { 23 fmt.Println("isOpaque") 24 } 25 26 //export IMPInitWithFrame 27 func IMPInitWithFrame() { 28 fmt.Println("IInitWithFrame") 29 } 30 31 //export IMPDrawRect 32 func IMPDrawRect() { 33 fmt.Println("drawRect:") 34 } 35 36 //export IMPWindowResize 37 func IMPWindowResize() { 38 fmt.Println("windowDidResize:") 39 } 40 41 func test4029(t *testing.T) { 42 loadThySelf(t, "IMPWindowResize") 43 loadThySelf(t, "IMPDrawRect") 44 loadThySelf(t, "IMPInitWithFrame") 45 loadThySelf(t, "IMPIsOpaque") 46 } 47 48 func loadThySelf(t *testing.T, symbol string) { 49 this_process := C.dlopen(nil, C.RTLD_NOW) 50 if this_process == nil { 51 t.Error("dlopen:", C.GoString(C.dlerror())) 52 return 53 } 54 defer C.dlclose(this_process) 55 56 symbol_address := C.dlsym(this_process, C.CString(symbol)) 57 if symbol_address == nil { 58 t.Error("dlsym:", C.GoString(C.dlerror())) 59 return 60 } 61 t.Log(symbol, symbol_address) 62 }