Source file
misc/cgo/test/issue4029.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package cgotest
15
16
27 import "C"
28
29 import (
30 "testing"
31 )
32
33 var callbacks int
34
35
36 func IMPIsOpaque() {
37 callbacks++
38 }
39
40
41 func IMPInitWithFrame() {
42 callbacks++
43 }
44
45
46 func IMPDrawRect() {
47 callbacks++
48 }
49
50
51 func IMPWindowResize() {
52 callbacks++
53 }
54
55 func test4029(t *testing.T) {
56 loadThySelf(t, "IMPWindowResize")
57 loadThySelf(t, "IMPDrawRect")
58 loadThySelf(t, "IMPInitWithFrame")
59 loadThySelf(t, "IMPIsOpaque")
60 if callbacks != 4 {
61 t.Errorf("got %d callbacks, expected 4", callbacks)
62 }
63 }
64
65 func loadThySelf(t *testing.T, symbol string) {
66 this_process := C.dlopen4029(nil, C.RTLD_NOW)
67 if this_process == 0 {
68 t.Error("dlopen:", C.GoString(C.dlerror()))
69 return
70 }
71 defer C.dlclose4029(this_process)
72
73 symbol_address := C.dlsym4029(this_process, C.CString(symbol))
74 if symbol_address == 0 {
75 t.Error("dlsym:", C.GoString(C.dlerror()))
76 return
77 }
78 t.Log(symbol, symbol_address)
79 C.call4029(symbol_address)
80 }
81
View as plain text