Commit 03956178 authored by Jakub Sztandera's avatar Jakub Sztandera

test: add reverse relative seeking test to dagreader

License: MIT
Signed-off-by: default avatarJakub Sztandera <kubuxu@protonmail.ch>
parent 0cb0052a
......@@ -77,6 +77,8 @@ func TestRelativeSeek(t *testing.T) {
for i := 0; i < 256; i++ {
inbuf[i*4] = byte(i)
}
inbuf[1023] = 1 // force the reader to be 1024 bytes
node := testu.GetNode(t, dserv, inbuf)
reader, err := NewDagReader(ctx, node, dserv)
......@@ -85,11 +87,35 @@ func TestRelativeSeek(t *testing.T) {
}
for i := 0; i < 256; i++ {
if reader.Offset() != int64(i*4) {
t.Fatalf("offset should be %d, was %d", i*4, reader.Offset())
}
out := readByte(t, reader)
if int(out) != i {
t.Fatalf("expected to read: %d at %d, read %d", i, reader.Offset(), out)
t.Fatalf("expected to read: %d at %d, read %d", i, reader.Offset()-1, out)
}
if i != 255 {
_, err := reader.Seek(3, os.SEEK_CUR)
if err != nil {
t.Fatal(err)
}
}
}
_, err = reader.Seek(4, os.SEEK_END)
if err != nil {
t.Fatal(err)
}
for i := 0; i < 256; i++ {
if reader.Offset() != int64(1020-i*4) {
t.Fatalf("offset should be %d, was %d", 1020-i*4, reader.Offset())
}
out := readByte(t, reader)
if int(out) != 255-i {
t.Fatalf("expected to read: %d at %d, read %d", 255-i, reader.Offset()-1, out)
}
reader.Seek(3, os.SEEK_CUR)
reader.Seek(-5, os.SEEK_CUR) // seek 4 bytes but we read one byte every time so 5 bytes
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment