Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

76 lines (67 sloc) 2.202 kB
open Rsync
open Signature
open Hash
module S = SDigest
module AA = Rsync(Adler)(S)
module MySig = Signature(Adler)(S)
let old_dir = "tests/old/"
let new_dir = "tests/new/"
let sync_dir = "tests/synced/"
let test_io () =
let values = [128;127;4;1;0;] in
let do_one v =
let fn = "/tmp/test_io.bin" in
let oc = open_out fn in
let () = Io.write_int oc v in
let () = close_out oc in
let ic = open_in fn in
let v2 = Io.read_int ic in
let () = close_in ic in
Printf.printf "%i <> %i\n" v v2;
assert (v = v2)
in
List.iter do_one values
let test_signature fn bs =
Printf.printf "SIGNATURE:%s\n" fn;
let old_fn = old_dir ^ fn in
let signature = MySig.create old_fn bs in
let signature_fn = sync_dir ^ fn ^ ".signature" in
let () = MySig.to_file signature signature_fn in
let signature2 = MySig.from_file signature_fn in
Printf.printf "%s: %b \n%!" fn (MySig.equals signature2 signature)
let test_one fn bs =
let old_fn = old_dir ^ fn in
let signature = MySig.create old_fn bs in
let signature_fn = sync_dir ^ fn ^ ".signature" in
let delta_fn = sync_dir ^ fn ^ ".delta" in
let () = MySig.to_file signature signature_fn in
let oc = open_out delta_fn in
let handle_action action = output_action oc action in
let new_fn = new_dir ^ fn in
let signature2 = MySig.from_file signature_fn in
(* let signature2 = signature in *)
assert (signature2 = signature);
let emitter = new AA.delta_emitter signature2 new_fn handle_action in
let () = emitter # run () in
let () = close_out oc in
let ic = open_in delta_fn in
let sync_fn = sync_dir ^ fn in
let sync_oc = open_out sync_fn in
let applier = new AA.delta_applier ic old_fn sync_oc in
applier # run () ;
close_out sync_oc;
let d_new = S.to_hex(S.file new_fn) in
let d_synced = S.to_hex(S.file sync_fn) in
Printf.printf "%s: %s =?= %s\n%!" fn d_new d_synced;
()
let test_correctness () =
let tests = ["small.txt", 16;
"fischer.txt",16;
"big.bmp", 256;
]
in
List.iter (fun (fn,bs) -> test_signature fn bs) tests;
List.iter (fun (fn,bs) -> test_one fn bs) tests ;;
let suite () =
test_io ();
test_correctness();;
Jump to Line
Something went wrong with that request. Please try again.