From 81890f40acc5589563ec1206fe119873fb46dc1b Mon Sep 17 00:00:00 2001 From: HowJMay Date: Thu, 2 Jul 2020 00:28:54 +0800 Subject: [PATCH] misc/cgo/test: Test casting a C enumration object Declare an object to C Enumeration and check if it has been assigned correct values. --- misc/cgo/test/cgo_test.go | 1 + misc/cgo/test/test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/misc/cgo/test/cgo_test.go b/misc/cgo/test/cgo_test.go index 4d3bd09a8b..f7a76d047b 100644 --- a/misc/cgo/test/cgo_test.go +++ b/misc/cgo/test/cgo_test.go @@ -77,6 +77,7 @@ 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 8c815f06f8..5be74c14cc 100644 --- a/misc/cgo/test/test.go +++ b/misc/cgo/test/test.go @@ -1013,6 +1013,18 @@ func testNamedEnum(t *testing.T) { } } +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 {