Stop using allocation trick in fastpath functions (OCaml 4.02).
[ocaml-bitstring.git] / tests / test_65_save_offset_to.ml
1 (* Test save_offset_to.
2  * $Id$
3  *)
4
5 open Printf
6 open Bitstring
7
8 let make_bits p i n j m k = (
9   let pad0 = ones_bitstring p in
10   let pad1 = ones_bitstring (n-8) in
11   let pad2 = ones_bitstring (m-n-8) in
12   BITSTRING {
13     pad0 : p : bitstring;            (* will be skipped below *)
14     i : 8;
15     pad1 : n-8 : bitstring;
16     j : 8;                           (* this should be at offset(n) *)
17     pad2 : m-n-8 : bitstring;
18     k : 8                            (* this should be at offset(m) *)
19   }
20 )
21
22 let test_bits bits p i n j m k =
23   (* Skip the 'p' padding bits so the match starts at a non-zero offset. *)
24   let bits = dropbits p bits in
25
26   bitmatch bits with
27   | { i' : 8;
28       _ : n-8 : bitstring;
29       j' : 8 : save_offset_to (j_offset);
30       _ : m-n-8 : bitstring;
31       k' : 8 : save_offset_to (k_offset) }
32       when i = i' && j = j' && k = k' && j_offset = n && k_offset = m ->
33       () (* ok *)
34   | { _ } ->
35       failwith (sprintf
36                   "65_save_offset_to: test_bits: failed %d %d %d %d %d %d"
37                   p i n j m k)
38
39 let () =
40   for p = 0 to 4 do
41     for n = 8 to 64 do
42       for m = n+8 to 128 do
43         List.iter (fun (i,j,k) -> test_bits (make_bits p i n j m k) p i n j m k)
44           [0x55, 0xaa, 0x33; 0x33, 0xaa, 0x55; 0x12, 0x34, 0x56]
45       done;
46     done;
47   done