From 3f6b1a0d5eea4756b905db1c2b2c03e8594850d3 Mon Sep 17 00:00:00 2001 From: HowJMay Date: Tue, 27 Oct 2020 17:03:48 +0000 Subject: misc/cgo/test: test C.enum_* Allocate a C enum object, and test if it can be assigned a value successfully. For #39537 Change-Id: I7b5482112486440b9d99f2ee4051328d87f45dca GitHub-Last-Rev: 81890f40acc5589563ec1206fe119873fb46dc1b GitHub-Pull-Request: golang/go#39977 Reviewed-on: https://go-review.googlesource.com/c/go/+/240697 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor Trust: Emmanuel Odeke --- misc/cgo/test/cgo_test.go | 2 ++ misc/cgo/test/test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'misc') diff --git a/misc/cgo/test/cgo_test.go b/misc/cgo/test/cgo_test.go index b745a4417f..f7a76d047b 100644 --- a/misc/cgo/test/cgo_test.go +++ b/misc/cgo/test/cgo_test.go @@ -76,6 +76,8 @@ func TestCheckConst(t *testing.T) { testCheckConst(t) } func TestConst(t *testing.T) { testConst(t) } func TestCthread(t *testing.T) { testCthread(t) } func TestEnum(t *testing.T) { testEnum(t) } +func TestNamedEnum(t *testing.T) { testNamedEnum(t) } +func TestCastToEnum(t *testing.T) { testCastToEnum(t) } func TestErrno(t *testing.T) { testErrno(t) } func TestFpVar(t *testing.T) { testFpVar(t) } func TestHelpers(t *testing.T) { testHelpers(t) } diff --git a/misc/cgo/test/test.go b/misc/cgo/test/test.go index a78f88499b..65823b1ca0 100644 --- a/misc/cgo/test/test.go +++ b/misc/cgo/test/test.go @@ -1000,6 +1000,32 @@ func testEnum(t *testing.T) { } } +func testNamedEnum(t *testing.T) { + e := new(C.enum_E) + + *e = C.Enum1 + if *e != 1 { + t.Error("bad enum", C.Enum1) + } + + *e = C.Enum2 + if *e != 2 { + t.Error("bad enum", C.Enum2) + } +} + +func testCastToEnum(t *testing.T) { + e := C.enum_E(C.Enum1) + if e != 1 { + t.Error("bad enum", C.Enum1) + } + + e = C.enum_E(C.Enum2) + if e != 2 { + t.Error("bad enum", C.Enum2) + } +} + func testAtol(t *testing.T) { l := Atol("123") if l != 123 { -- cgit v1.2.3-54-g00ecf