Example #1
0
func TestNonNullableNullInUnion(t *testing.T) {
	var wrapper test_unions.WrapperStruct
	fdummy := test_unions.ObjectUnionFDummy{test_unions.DummyStruct{10}}
	wrapper.ObjectUnion = &fdummy

	bytes, handles, _ := encode(t, &wrapper)
	bytes[16] = 0

	var decoded test_unions.WrapperStruct
	decoder := bindings.NewDecoder(bytes, handles)

	if err := decoded.Decode(decoder); err == nil {
		t.Fatalf("Null non-nullable should have failed validation.")
	}
}
Example #2
0
func TestObjectUnion(t *testing.T) {
	tests := []test_unions.ObjectUnion{
		&test_unions.ObjectUnionFDummy{test_unions.DummyStruct{10}},
		&test_unions.ObjectUnionFArrayInt8{[]int8{1, 2, 3, 4}},
		&test_unions.ObjectUnionFMapInt8{map[string]int8{"hello": 1, "world": 2}},
		&test_unions.ObjectUnionFNullable{},
		&test_unions.ObjectUnionFPodUnion{&test_unions.PodUnionFInt8{8}},
		&test_unions.ObjectUnionFPodUnion{&test_unions.PodUnionFInt64{64}},
		&test_unions.ObjectUnionFPodUnion{&test_unions.PodUnionFBool{true}},
		&test_unions.ObjectUnionFPodUnion{&test_unions.PodUnionFEnum{test_unions.AnEnum_Second}},
	}

	for _, union := range tests {
		var wrapper, zeroWrapper test_unions.WrapperStruct
		wrapper.ObjectUnion = union
		check(t, &wrapper, &zeroWrapper)
	}
}