Esempio n. 1
0
func TestV1DataVersioningEmptyToBigger(t *testing.T) {
	t.Parallel()
	in := mustEncodeTestMessage(t, "HoldsVerEmptyList", "(mylist = [(),()])", []byte{
		0, 0, 0, 0, 3, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 1, 0,
		1, 0, 0, 0, 7, 0, 0, 0,
		8, 0, 0, 0, 0, 0, 0, 0,
	})

	remsg, err := capnp.Unmarshal(in)
	if err != nil {
		t.Fatal("Unmarshal:", err)
	}

	reHolder1, err := air.ReadRootHoldsVerOneDataList(remsg)
	if err != nil {
		t.Fatal("ReadRootHoldsVerOneDataList:", err)
	}
	list1, err := reHolder1.Mylist()
	if err != nil {
		t.Fatal("HoldsVerOneDataList.mylist:", err)
	}
	if list1.Len() == 2 {
		if v := list1.At(0).Val(); v != 0 {
			t.Errorf("HoldsVerOneDataList.mylist[0].val = %d; want 0", v)
		}
		if v := list1.At(1).Val(); v != 0 {
			t.Errorf("HoldsVerOneDataList.mylist[1].val = %d; want 0", v)
		}
	} else {
		t.Errorf("len(HoldsVerOneDataList.mylist) = %d; want 2", list1.Len())
	}

	reHolder2, err := air.ReadRootHoldsVerTwoDataList(remsg)
	if err != nil {
		t.Fatal("ReadRootHoldsVerOneDataList:", err)
	}
	list2, err := reHolder2.Mylist()
	if err != nil {
		t.Fatal("HoldsVerOneDataList.mylist:", err)
	}
	if list2.Len() == 2 {
		if v := list2.At(0).Val(); v != 0 {
			t.Errorf("HoldsVerTwoDataList.mylist[0].val = %d; want 0", v)
		}
		if v := list2.At(0).Duo(); v != 0 {
			t.Errorf("HoldsVerTwoDataList.mylist[0].duo = %d; want 0", v)
		}
		if v := list2.At(1).Val(); v != 0 {
			t.Errorf("HoldsVerTwoDataList.mylist[1].val = %d; want 0", v)
		}
		if v := list2.At(1).Duo(); v != 0 {
			t.Errorf("HoldsVerTwoDataList.mylist[1].duo = %d; want 0", v)
		}
	} else {
		t.Errorf("len(HoldsVerTwoDataList.mylist) = %d; want 2", list2.Len())
	}
}
Esempio n. 2
0
func TestV1DataVersioningBiggerToEmpty(t *testing.T) {
	t.Parallel()
	in := mustEncodeTestMessage(t, "HoldsVerTwoDataList", "(mylist = [(val = 27, duo = 26), (val = 42, duo = 41)])", []byte{
		0, 0, 0, 0, 7, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 1, 0,
		1, 0, 0, 0, 39, 0, 0, 0,
		8, 0, 0, 0, 2, 0, 0, 0,
		27, 0, 0, 0, 0, 0, 0, 0,
		26, 0, 0, 0, 0, 0, 0, 0,
		42, 0, 0, 0, 0, 0, 0, 0,
		41, 0, 0, 0, 0, 0, 0, 0,
	})

	remsg, err := capnp.Unmarshal(in)
	if err != nil {
		t.Fatal("Unmarshal:", err)
	}

	// 0 data
	func() {
		reHolder0, err := air.ReadRootHoldsVerEmptyList(remsg)
		if err != nil {
			t.Error("ReadRootHoldsVerEmptyList:", err)
			return
		}
		list0, err := reHolder0.Mylist()
		if err != nil {
			t.Error("HoldsVerEmptyList.mylist:", err)
			return
		}
		if list0.Len() != 2 {
			t.Errorf("len(HoldsVerEmptyList.mylist) = %d; want 2", list0.Len())
		}
	}()

	// 1 datum
	func() {
		reHolder1, err := air.ReadRootHoldsVerOneDataList(remsg)
		if err != nil {
			t.Error("ReadRootHoldsVerOneDataList:", err)
			return
		}
		list1, err := reHolder1.Mylist()
		if err != nil {
			t.Error("HoldsVerOneDataList.mylist:", err)
			return
		}
		if list1.Len() == 2 {
			if v := list1.At(0).Val(); v != 27 {
				t.Errorf("HoldsVerOneDataList.mylist[0].val = %d; want 27", v)
			}
			if v := list1.At(1).Val(); v != 42 {
				t.Errorf("HoldsVerOneDataList.mylist[1].val = %d; want 42", v)
			}
		} else {
			t.Errorf("len(HoldsVerOneDataList.mylist) = %d; want 2", list1.Len())
		}
	}()

	// 2 data
	func() {
		reHolder2, err := air.ReadRootHoldsVerTwoDataList(remsg)
		if err != nil {
			t.Error("ReadRootHoldsVerTwoDataList:", err)
			return
		}
		list2, err := reHolder2.Mylist()
		if err != nil {
			t.Error("HoldsVerTwoDataList.mylist:", err)
			return
		}
		if list2.Len() == 2 {
			if v := list2.At(0).Val(); v != 27 {
				t.Errorf("HoldsVerTwoDataList.mylist[0].val = %d; want 27", v)
			}
			if v := list2.At(0).Duo(); v != 26 {
				t.Errorf("HoldsVerTwoDataList.mylist[0].duo = %d; want 26", v)
			}
			if v := list2.At(1).Val(); v != 42 {
				t.Errorf("HoldsVerTwoDataList.mylist[1].val = %d; want 42", v)
			}
			if v := list2.At(1).Duo(); v != 41 {
				t.Errorf("HoldsVerTwoDataList.mylist[1].duo = %d; want 41", v)
			}
		} else {
			t.Errorf("len(HoldsVerTwoDataList.mylist) = %d; want 2", list2.Len())
		}
	}()
}