File tree 2 files changed +24
-0
lines changed 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ func TestCthread(t *testing.T) { testCthread(t) }
79
79
func TestEnum (t * testing.T ) { testEnum (t ) }
80
80
func TestNamedEnum (t * testing.T ) { testNamedEnum (t ) }
81
81
func TestCastToEnum (t * testing.T ) { testCastToEnum (t ) }
82
+ func TestUnion (t * testing.T ) { testUnion (t ) }
82
83
func TestErrno (t * testing.T ) { testErrno (t ) }
83
84
func TestFpVar (t * testing.T ) { testFpVar (t ) }
84
85
func TestHandle (t * testing.T ) { testHandle (t ) }
Original file line number Diff line number Diff line change @@ -95,6 +95,11 @@ enum E {
95
95
Enum2 = 2,
96
96
};
97
97
98
+ union U {
99
+ float f32;
100
+ uint64_t u64;
101
+ };
102
+
98
103
typedef unsigned char cgo_uuid_t[20];
99
104
100
105
void uuid_generate(cgo_uuid_t x) {
@@ -1034,6 +1039,24 @@ func testCastToEnum(t *testing.T) {
1034
1039
}
1035
1040
}
1036
1041
1042
+ func testUnion (t * testing.T ) {
1043
+ var u C.union_U
1044
+
1045
+ goU64 := (* uint64 )(unsafe .Pointer (& u ))
1046
+ * goU64 = math .MaxUint64
1047
+
1048
+ if * goU64 != math .MaxUint64 {
1049
+ t .Error ("failed to assign value to union" , * goU64 )
1050
+ }
1051
+
1052
+ goF32 := (* float32 )(unsafe .Pointer (& u ))
1053
+ * goF32 = 1.0
1054
+
1055
+ if * goF32 != 1.0 {
1056
+ t .Error ("failed to assign value to union" , * goF32 )
1057
+ }
1058
+ }
1059
+
1037
1060
func testAtol (t * testing.T ) {
1038
1061
l := Atol ("123" )
1039
1062
if l != 123 {
You can’t perform that action at this time.
0 commit comments