示例#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.")
	}
}
示例#2
0
func TestHandleUnion(t *testing.T) {
	tests := []test_unions.HandleUnion{
		&test_unions.HandleUnionFHandle{system.Handle(&mockHandle{handle: 1})},
		&test_unions.HandleUnionFMessagePipe{system.MessagePipeHandle(&mockHandle{handle: 2})},
		&test_unions.HandleUnionFDataPipeConsumer{system.ConsumerHandle(&mockHandle{handle: 3})},
		&test_unions.HandleUnionFDataPipeProducer{system.ProducerHandle(&mockHandle{handle: 4})},
		&test_unions.HandleUnionFSharedBuffer{system.SharedBufferHandle(&mockHandle{handle: 5})},
	}

	for _, union := range tests {
		var wrapper, zeroWrapper test_unions.WrapperStruct
		wrapper.HandleUnion = union
		check(t, &wrapper, &zeroWrapper)
	}
}
示例#3
0
func TestPodUnion(t *testing.T) {
	tests := []test_unions.PodUnion{
		&test_unions.PodUnionFInt8{8},
		&test_unions.PodUnionFInt16{16},
		&test_unions.PodUnionFUint64{64},
		&test_unions.PodUnionFBool{true},
		&test_unions.PodUnionFEnum{test_unions.AnEnum_Second},
	}

	for _, union := range tests {
		var wrapper, zeroWrapper test_unions.WrapperStruct
		wrapper.PodUnion = union
		check(t, &wrapper, &zeroWrapper)
	}
}
示例#4
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)
	}
}
示例#5
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")
	}
}