File: 60_simple_offset.ml

package info (click to toggle)
ocaml-bitstring 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,276 kB
  • ctags: 492
  • sloc: ml: 3,360; sh: 377; makefile: 324; ansic: 113
file content (35 lines) | stat: -rw-r--r-- 901 bytes parent folder | download | duplicates (2)
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
(* Simple offset test
 * $Id: 60_simple_offset.ml 142 2008-07-17 15:45:56Z richard.wm.jones $
 *)

open Printf
open Bitstring

let make_bits i n j m k = (
  let pad1 = ones_bitstring (n-8) in
  let pad2 = ones_bitstring (m-n-8) in
  BITSTRING {
    i : 8;
    pad1 : n-8 : bitstring;
    j : 8;			     (* this should be at offset(n) *)
    pad2 : m-n-8 : bitstring;
    k : 8			     (* this should be at offset(m) *)
  }
)

let test_bits bits i n j m k =
  bitmatch bits with
  | { i' : 8;
      j' : 8 : offset(n);
      k' : 8 : offset(m) } when i = i' && j = j' && k = k' -> () (* ok *)
  | { _ } ->
      failwith (sprintf "60_simple_offset: test_bits: failed %d %d %d %d %d"
		  i n j m k)

let () =
  for n = 8 to 128 do
    for m = n+8 to 256 do
      List.iter (fun (i,j,k) -> test_bits (make_bits i n j m k) i n j m k)
	[0x55, 0xaa, 0x33; 0x33, 0xaa, 0x55; 0x12, 0x34, 0x56]
    done;
  done