Add bencode FuzzInterfaceRoundTrip

This commit is contained in:
Matt Joiner 2021-12-10 13:35:57 +11:00
parent 4cfdc2f497
commit 42dca16753
4 changed files with 23 additions and 0 deletions

View File

@ -34,3 +34,20 @@ func Fuzz(f *testing.F) {
c.Assert(d0, bencodeInterfaceChecker, d) c.Assert(d0, bencodeInterfaceChecker, d)
}) })
} }
func FuzzInterfaceRoundTrip(f *testing.F) {
for _, ret := range random_encode_tests {
f.Add([]byte(ret.expected))
}
f.Fuzz(func(t *testing.T, b []byte) {
c := qt.New(t)
var d interface{}
err := Unmarshal(b, &d)
if err != nil {
c.Skip(err)
}
b0, err := Marshal(d)
c.Assert(err, qt.IsNil)
c.Check(b0, qt.DeepEquals, b)
})
}

View File

@ -0,0 +1,2 @@
go test fuzz v1
[]byte("00:")

View File

@ -0,0 +1,2 @@
go test fuzz v1
[]byte("d3:000e")

View File

@ -0,0 +1,2 @@
go test fuzz v1
[]byte("i00e")