tangled
alpha
login
or
join now
anil.recoil.org
/
unpac-unpac
0
fork
atom
The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork
atom
overview
issues
pulls
pipelines
Fix fuzzer about removed deprecated functions
dinosaure.tngl.sh
4 years ago
c97e3bde
0b12e27f
+21
-38
1 changed file
expand all
collapse all
unified
split
vendor
opam
cstruct
fuzz
fuzz.ml
+21
-38
vendor/opam/cstruct/fuzz/fuzz.ml
···
37
37
add_test ~name:"blit" [cstruct; int; cstruct; int; int] (fun src srcoff dst dstoff len ->
38
38
try Cstruct.blit src srcoff dst dstoff len
39
39
with Invalid_argument _ ->
40
40
-
check (srcoff < 0 || srcoff > Cstruct.len src ||
41
41
-
dstoff < 0 || dstoff > Cstruct.len src ||
40
40
+
check (srcoff < 0 || srcoff > Cstruct.length src ||
41
41
+
dstoff < 0 || dstoff > Cstruct.length src ||
42
42
len < 0 ||
43
43
-
len > Cstruct.len src - srcoff ||
44
44
-
len > Cstruct.len dst - dstoff)
43
43
+
len > Cstruct.length src - srcoff ||
44
44
+
len > Cstruct.length dst - dstoff)
45
45
);
46
46
add_test ~name:"sexp" [buffer] (fun b ->
47
47
b |> Cstruct_sexp.sexp_of_buffer |> Cstruct_sexp.buffer_of_sexp
···
51
51
);
52
52
add_test ~name:"of_bigarray" [buffer; option int; option int] (fun b off len ->
53
53
match Cstruct.of_bigarray b ?off ?len with
54
54
-
| c -> check (Cstruct.len c <= Bigarray.Array1.dim b)
54
54
+
| c -> check (Cstruct.length c <= Bigarray.Array1.dim b)
55
55
| exception Invalid_argument _ -> ()
56
56
);
57
57
add_test ~name:"get_char" [cstruct; int] (fun c off ->
58
58
-
let in_range = off >= 0 && off < Cstruct.len c in
58
58
+
let in_range = off >= 0 && off < Cstruct.length c in
59
59
match Cstruct.get_char c off with
60
60
| _ -> check in_range
61
61
| exception Invalid_argument _ -> check (not in_range)
62
62
);
63
63
add_test ~name:"set_char" [cstruct; int] (fun c off ->
64
64
-
let in_range = off >= 0 && off < Cstruct.len c in
64
64
+
let in_range = off >= 0 && off < Cstruct.length c in
65
65
match Cstruct.set_char c off 'x' with
66
66
| () -> check in_range
67
67
| exception Invalid_argument _ -> check (not in_range)
···
70
70
match Cstruct.sub base off len with
71
71
| sub ->
72
72
check_within ~base sub;
73
73
-
check (Cstruct.len sub = len)
73
73
+
check (Cstruct.length sub = len)
74
74
| exception Invalid_argument _ ->
75
75
-
check (off < 0 || len < 0 || off + len < 0 || off + len > Cstruct.len base)
75
75
+
check (off < 0 || len < 0 || off + len < 0 || off + len > Cstruct.length base)
76
76
);
77
77
add_test ~name:"shift" [cstruct; int] (fun base off ->
78
78
match Cstruct.shift base off with
79
79
| sub ->
80
80
check_within ~base sub;
81
81
-
check (Cstruct.len sub = max (Cstruct.len base - off) 0);
82
82
-
| exception Invalid_argument _ -> check (off < 0 || off > Cstruct.len base)
81
81
+
check (Cstruct.length sub = max (Cstruct.length base - off) 0);
82
82
+
| exception Invalid_argument _ -> check (off < 0 || off > Cstruct.length base)
83
83
);
84
84
add_test ~name:"shiftv" [list cstruct; int] (fun ts n ->
85
85
match Cstruct.shiftv ts n with
···
97
97
check (String.length x = len);
98
98
check (String.equal x (Cstruct.sub base off len |> Cstruct.to_string))
99
99
| exception Invalid_argument _ ->
100
100
-
check (off < 0 || len < 0 || off + len < 0 || off + len > Cstruct.len base)
100
100
+
check (off < 0 || len < 0 || off + len < 0 || off + len > Cstruct.length base)
101
101
);
102
102
add_test ~name:"blit_from_bytes" [bytes; int; cstruct; int; int] (fun src srcoff dst dstoff len ->
103
103
match Cstruct.blit_from_bytes src srcoff dst dstoff len with
···
108
108
dstoff < 0 || dstoff > Bytes.length src ||
109
109
len < 0 ||
110
110
len > Bytes.length src - srcoff ||
111
111
-
len > Cstruct.len dst - dstoff)
111
111
+
len > Cstruct.length dst - dstoff)
112
112
);
113
113
add_test ~name:"blit_to_bytes" [cstruct; int; bytes; int; int] (fun src srcoff dst dstoff len ->
114
114
match Cstruct.blit_to_bytes src srcoff dst dstoff len with
115
115
| () -> check (Cstruct.equal (Cstruct.sub src srcoff len)
116
116
(Cstruct.sub (Cstruct.of_bytes dst) dstoff len))
117
117
| exception Invalid_argument _ ->
118
118
-
check (srcoff < 0 || srcoff > Cstruct.len src ||
119
119
-
dstoff < 0 || dstoff > Cstruct.len src ||
118
118
+
check (srcoff < 0 || srcoff > Cstruct.length src ||
119
119
+
dstoff < 0 || dstoff > Cstruct.length src ||
120
120
len < 0 ||
121
121
-
len > Cstruct.len src - srcoff ||
121
121
+
len > Cstruct.length src - srcoff ||
122
122
len > Bytes.length dst - dstoff)
123
123
);
124
124
add_test ~name:"memset" [cstruct; int; int] (fun c x i ->
125
125
-
guard (i >= 0 && i < Cstruct.len c);
125
125
+
guard (i >= 0 && i < Cstruct.length c);
126
126
Cstruct.memset c x;
127
127
check (Cstruct.get_uint8 c i = x land 0xff)
128
128
);
129
129
-
add_test ~name:"set_len" [cstruct; int] (fun base len ->
130
130
-
match[@ocaml.warning "-3"] Cstruct.set_len base len with
131
131
-
| x ->
132
132
-
(* check_within ~base x; *) (* Maybe deprecate set_len extending the allocation? *)
133
133
-
check (Cstruct.len x >= 0);
134
134
-
check (Cstruct.len x <= Bigarray.Array1.dim (base.Cstruct.buffer));
135
135
-
check (Cstruct.len x = len)
136
136
-
| exception Invalid_argument _ -> ()
137
137
-
);
138
138
-
add_test ~name:"add_len" [cstruct; int] (fun base len ->
139
139
-
match[@ocaml.warning "-3"] Cstruct.add_len base len with
140
140
-
| x ->
141
141
-
check (Cstruct.len x >= 0);
142
142
-
check (Cstruct.len x <= Bigarray.Array1.dim (base.Cstruct.buffer));
143
143
-
check (Cstruct.len x = Cstruct.len base + len)
144
144
-
| exception Invalid_argument _ -> ()
145
145
-
);
146
129
add_test ~name:"split" [cstruct; option int; int] (fun base start len ->
147
130
match Cstruct.split ?start base len with
148
131
| c1, c2 ->
···
154
137
| exception Invalid_argument _ -> ()
155
138
);
156
139
add_test ~name:"BE.set_uint64" [cstruct; int] (fun c off ->
157
157
-
let in_range = off >= 0 && off < Cstruct.len c - 7 in
140
140
+
let in_range = off >= 0 && off < Cstruct.length c - 7 in
158
141
match Cstruct.BE.set_uint64 c off 42L with
159
142
| () -> check in_range
160
143
| exception Invalid_argument _ -> check (not in_range)
···
173
156
);
174
157
add_test ~name:"concat" [list cstruct] (fun cs ->
175
158
let x = Cstruct.concat cs in
176
176
-
check (Cstruct.len x = Cstruct.lenv cs)
159
159
+
check (Cstruct.length x = Cstruct.lenv cs)
177
160
);
178
161
add_test ~name:"span" [ cstruct; list char ] (fun cs p ->
179
162
let sat chr = List.exists ((=) chr) p in
···
181
164
let r = Cstruct.concat [ a; b ] in
182
165
check (Cstruct.to_string r = Cstruct.to_string cs));
183
166
add_test ~name:"cut" [ cstruct; cstruct; ] (fun buf sep ->
184
184
-
guard (Cstruct.len sep > 0);
167
167
+
guard (Cstruct.length sep > 0);
185
168
( match Cstruct.cut ~sep buf with
186
169
| Some (l, r) ->
187
170
let r = Cstruct.concat [ l; sep; r; ] in
188
171
check (Cstruct.to_string r = Cstruct.to_string buf)
189
172
| None -> () ));
190
173
add_test ~name:"cuts" [ cstruct; cstruct; ] (fun buf sep ->
191
191
-
guard (Cstruct.len sep > 0);
174
174
+
guard (Cstruct.length sep > 0);
192
175
let lst = Cstruct.cuts ~sep buf in
193
176
let lst = List.map Cstruct.to_string lst in
194
177
let res = String.concat (Cstruct.to_string sep) lst in