예제 #1
0
func TestTextContaintingStruct(t *testing.T) {

	zjobBytes := CapnpEncode(`(cmd = "abc")`, "Zjob")

	cv.Convey("Given a simple struct message Zjob containing a string 'abc' and a list of string (empty)", t, func() {
		cv.Convey("then the go-capnproto serialization should match the capnp c++ serialization", func() {

			seg := capn.NewBuffer(nil)
			zjob := air.NewRootZjob(seg)
			zjob.SetCmd("abc")

			buf := bytes.Buffer{}
			seg.WriteTo(&buf)

			act := buf.Bytes()
			fmt.Printf("          actual:\n")
			ShowBytes(act, 10)

			fmt.Printf("\n\n          expected:\n")
			ShowBytes(zjobBytes, 10)

			cv.So(act, cv.ShouldResemble, zjobBytes)
		})
	})
}
예제 #2
0
func TestTextAndTextListContaintingStruct(t *testing.T) {

	zjobBytes := CapnpEncode(`(cmd = "abc", args = ["xyz"])`, "Zjob")

	cv.Convey("Given a simple struct message Zjob containing a string (cmd='abc') and a list of string (args=['xyz'])", t, func() {
		cv.Convey("then the go-capnproto serialization should match the capnp c++ serialization", func() {

			seg := capn.NewBuffer(nil)
			zjob := air.NewRootZjob(seg)
			zjob.SetCmd("abc")
			tl := seg.NewTextList(1)
			tl.Set(0, "xyz")
			zjob.SetArgs(tl)

			buf := bytes.Buffer{}
			seg.WriteTo(&buf)

			act := buf.Bytes()
			fmt.Printf("          actual:\n")
			ShowBytes(act, 10)

			fmt.Printf("expected:\n")
			ShowBytes(zjobBytes, 10)

			cv.So(act, cv.ShouldResemble, zjobBytes)
		})
	})
}
예제 #3
0
func TestTextAndListTextContaintingEmptyStruct(t *testing.T) {

	emptyZjobBytes := CapnpEncode("()", "Zjob")

	cv.Convey("Given a simple struct message Zjob containing a string and a list of string (all empty)", t, func() {
		cv.Convey("then the go-capnproto serialization should match the capnp c++ serialization", func() {
			ShowBytes(emptyZjobBytes, 10)

			seg := capn.NewBuffer(nil)
			air.NewRootZjob(seg)

			buf := bytes.Buffer{}
			seg.WriteTo(&buf)

			cv.So(buf.Bytes(), cv.ShouldResemble, emptyZjobBytes)
		})
	})
}