From: Richard W.M. Jones Date: Mon, 16 Jun 2008 20:33:39 +0000 (+0000) Subject: Test for offsets X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=c3f6b2dd0087886cdbd97b0abe3aa5ec55c67d0a;p=ocaml-bitstring.git Test for offsets --- diff --git a/tests/60_simple_offset.ml b/tests/60_simple_offset.ml new file mode 100644 index 0000000..556fd86 --- /dev/null +++ b/tests/60_simple_offset.ml @@ -0,0 +1,35 @@ +(* Simple offset test + * $Id: 50_named_pattern.ml 86 2008-06-13 15:56:04Z richard.wm.jones $ + *) + +open Printf +open Bitmatch + +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