Ejemplo n.º 1
0
func TestExtract_EmbedName(t *testing.T) {
	_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatalf("NewMessage: %v", err)
	}
	f16, err := air.NewRootF16(seg)
	if err != nil {
		t.Fatalf("NewRootF16: %v", err)
	}
	base, err := f16.NewBase()
	if err != nil {
		t.Fatalf("F16.NewBase: %v", err)
	}
	if err := base.SetName("ALL YOUR BASE"); err != nil {
		t.Fatalf("Planebase.SetName: %v", err)
	}
	base.SetRating(5)
	base.SetCanFly(true)

	out := new(F16)
	if err := Extract(out, air.F16_TypeID, f16.Struct); err != nil {
		t.Errorf("Extract error: %v", err)
	}
	if out.Name != "ALL YOUR BASE" || out.Rating != 5 || !out.CanFly {
		t.Errorf("Extract produced %s; want %s", zpretty.Sprint(out), zpretty.Sprint(&F16{PlaneBase{Name: "ALL YOUR BASE", Rating: 5, CanFly: true}}))
	}
}
Ejemplo n.º 2
0
func TestInsert_EmbedNamed(t *testing.T) {
	_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatalf("NewMessage: %v", err)
	}
	f16, err := air.NewRootF16(seg)
	if err != nil {
		t.Fatalf("NewRootF16: %v", err)
	}
	in := &F16{PlaneBase{Name: "ALL YOUR BASE", Rating: 5, CanFly: true}}
	err = Insert(air.F16_TypeID, f16.Struct, in)
	if err != nil {
		t.Errorf("Insert(%s) error: %v", zpretty.Sprint(in), err)
	}
	base, err := f16.Base()
	if err != nil {
		t.Errorf("f16.base: %v", err)
	}
	name, err := base.Name()
	if err != nil {
		t.Errorf("f16.base.name: %v", err)
	}
	if name != "ALL YOUR BASE" || base.Rating() != 5 || !base.CanFly() {
		t.Errorf("Insert(%s) produced %v", zpretty.Sprint(in), f16)
	}
}