summaryrefslogtreecommitdiff
path: root/misc/cgo/test
diff options
context:
space:
mode:
Diffstat (limited to 'misc/cgo/test')
-rw-r--r--misc/cgo/test/Makefile1
-rw-r--r--misc/cgo/test/align.go2
-rw-r--r--misc/cgo/test/basic.go10
-rw-r--r--misc/cgo/test/callback.go14
-rw-r--r--misc/cgo/test/cgo_test.go29
-rw-r--r--misc/cgo/test/env.go32
-rw-r--r--misc/cgo/test/issue1328.go2
-rw-r--r--misc/cgo/test/issue1560.go2
8 files changed, 74 insertions, 18 deletions
diff --git a/misc/cgo/test/Makefile b/misc/cgo/test/Makefile
index 893540d97..43c45f416 100644
--- a/misc/cgo/test/Makefile
+++ b/misc/cgo/test/Makefile
@@ -10,6 +10,7 @@ CGOFILES=\
align.go\
basic.go\
callback.go\
+ env.go\
issue1222.go\
issue1328.go\
issue1560.go\
diff --git a/misc/cgo/test/align.go b/misc/cgo/test/align.go
index 2d2979595..07ab9ef50 100644
--- a/misc/cgo/test/align.go
+++ b/misc/cgo/test/align.go
@@ -58,7 +58,7 @@ import (
"testing"
)
-func TestAlign(t *testing.T) {
+func testAlign(t *testing.T) {
var evt C.SDL_KeyboardEvent
C.makeEvent(&evt)
if C.same(&evt, evt.typ, evt.which, evt.state, evt.keysym.scancode, evt.keysym.sym, evt.keysym.mod, evt.keysym.unicode) == 0 {
diff --git a/misc/cgo/test/basic.go b/misc/cgo/test/basic.go
index a94074c52..b9d0953bd 100644
--- a/misc/cgo/test/basic.go
+++ b/misc/cgo/test/basic.go
@@ -90,31 +90,31 @@ func Atol(s string) int {
return int(n)
}
-func TestConst(t *testing.T) {
+func testConst(t *testing.T) {
C.myConstFunc(nil, 0, nil)
}
-func TestEnum(t *testing.T) {
+func testEnum(t *testing.T) {
if C.Enum1 != 1 || C.Enum2 != 2 {
t.Error("bad enum", C.Enum1, C.Enum2)
}
}
-func TestAtol(t *testing.T) {
+func testAtol(t *testing.T) {
l := Atol("123")
if l != 123 {
t.Error("Atol 123: ", l)
}
}
-func TestErrno(t *testing.T) {
+func testErrno(t *testing.T) {
n, err := Strtol("asdf", 123)
if n != 0 || err != os.EINVAL {
t.Error("Strtol: ", n, err)
}
}
-func TestMultipleAssign(t *testing.T) {
+func testMultipleAssign(t *testing.T) {
p := C.CString("234")
n, m := C.strtol(p, nil, 345), C.strtol(p, nil, 10)
if n != 0 || m != 234 {
diff --git a/misc/cgo/test/callback.go b/misc/cgo/test/callback.go
index 450a7cbf2..3edee9758 100644
--- a/misc/cgo/test/callback.go
+++ b/misc/cgo/test/callback.go
@@ -27,7 +27,7 @@ func goCallback(p unsafe.Pointer) {
(*(*func())(unsafe.Pointer(&p)))()
}
-func TestCallback(t *testing.T) {
+func testCallback(t *testing.T) {
var x = false
nestedCall(func() { x = true })
if !x {
@@ -35,13 +35,13 @@ func TestCallback(t *testing.T) {
}
}
-func TestCallbackGC(t *testing.T) {
+func testCallbackGC(t *testing.T) {
nestedCall(runtime.GC)
}
func lockedOSThread() bool // in runtime.c
-func TestCallbackPanic(t *testing.T) {
+func testCallbackPanic(t *testing.T) {
// Make sure panic during callback unwinds properly.
if lockedOSThread() {
t.Fatal("locked OS thread on entry to TestCallbackPanic")
@@ -62,14 +62,14 @@ func TestCallbackPanic(t *testing.T) {
panic("nestedCall returned")
}
-func TestCallbackPanicLoop(t *testing.T) {
+func testCallbackPanicLoop(t *testing.T) {
// Make sure we don't blow out m->g0 stack.
for i := 0; i < 100000; i++ {
TestCallbackPanic(t)
}
}
-func TestCallbackPanicLocked(t *testing.T) {
+func testCallbackPanicLocked(t *testing.T) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
@@ -94,7 +94,7 @@ func TestCallbackPanicLocked(t *testing.T) {
// Callback with zero arguments used to make the stack misaligned,
// which broke the garbage collector and other things.
-func TestZeroArgCallback(t *testing.T) {
+func testZeroArgCallback(t *testing.T) {
defer func() {
s := recover()
if s != nil {
@@ -118,7 +118,7 @@ func goFoo() {
func variadic(x ...interface{}) {}
-func TestBlocking(t *testing.T) {
+func testBlocking(t *testing.T) {
c := make(chan int)
go func() {
for i := 0; i < 10; i++ {
diff --git a/misc/cgo/test/cgo_test.go b/misc/cgo/test/cgo_test.go
index 967dc0e92..94fba15db 100644
--- a/misc/cgo/test/cgo_test.go
+++ b/misc/cgo/test/cgo_test.go
@@ -1,5 +1,28 @@
+// 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 cgotest
-// dummy file so gotest thinks there are tests.
-// the actual tests are in the main go files, next
-// to the code they test.
+import "testing"
+
+// The actual test functions are in non-_test.go files
+// so that they can use cgo (import "C").
+// These wrappers are here for gotest to find.
+
+func TestAlign(t *testing.T) { testAlign(t) }
+func TestConst(t *testing.T) { testConst(t) }
+func TestEnum(t *testing.T) { testEnum(t) }
+func TestAtol(t *testing.T) { testAtol(t) }
+func TestErrno(t *testing.T) { testErrno(t) }
+func TestMultipleAssign(t *testing.T) { testMultipleAssign(t) }
+func TestCallback(t *testing.T) { testCallback(t) }
+func TestCallbackGC(t *testing.T) { testCallbackGC(t) }
+func TestCallbackPanic(t *testing.T) { testCallbackPanic(t) }
+func TestCallbackPanicLoop(t *testing.T) { testCallbackPanicLoop(t) }
+func TestCallbackPanicLocked(t *testing.T) { testCallbackPanicLocked(t) }
+func TestZeroArgCallback(t *testing.T) { testZeroArgCallback(t) }
+func TestBlocking(t *testing.T) { testBlocking(t) }
+func Test1328(t *testing.T) { test1328(t) }
+func TestParallelSleep(t *testing.T) { testParallelSleep(t) }
+func TestSetEnv(t *testing.T) { testSetEnv(t) }
diff --git a/misc/cgo/test/env.go b/misc/cgo/test/env.go
new file mode 100644
index 000000000..1fb4e684c
--- /dev/null
+++ b/misc/cgo/test/env.go
@@ -0,0 +1,32 @@
+// 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 cgotest
+
+/*
+#include <stdlib.h>
+*/
+import "C"
+import (
+ "os"
+ "testing"
+ "unsafe"
+)
+
+// This is really an os package test but here for convenience.
+func testSetEnv(t *testing.T) {
+ const key = "CGO_OS_TEST_KEY"
+ const val = "CGO_OS_TEST_VALUE"
+ os.Setenv(key, val)
+ keyc := C.CString(key)
+ defer C.free(unsafe.Pointer(keyc))
+ v := C.getenv(keyc)
+ if v == (*C.char)(unsafe.Pointer(uintptr(0))) {
+ t.Fatal("getenv returned NULL")
+ }
+ vs := C.GoString(v)
+ if vs != val {
+ t.Fatalf("getenv() = %q; want %q", vs, val)
+ }
+}
diff --git a/misc/cgo/test/issue1328.go b/misc/cgo/test/issue1328.go
index f29d7057e..e01207dd9 100644
--- a/misc/cgo/test/issue1328.go
+++ b/misc/cgo/test/issue1328.go
@@ -25,6 +25,6 @@ func BackIntoGo() {
func xvariadic(x ...interface{}) {
}
-func Test1328(t *testing.T) {
+func test1328(t *testing.T) {
C.IntoC()
}
diff --git a/misc/cgo/test/issue1560.go b/misc/cgo/test/issue1560.go
index 75d31c035..e534cce47 100644
--- a/misc/cgo/test/issue1560.go
+++ b/misc/cgo/test/issue1560.go
@@ -35,7 +35,7 @@ func BackgroundSleep(n int) {
}()
}
-func TestParallelSleep(t *testing.T) {
+func testParallelSleep(t *testing.T) {
dt := -time.Nanoseconds()
parallelSleep(1)
dt += time.Nanoseconds()