generated from dnnrly/goclitem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzz_test.go
87 lines (74 loc) · 1.86 KB
/
fuzz_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//go:build fuzz
package layli
import (
"os"
"strings"
"testing"
"github.com/antchfx/xmlquery"
"github.com/dnnrly/layli/pathfinder/dijkstra"
)
func FuzzConfig(f *testing.F) {
dir, _ := os.ReadDir("./examples")
for _, d := range dir {
if !d.IsDir() && strings.HasSuffix(d.Name(), ".layli") {
config, err := os.ReadFile("./examples/" + d.Name())
if err != nil {
panic(err)
}
f.Add(string(config)) // Use f.Add to provide a seed corpus
}
}
f.Fuzz(func(t *testing.T, orig string) {
_, _ = NewConfigFromFile(strings.NewReader(orig))
})
}
func FuzzDrawing(f *testing.F) {
dir, _ := os.ReadDir("./examples")
for _, d := range dir {
if !d.IsDir() && strings.HasSuffix(d.Name(), ".layli") {
config, err := os.ReadFile("./examples/" + d.Name())
if err != nil {
panic(err)
}
f.Add(string(config)) // Use f.Add to provide a seed corpus
}
}
f.Fuzz(func(t *testing.T, orig string) {
config, err := NewConfigFromFile(strings.NewReader(orig))
if err != nil || config.Layout == "tarjan" {
t.Skip()
}
layout, err := NewLayoutFromConfig(func(start, end dijkstra.Point) PathFinder {
return dijkstra.NewPathFinder(start, end)
}, config)
if err != nil {
t.Skip()
}
d := Diagram{
Output: func(data string) error { return nil },
ShowGrid: false,
Config: *config,
Layout: layout,
}
_ = d.Draw()
})
}
func FuzzToAbsolute(f *testing.F) {
dir, _ := os.ReadDir("./examples")
for _, d := range dir {
if !d.IsDir() && strings.HasSuffix(d.Name(), ".svg") {
config, err := os.ReadFile("./examples/" + d.Name())
if err != nil {
panic(err)
}
f.Add(string(config)) // Use f.Add to provide a seed corpus
}
}
f.Fuzz(func(t *testing.T, orig string) {
_, err := xmlquery.Parse(strings.NewReader(orig))
if err != nil {
t.Skip()
}
_ = AbsoluteFromSVG(orig, func(string) error { return nil })
})
}