diff options
author | HowJMay <vulxj0j8j8@gmail.com> | 2020-10-27 17:03:48 +0000 |
---|---|---|
committer | Emmanuel Odeke <emmanuel@orijtech.com> | 2020-10-27 18:13:59 +0000 |
commit | 3f6b1a0d5eea4756b905db1c2b2c03e8594850d3 (patch) | |
tree | 74ba9a92f428e74769a9be47491fee6e784c4f8a /misc | |
parent | 8fdc79e18a9704185bd6471b592db1e8004bd993 (diff) | |
download | go-3f6b1a0d5eea4756b905db1c2b2c03e8594850d3.tar.gz go-3f6b1a0d5eea4756b905db1c2b2c03e8594850d3.zip |
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 <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'misc')
-rw-r--r-- | misc/cgo/test/cgo_test.go | 2 | ||||
-rw-r--r-- | misc/cgo/test/test.go | 26 |
2 files changed, 28 insertions, 0 deletions
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 { |