Ejemplo n.º 1
0
func iotest(writer io.WriteCloser, reader io.ReadCloser) {
	size := 1000
	msgs := make([]*test.NinOptNative, size)
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	for i := range msgs {
		msgs[i] = test.NewPopulatedNinOptNative(r, true)
		err := writer.WriteMsg(msgs[i])
		if err != nil {
			panic(err)
		}
	}
	if err := writer.Close(); err != nil {
		panic(err)
	}
	i := 0
	for {
		msg := &test.NinOptNative{}
		if err := reader.ReadMsg(msg); err != nil {
			if err == goio.EOF {
				break
			}
			panic(err)
		}
		if err := msg.VerboseEqual(msgs[i]); err != nil {
			panic(err)
		}
		i++
	}
	if i != size {
		panic("not enough messages read")
	}
	if err := reader.Close(); err != nil {
		panic(err)
	}
}
Ejemplo n.º 2
0
func TestFull(t *testing.T) {
	buf := bytes.NewBuffer(nil)
	writer := io.NewFullWriter(buf)
	reader := io.NewFullReader(buf, 1024*1024)
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	msgIn := test.NewPopulatedNinOptNative(r, true)
	if err := writer.WriteMsg(msgIn); err != nil {
		panic(err)
	}
	if err := writer.Close(); err != nil {
		panic(err)
	}
	msgOut := &test.NinOptNative{}
	if err := reader.ReadMsg(msgOut); err != nil {
		panic(err)
	}
	if err := msgIn.VerboseEqual(msgOut); err != nil {
		panic(err)
	}
	if err := reader.ReadMsg(msgOut); err != nil {
		if err != goio.EOF {
			panic(err)
		}
	}
	if err := reader.Close(); err != nil {
		panic(err)
	}
}