...
1
16
17 package fuzzer
18
19 import "testing"
20
21 func TestValueFuzz(t *testing.T) {
22 type (
23 Y struct {
24 I int
25 B bool
26 F float32
27 U uint
28 }
29 X struct {
30 Ptr *X
31 Y Y
32 Map map[string]int
33 Slice []int
34 }
35 )
36
37 x := X{
38 Ptr: &X{},
39 Map: map[string]int{"foo": 42},
40 Slice: []int{1, 2, 3},
41 }
42
43 p := x.Ptr
44 m := x.Map
45 s := x.Slice
46
47 ValueFuzz(x)
48
49 if x.Ptr.Y.I == 0 {
50 t.Errorf("x.Ptr.Y.I should have changed")
51 }
52
53 if x.Map["foo"] == 42 {
54 t.Errorf("x.Map[foo] should have changed")
55 }
56
57 if x.Slice[0] == 1 {
58 t.Errorf("x.Slice[0] should have changed")
59 }
60
61 if x.Ptr != p {
62 t.Errorf("x.Ptr changed")
63 }
64
65 m["foo"] = 7
66 if x.Map["foo"] != m["foo"] {
67 t.Errorf("x.Map changed")
68 }
69 s[0] = 7
70 if x.Slice[0] != s[0] {
71 t.Errorf("x.Slice changed")
72 }
73 }
74
View as plain text