From 04b08da9af0c450d645ab7389d1467308cfc2db8 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 4 Mar 2013 21:27:36 +0100 Subject: Imported Upstream version 1.1~hg20130304 --- misc/cgo/test/basic.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'misc/cgo/test/basic.go') 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) + } +} -- cgit v1.2.3