1
0
mirror of https://github.com/golang/go synced 2024-11-14 06:10:24 -07:00

misc/cgo/test: Test casting a C enumration object

Declare an object to C Enumeration and check if it has been assigned
correct values.
This commit is contained in:
HowJMay 2020-07-02 00:28:54 +08:00
parent be241e9229
commit 81890f40ac
2 changed files with 13 additions and 0 deletions

View File

@ -77,6 +77,7 @@ func TestConst(t *testing.T) { testConst(t) }
func TestCthread(t *testing.T) { testCthread(t) } func TestCthread(t *testing.T) { testCthread(t) }
func TestEnum(t *testing.T) { testEnum(t) } func TestEnum(t *testing.T) { testEnum(t) }
func TestNamedEnum(t *testing.T) { testNamedEnum(t) } func TestNamedEnum(t *testing.T) { testNamedEnum(t) }
func TestCastToEnum(t *testing.T) { testCastToEnum(t) }
func TestErrno(t *testing.T) { testErrno(t) } func TestErrno(t *testing.T) { testErrno(t) }
func TestFpVar(t *testing.T) { testFpVar(t) } func TestFpVar(t *testing.T) { testFpVar(t) }
func TestHelpers(t *testing.T) { testHelpers(t) } func TestHelpers(t *testing.T) { testHelpers(t) }

View File

@ -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) { func testAtol(t *testing.T) {
l := Atol("123") l := Atol("123")
if l != 123 { if l != 123 {