本文整理匯總了Golang中github.com/dvyukov/go-fuzz/examples/fuzz.DeepEqual函數的典型用法代碼示例。如果您正苦於以下問題:Golang DeepEqual函數的具體用法?Golang DeepEqual怎麽用?Golang DeepEqual使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DeepEqual函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Fuzz
func Fuzz(data []byte) int {
sdata := string(data)
mt, params, err := mime.ParseMediaType(sdata)
if err != nil {
return 0
}
sdata1 := mime.FormatMediaType(mt, params)
mt1, params1, err := mime.ParseMediaType(sdata1)
if err != nil {
if err.Error() == "mime: no media type" {
// https://github.com/golang/go/issues/11289
return 0
}
if err.Error() == "mime: invalid media parameter" {
// https://github.com/golang/go/issues/11290
return 0
}
fmt.Printf("%q(%q, %+v) -> %q\n", sdata, mt, params, sdata1)
panic(err)
}
if !fuzz.DeepEqual(mt, mt1) {
fmt.Printf("%q -> %q\n", mt, mt1)
panic("mediatype changed")
}
if !fuzz.DeepEqual(params, params1) {
fmt.Printf("%+v -> %+v\n", params, params1)
panic("params changed")
}
return 1
}
示例2: FuzzPKCS
func FuzzPKCS(data []byte) int {
score := 0
if k, err := x509.ParsePKCS1PrivateKey(data); err == nil {
score = 1
data1 := x509.MarshalPKCS1PrivateKey(k)
k1, err := x509.ParsePKCS1PrivateKey(data1)
if err != nil {
panic(err)
}
if !fuzz.DeepEqual(k, k1) {
panic("keys are not equal")
}
}
if k0, err := x509.ParsePKCS8PrivateKey(data); err == nil {
score = 1
if k, ok := k0.(*rsa.PrivateKey); ok {
data1 := x509.MarshalPKCS1PrivateKey(k)
k1, err := x509.ParsePKCS1PrivateKey(data1)
if err != nil {
panic(err)
}
if !fuzz.DeepEqual(k, k1) {
panic("keys are not equal")
}
}
}
return score
}
示例3: FuzzAll
func FuzzAll(data []byte) int {
cfg, err := gif.DecodeConfig(bytes.NewReader(data))
if err != nil {
return 0
}
if cfg.Width*cfg.Height > 1e6 {
return 0
}
img, err := gif.DecodeAll(bytes.NewReader(data))
if err != nil {
return 0
}
w := new(bytes.Buffer)
err = gif.EncodeAll(w, img)
if err != nil {
panic(err)
}
img1, err := gif.DecodeAll(w)
if err != nil {
panic(err)
}
if img.LoopCount == 0 && img1.LoopCount == -1 {
// https://github.com/golang/go/issues/11287
img1.LoopCount = 0
}
// https://github.com/golang/go/issues/11288
img1.Disposal = img.Disposal
if !fuzz.DeepEqual(img, img1) {
fmt.Printf("gif0: %#v\n", img)
fmt.Printf("gif1: %#v\n", img1)
panic("gif changed")
}
return 1
}
示例4: Fuzz
func Fuzz(data []byte) int {
ctors := []func() interface{}{
func() interface{} { return new(int) },
func() interface{} { return new(int32) },
func() interface{} { return new(int64) },
func() interface{} { return new(*big.Int) },
func() interface{} { return new(asn1.BitString) },
func() interface{} { return new([]byte) },
func() interface{} { return new(asn1.ObjectIdentifier) },
func() interface{} { return new(asn1.Enumerated) },
func() interface{} { return new(interface{}) },
func() interface{} { return new(string) },
func() interface{} { return new(time.Time) },
func() interface{} { return new([]interface{}) },
func() interface{} { return new(X) },
}
score := 0
for _, ctor := range ctors {
v := ctor()
_, err := asn1.Unmarshal(data, v)
if err != nil {
continue
}
score = 1
x := reflect.ValueOf(v).Elem().Interface()
if x == nil {
continue // https://github.com/golang/go/issues/11127
}
data1, err := asn1.Marshal(x)
if err != nil {
panic(err)
}
v1 := ctor()
rest, err := asn1.Unmarshal(data1, v1)
if err != nil {
panic(err)
}
if len(rest) != 0 {
fmt.Printf("data: %q\n", rest)
panic("leftover data")
}
if !fuzz.DeepEqual(v, v1) {
fmt.Printf("v0: %#v\n", reflect.ValueOf(v).Elem().Interface())
fmt.Printf("v1: %#v\n", reflect.ValueOf(v1).Elem().Interface())
panic(fmt.Sprintf("not equal %T", x))
}
}
return score
}
示例5: Fuzz
func Fuzz(data []byte) int {
score := 0
for _, ctor := range []func() interface{}{
func() interface{} { return nil },
func() interface{} { return new(string) },
func() interface{} { return new([]string) },
func() interface{} { return new(X) },
func() interface{} { return new([]X) },
} {
v0 := ctor()
valid := false
dec := xml.NewDecoder(bytes.NewReader(data))
if dec.Decode(v0) == nil {
valid = true
}
v := ctor()
dec1 := xml.NewDecoder(bytes.NewReader(data))
dec1.Strict = false
dec1.AutoClose = xml.HTMLAutoClose
dec1.Entity = xml.HTMLEntity
if dec1.Decode(v) != nil {
if valid {
panic("non-strict mode is weaker than strict")
}
continue
}
score = 1
data1, err := xml.Marshal(v)
if err != nil {
panic(err)
}
v1 := ctor()
dec2 := xml.NewDecoder(bytes.NewReader(data1))
dec2.Strict = false
dec2.AutoClose = xml.HTMLAutoClose
dec2.Entity = xml.HTMLEntity
if err := dec2.Decode(v1); err != nil {
panic(err)
}
if !fuzz.DeepEqual(v, v1) {
fmt.Printf("v0: %#v\n", reflect.ValueOf(v).Elem().Interface())
fmt.Printf("v1: %#v\n", reflect.ValueOf(v1).Elem().Interface())
panic(fmt.Sprintf("not equal %T", v))
}
}
return score
}
示例6: FuzzEC
func FuzzEC(data []byte) int {
k, err := x509.ParseECPrivateKey(data)
if err != nil {
return 0
}
data1, err := x509.MarshalECPrivateKey(k)
if err != nil {
panic(err)
}
k1, err := x509.ParseECPrivateKey(data1)
if err != nil {
panic(err)
}
if !fuzz.DeepEqual(k, k1) {
panic("keys are not equal")
}
return 1
}
示例7: Fuzz
func Fuzz(data []byte) int {
score := 0
for _, ctor := range []func() interface{}{
func() interface{} { return nil },
func() interface{} { return new([]interface{}) },
func() interface{} { m := map[string]string{}; return &m },
func() interface{} { m := map[string]interface{}{}; return &m },
func() interface{} { return new(S) },
} {
v := ctor()
if json.Unmarshal(data, v) != nil {
continue
}
score = 1
if s, ok := v.(*S); ok {
if len(s.P) == 0 {
s.P = []byte(`""`)
}
}
data1, err := json.Marshal(v)
if err != nil {
panic(err)
}
v1 := ctor()
if json.Unmarshal(data1, v1) != nil {
continue
}
if s, ok := v.(*S); ok {
// Some additional escaping happens with P.
s.P = nil
v1.(*S).P = nil
}
if !fuzz.DeepEqual(v, v1) {
fmt.Printf("v0: %#v\n", v)
fmt.Printf("v1: %#v\n", v1)
panic("not equal")
}
}
return score
}
示例8: FuzzPKIX
func FuzzPKIX(data []byte) int {
key, err := x509.ParsePKIXPublicKey(data)
if err != nil {
return 0
}
if _, ok := key.(*dsa.PublicKey); ok {
// Marshalling of DSA keys is not implemented.
return 1
}
data1, err := x509.MarshalPKIXPublicKey(key)
if err != nil {
panic(err)
}
key1, err := x509.ParsePKIXPublicKey(data1)
if err != nil {
panic(err)
}
if !fuzz.DeepEqual(key, key1) {
panic("keys are not equal")
}
return 1
}
示例9: Fuzz
func Fuzz(data []byte) int {
score := 0
for _, ctor := range []func() interface{}{
func() interface{} { return make(bson.M) },
func() interface{} { return new(bson.D) },
func() interface{} { return new(S) },
func() interface{} { return new(O) },
} {
v := ctor()
if bson.Unmarshal(data, v) != nil {
continue
}
score = 1
data1, err := bson.Marshal(v)
if err != nil {
if strings.HasPrefix(err.Error(), "ObjectIDs must be exactly 12 bytes long") {
continue
}
panic(err)
}
v1 := ctor()
if err := bson.Unmarshal(data1, v1); err != nil {
// https://github.com/go-mgo/mgo/issues/117
if err.Error() == "Document is corrupted" {
continue
}
panic(err)
}
if !fuzz.DeepEqual(v, v1) {
fmt.Printf("v0: %#v\n", v)
fmt.Printf("v1: %#v\n", v1)
panic("non-idempotent unmarshalling")
}
}
return score
}
示例10: Fuzz
func Fuzz(data []byte) int {
stmt, err := sqlparser.Parse(string(data))
if err != nil {
if stmt != nil {
panic("stmt is not nil on error")
}
return 0
}
if true {
data1 := sqlparser.String(stmt)
stmt1, err := sqlparser.Parse(data1)
if err != nil {
fmt.Printf("data0: %q\n", data)
fmt.Printf("data1: %q\n", data1)
panic(err)
}
if !fuzz.DeepEqual(stmt, stmt1) {
fmt.Printf("data0: %q\n", data)
fmt.Printf("data1: %q\n", data1)
panic("not equal")
}
} else {
sqlparser.String(stmt)
}
if sel, ok := stmt.(*sqlparser.Select); ok {
var nodes []sqlparser.SQLNode
for _, x := range sel.From {
nodes = append(nodes, x)
}
for _, x := range sel.From {
nodes = append(nodes, x)
}
for _, x := range sel.SelectExprs {
nodes = append(nodes, x)
}
for _, x := range sel.GroupBy {
nodes = append(nodes, x)
}
for _, x := range sel.OrderBy {
nodes = append(nodes, x)
}
nodes = append(nodes, sel.Where)
nodes = append(nodes, sel.Having)
nodes = append(nodes, sel.Limit)
for _, n := range nodes {
if n == nil {
continue
}
if x, ok := n.(sqlparser.SimpleTableExpr); ok {
sqlparser.GetTableName(x)
}
if x, ok := n.(sqlparser.Expr); ok {
sqlparser.GetColName(x)
}
if x, ok := n.(sqlparser.ValExpr); ok {
sqlparser.IsValue(x)
}
if x, ok := n.(sqlparser.ValExpr); ok {
sqlparser.IsColName(x)
}
if x, ok := n.(sqlparser.ValExpr); ok {
sqlparser.IsSimpleTuple(x)
}
if x, ok := n.(sqlparser.ValExpr); ok {
sqlparser.AsInterface(x)
}
if x, ok := n.(sqlparser.BoolExpr); ok {
sqlparser.HasINClause([]sqlparser.BoolExpr{x})
}
}
}
buf := sqlparser.NewTrackedBuffer(nil)
stmt.Format(buf)
pq := buf.ParsedQuery()
vars := map[string]interface{}{
"A": 42,
"B": 123123123,
"C": "",
"D": "a",
"E": "foobar",
"F": 1.1,
}
pq.GenerateQuery(vars)
return 1
}
示例11: Fuzz
//.........這裏部分代碼省略.........
}
// https://github.com/golang/go/issues/11208
r0.Host = strings.Replace(r0.Host, "%", "a", -1)
r0.URL.Opaque = strings.Replace(r0.URL.Opaque, "%", "a", -1)
r0.Trailer = nil
r0.ProtoMajor = 1
r0.ProtoMinor = 1
r0.Header.Del("Trailer")
r0.Header.Del("Connection")
for k, v := range r0.Header {
for i := range v {
// https://github.com/golang/go/issues/11204
v[i] = strings.Trim(v[i], " \t\r\n")
// https://github.com/golang/go/issues/11207
v[i] = strings.Replace(v[i], "\r", " ", -1)
}
r0.Header[k] = v
}
}
fix(r0)
buf := new(bytes.Buffer)
if err := r0.WriteProxy(buf); err != nil {
panic(err)
}
data1 := buf.Bytes()
r1, err := http.ReadRequest(bufio.NewReader(buf))
if err != nil {
// https://github.com/golang/go/issues/11202
// https://github.com/golang/go/issues/11203
if strings.Contains(err.Error(), "invalid URI for request") {
return 0
}
if strings.Contains(err.Error(), "missing protocol scheme") {
return 0
}
// https://github.com/golang/go/issues/11206
if strings.Contains(err.Error(), "malformed HTTP version") {
return 0
}
fmt.Printf("req0: %q\nURL: %#v\n", data, *r0.URL)
fmt.Printf("req1: %q\n", data1)
panic(err)
}
// Read it in again, because we consumed body.
r0, err = http.ReadRequest(bufio.NewReader(bytes.NewReader(data)))
if err != nil {
panic(err)
}
fix(r0)
r0.RequestURI = r1.RequestURI
r0.Proto = r1.Proto
if r1.Header.Get("Connection") != "" {
r0.Header.Set("Connection", r1.Header.Get("Connection"))
} else {
r0.Header.Del("Connection")
r1.Header.Del("Connection")
}
if r1.Header.Get("Content-Length") != "" {
r0.Header.Set("Content-Length", r1.Header.Get("Content-Length"))
} else {
r0.Header.Del("Content-Length")
r1.Header.Del("Content-Length")
}
if r0.URL.Path == "" && r1.URL.Path == "/" {
r0.URL.Path = r1.URL.Path
}
// Rules for host are too complex.
r0.Host = ""
r1.Host = ""
r0.URL.Host = ""
r1.URL.Host = ""
if (r0.URL.Scheme != "" && r0.URL.Opaque != "") || r0.Method == "CONNECT" {
r0.URL = nil
r1.URL = nil
}
body0, err := ioutil.ReadAll(r0.Body)
if err != nil {
panic(err)
}
body1, err := ioutil.ReadAll(r1.Body)
if err != nil {
panic(err)
}
if !bytes.Equal(body0, body1) {
fmt.Printf("body0: %q\n", body0)
fmt.Printf("body1: %q\n", body1)
panic("body changed")
}
r0.Body = nil
r1.Body = nil
if !fuzz.DeepEqual(r0, r1) {
fmt.Printf("req0: %#v\n", *r0)
fmt.Printf("req1: %#v\n", *r1)
fmt.Printf("url0: %#v\n", *r0.URL)
fmt.Printf("url1: %#v\n", *r1.URL)
panic("not equal")
}
return 1
}