summaryrefslogtreecommitdiff
path: root/misc/swig/callback
diff options
context:
space:
mode:
Diffstat (limited to 'misc/swig/callback')
-rw-r--r--misc/swig/callback/Makefile17
-rw-r--r--misc/swig/callback/callback.go11
-rw-r--r--misc/swig/callback/callback_test.go34
-rw-r--r--misc/swig/callback/run.go39
4 files changed, 45 insertions, 56 deletions
diff --git a/misc/swig/callback/Makefile b/misc/swig/callback/Makefile
deleted file mode 100644
index 0ca33ef60..000000000
--- a/misc/swig/callback/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copyright 2011 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-include ../../../src/Make.inc
-
-TARG=swig/callback
-SWIGFILES=\
- callback.swigcxx
-
-CLEANFILES+=run
-
-include ../../../src/Make.pkg
-
-%: install %.go
- $(GC) $(GCFLAGS) $(GCIMPORTS) $*.go
- $(LD) $(SWIG_RPATH) -o $@ $*.$O
diff --git a/misc/swig/callback/callback.go b/misc/swig/callback/callback.go
new file mode 100644
index 000000000..39c1719d2
--- /dev/null
+++ b/misc/swig/callback/callback.go
@@ -0,0 +1,11 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package callback
+
+type GoCallback struct{}
+
+func (p *GoCallback) Run() string {
+ return "GoCallback.Run"
+}
diff --git a/misc/swig/callback/callback_test.go b/misc/swig/callback/callback_test.go
new file mode 100644
index 000000000..cf008fb54
--- /dev/null
+++ b/misc/swig/callback/callback_test.go
@@ -0,0 +1,34 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package callback_test
+
+import (
+ "../callback"
+ "testing"
+)
+
+func TestCall(t *testing.T) {
+ c := callback.NewCaller()
+ cb := callback.NewCallback()
+
+ c.SetCallback(cb)
+ s := c.Call()
+ if s != "Callback::run" {
+ t.Errorf("unexpected string from Call: %q", s)
+ }
+ c.DelCallback()
+}
+
+func TestCallback(t *testing.T) {
+ c := callback.NewCaller()
+ cb := callback.NewDirectorCallback(&callback.GoCallback{})
+ c.SetCallback(cb)
+ s := c.Call()
+ if s != "GoCallback.Run" {
+ t.Errorf("unexpected string from Call with callback: %q", s)
+ }
+ c.DelCallback()
+ callback.DeleteDirectorCallback(cb)
+}
diff --git a/misc/swig/callback/run.go b/misc/swig/callback/run.go
deleted file mode 100644
index b3f13ad90..000000000
--- a/misc/swig/callback/run.go
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-import (
- "fmt"
- "swig/callback"
-)
-
-type GoCallback struct{}
-
-func (p *GoCallback) Run() string {
- return "GoCallback.Run"
-}
-
-func main() {
- c := callback.NewCaller()
- cb := callback.NewCallback()
-
- c.SetCallback(cb)
- s := c.Call()
- fmt.Println(s)
- if s != "Callback::run" {
- panic(s)
- }
- c.DelCallback()
-
- cb = callback.NewDirectorCallback(&GoCallback{})
- c.SetCallback(cb)
- s = c.Call()
- fmt.Println(s)
- if s != "GoCallback.Run" {
- panic(s)
- }
- c.DelCallback()
- callback.DeleteDirectorCallback(cb)
-}