bencode: Fuzz

This commit is contained in:
Matt Joiner 2015-08-23 15:59:49 +10:00
parent 4472a0e27a
commit 4fbbc0dd41
1 changed files with 29 additions and 0 deletions

29
bencode/fuzz.go Normal file
View File

@ -0,0 +1,29 @@
// +build gofuzz
package bencode
import (
"fmt"
"reflect"
)
func Fuzz(b []byte) int {
var d interface{}
err := Unmarshal(b, &d)
if err != nil {
return 0
}
b0, err := Marshal(d)
if err != nil {
panic(err)
}
var d0 interface{}
err = Unmarshal(b0, &d0)
if err != nil {
panic(err)
}
if !reflect.DeepEqual(d, d0) {
panic(fmt.Sprintf("%s != %s", d, d0))
}
return 1
}