Skip to content

Commit 81890f4

Browse files
committed
misc/cgo/test: Test casting a C enumration object
Declare an object to C Enumeration and check if it has been assigned correct values.
1 parent be241e9 commit 81890f4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

misc/cgo/test/cgo_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func TestConst(t *testing.T) { testConst(t) }
7777
func TestCthread(t *testing.T) { testCthread(t) }
7878
func TestEnum(t *testing.T) { testEnum(t) }
7979
func TestNamedEnum(t *testing.T) { testNamedEnum(t) }
80+
func TestCastToEnum(t *testing.T) { testCastToEnum(t) }
8081
func TestErrno(t *testing.T) { testErrno(t) }
8182
func TestFpVar(t *testing.T) { testFpVar(t) }
8283
func TestHelpers(t *testing.T) { testHelpers(t) }

misc/cgo/test/test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,18 @@ func testNamedEnum(t *testing.T) {
10131013
}
10141014
}
10151015

1016+
func testCastToEnum(t *testing.T) {
1017+
e := C.enum_E(C.Enum1)
1018+
if e != 1 {
1019+
t.Error("bad enum", C.Enum1)
1020+
}
1021+
1022+
e = C.enum_E(C.Enum2)
1023+
if e != 2 {
1024+
t.Error("bad enum", C.Enum2)
1025+
}
1026+
}
1027+
10161028
func testAtol(t *testing.T) {
10171029
l := Atol("123")
10181030
if l != 123 {

0 commit comments

Comments
 (0)