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