Example #1
0
func TestFull(t *testing.T) {
	buf := newBuffer()
	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)
	}
	if !buf.closed {
		t.Fatalf("did not close buffer")
	}
}
Example #2
0
func iotest(writer io.WriteCloser, reader io.ReadCloser) error {
	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)
		//issue 31
		if i == 5 {
			msgs[i] = &test.NinOptNative{}
		}
		//issue 31
		if i == 999 {
			msgs[i] = &test.NinOptNative{}
		}
		err := writer.WriteMsg(msgs[i])
		if err != nil {
			return err
		}
	}
	if err := writer.Close(); err != nil {
		return err
	}
	i := 0
	for {
		msg := &test.NinOptNative{}
		if err := reader.ReadMsg(msg); err != nil {
			if err == goio.EOF {
				break
			}
			return err
		}
		if err := msg.VerboseEqual(msgs[i]); err != nil {
			return err
		}
		i++
	}
	if i != size {
		panic("not enough messages read")
	}
	if err := reader.Close(); err != nil {
		return err
	}
	return nil
}