Skip to content

Commit 3f6b1a0

Browse files
howjmayodeke-em
authored andcommitted
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: 81890f4 GitHub-Pull-Request: #39977 Reviewed-on: https://go-review.googlesource.com/c/go/+/240697 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Trust: Emmanuel Odeke <[email protected]>
1 parent 8fdc79e commit 3f6b1a0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

misc/cgo/test/cgo_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ func TestCheckConst(t *testing.T) { testCheckConst(t) }
7676
func TestConst(t *testing.T) { testConst(t) }
7777
func TestCthread(t *testing.T) { testCthread(t) }
7878
func TestEnum(t *testing.T) { testEnum(t) }
79+
func TestNamedEnum(t *testing.T) { testNamedEnum(t) }
80+
func TestCastToEnum(t *testing.T) { testCastToEnum(t) }
7981
func TestErrno(t *testing.T) { testErrno(t) }
8082
func TestFpVar(t *testing.T) { testFpVar(t) }
8183
func TestHelpers(t *testing.T) { testHelpers(t) }

misc/cgo/test/test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,32 @@ func testEnum(t *testing.T) {
10001000
}
10011001
}
10021002

1003+
func testNamedEnum(t *testing.T) {
1004+
e := new(C.enum_E)
1005+
1006+
*e = C.Enum1
1007+
if *e != 1 {
1008+
t.Error("bad enum", C.Enum1)
1009+
}
1010+
1011+
*e = C.Enum2
1012+
if *e != 2 {
1013+
t.Error("bad enum", C.Enum2)
1014+
}
1015+
}
1016+
1017+
func testCastToEnum(t *testing.T) {
1018+
e := C.enum_E(C.Enum1)
1019+
if e != 1 {
1020+
t.Error("bad enum", C.Enum1)
1021+
}
1022+
1023+
e = C.enum_E(C.Enum2)
1024+
if e != 2 {
1025+
t.Error("bad enum", C.Enum2)
1026+
}
1027+
}
1028+
10031029
func testAtol(t *testing.T) {
10041030
l := Atol("123")
10051031
if l != 123 {

0 commit comments

Comments
 (0)