-
Notifications
You must be signed in to change notification settings - Fork 4
/
sql_mock.go
155 lines (134 loc) · 4.6 KB
/
sql_mock.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import (
"fmt"
)
type successorsT struct {
es []entry
err error
}
type subsysnameT struct {
subsysN string
err error
}
type numT struct {
num int
err error
}
type entryT struct {
e entry
err error
}
type sqlMock struct {
GetExploredSubsystemByNameValues map[string]string
getSuccessorsByIdValues map[string]successorsT
getSubsysFromSymbolNameValues map[string]subsysnameT
sym2numValues map[string]numT
symbSubsysValues map[string]subsysnameT
getEntryByIdValues map[string]entryT
}
func (d *sqlMock) LOADGetExploredSubsystemByNameValues(subs, explored string) {
d.GetExploredSubsystemByNameValues[subs] = explored
}
func (d *sqlMock) LOADgetSuccessorsByIdValues(symbolId int, instance int, es []entry, err error) {
key := fmt.Sprintf("%04x%02x", symbolId, instance)
d.getSuccessorsByIdValues[key] = successorsT{es, err}
}
func (d *sqlMock) LOADgetSubsysFromSymbolNameValues(symbol string, instance int, subsysN string, err error) {
key := fmt.Sprintf("%s%02x", symbol, instance)
d.getSubsysFromSymbolNameValues[key] = subsysnameT{subsysN, err}
}
func (d *sqlMock) LOADsym2numValues(symb string, instance int, num int, err error) {
key := fmt.Sprintf("%s%02x", symb, instance)
d.sym2numValues[key] = numT{num, err}
}
func (d *sqlMock) LOADsymbSubsysValues(symblist []int, instance int, subsysN string, err error) {
key := fmt.Sprintf("%04x%02x", murmurHash3(symblist), instance)
d.symbSubsysValues[key] = subsysnameT{subsysN, err}
}
func (d *sqlMock) LOADgetEntryByIdValues(symbolId int, instance int, e entry, err error) {
key := fmt.Sprintf("%04x%02x", symbolId, instance)
d.getEntryByIdValues[key] = entryT{e, err}
}
func (d *sqlMock) init(arg interface{}) (err error) {
d.GetExploredSubsystemByNameValues = make(map[string]string, 100)
d.getSuccessorsByIdValues = make(map[string]successorsT, 100)
d.getSubsysFromSymbolNameValues = make(map[string]subsysnameT, 100)
d.sym2numValues = make(map[string]numT, 100)
d.symbSubsysValues = make(map[string]subsysnameT, 100)
d.getEntryByIdValues = make(map[string]entryT, 100)
return nil
}
func (d *sqlMock) GetExploredSubsystemByName(subs string) string {
debugIOPrintln("input subs=", subs)
app := d.GetExploredSubsystemByNameValues[subs]
debugIOPrintln("output =", subs)
return app
}
func (d *sqlMock) getSuccessorsById(symbolId int, instance int) ([]entry, error) {
debugIOPrintf("input symbolId=%d, instance=%d\n", symbolId, instance)
key := fmt.Sprintf("%04x%02x", symbolId, instance)
app1 := d.getSuccessorsByIdValues[key].es
app2 := d.getSuccessorsByIdValues[key].err
debugIOPrintf("output []entry=%+v, error=%s\n", app1, app2)
return app1, app2
}
func (d *sqlMock) getSubsysFromSymbolName(symbol string, instance int) (string, error) {
debugIOPrintf("input symbol=%s, instance=%d\n", symbol, instance)
key := fmt.Sprintf("%s%02x", symbol, instance)
app1 := d.getSubsysFromSymbolNameValues[key].subsysN
app2 := d.getSubsysFromSymbolNameValues[key].err
debugIOPrintf("output string=%s, error=%s\n", app1, app2)
return app1, app2
}
func (d *sqlMock) sym2num(symb string, instance int) (int, error) {
debugIOPrintf("input symbol=%s, instance=%d\n", symb, instance)
key := fmt.Sprintf("%s%02x", symb, instance)
app1 := d.sym2numValues[key].num
app2 := d.sym2numValues[key].err
debugIOPrintf("output int=%d, error=%s\n", app1, app2)
return app1, app2
}
func (d *sqlMock) symbSubsys(symblist []int, instance int) (string, error) {
debugIOPrintf("input symblist=%+v, instance=%d\n", symblist, instance)
key := fmt.Sprintf("%04x%02x", murmurHash3(symblist), instance)
app1 := d.symbSubsysValues[key].subsysN
app2 := d.symbSubsysValues[key].err
debugIOPrintf("output string=%s, error=%s\n", app1, app2)
return app1, app2
}
func (d *sqlMock) getEntryById(symbolId int, instance int) (entry, error) {
debugIOPrintf("input symbolId=%d, instance=%d\n", symbolId, instance)
key := fmt.Sprintf("%04x%02x", symbolId, instance)
app1 := d.getEntryByIdValues[key].e
app2 := d.getEntryByIdValues[key].err
debugIOPrintf("output entry=%+v, error=%s\n", app1, app2)
return app1, app2
}
func murmurHash3(arr []int) uint32 {
const (
seed = 0x9747b28c
c1 = 0xcc9e2d51
c2 = 0x1b873593
r1 = 15
r2 = 13
m = 5
n = 0xe6546b64
)
var hash uint32 = seed
for i, val := range arr {
k := uint32(val)
k *= c1
k = (k << r1) | (k >> (32 - r1))
k *= c2
hash ^= k
hash = (hash << r2) | (hash >> (32 - r2))
hash = (hash * m) + n + uint32(i*4)
}
hash ^= uint32(len(arr) * 4)
hash ^= hash >> 16
hash *= 0x85ebca6b
hash ^= hash >> 13
hash *= 0xc2b2ae35
hash ^= hash >> 16
return hash
}