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 TestUnknownTag(t *testing.T) {
	var wrapper test_unions.WrapperStruct
	wrapper.PodUnion = &test_unions.PodUnionFInt16{10}
	bytes, handles, err := encode(t, &wrapper)
	if err != nil {
		t.Fatalf("Test failed prematurely.")
	}

	// Set PodUnion tag to unknown.
	bytes[8*3+4] = 100

	decoder := bindings.NewDecoder(bytes, handles)
	var decoded test_unions.WrapperStruct
	err = decoded.Decode(decoder)
	if err != nil {
		t.Fatalf("Failed to decode union with unknown tag.")
	}

	if decoded.PodUnion.Tag() != 100 {
		t.Fatalf("Wrong unknown tag number")
	}
}