diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:36 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:36 +0100 |
commit | 04b08da9af0c450d645ab7389d1467308cfc2db8 (patch) | |
tree | db247935fa4f2f94408edc3acd5d0d4f997aa0d8 /misc/cgo/test/basic.go | |
parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
download | golang-upstream/1.1_hg20130304.tar.gz |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'misc/cgo/test/basic.go')
-rw-r--r-- | misc/cgo/test/basic.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/misc/cgo/test/basic.go b/misc/cgo/test/basic.go index 70ec5e43a..79cbf2b9c 100644 --- a/misc/cgo/test/basic.go +++ b/misc/cgo/test/basic.go @@ -14,15 +14,16 @@ package cgotest #define SHIFT(x, y) ((x)<<(y)) #define KILO SHIFT(1, 10) +#define UINT32VAL 0xc008427bU enum E { Enum1 = 1, Enum2 = 2, }; -typedef unsigned char uuid_t[20]; +typedef unsigned char cgo_uuid_t[20]; -void uuid_generate(uuid_t x) { +void uuid_generate(cgo_uuid_t x) { x[0] = 0; } @@ -55,6 +56,7 @@ int add(int x, int y) { */ import "C" import ( + "runtime" "syscall" "testing" "unsafe" @@ -65,7 +67,7 @@ const EINVAL = C.EINVAL /* test #define */ var KILO = C.KILO func uuidgen() { - var uuid C.uuid_t + var uuid C.cgo_uuid_t C.uuid_generate(&uuid[0]) } @@ -118,7 +120,12 @@ func testErrno(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 { + if runtime.GOOS == "openbsd" { + // Bug in OpenBSD strtol(3) - base > 36 succeeds. + if (n != 0 && n != 239089) || m != 234 { + t.Fatal("Strtol x2: ", n, m) + } + } else if n != 0 || m != 234 { t.Fatal("Strtol x2: ", n, m) } C.free(unsafe.Pointer(p)) @@ -141,3 +148,12 @@ func benchCgoCall(b *testing.B) { C.add(x, y) } } + +// Issue 2470. +func testUnsignedInt(t *testing.T) { + a := (int64)(C.UINT32VAL) + b := (int64)(0xc008427b) + if a != b { + t.Errorf("Incorrect unsigned int - got %x, want %x", a, b) + } +} |